📄 statbycontact.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using MisSale.Components;
using SQLHelper;
namespace MisSale.DesktopModules.Statistics
{
/// <summary>
/// StatByContact 的摘要说明。
/// </summary>
public class StatByContact : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ContactList;
protected System.Web.UI.WebControls.DataGrid ProductList;
protected System.Web.UI.WebControls.Button ReturnBtn;
private void Page_Load(object sender, System.EventArgs e)
{
///判断用户是否登陆
if(Session["UserID"] == null)
{
Response.Redirect("~/Default.aspx");
}
///判断用户是否是超级管理员
if(Components.User.IsAuthorityAdmin(Session["UserID"].ToString()) >= Components.User.USERTYPENORMAL)
{
Response.Write("<script>alert(\"你没有权限,请与管理员联系!\")</script>");
Response.Write("<script>history.back();</script>");
}
if(!Page.IsPostBack)
{
///显示商品信息
BindContactData();
if(ContactList.Items.Count > 0)
{
///显示商品的销售信息
BindProductData(Int32.Parse(ContactList.SelectedValue));
}
}
}
private void BindContactData()
{
///定义获取数据的类
MisSale.Components.Contact contact = new MisSale.Components.Contact();
SqlDataReader recc = contact.GetContacts();
///设定控件的数据源
ContactList.DataSource = recc;
///设定控件的Text属性和Value属性
ContactList.DataTextField = "Name";
ContactList.DataValueField = "ContactID";
///绑定控件的数据
ContactList.DataBind();
///关闭数据读取器和数据库的连接
recc.Close();
}
private void BindProductData(int nContactID)
{
///定义获取数据的类
MisSale.Components.Product product = new MisSale.Components.Product();
SqlDataReader recp = product.GetProductByContact(nContactID);
///创建DataSet数据源
DataTable dataTable = SystemTools.ConvertDataReaderToDataTable(recp);
DataSet dataSet = new DataSet("Product");
dataSet.Tables.Add(dataTable);
///设定控件的数据源
ProductList.DataSource = dataSet;
///绑定控件的数据
ProductList.DataBind();
}
public string FormatString(string oldString)
{
return(oldString.Length > 50 ? oldString.Substring(0,50) + "..." : oldString);
}
public string FormatDate(string dateString)
{
return(Convert.ToDateTime(dateString).ToShortDateString());
}
private void ContactList_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(ContactList.SelectedIndex > -1)
{
///显示商品的销售信息
BindProductData(Int32.Parse(ContactList.SelectedValue));
}
else
{
///清空销售列表的旧数据
ProductList.DataSource = null;
ProductList.DataBind();
}
}
private void ReturnBtn_Click(object sender, System.EventArgs e)
{
///跳转到管理页面
Response.Redirect("~/DesktopModules/SaleOrder/SaleOrderManage.aspx");
}
private void ProductList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
if(ContactList.SelectedIndex > -1)
{
///设置新的页码,并重新绑定数据
ProductList.CurrentPageIndex = e.NewPageIndex;
BindProductData(Int32.Parse(ContactList.SelectedValue));
}
else
{
///清空销售列表的旧数据
ProductList.DataSource = null;
ProductList.DataBind();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ContactList.SelectedIndexChanged += new System.EventHandler(this.ContactList_SelectedIndexChanged);
this.ProductList.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.ProductList_PageIndexChanged);
this.ReturnBtn.Click += new System.EventHandler(this.ReturnBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -