PageRenderTime 236ms CodeModel.GetById 23ms RepoModel.GetById 11ms app.codeStats 0ms

/website/control/ExamResultControl.ashx.cs

https://github.com/panmingzhi815/SchoolManagementSystem
C# | 196 lines | 181 code | 12 blank | 3 comment | 26 complexity | e509d5af2183033f132aed9eea42f3f0 MD5 | raw file
Possible License(s): LGPL-2.1
  1. using System;
  2. using System.Collections;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Services;
  7. using System.Web.Services.Protocols;
  8. using System.Xml.Linq;
  9. using DataService.service.dao;
  10. using Domain.Entities;
  11. using System.Collections.Generic;
  12. using Newtonsoft.Json;
  13. namespace Domain.control
  14. {
  15. /// <summary>
  16. /// Summary description for $codebehindclassname$
  17. /// </summary>
  18. [WebService(Namespace = "http://tempuri.org/")]
  19. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  20. public class ExamResultControl : IHttpHandler
  21. {
  22. public HttpContext context;
  23. public void ProcessRequest(HttpContext context)
  24. {
  25. this.context = context;
  26. context.Response.ContentType = "text/plain";
  27. string method = context.Request.Form.Get("method");
  28. if (method == null)
  29. {
  30. method = context.Request.QueryString["method"];
  31. }
  32. switch (method)
  33. {
  34. case "getColumn":
  35. getColumn();
  36. break;
  37. case "searchExamResult":
  38. searchExamResult();
  39. break;
  40. case "saveExamResult":
  41. saveExamResult();
  42. break;
  43. case "deleteExamResult":
  44. deleteExamResult();
  45. break;
  46. default:
  47. context.Response.Write("-1");
  48. break;
  49. }
  50. }
  51. private void deleteExamResult()
  52. {
  53. throw new NotImplementedException();
  54. }
  55. private void saveExamResult()
  56. {
  57. try{
  58. string[] keys = context.Request.Form.AllKeys;
  59. ExamResultService res = new ExamResultService();
  60. ExamResult er = res.getExamResultByID(context.Request.Form.Get("Id"));
  61. IDictionary<string, string> map = new Dictionary<string, string>();
  62. foreach (string s in keys)
  63. {
  64. if (!s.Equals("Id") && !s.Equals("StudentSN") && !s.Equals("StudentName") && !s.Equals("ExamPlanName")) {
  65. map.Add(s, context.Request.Form.Get(s));
  66. }
  67. }
  68. er.CouresScoreMap = map;
  69. res.save(er);
  70. context.Response.Write("1");
  71. }
  72. catch (Exception e)
  73. {
  74. context.Response.Write("0");
  75. }
  76. }
  77. public void getColumn() {
  78. DepartmentService ds = new DepartmentService();
  79. IList professionList = new ArrayList();
  80. string ProfessionID = context.Request.Form.Get("ProfessionID");
  81. string YearNo = context.Request.Form.Get("YearNo");
  82. string LevelNo = context.Request.Form.Get("LevelNo");
  83. if (!string.IsNullOrEmpty(ProfessionID))
  84. {
  85. Profession profession = ds.getProfessionByID(ProfessionID);
  86. professionList.Add(profession);
  87. }
  88. PlanService ps = new PlanService();
  89. object[] planObjArr = ps.searchPlan(professionList, YearNo, LevelNo,
  90. int.MaxValue, 1);
  91. if (planObjArr[1] != null)
  92. {
  93. IList<ExamPlan> examPlanList = (IList<ExamPlan>)planObjArr[1];
  94. if (examPlanList == null) return;
  95. ExamPlan ep = examPlanList.ElementAt(0);
  96. ArrayList newArrayList = new ArrayList();
  97. if (examPlanList.ElementAt(0).CouresSet == null) return;
  98. foreach (Coures c in examPlanList.ElementAt(0).CouresSet)
  99. {
  100. newArrayList.Add(c.Name);
  101. }
  102. newArrayList.Sort();
  103. IList<Hashtable> columnList = new List<Hashtable>();
  104. foreach (string s in newArrayList) {
  105. Hashtable ht = new Hashtable();
  106. ht.Add("columnName",s);
  107. columnList.Add(ht);
  108. }
  109. String json = JsonConvert.SerializeObject(columnList);
  110. context.Response.Write(json);
  111. }
  112. }
  113. private void searchExamResult()
  114. {
  115. DepartmentService ds = new DepartmentService();
  116. IList professionList = new ArrayList();
  117. string ProfessionID = context.Request.Form.Get("ProfessionID");
  118. string YearNo = context.Request.Form.Get("YearNo");
  119. string LevelNo = context.Request.Form.Get("LevelNo");
  120. if (!string.IsNullOrEmpty(ProfessionID))
  121. {
  122. Profession profession = ds.getProfessionByID(ProfessionID);
  123. professionList.Add(profession);
  124. }
  125. PlanService ps = new PlanService();
  126. object[] planObjArr = ps.searchPlan(professionList, YearNo, LevelNo,
  127. int.MaxValue, 1);
  128. if (planObjArr[1] != null)
  129. {
  130. IList<ExamPlan> examPlanList = (IList<ExamPlan>)planObjArr[1];
  131. if (examPlanList == null || examPlanList.Count == 0) return;
  132. ExamResultService ers = new ExamResultService();
  133. IList<ExamPlan> planList = new List<ExamPlan>();
  134. planList.Add(examPlanList[0]);
  135. object[] examResultObjArr = ers.searchExamResult(planList, int.MaxValue, 1);
  136. if (examResultObjArr[1] != null)
  137. {
  138. IList<ExamResult> examResultList = (IList<ExamResult>)examResultObjArr[1];
  139. IList<Hashtable> examRsultMapList = new List<Hashtable>();
  140. foreach (ExamResult er in examResultList)
  141. {
  142. Hashtable cht = new Hashtable();
  143. cht.Add("Id", er.Id);
  144. cht.Add("StudentSN", er.StudentSN);
  145. cht.Add("StudentName", er.StudentName);
  146. cht.Add("ExamPlanName", er.ExamPlanName);
  147. if (er.CouresScoreMap != null)
  148. {
  149. ArrayList newArrayList = new ArrayList();
  150. foreach (Coures c in planList.ElementAt(0).CouresSet)
  151. {
  152. newArrayList.Add(c.Name);
  153. }
  154. newArrayList.Sort();
  155. foreach (string key in newArrayList)
  156. {
  157. if (er.CouresScoreMap.ContainsKey(key)) {
  158. cht.Add(key, er.CouresScoreMap[key]);
  159. }
  160. }
  161. }
  162. examRsultMapList.Add(cht);
  163. }
  164. Hashtable ht = new Hashtable();
  165. ht.Add("total", examResultObjArr[0]);
  166. ht.Add("rows", examRsultMapList);
  167. String json = JsonConvert.SerializeObject(ht);
  168. context.Response.Write(json);
  169. }
  170. }
  171. }
  172. private void getExamResultByID()
  173. {
  174. throw new NotImplementedException();
  175. }
  176. public bool IsReusable
  177. {
  178. get
  179. {
  180. return false;
  181. }
  182. }
  183. }
  184. }