ManageProject.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.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. using UDS.Components;
  13. namespace UDS.SubModule.UnitiveDocument
  14. {
  15. /// <summary>
  16. /// ManagerProject 的摘要说明。
  17. /// </summary>
  18. public class ManagerProject : System.Web.UI.Page
  19. {
  20. public static string ClassID="";
  21. protected System.Web.UI.WebControls.Label lblCreate;
  22. protected System.Web.UI.WebControls.Label lblDelete;
  23. protected System.Web.UI.WebControls.Label lblRevise;
  24. protected System.Web.UI.WebControls.RequiredFieldValidator rfv1;
  25. protected System.Web.UI.WebControls.Button btnSubmit;
  26. protected System.Web.UI.HtmlControls.HtmlInputText txtClassName;
  27. protected System.Web.UI.HtmlControls.HtmlInputText txtScale;
  28. protected System.Web.UI.HtmlControls.HtmlTextArea txtBrief;
  29. protected System.Web.UI.WebControls.TextBox txtStartDate;
  30. protected System.Web.UI.WebControls.TextBox txtEndDate;
  31. protected System.Web.UI.WebControls.RequiredFieldValidator rfv2;
  32. protected System.Web.UI.WebControls.RequiredFieldValidator rfv3;
  33. protected System.Web.UI.WebControls.Button btnRevise;
  34. protected System.Web.UI.WebControls.Button btnDelete;
  35. protected System.Web.UI.WebControls.RadioButtonList Status;
  36. protected System.Web.UI.WebControls.RequiredFieldValidator rfv4;
  37. public string Action="";
  38. private void Page_Load(object sender, System.EventArgs e)
  39. {
  40. ClassID = (Request.QueryString["ClassID"]!=null)?Request.QueryString["ClassID"].ToString():"";
  41. Action  = (Request.QueryString["Action"]!=null)?Request.QueryString["Action"].ToString():"";
  42. if(!Page.IsPostBack)
  43. {
  44. PopulateRadioList();
  45. if(Action=="1")
  46. {
  47. this.lblCreate.BackColor = Color.FromName("#1ED2CA");
  48. this.btnRevise.Visible = false;
  49. this.btnDelete.Visible = false;
  50. }
  51. if(Action=="2")
  52. {
  53. UDS.Components .ProjectClass prj = new ProjectClass();
  54. this.lblDelete.BackColor = Color.FromName("#1ED2CA");
  55. this.btnRevise .Visible = false;
  56. this.btnDelete.Visible = true;
  57. this.btnSubmit .Visible = false;
  58. PopulateReviseData();
  59. if(ClassID!="1")
  60. {
  61. if(prj.IsExistSubClass(Int32.Parse(ClassID)))
  62. this.btnDelete.Attributes["onClick"] = "javascript:alert('此项目还存在子节点,不能删除!!');return false;";
  63. else
  64. this.btnDelete.Attributes["onClick"] = "javascript:return confirm('您确认吗?');";
  65. }
  66. else
  67. {
  68. this.btnDelete.Attributes["onClick"] = "javascript:alert('根节点不能被删除!');return false;";
  69. }
  70. }
  71. if(Action=="3")
  72. {
  73. this.lblRevise.BackColor = Color.FromName("#1ED2CA");
  74. this.btnSubmit.Visible = false;
  75. this.btnDelete .Visible = false;
  76. PopulateReviseData();
  77. }
  78.  }
  79. }
  80. #region 添加项目
  81. /// <summary>
  82. /// 添加项目
  83. /// </summary>
  84. private void AddProject() 
  85. {
  86. ProjectClass prj = new ProjectClass();
  87. HttpCookie UserCookie = Request.Cookies["Username"];
  88. String Username = UserCookie.Value.ToString();
  89. if(DateTime.Parse(this.txtStartDate.Text.ToString())>DateTime.Parse(this.txtEndDate.Text.ToString()))
  90. {
  91. Response.Write("<script language=javascript>alert('开始时间不能大于结束时间!');</script>");
  92. }
  93. else
  94. {
  95. try
  96. {
  97. prj.Add(Int32.Parse(ClassID),this.txtClassName.Value.ToString(),this.txtBrief.Value.ToString(),
  98. Username,Int32.Parse(this.Status.SelectedIndex.ToString()),Int32.Parse(this.txtScale.Value.ToString()),
  99. DateTime.Parse(this.txtStartDate.Text.ToString()),DateTime.Parse(this.txtEndDate.Text.ToString()));
  100. prj = null;
  101. Response.Write("<script language=javascript>alert('添加成功!');parent.LeftFrame.location='ProjectTreeView.aspx?classID="+ClassID+"';</script>");
  102. }
  103. catch(Exception ex)
  104. {
  105. UDS.Components.Error.Log(ex.ToString());
  106. Server.Transfer("../Error.aspx");
  107. }
  108. }
  109. }
  110. #endregion
  111. #region 修改项目
  112. /// <summary>
  113. /// 修改项目
  114. /// </summary>
  115. private void ReviseProject() 
  116. {
  117. ProjectClass prj = new ProjectClass();
  118. HttpCookie UserCookie = Request.Cookies["Username"];
  119. String Username = UserCookie.Value.ToString();
  120. if(DateTime.Parse(this.txtStartDate.Text.ToString())>DateTime.Parse(this.txtEndDate.Text.ToString()))
  121. {
  122. Response.Write("<script language=javascript>alert('开始时间不能大于结束时间!');</script>");
  123. }
  124. else
  125. {
  126. try
  127. {
  128. prj.Revise(Int32.Parse(ClassID),this.txtClassName.Value.ToString(),this.txtBrief.Value.ToString(),
  129. Int32.Parse(this.Status.SelectedIndex.ToString()),Int32.Parse(this.txtScale.Value.ToString()),
  130. DateTime.Parse(this.txtStartDate.Text.ToString()),DateTime.Parse(this.txtEndDate.Text.ToString()));
  131. prj = null;
  132. Response.Write("<script language=javascript>alert('修改成功!');parent.LeftFrame.location='ProjectTreeView.aspx?classID="+ClassID+"';</script>");
  133. }
  134. catch(Exception ex)
  135. {
  136. UDS.Components.Error.Log(ex.ToString());
  137. Server.Transfer("../Error.aspx");
  138. }
  139. }
  140. }
  141. #endregion
  142. #region 删除项目
  143. /// <summary>
  144. /// 删除项目
  145. /// </summary>
  146. private void DeleteProject() 
  147. {
  148. ProjectClass prj = new ProjectClass();
  149. HttpCookie UserCookie = Request.Cookies["Username"];
  150. String Username = UserCookie.Value.ToString();
  151. try
  152. {
  153. prj.Delete(Int32.Parse(ClassID));
  154. prj = null;
  155. Response.Write("<script language=javascript>alert('删除成功!');parent.location.reload();</script>");
  156. }
  157. catch(Exception ex)
  158. {
  159. UDS.Components.Error.Log(ex.ToString());
  160. Server.Transfer("../Error.aspx");
  161. }
  162. }
  163. #endregion
  164. #region 绑定修改时数据
  165. /// <summary>
  166. /// 绑定修改时数据
  167. /// </summary>
  168. private void PopulateReviseData() 
  169. {
  170. SqlDataReader dataReader = null; 
  171. ProjectClass prj = new ProjectClass();
  172. try
  173. {
  174.                 dataReader = prj.GetProjectDetail(Int32.Parse(ClassID));
  175. dataReader.Read();
  176. this.txtClassName.Value = dataReader[0].ToString();
  177. this.txtBrief.Value     = dataReader[7].ToString();
  178. this.txtScale .Value    = dataReader[6].ToString();
  179. this.txtStartDate.Text  = ProjectClass.changeString(dataReader[3].ToString());
  180. this.txtEndDate.Text    = ProjectClass.changeString(dataReader[4].ToString());
  181. this.Status.SelectedIndex = Int32.Parse(dataReader[5].ToString());
  182. prj = null;
  183. dataReader = null;
  184. }
  185. catch(Exception ex)
  186. {
  187. UDS.Components.Error.Log(ex.ToString());
  188. Server.Transfer("../Error.aspx");
  189. }
  190. }
  191. #endregion
  192. #region 初始化单选框
  193. /// <summary>
  194. /// 对单选框进行初始化
  195. /// </summary>
  196. private void PopulateRadioList() 
  197. {
  198. this.Status.Items.Add(new ListItem("运行中","1"));
  199. this.Status.Items.Add(new ListItem("等待运行","2"));
  200. this.Status.Items.Add(new ListItem("挂起","3"));
  201. this.Status.Items.Add(new ListItem("取消","4"));
  202. this.Status.Items.Add(new ListItem("完成","5"));
  203. this.Status.SelectedIndex = 0;
  204. }
  205. #endregion
  206. #region Web Form Designer generated code
  207. override protected void OnInit(EventArgs e)
  208. {
  209. //
  210. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  211. //
  212. InitializeComponent();
  213. base.OnInit(e);
  214. }
  215. /// <summary>
  216. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  217. /// 此方法的内容。
  218. /// </summary>
  219. private void InitializeComponent()
  220. {    
  221. this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
  222. this.btnRevise.Click += new System.EventHandler(this.btnRevise_Click);
  223. this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
  224. this.Load += new System.EventHandler(this.Page_Load);
  225. }
  226. #endregion
  227. private void btnSubmit_Click(object sender, System.EventArgs e)
  228. {
  229. AddProject();
  230. }
  231. private void btnRevise_Click(object sender, System.EventArgs e)
  232. {
  233. ReviseProject();
  234. }
  235. private void btnDelete_Click(object sender, System.EventArgs e)
  236. {
  237. DeleteProject();
  238. }
  239. }
  240. }