NewStaff.aspx.cs
上传用户:xuming1973
上传日期:2014-02-27
资源大小:17511k
文件大小:10k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

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. using UDS.Components;
  13. namespace UDS.SubModule.Position
  14. {
  15. /// <summary>
  16. /// NewStaff 的摘要说明。
  17. /// </summary>
  18. public class NewStaff : System.Web.UI.Page
  19. {
  20. public static string  PositionID;
  21. private static long StaffID=0;
  22. private static int sex=1;
  23. private static int EditStatus =0;
  24. public int ReturnPage=0;
  25. protected static string Username;
  26. protected System.Web.UI.WebControls.TextBox txtStaffName;
  27. protected System.Web.UI.WebControls.TextBox txtRealName;
  28. protected System.Web.UI.WebControls.TextBox txtBirthday;
  29. protected System.Web.UI.WebControls.TextBox txtEmail;
  30. protected System.Web.UI.WebControls.TextBox txtPhone;
  31. protected System.Web.UI.WebControls.TextBox txtMobile;
  32. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
  33. protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
  34. protected System.Web.UI.WebControls.RadioButton rb_male;
  35. protected System.Web.UI.WebControls.RadioButton rb_female;
  36. protected System.Web.UI.WebControls.RegularExpressionValidator checkmail;
  37. protected System.Web.UI.WebControls.Literal message;
  38. protected System.Web.UI.WebControls.RegularExpressionValidator checkmobile;
  39. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
  40. protected System.Web.UI.WebControls.DropDownList cboPosition;
  41. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
  42. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; //记录所属部门
  43. protected System.Web.UI.HtmlControls.HtmlTableRow myposition;
  44. protected System.Web.UI.WebControls.TextBox txtRePassword;
  45. protected System.Web.UI.WebControls.Button cmdSubmit;
  46. protected System.Web.UI.HtmlControls.HtmlTable AutoNumber1;
  47. protected System.Web.UI.WebControls.TextBox txtCaste;
  48. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator5;
  49. protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
  50. protected System.Web.UI.WebControls.CheckBox cbRemind;
  51. // protected System.Web.UI.WebControls.DropDownList cboPosition;
  52. protected System.Web.UI.WebControls.TextBox txtPassword;
  53. private void Page_Load(object sender, System.EventArgs e)
  54. {
  55. // 在此处放置用户代码以初始化页面
  56. if(!Page.IsPostBack)
  57. {
  58. //操作者登录名
  59. HttpCookie UserCookie = Request.Cookies["Username"];
  60. Username = UserCookie.Value.ToString();
  61. //绑定部门
  62. BindPosition();
  63. //修改于2003-10-8日 目的:改正生日103岁问题
  64. //txtBirthday.Text = DateTime.Now.ToShortDateString();
  65. if(Request.QueryString["PositionID"]!=null)
  66. {
  67. PositionID = Request.QueryString["PositionID"].ToString();
  68. SelectPosition(Int32.Parse(PositionID));
  69. }
  70. else
  71. PositionID = "0";
  72. if(Request.QueryString["StaffID"]!=null)
  73. {
  74. StaffID = Int32.Parse(Request.QueryString["StaffID"].ToString());
  75. GetStaffInfo(StaffID);
  76. EditStatus = 1;
  77. cbRemind.Visible =false;
  78. //cboPosition.Visible =false;
  79. cboPosition.Enabled =false;
  80. }
  81. else
  82. {
  83. EditStatus = 0;
  84. sex = 1;
  85. }
  86. }
  87. if(Request.QueryString["ReturnPage"]!=null)
  88. {
  89. ReturnPage = Int32.Parse(Request.QueryString["ReturnPage"].ToString());
  90. }
  91. else
  92. ReturnPage = 0;
  93. //if(PositionID!="0")
  94. //myposition.Visible = false;
  95. }
  96. #region Web Form Designer generated code
  97. override protected void OnInit(EventArgs e)
  98. {
  99. //
  100. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  101. //
  102. InitializeComponent();
  103. base.OnInit(e);
  104. }
  105. /// <summary>
  106. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  107. /// 此方法的内容。
  108. /// </summary>
  109. private void InitializeComponent()
  110. {    
  111. this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
  112. this.Load += new System.EventHandler(this.Page_Load);
  113. }
  114. #endregion
  115. private void BindPosition()
  116. {
  117. UDS.Components.Database db = new UDS.Components.Database();
  118. SqlDataReader dr_position = null;
  119. db.RunProc("sp_GetAllPosition",out dr_position);
  120. cboPosition.DataSource = dr_position;
  121. cboPosition.DataTextField = "Position_Name";
  122. cboPosition.DataValueField = "Position_ID";
  123. cboPosition.DataBind();
  124. }
  125. private void GetStaffInfo(long StaffID)
  126. {
  127. SqlDataReader dr;
  128. UDS.Components.Staff person = new UDS.Components.Staff();
  129. dr = person.GetStaffInfo(StaffID);
  130. txtPassword.TextMode = System.Web.UI.WebControls.TextBoxMode.SingleLine;
  131. txtRePassword.TextMode = System.Web.UI.WebControls.TextBoxMode.SingleLine;
  132. if(dr.Read ())
  133. {
  134. txtStaffName.Text = dr["Staff_Name"].ToString();
  135. txtStaffName.ReadOnly =true;
  136. txtRealName.Text = dr["RealName"].ToString();
  137. if(dr["Sex"].ToString() =="True")
  138. {
  139. rb_male.Checked =true;
  140. sex =1;
  141. }
  142. else
  143. {
  144. rb_female.Checked =true;
  145. sex = 0;
  146. }
  147.  
  148. //修改于2003-10-8日 目的:改正生日103岁问题
  149. // if( txtBirthday.Text =="")
  150. // txtBirthday.Text = DateTime.Now.ToShortDateString();
  151. // txtBirthday.Text = dr["Birthday"].ToString().IndexOf(" ")>0?dr["Birthday"].ToString().Substring(0,dr["Birthday"].ToString().IndexOf(" ")):dr["Birthday"].ToString() ;
  152. txtBirthday .Text = ((dr["Birthday"]==DBNull.Value) || (DateTime.Parse(dr["Birthday"].ToString()).Date==DateTime.Parse("1900-1-1").Date))?"-":DateTime.Parse(dr["Birthday"].ToString()).ToLongDateString();
  153. txtPassword .Text = dr["Password"].ToString();
  154. txtRePassword .Text = dr["Password"].ToString();
  155. txtEmail .Text = dr["Email"].ToString();
  156. txtPhone .Text = dr["Phone"].ToString();
  157. txtMobile .Text = dr["Mobile"].ToString();
  158. txtCaste .Text = dr["Caste"].ToString();
  159. PositionID = dr["Position_ID"].ToString();
  160. SelectPosition(Int32.Parse(dr["Position_ID"].ToString()));
  161. }
  162. person = null;
  163. dr.Close();
  164. dr =null;
  165. }
  166. private void SelectPosition(int PositionID)
  167. {
  168. for(int i = 0;i<cboPosition.Items.Count;i++ )
  169. {
  170. if(Int32.Parse(cboPosition.Items[i].Value) == PositionID)
  171. cboPosition.SelectedIndex = i;
  172. }
  173. }
  174. private void cmdSubmit_Click(object sender, System.EventArgs e)
  175. {
  176. if(rb_male.Checked==true)
  177. sex =1;
  178. else
  179. sex =0;
  180. if(EditStatus ==0)
  181. {
  182. UDS.Components.Database db = new UDS.Components.Database();
  183. SqlDataReader dr;
  184. if(myposition.Visible==true)
  185. PositionID = cboPosition.Items[cboPosition.SelectedIndex].Value.ToString();
  186. SqlParameter[] prams = {
  187.    db.MakeInParam("@StaffName",SqlDbType.VarChar,300,txtStaffName.Text),
  188.    db.MakeInParam("@Password",SqlDbType.VarChar,300,txtPassword.Text ),
  189.    db.MakeInParam("@RealName",SqlDbType.VarChar,300,txtRealName.Text),
  190.    db.MakeInParam("@Sex",SqlDbType.Int,4,sex),
  191.    db.MakeInParam("@Status",SqlDbType.Int,4,0),
  192.    db.MakeInParam("@Email",SqlDbType.VarChar,300,txtEmail.Text),
  193.    db.MakeInParam("@RegistedDate",SqlDbType.DateTime,8,DateTime.Now.ToString()),
  194.    db.MakeInParam("@PositionID",SqlDbType.Int,4,Int32.Parse(PositionID)),
  195.    db.MakeInParam("@Phone",SqlDbType.VarChar,50,txtPhone.Text),
  196.    db.MakeInParam("@Mobile",SqlDbType.VarChar,50,txtMobile.Text),
  197.    db.MakeInParam("@Birthday",SqlDbType.DateTime,8,(txtBirthday.Text.Trim()=="")?"1900-1-1":txtBirthday.Text),
  198.    db.MakeInParam("@Caste",SqlDbType.Int,4,Int32.Parse(txtCaste.Text))
  199.    };
  200. db.RunProc("sp_AddStaff",prams,out dr);
  201. if(dr.Read())
  202. {
  203. SqlDataReader dr_isok;//所有在职人员
  204. UDS.Components.Staff sta=new UDS.Components.Staff();
  205. dr_isok=sta.GetAllStaffs();
  206. //处理短信提醒
  207. if(this.cbRemind.Checked ==true)
  208. {
  209. while(dr_isok.Read())
  210. {
  211. SMS sm = new SMS();
  212. sm.SendMsg(Username,dr_isok["Staff_name"].ToString(),cboPosition.SelectedItem.Text+"处新到员工 "+txtRealName.Text+",特此通知.",1,DateTime.Now,"",0,0);
  213. //sm.SendMsg(Username,mailbody.MailReceiverStr+mailbody.MailCcToAddr+mailbody.MailBccToAddr,"您从"+Username+"处收到了一封新的邮件",1,DateTime.Now,"",0,0);
  214. sm = null;
  215. }
  216. dr_isok=null;
  217. }
  218. if(ReturnPage==0)
  219. Response.Redirect("ListView.aspx?Position_ID="+PositionID);
  220. else
  221. Response.Redirect("../Staff/ManageStaff.aspx");
  222. dr=null;
  223. }
  224. else
  225. message.Text = "<font color=red>该用户已经存在!</font>";
  226. }
  227. else
  228. {
  229. UDS.Components.Staff person = new UDS.Components.Staff();
  230. switch(person.UpdateInfo(StaffID,txtRealName.Text,sex,txtBirthday.Text=="-"?"1900-01-01":txtBirthday.Text,txtPassword.Text,txtEmail.Text,txtPhone.Text,txtMobile.Text,Int32.Parse(cboPosition.Items[cboPosition.SelectedIndex].Value ),Int32.Parse(txtCaste.Text)))
  231. {
  232. case 0:
  233. PositionID = Int32.Parse(cboPosition.Items[cboPosition.SelectedIndex].Value ).ToString();
  234. if(ReturnPage==0)
  235. Response.Redirect("ListView.aspx?Position_ID="+PositionID);
  236. else
  237. Response.Redirect("../Staff/ManageStaff.aspx");
  238. message.Text = "修改成功!";
  239. break;
  240. case -1:
  241. message.Text = "验证密码不对!";
  242. break;
  243. default:
  244. break;
  245. }
  246. }
  247. }
  248. }
  249. }