OPosition.aspx.cs
上传用户:jdb8708888
上传日期:2013-05-29
资源大小:19971k
文件大小:12k
源码类别:

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. namespace UDS.SubModule.Position
  13. {
  14. /// <summary>
  15. /// OPosition 的摘要说明。
  16. /// </summary>
  17. public class OPosition : System.Web.UI.Page
  18. {
  19. protected System.Web.UI.WebControls.Label title_add;
  20. protected System.Web.UI.WebControls.Label addPositionName;
  21. protected System.Web.UI.WebControls.Label title_del;
  22. protected System.Web.UI.WebControls.Label delPositionName;
  23. protected System.Web.UI.WebControls.TextBox txtPositionName;
  24. protected System.Web.UI.WebControls.TextBox txtAPositionName;
  25. protected System.Web.UI.WebControls.TextBox txtAPositionRemark;
  26. protected System.Web.UI.WebControls.TextBox txtMPositionRemark;
  27. protected System.Web.UI.WebControls.TextBox txtOnDutyTime;
  28. protected System.Web.UI.WebControls.TextBox txtOffDutyTime;
  29. protected System.Web.UI.HtmlControls.HtmlInputButton cmdAdd;
  30. protected System.Web.UI.HtmlControls.HtmlInputButton cmdDelete;
  31. protected System.Web.UI.HtmlControls.HtmlInputButton cmdModify;
  32. protected System.Web.UI.WebControls.RegularExpressionValidator rev_OnDutyTime;
  33. protected System.Web.UI.WebControls.RegularExpressionValidator rev_uOnDutyTime;
  34. protected System.Web.UI.WebControls.RegularExpressionValidator rev_OffDutyTime;
  35. protected System.Web.UI.WebControls.RegularExpressionValidator rev_uOffDutyTime;
  36. private static int PositionID;//职位id
  37. private static string PositionName;//职位名称
  38. private static string PositionDescription;
  39. private static string OnDutyTime = "";
  40. private static int DisplayType;
  41. protected System.Web.UI.WebControls.LinkButton lbAddPosition;
  42. protected System.Web.UI.WebControls.LinkButton lbDeletePosition;
  43. protected System.Web.UI.WebControls.LinkButton lbModifyPosition;
  44. protected System.Web.UI.HtmlControls.HtmlTableCell TD1;
  45. protected System.Web.UI.HtmlControls.HtmlTable tabModify;
  46. protected System.Web.UI.HtmlControls.HtmlGenericControl FONT1;
  47. protected System.Web.UI.HtmlControls.HtmlGenericControl FONT2;
  48. protected System.Web.UI.HtmlControls.HtmlTable tabAdd;
  49. protected System.Web.UI.HtmlControls.HtmlTable tabDelete;
  50. protected System.Web.UI.WebControls.TextBox txtuOnDutyTime;
  51. protected System.Web.UI.WebControls.TextBox txtuOffDutyTime;
  52. protected System.Web.UI.WebControls.Literal litAMessage;
  53. protected System.Web.UI.WebControls.Literal litMMessage;
  54. protected System.Web.UI.WebControls.LinkButton lbMovePosition;
  55. protected System.Web.UI.WebControls.Label lblPosition;
  56. protected System.Web.UI.WebControls.ListBox lstDeparment;
  57. protected System.Web.UI.WebControls.Button cmdMove;
  58. protected System.Web.UI.HtmlControls.HtmlTable tabMove;
  59. protected System.Web.UI.WebControls.Button cmdModifyReturn;
  60. protected System.Web.UI.WebControls.Button cmdDeleteReturn;
  61. protected System.Web.UI.WebControls.Button cmdAddReturn;
  62. protected System.Web.UI.WebControls.Button cmdMoveReturn;//上班时间
  63. private static string OffDutyTime = "";//下班时间
  64.         
  65. private void Page_Load(object sender, System.EventArgs e)
  66. {
  67. if(!Page.IsPostBack)
  68. {
  69. txtPositionName.Text = "";
  70. OnDutyTime = "";
  71. OffDutyTime = "";
  72. SqlDataReader dr;
  73. //得到职位ID
  74. PositionID=(Request.QueryString["PositionID"]==null?0:Int32.Parse(Request.QueryString["PositionID"].ToString()));
  75. UDS.Components.Position dp = new UDS.Components.Position();
  76. dr = dp.GetPositionInfo(PositionID);
  77. if(dr.Read())
  78. {
  79. PositionName = dr["Position_Name"].ToString();
  80. PositionDescription = dr["Position_Description"].ToString();
  81. }
  82. dr.Close();
  83. dr = dp.GetPositionDutyTime(PositionID);
  84. if(dr.Read())
  85. {
  86. OnDutyTime = DateTime.Parse(dr["OnDutyTime"].ToString()).ToShortTimeString();
  87. OffDutyTime = DateTime.Parse(dr["OffDutyTime"].ToString()).ToShortTimeString();
  88. }
  89. if(Request.QueryString["DisplayType"] !=null)
  90. DisplayType = Int32.Parse(Request.QueryString["DisplayType"].ToString());
  91. else
  92. DisplayType = 0;
  93. // 显示不同表格
  94. switch(DisplayType)
  95. {
  96. case 0:
  97. tabAdd.Visible = true;
  98. tabDelete.Visible = false;
  99. tabModify.Visible = false;
  100. tabMove.Visible =false;
  101. lbAddPosition.BackColor = Color.FromArgb(0xf0f0f0);
  102. lbDeletePosition.BackColor = Color.FromArgb(0xffffff);
  103. lbModifyPosition.BackColor = Color.FromArgb(0xffffff);
  104. lbMovePosition.BackColor  = Color.FromArgb(0xffffff);
  105. addPositionName.Text = PositionName;
  106. break;
  107. case 1:
  108. tabAdd.Visible = false;
  109. tabDelete.Visible = true;
  110. tabModify.Visible = false;
  111. tabMove.Visible =false;
  112. lbAddPosition.BackColor = Color.FromArgb(0xffffff);
  113. lbDeletePosition.BackColor = Color.FromArgb(0xf0f0f0);
  114. lbModifyPosition.BackColor = Color.FromArgb(0xffffff);
  115. lbMovePosition.BackColor  = Color.FromArgb(0xffffff);
  116. delPositionName.Text  = PositionName;
  117. break;
  118. case 2:
  119. tabAdd.Visible = false;
  120. tabDelete.Visible = false;
  121. tabModify.Visible = true;
  122. tabMove.Visible =false;
  123. txtPositionName.Text = PositionName;
  124. txtMPositionRemark.Text = PositionDescription;
  125. lbAddPosition.BackColor = Color.FromArgb(0xffffff);
  126. lbDeletePosition.BackColor = Color.FromArgb(0xffffff);
  127. lbModifyPosition.BackColor = Color.FromArgb(0xf0f0f0);
  128. lbMovePosition.BackColor  = Color.FromArgb(0xffffff);
  129. txtuOnDutyTime.Text  = OnDutyTime;
  130. txtuOffDutyTime.Text  = OffDutyTime;
  131. break;
  132. case 3:
  133. tabAdd.Visible = false;
  134. tabDelete.Visible = false;
  135. tabModify.Visible = false;
  136. tabMove.Visible =true;
  137. lbAddPosition.BackColor = Color.FromArgb(0xffffff);
  138. lbDeletePosition.BackColor = Color.FromArgb(0xffffff);
  139. lbModifyPosition.BackColor = Color.FromArgb(0xffffff);
  140. lbMovePosition.BackColor  = Color.FromArgb(0xf0f0f0);
  141. lblPosition.Text = PositionName;
  142. BindPosition();
  143. break;
  144. default:
  145. break;
  146. }
  147. }
  148. }
  149. #region Web Form Designer generated code
  150. override protected void OnInit(EventArgs e)
  151. {
  152. //
  153. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  154. //
  155. InitializeComponent();
  156. base.OnInit(e);
  157. }
  158. /// <summary>
  159. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  160. /// 此方法的内容。
  161. /// </summary>
  162. private void InitializeComponent()
  163. {    
  164. this.lbAddPosition.Click += new System.EventHandler(this.lbAddPosition_Click);
  165. this.lbDeletePosition.Click += new System.EventHandler(this.lbDeletePosition_Click);
  166. this.lbModifyPosition.Click += new System.EventHandler(this.lbModifyPosition_Click);
  167. this.lbMovePosition.Click += new System.EventHandler(this.lbMovePosition_Click);
  168. this.cmdAddReturn.Click += new System.EventHandler(this.cmdReturn_Click);
  169. this.cmdDeleteReturn.Click += new System.EventHandler(this.cmdReturn_Click);
  170. this.cmdModifyReturn.Click += new System.EventHandler(this.cmdReturn_Click);
  171. this.cmdMove.Click += new System.EventHandler(this.cmdMove_Click);
  172. this.cmdMoveReturn.Click += new System.EventHandler(this.cmdReturn_Click);
  173. this.cmdAdd.ServerClick += new System.EventHandler(this.cmdAdd_ServerClick);
  174. this.cmdDelete.ServerClick += new System.EventHandler(this.cmdDelete_ServerClick);
  175. this.cmdModify.ServerClick += new System.EventHandler(this.cmdModify_ServerClick);
  176. this.Load += new System.EventHandler(this.Page_Load);
  177. }
  178. #endregion
  179. private void BindPosition()
  180. {
  181. UDS.Components.Database db = new UDS.Components.Database();
  182. SqlDataReader dr_department = null;
  183. db.RunProc("sp_GetAllPosition",out dr_department);
  184. lstDeparment.DataSource = dr_department;
  185. lstDeparment.DataTextField = "Position_Name";
  186. lstDeparment.DataValueField = "Position_ID";
  187. lstDeparment.DataBind();
  188. }
  189. private void cmdAdd_ServerClick(object sender,System.EventArgs e)
  190. {
  191. if(txtAPositionName.Text.Trim()!="")
  192. {
  193. long NewDeptID = UDS.Components.Position.Add(PositionID,txtAPositionName.Text,txtAPositionRemark.Text);
  194. if(PositionID>0)
  195. {
  196. if((txtOnDutyTime.Text.Trim()!="")&&(txtOffDutyTime.Text.Trim()!=""))
  197. {
  198. if(UDS.Components.Position.AddDutyTime(NewDeptID,DateTime.Parse(txtOnDutyTime.Text),DateTime.Parse(txtOffDutyTime.Text))!=0)
  199. Response.Write("<script laguage='javascript'>alert('添加职位出错!');</script>");
  200. else
  201. Response.Redirect("ListView.aspx?PositionID=" +PositionID + "&Refresh=1");
  202. }
  203. else
  204. Response.Redirect("ListView.aspx?PositionID=" +PositionID + "&Refresh=1");
  205. }
  206. else
  207. Response.Write("<script laguage='javascript'>alert('添加职位出错!');</script>");
  208. }
  209. else
  210. {
  211. litAMessage.Text ="请输入职位";
  212. }
  213. }
  214. private void cmdDelete_ServerClick(object sender,System.EventArgs e)
  215. {
  216. switch(UDS.Components.Position.Delete(PositionID))
  217. {
  218. case 0:
  219. Response.Redirect("ListView.aspx?PositionID="+PositionID+"&Refresh=1");
  220. break;
  221. case -1:
  222. Response.Write("<script laguage='javascript'>alert('有下级职位,不能删除!');</script>");
  223. break;
  224. case -2:
  225. Response.Write("<script laguage='javascript'>alert('职位有成员,不能删除!');</script>");
  226. break;
  227. default:
  228. break;
  229. }
  230. }
  231. private void cmdModify_ServerClick(object sender,System.EventArgs e)
  232. {
  233. if(txtPositionName.Text.Trim()!="")
  234. {
  235. if((UDS.Components.Position.Modify(PositionID,txtPositionName.Text,txtMPositionRemark.Text)==0))
  236. {
  237. if((txtuOnDutyTime.Text.Trim()!="")&&(txtuOffDutyTime.Text.Trim()!=""))
  238. {
  239. if((UDS.Components.Position.UpdateDutyTime(PositionID,DateTime.Parse(txtuOnDutyTime.Text),DateTime.Parse(txtuOffDutyTime.Text))!=0))
  240. {
  241. Response.Write("<script laguage='javascript'>alert('修改职位出错!');</script>");
  242. return;
  243. }
  244. }
  245. else
  246. {
  247. UDS.Components.Position.DeleteDutyTime(PositionID);
  248. }
  249. Response.Redirect("ListView.aspx?PositionID="+PositionID+"&Refresh=1");
  250. }
  251. else
  252. Response.Write("<script laguage='javascript'>alert('修改职位出错!');</script>");
  253. }
  254. else
  255. litMMessage.Text ="请输入职位";
  256. }
  257. private void Operation_SelectedIndexChanged(object sender, System.EventArgs e)
  258. {
  259. }
  260. private void lbAddPosition_Click(object sender, System.EventArgs e)
  261. {
  262. Server.Transfer("OPosition.aspx?PositionID=" + PositionID.ToString() + "&DisplayType=0");
  263. }
  264. private void lbDeletePosition_Click(object sender, System.EventArgs e)
  265. {
  266. Server.Transfer("OPosition.aspx?PositionID=" + PositionID.ToString() + "&DisplayType=1");
  267. }
  268. private void lbModifyPosition_Click(object sender, System.EventArgs e)
  269. {
  270. Server.Transfer("OPosition.aspx?PositionID=" + PositionID.ToString() + "&DisplayType=2");
  271. }
  272. private void lbMovePosition_Click(object sender, System.EventArgs e)
  273. {
  274. Server.Transfer("OPosition.aspx?PositionID=" + PositionID.ToString() + "&DisplayType=3");
  275. }
  276. private void cmdMove_Click(object sender, System.EventArgs e)
  277. {
  278. UDS.Components.Position dept = new UDS.Components.Position();
  279. switch(dept.MoveDeparement(PositionID,Int32.Parse(lstDeparment.Items[lstDeparment.SelectedIndex].Value)))
  280. {
  281. case 0:
  282. Response.Write("<script laguage='javascript'>alert('移动到" + lstDeparment.Items[lstDeparment.SelectedIndex].Text +" 职位成功!');</script>");
  283. Response.Redirect("ListView.aspx?PositionID="+PositionID+"&Refresh=1");
  284. break;
  285. case -1:
  286. Response.Write("<script laguage='javascript'>alert('不能移动到下级职位!');</script>");
  287. break;
  288. default:
  289. break;
  290. }
  291. }
  292. private void cmdReturn_Click(object sender, System.EventArgs e)
  293. {
  294. Server.Transfer("Listview.aspx?PositionID=" + PositionID.ToString());
  295. }
  296. }
  297. }