ODepartment.aspx.cs
上传用户:xgw_05
上传日期:2009-12-11
资源大小:20208k
文件大小:12k
源码类别:

OA系统

开发平台:

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. /// ODepartment 的摘要说明。
  16. /// </summary>
  17. public class ODepartment : System.Web.UI.Page
  18. {
  19. protected System.Web.UI.WebControls.Label title_add;
  20. protected System.Web.UI.WebControls.Label addDepartmentName;
  21. protected System.Web.UI.WebControls.Label title_del;
  22. protected System.Web.UI.WebControls.Label delDepartmentName;
  23. protected System.Web.UI.WebControls.TextBox txtDepartmentName;
  24. protected System.Web.UI.WebControls.TextBox txtADepartmentName;
  25. protected System.Web.UI.WebControls.TextBox txtADepartmentRemark;
  26. protected System.Web.UI.WebControls.TextBox txtMDepartmentRemark;
  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 DeptID;//部门id
  37. private static string DepartmentName;//部门名称
  38. private static string DepartmentDescription;
  39. private static string OnDutyTime = "";
  40. private static int DisplayType;
  41. protected System.Web.UI.WebControls.LinkButton lbAddDepartment;
  42. protected System.Web.UI.WebControls.LinkButton lbDeleteDepartment;
  43. protected System.Web.UI.WebControls.LinkButton lbModifyDepartment;
  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 lbMoveDepartment;
  55. protected System.Web.UI.WebControls.Label lblDepartment;
  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. txtDepartmentName.Text = "";
  70. OnDutyTime = "";
  71. OffDutyTime = "";
  72. SqlDataReader dr;
  73. //得到部门ID
  74. DeptID=(Request.QueryString["DeptID"]==null?0:Int32.Parse(Request.QueryString["DeptID"].ToString()));
  75. UDS.Components.Department dp = new UDS.Components.Department();
  76. dr = dp.GetDepartmentInfo(DeptID);
  77. if(dr.Read())
  78. {
  79. DepartmentName = dr["Department_Name"].ToString();
  80. DepartmentDescription = dr["Department_Description"].ToString();
  81. }
  82. dr.Close();
  83. dr = dp.GetDepartmentDutyTime(DeptID);
  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. lbAddDepartment.BackColor = Color.FromArgb(0xf0f0f0);
  102. lbDeleteDepartment.BackColor = Color.FromArgb(0xffffff);
  103. lbModifyDepartment.BackColor = Color.FromArgb(0xffffff);
  104. lbMoveDepartment.BackColor  = Color.FromArgb(0xffffff);
  105. addDepartmentName.Text = DepartmentName;
  106. break;
  107. case 1:
  108. tabAdd.Visible = false;
  109. tabDelete.Visible = true;
  110. tabModify.Visible = false;
  111. tabMove.Visible =false;
  112. lbAddDepartment.BackColor = Color.FromArgb(0xffffff);
  113. lbDeleteDepartment.BackColor = Color.FromArgb(0xf0f0f0);
  114. lbModifyDepartment.BackColor = Color.FromArgb(0xffffff);
  115. lbMoveDepartment.BackColor  = Color.FromArgb(0xffffff);
  116. delDepartmentName.Text  = DepartmentName;
  117. break;
  118. case 2:
  119. tabAdd.Visible = false;
  120. tabDelete.Visible = false;
  121. tabModify.Visible = true;
  122. tabMove.Visible =false;
  123. txtDepartmentName.Text = DepartmentName;
  124. txtMDepartmentRemark.Text = DepartmentDescription;
  125. lbAddDepartment.BackColor = Color.FromArgb(0xffffff);
  126. lbDeleteDepartment.BackColor = Color.FromArgb(0xffffff);
  127. lbModifyDepartment.BackColor = Color.FromArgb(0xf0f0f0);
  128. lbMoveDepartment.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. lbAddDepartment.BackColor = Color.FromArgb(0xffffff);
  138. lbDeleteDepartment.BackColor = Color.FromArgb(0xffffff);
  139. lbModifyDepartment.BackColor = Color.FromArgb(0xffffff);
  140. lbMoveDepartment.BackColor  = Color.FromArgb(0xf0f0f0);
  141. lblDepartment.Text = DepartmentName;
  142. BindDepartment();
  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.lbAddDepartment.Click += new System.EventHandler(this.lbAddDepartment_Click);
  165. this.lbDeleteDepartment.Click += new System.EventHandler(this.lbDeleteDepartment_Click);
  166. this.lbModifyDepartment.Click += new System.EventHandler(this.lbModifyDepartment_Click);
  167. this.lbMoveDepartment.Click += new System.EventHandler(this.lbMoveDepartment_Click);
  168. this.cmdAdd.ServerClick += new System.EventHandler(this.cmdAdd_ServerClick);
  169. this.cmdAddReturn.Click += new System.EventHandler(this.cmdReturn_Click);
  170. this.cmdDeleteReturn.Click += new System.EventHandler(this.cmdReturn_Click);
  171. this.cmdModifyReturn.Click += new System.EventHandler(this.cmdReturn_Click);
  172. this.cmdMove.Click += new System.EventHandler(this.cmdMove_Click);
  173. this.cmdMoveReturn.Click += new System.EventHandler(this.cmdReturn_Click);
  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 BindDepartment()
  180. {
  181. UDS.Components.Database db = new UDS.Components.Database();
  182. SqlDataReader dr_department = null;
  183. db.RunProc("sp_GetAllDepartment",out dr_department);
  184. lstDeparment.DataSource = dr_department;
  185. lstDeparment.DataTextField = "Department_Name";
  186. lstDeparment.DataValueField = "Department_ID";
  187. lstDeparment.DataBind();
  188. }
  189. private void cmdAdd_ServerClick(object sender,System.EventArgs e)
  190. {
  191. if(txtADepartmentName.Text.Trim()!="")
  192. {
  193. long NewDeptID = UDS.Components.Department.Add(DeptID,txtADepartmentName.Text,txtADepartmentRemark.Text);
  194. if(DeptID>0)
  195. {
  196. if((txtOnDutyTime.Text.Trim()!="")&&(txtOffDutyTime.Text.Trim()!=""))
  197. {
  198. if(UDS.Components.Department.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?DeptID=" +DeptID + "&Refresh=1");
  202. }
  203. else
  204. Response.Redirect("ListView.aspx?DeptID=" +DeptID + "&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.Department.Delete(DeptID))
  217. {
  218. case 0:
  219. Response.Redirect("ListView.aspx?DeptID="+DeptID+"&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(txtDepartmentName.Text.Trim()!="")
  234. {
  235. if((UDS.Components.Department.Modify(DeptID,txtDepartmentName.Text,txtMDepartmentRemark.Text)==0))
  236. {
  237. if((txtuOnDutyTime.Text.Trim()!="")&&(txtuOffDutyTime.Text.Trim()!=""))
  238. {
  239. if((UDS.Components.Department.UpdateDutyTime(DeptID,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.Department.DeleteDutyTime(DeptID);
  248. }
  249. Response.Redirect("ListView.aspx?DeptID="+DeptID+"&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 lbAddDepartment_Click(object sender, System.EventArgs e)
  261. {
  262. Server.Transfer("ODepartment.aspx?DeptID=" + DeptID.ToString() + "&DisplayType=0");
  263. }
  264. private void lbDeleteDepartment_Click(object sender, System.EventArgs e)
  265. {
  266. Server.Transfer("ODepartment.aspx?DeptID=" + DeptID.ToString() + "&DisplayType=1");
  267. }
  268. private void lbModifyDepartment_Click(object sender, System.EventArgs e)
  269. {
  270. Server.Transfer("ODepartment.aspx?DeptID=" + DeptID.ToString() + "&DisplayType=2");
  271. }
  272. private void lbMoveDepartment_Click(object sender, System.EventArgs e)
  273. {
  274. Server.Transfer("ODepartment.aspx?DeptID=" + DeptID.ToString() + "&DisplayType=3");
  275. }
  276. private void cmdMove_Click(object sender, System.EventArgs e)
  277. {
  278. UDS.Components.Department dept = new UDS.Components.Department();
  279. switch(dept.MoveDeparement(DeptID,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?DeptID="+DeptID+"&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?DeptID=" + DeptID.ToString());
  295. }
  296. }
  297. }