PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Web/Information/ComputerEdit.aspx.cs

#
C# | 260 lines | 217 code | 35 blank | 8 comment | 36 complexity | 2b07baf35488087d58080935c0728e97 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using GMS.BIZ;
  8. using System.Collections;
  9. namespace Web.Information
  10. {
  11. public partial class WebForm6 : System.Web.UI.Page
  12. {
  13. protected void Page_LoadComplete(object sender, EventArgs e)
  14. {
  15. if (!((Account)Session["Account"]).RoleCurrent.Equals('s')) Response.Redirect("Default.aspx");
  16. //初始化学生计算机能力信息
  17. Student myStudent = (Student)Session["Student"];
  18. if (myStudent.StudentName == "")
  19. Response.Redirect("StuInformation.aspx");
  20. GridView_Computer.DataSource = myStudent.Computers.GetDataSet();
  21. GridView_Computer.DataBind();
  22. //绑定DropDownList数据
  23. if (!IsPostBack)
  24. {
  25. ArrayList arraylist = new ArrayList();
  26. arraylist = Library.GetComputerLib();
  27. for (int i = 0; i < arraylist.Count; i++)
  28. {
  29. ListItem myListItem = new ListItem();
  30. myListItem = (ListItem)arraylist[i];
  31. DropDownList_computerlevel.Items.Add(myListItem);
  32. }
  33. ListItem otherListItem=new ListItem();
  34. otherListItem.Text="其它";
  35. otherListItem.Value="others";
  36. DropDownList_computerlevel.Items.Add(otherListItem);
  37. }
  38. if (DropDownList_computerlevel.SelectedValue == "others")
  39. {
  40. Label_nolist.Visible = true;
  41. TextBox_nolist.Visible = true;
  42. RequiredFieldValidator_nolist.Enabled = true;
  43. }
  44. else
  45. {
  46. Label_nolist.Visible = false;
  47. TextBox_nolist.Visible = false;
  48. RequiredFieldValidator_nolist.Enabled = false;
  49. }
  50. #region ViewState
  51. //初始化ViewState
  52. if (ViewState["status"] == null)
  53. ViewState["status"] = 1;
  54. this.ViewStateControls(int.Parse(ViewState["status"].ToString()));
  55. #endregion ViewState
  56. }
  57. protected void ViewStateControls(int i)
  58. {
  59. if (i == 1)//添加
  60. {
  61. ImageButton_Cancel.Visible = false;
  62. ImageButton_Add.Visible = true;
  63. ImageButton_Edit.Visible = false;
  64. ImageButton_Delete.Visible = false;
  65. }
  66. else if (i == 2)//修改
  67. {
  68. ImageButton_Cancel.Visible = true;
  69. ImageButton_Add.Visible = false;
  70. ImageButton_Edit.Visible = true;
  71. ImageButton_Delete.Visible = false;
  72. }
  73. else if (i == 3) //删除
  74. {
  75. ImageButton_Cancel.Visible = true;
  76. ImageButton_Add.Visible = false;
  77. ImageButton_Edit.Visible = false;
  78. ImageButton_Delete.Visible = true;
  79. }
  80. }
  81. //GridView的修改按钮
  82. protected void GridViewButton_Edit_Click(object sender, ImageClickEventArgs e)
  83. {
  84. Computer myComputer = new Computer();
  85. Student myStudent = (Student)Session["Student"];
  86. myComputer = myStudent.Computers.GetOne(decimal.Parse(((ImageButton)sender).CommandArgument));
  87. Label_ComputerID.Text = myComputer.id.ToString();
  88. TextBox_computertime.Text = ((DateTime)myComputer.computer_time).ToShortDateString();
  89. ViewState["status"] = 2;
  90. Label_result.Text = "";
  91. Label_nolist.Visible = false;
  92. TextBox_nolist.Visible = false;
  93. TextBox_nolist.Text = "";
  94. Label_EditInformation2.Text = myComputer.computer_level +" "+ ((DateTime)myComputer.computer_time).ToShortDateString();
  95. }
  96. //GridView的删除按钮
  97. protected void GridViewButton_Delete_Click(object sender, ImageClickEventArgs e)
  98. {
  99. Computer myComputer = new Computer();
  100. Student myStudent = (Student)Session["Student"];
  101. myComputer = myStudent.Computers.GetOne(decimal.Parse(((ImageButton)sender).CommandArgument));
  102. Label_ComputerID.Text = myComputer.id.ToString();
  103. TextBox_computertime.Text = ((DateTime)myComputer.computer_time).ToShortDateString();
  104. ViewState["status"] = 3;
  105. Label_result.Text = "";
  106. Label_nolist.Visible = false;
  107. TextBox_nolist.Visible = false;
  108. TextBox_nolist.Text = "";
  109. Label_EditInformation2.Text = myComputer.computer_level + " "+((DateTime)myComputer.computer_time).ToShortDateString();
  110. }
  111. //修改按钮
  112. protected void ImageButton_Edit_Click(object sender, ImageClickEventArgs e)
  113. {
  114. Computer myComputer = new Computer();
  115. Student myStudent1 = (Student)Session["Student"];
  116. myComputer.id = decimal.Parse(Label_ComputerID.Text.ToString());
  117. if (TextBox_nolist.Text == null || TextBox_nolist.Text == string.Empty)
  118. myComputer.computer_level = DropDownList_computerlevel.SelectedValue;
  119. else
  120. {
  121. myComputer.computer_level = TextBox_nolist.Text.ToString();
  122. }
  123. try
  124. {
  125. myComputer.computer_time = (DateTime.Parse(TextBox_computertime.Text.ToString()));
  126. string str = myStudent1.Computers.Update(myComputer);
  127. if (str.CompareTo(Resources.ErrorMessage.OK) == 0)
  128. {
  129. Label_result.Text = Resources.ErrorMessage.OK;
  130. Student myStudent2 = (Student)Session["Student"];
  131. GridView_Computer.DataSource = myStudent2.Computers.GetDataSet();
  132. GridView_Computer.DataBind();
  133. }
  134. else Label_result.Text = Resources.ErrorMessage.DBOptError;
  135. ViewState["status"] = 1;
  136. Label_nolist.Visible = false;
  137. TextBox_nolist.Visible = false;
  138. TextBox_nolist.Text = "";
  139. Label_EditInformation2.Text = "";
  140. }
  141. catch
  142. {
  143. Label_result.Text = "输入时间格式不正确";
  144. }
  145. }
  146. //删除按钮
  147. protected void ImageButton_Delete_Click(object sender, ImageClickEventArgs e)
  148. {
  149. Computer myComputer = new Computer();
  150. Student myStudent1 = (Student)Session["Student"];
  151. string str = myStudent1.Computers.Delete(decimal.Parse(Label_ComputerID.Text.ToString()));
  152. if (str.CompareTo(Resources.ErrorMessage.OK) == 0)
  153. {
  154. Label_result.Text = Resources.ErrorMessage.OK;
  155. Student myStudent2 = (Student)Session["Student"];
  156. GridView_Computer.DataSource = myStudent2.Computers.GetDataSet();
  157. GridView_Computer.DataBind();
  158. }
  159. else Label_result.Text = Resources.ErrorMessage.DBOptError;
  160. ViewState["status"] = 1;
  161. Label_nolist.Visible = false;
  162. TextBox_nolist.Visible = false;
  163. TextBox_nolist.Text = "";
  164. Label_EditInformation2.Text = "";
  165. }
  166. //添加按钮
  167. protected void ImageButton_Add_Click(object sender, ImageClickEventArgs e)
  168. {
  169. Computer myComputer = new Computer();
  170. Student myStudent1 = (Student)Session["Student"];
  171. if (TextBox_nolist.Text == null || TextBox_nolist.Text == string.Empty)
  172. myComputer.computer_level = DropDownList_computerlevel.SelectedValue;
  173. else
  174. {
  175. myComputer.computer_level = TextBox_nolist.Text.ToString();
  176. }
  177. try
  178. {
  179. myComputer.computer_time = DateTime.Parse(TextBox_computertime.Text.ToString());
  180. string str = myStudent1.Computers.Add(myComputer);
  181. if (str.CompareTo(Resources.ErrorMessage.OK) == 0)
  182. {
  183. Label_result.Text = Resources.ErrorMessage.OK;
  184. Student myStudent2 = (Student)Session["Student"];
  185. GridView_Computer.DataSource = myStudent2.Computers.GetDataSet();
  186. GridView_Computer.DataBind();
  187. }
  188. else Label_result.Text = Resources.ErrorMessage.DBOptError;
  189. ViewState["status"] = 1;
  190. Label_nolist.Visible = false;
  191. TextBox_nolist.Visible = false;
  192. TextBox_nolist.Text = "";
  193. Label_EditInformation2.Text = "";
  194. }
  195. catch
  196. {
  197. Label_result.Text = "输入时间格式不正确";
  198. }
  199. }
  200. protected void ImageButton_Cancel_Click(object sender, ImageClickEventArgs e)
  201. {
  202. TextBox_computertime.Text = null;
  203. ViewState["status"] = 1;
  204. Label_nolist.Visible = false;
  205. TextBox_nolist.Visible = false;
  206. TextBox_nolist.Text = "";
  207. Label_EditInformation2.Text = "";
  208. }
  209. protected void DropDownList_computerlevel_SelectedIndexChanged(object sender, EventArgs e)
  210. {
  211. if (DropDownList_computerlevel.SelectedValue == "others")
  212. {
  213. Label_nolist.Visible = true;
  214. TextBox_nolist.Visible = true;
  215. RequiredFieldValidator_nolist.Enabled = true;
  216. }
  217. else
  218. {
  219. Label_nolist.Visible = false;
  220. TextBox_nolist.Visible = false;
  221. RequiredFieldValidator_nolist.Enabled = false;
  222. }
  223. }
  224. }
  225. }