ASP.NET编写的眼镜行分销系统的程序.
源代码在线查看: employee.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace NewGlassBook
{
///
/// Summary description for employee.
///
public class Employee : MyPage
{
protected System.Web.UI.WebControls.Label lblWarning;
protected NewGlassBook.MyButton dbtnReset;
protected NewGlassBook.MyButton dbtnOk;
protected NewGlassBook.MyTextBox aTel;
protected NewGlassBook.MyTextBox aMobile;
protected NewGlassBook.MyTextBox aAddress;
protected NewGlassBook.MyTextBox aName;
protected NewGlassBook.MyTextBox aPassword;
protected NewGlassBook.MyTextBox aid;
protected NewGlassBook.MyDropDownList aCompanyID;
protected Record r=new Record();//增加Record对象用来访问数据库
#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.dbtnOk.Click += new System.EventHandler(this.dbtnOk_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
bSubcompanyIDBind();//绑定公司到dropdownlist
GenID();//生成员工的编号
dbtnOk.Attributes["onClick"]="return employeeValid();";
}
}
private void GenID()
{
DataSet ds=r.GetData("employee","select top 1 id from employee order by id desc");
string strID=ds.Tables["employee"].Rows[0]["id"].ToString();
int tempID=Int32.Parse(strID)+1;
strID=tempID.ToString();
if(strID.Length==1)
{
strID="00"+strID;
}
else if(strID.Length==2)
{
strID="0"+strID;
}
aid.Text=strID;
}
private void bSubcompanyIDBind()
{
string strSql;
strSql="select id,id+' | '+companyname as companyname from company where id not like 'f%'";
DataSet ds=r.GetData("company",strSql);
aCompanyID.DataValueField="id";
aCompanyID.DataTextField="companyName";
aCompanyID.DataSource=ds;
aCompanyID.DataBind();
ListItem newitem=new ListItem("请选择公司","0");
aCompanyID.Items.Insert(0,newitem);
}
private void dbtnOk_Click(object sender, System.EventArgs e)
{
string strUsername;
strUsername=aid.Text;
if(r.RequestInsert("employee",Request)==1)//插入员工信息
{
lblWarning.Text=aid.Text+"的信息添加成功!";
ClearTextBox();//调用Page类中的方法清空当前页面上的TextBox
aPassword.Text="123456";
GenID();
}
else
{
lblWarning.Text=r.ErrMsg;
}
}
private void dbtnReset_Click(object sender, System.EventArgs e)
{
ClearTextBox();
aPassword.Text="123456";
}
}
}