NewStaff.aspx.cs
上传用户:cha0314
上传日期:2014-03-02
资源大小:12522k
文件大小:8k
源码类别:

C#编程

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Web;
  8. using System.Web.SessionState;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.HtmlControls;
  12. namespace UDS.SubModule.Department
  13. {
  14. /// <summary>
  15. /// NewStaff 的摘要说明。
  16. /// </summary>
  17. public class NewStaff : System.Web.UI.Page
  18. {
  19. public static string  DeptID;
  20. private static long StaffID=0;
  21. private static int sex=1;
  22. private static int EditStatus =0;
  23. private int ReturnPage=0;
  24. protected System.Web.UI.WebControls.TextBox txtStaffName;
  25. protected System.Web.UI.WebControls.TextBox txtRealName;
  26. protected System.Web.UI.WebControls.TextBox txtBirthday;
  27. protected System.Web.UI.WebControls.TextBox txtEmail;
  28. protected System.Web.UI.WebControls.TextBox txtPhone;
  29. protected System.Web.UI.WebControls.TextBox txtMobile;
  30. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
  31. protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
  32. protected System.Web.UI.WebControls.RadioButton rb_male;
  33. protected System.Web.UI.WebControls.RadioButton rb_female;
  34. protected System.Web.UI.WebControls.RegularExpressionValidator checkmail;
  35. protected System.Web.UI.WebControls.Literal message;
  36. protected System.Web.UI.WebControls.RegularExpressionValidator checkmobile;
  37. protected System.Web.UI.WebControls.RegularExpressionValidator checkphone;
  38. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
  39. protected System.Web.UI.WebControls.DropDownList cboDepartment;
  40. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
  41. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; //记录所属部门
  42. protected System.Web.UI.HtmlControls.HtmlTableRow mydepartment;
  43. protected System.Web.UI.WebControls.TextBox txtRePassword;
  44. protected System.Web.UI.WebControls.Button cmdSubmit;
  45. protected System.Web.UI.HtmlControls.HtmlTable AutoNumber1;
  46. protected System.Web.UI.WebControls.TextBox txtPassword;
  47. private void Page_Load(object sender, System.EventArgs e)
  48. {
  49. // 在此处放置用户代码以初始化页面
  50. if(!Page.IsPostBack)
  51. {
  52. //绑定部门
  53. BindDepartment();
  54. if(Request.QueryString["DeptID"]!=null)
  55. {
  56. DeptID = Request.QueryString["DeptID"].ToString();
  57. SelectDepartment(Int32.Parse(DeptID));
  58. }
  59. else
  60. DeptID = "0";
  61. txtBirthday.Text = DateTime.Now.ToShortDateString();
  62. if(Request.QueryString["StaffID"]!=null)
  63. {
  64. StaffID = Int32.Parse(Request.QueryString["StaffID"].ToString());
  65. GetStaffInfo(StaffID);
  66. EditStatus = 1;
  67. }
  68. else
  69. {
  70. EditStatus = 0;
  71. sex = 1;
  72. }
  73. }
  74. if(Request.QueryString["ReturnPage"]!=null)
  75. {
  76. ReturnPage = 1;
  77. }
  78. //if(DeptID!="0")
  79. //mydepartment.Visible = false;
  80. }
  81. #region Web Form Designer generated code
  82. override protected void OnInit(EventArgs e)
  83. {
  84. //
  85. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  86. //
  87. InitializeComponent();
  88. base.OnInit(e);
  89. }
  90. /// <summary>
  91. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  92. /// 此方法的内容。
  93. /// </summary>
  94. private void InitializeComponent()
  95. {    
  96. this.txtBirthday.TextChanged += new System.EventHandler(this.txtBirthday_TextChanged);
  97. this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
  98. this.Load += new System.EventHandler(this.Page_Load);
  99. }
  100. #endregion
  101. private void BindDepartment()
  102. {
  103. UDS.Components.Database db = new UDS.Components.Database();
  104. SqlDataReader dr_department = null;
  105. db.RunProc("sp_GetAllDepartment",out dr_department);
  106. cboDepartment.DataSource = dr_department;
  107. cboDepartment.DataTextField = "Department_Name";
  108. cboDepartment.DataValueField = "Department_ID";
  109. cboDepartment.DataBind();
  110. }
  111. private void GetStaffInfo(long StaffID)
  112. {
  113. SqlDataReader dr;
  114. UDS.Components.Staff person = new UDS.Components.Staff();
  115. dr = person.GetStaffInfo(StaffID);
  116. txtPassword.TextMode = System.Web.UI.WebControls.TextBoxMode.SingleLine;
  117. txtRePassword.TextMode = System.Web.UI.WebControls.TextBoxMode.SingleLine;
  118. if(dr.Read ())
  119. {
  120. txtStaffName.Text = dr["Staff_Name"].ToString();
  121. txtStaffName.ReadOnly =true;
  122. txtRealName.Text = dr["RealName"].ToString();
  123. if(dr["Sex"].ToString() =="True")
  124. {
  125. rb_male.Checked =true;
  126. sex =1;
  127. }
  128. else
  129. {
  130. rb_female.Checked =true;
  131. sex = 0;
  132. }
  133.  
  134. txtBirthday.Text = dr["Birthday"].ToString().IndexOf(" ")>0?dr["Birthday"].ToString().Substring(0,dr["Birthday"].ToString().IndexOf(" ")):dr["Birthday"].ToString() ;
  135. if( txtBirthday.Text =="")
  136. txtBirthday.Text = DateTime.Now.ToShortDateString();
  137. txtPassword.Text  = dr["Password"].ToString();
  138. txtRePassword.Text  = dr["Password"].ToString();
  139. txtEmail.Text  = dr["Email"].ToString();
  140. txtPhone.Text =dr["Phone"].ToString();
  141. txtMobile.Text = dr["Mobile"].ToString();
  142. SelectDepartment(Int32.Parse(dr["Department_ID"].ToString()));
  143. }
  144. person = null;
  145. dr.Close();
  146. dr =null;
  147. }
  148. private void SelectDepartment(int DepartmentID)
  149. {
  150. for(int i = 0;i<cboDepartment.Items.Count;i++ )
  151. {
  152. if(Int32.Parse(cboDepartment.Items[i].Value) == DepartmentID)
  153. cboDepartment.SelectedIndex = i;
  154. }
  155. }
  156. private void txtBirthday_TextChanged(object sender, System.EventArgs e)
  157. {
  158. }
  159. private void cmdSubmit_Click(object sender, System.EventArgs e)
  160. {
  161. if(rb_male.Checked==true)
  162. sex =1;
  163. else
  164. sex =0;
  165. if(EditStatus ==0)
  166. {
  167. UDS.Components.Database db = new UDS.Components.Database();
  168. SqlDataReader dr;
  169. if(mydepartment.Visible==true)
  170. DeptID = cboDepartment.Items[cboDepartment.SelectedIndex].Value.ToString();
  171. SqlParameter[] prams = {
  172.    db.MakeInParam("@StaffName",SqlDbType.VarChar,300,txtStaffName.Text),
  173.    db.MakeInParam("@Password",SqlDbType.VarChar,300,txtPassword.Text ),
  174.    db.MakeInParam("@RealName",SqlDbType.VarChar,300,txtRealName.Text),
  175.    db.MakeInParam("@Sex",SqlDbType.Int,4,sex),
  176.    db.MakeInParam("@Status",SqlDbType.Int,4,0),
  177.    db.MakeInParam("@Email",SqlDbType.VarChar,300,txtEmail.Text),
  178.    db.MakeInParam("@RegistedDate",SqlDbType.DateTime,8,DateTime.Now.ToString()),
  179.    db.MakeInParam("@DeptID",SqlDbType.Int,4,Int32.Parse(DeptID)),
  180.    db.MakeInParam("@Phone",SqlDbType.VarChar,50,txtPhone.Text),
  181.    db.MakeInParam("@Mobile",SqlDbType.VarChar,50,txtMobile.Text),
  182.    db.MakeInParam("@Birthday",SqlDbType.DateTime,8,(txtBirthday.Text.Trim()=="")?"1900-1-1":txtBirthday.Text)
  183.    };
  184. db.RunProc("sp_AddStaff",prams,out dr);
  185. if(dr.Read())
  186. if(ReturnPage==0)
  187. Response.Redirect("ListView.aspx?Dep_ID="+DeptID);
  188. else
  189. Response.Redirect("../Staff/ManageStaff.aspx");
  190. else
  191. message.Text = "该用户已经存在!";
  192. }
  193. else
  194. {
  195. UDS.Components.Staff person = new UDS.Components.Staff();
  196. switch(person.UpdateInfo(StaffID,txtRealName.Text,sex,txtBirthday.Text,txtPassword.Text,txtEmail.Text,txtPhone.Text,txtMobile.Text,Int32.Parse(cboDepartment.Items[cboDepartment.SelectedIndex].Value )))
  197. {
  198. case 0:
  199. message.Text = "修改成功!";
  200. break;
  201. case -1:
  202. message.Text = "验证密码不对!";
  203. break;
  204. default:
  205. break;
  206. }
  207. }
  208. }
  209. }
  210. }