ASP.NET编写的眼镜行分销系统的程序.
源代码在线查看: customeradmin.aspx.cs
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace NewGlassBook
{
public class CustomerAdmin :MyPage
{
protected SuperDataGrid dgShow;
protected System.Web.UI.WebControls.LinkButton DeleteLink;
protected System.Web.UI.WebControls.Label lblWarning;
protected NewGlassBook.MyButton dbtn_search;
protected System.Web.UI.WebControls.DropDownList condition;
protected System.Web.UI.WebControls.TextBox conditionValue;
string strSql;
Record r=new Record();//访问数据库用
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
//取得所有客户信息
strSql="select * from Customer where id'00000000' order by id";
Session["strSql"]=strSql;
dgShowOpen();
}
}
//打开客户信息编辑页
protected string OpenWin(object obj)
{
if (!Convert.IsDBNull(obj))
{
return "window.open(\"customeredit.aspx?id=" + obj.ToString() + "\", \"\",\"width=300,height=410,top=100,left=290\");return false;";
}
return "";
}
//打开客户信息浏览页
protected string OpenWinB(object obj)
{
if (!Convert.IsDBNull(obj))
{
return "window.open(\"customerbrows.aspx?id=" + obj.ToString() + "\", \"\",\"width=300,height=410,top=100,left=290\");return false;";
}
return "";
}
public void dgShow_Change(Object sender, DataGridPageChangedEventArgs e)
{
dgShow.CurrentPageIndex = e.NewPageIndex;//更改datagrid的pageindex
dgShowOpen();
}
private void dgShowOpen()
{
DataSet ds=r.GetData("customer",Session["strSql"].ToString());
dgShow.DataSource=ds;
dgShow.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.dbtn_search.Click += new System.EventHandler(this.dbtn_search_Click);
this.dgShow.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgShow_Change);
this.dgShow.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgShow_DeleteCommand);
this.dgShow.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgShow_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void dgShow_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.FindControl("DeleteLink")!= null)
{
//增加确认信息框
((LinkButton) e.Item.FindControl("DeleteLink")).Attributes.Add("onClick", "return confirm('您确实要删除当前客户以及其消费信息吗?');");
}
}
private void dbtn_search_Click(object sender, System.EventArgs e)
{
string strValue,strCondition;
strValue=conditionValue.Text.Trim();
strCondition=condition.SelectedItem.Value.ToString();
//生成查询语句
Session["strSql"]="select customer.id,password,name,sex,address,tel,mobile,email from customer";
Session["strSql"]=Session["strSql"]+" where "+strCondition+" like '%"+strValue+"%' ";
dgShow.CurrentPageIndex=0;
dgShowOpen();
}
protected void dgShow_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
strSql="delete from customer where id='"+e.Item.Cells[0].Text.ToString()+"'";
r.ExecuteQuery(strSql);
dgShowOpen();
}
}
}