PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/website/control/PlanControl.ashx.cs

https://github.com/panmingzhi815/SchoolManagementSystem
C# | 257 lines | 235 code | 19 blank | 3 comment | 24 complexity | 17e143caecc96fd39744e23556977533 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 Domain.Entities;
  10. using DataService.service.dao;
  11. using NHibernate.Mapping;
  12. using Iesi.Collections.Generic;
  13. using System.Reflection;
  14. using Newtonsoft.Json;
  15. using System.Collections.Generic;
  16. namespace Domain.control
  17. {
  18. /// <summary>
  19. /// Summary description for $codebehindclassname$
  20. /// </summary>
  21. [WebService(Namespace = "http://tempuri.org/")]
  22. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  23. public class PlanControl : IHttpHandler
  24. {
  25. public HttpContext context;
  26. public void ProcessRequest(HttpContext context)
  27. {
  28. this.context = context;
  29. context.Response.ContentType = "text/plain";
  30. string method = context.Request.Form.Get("method");
  31. if (method == null)
  32. {
  33. method = context.Request.QueryString["method"];
  34. }
  35. switch (method)
  36. {
  37. case "getPlanByID":
  38. getPlanByID();
  39. break;
  40. case "searchPlan":
  41. searchPlan();
  42. break;
  43. case "savePlan":
  44. saveCoures();
  45. break;
  46. case "deleteExamPlan":
  47. deleteExamPlan();
  48. break;
  49. case "initStudentResult":
  50. initStudentResult();
  51. break;
  52. default:
  53. context.Response.Write("-1");
  54. break;
  55. }
  56. }
  57. private void initStudentResult()
  58. {
  59. try
  60. {
  61. string ExamPlanID = context.Request.Form.Get("ExamPlanID");
  62. PlanService planService = new PlanService();
  63. ExamPlan examPlan = planService.getExamPlanByID(ExamPlanID);
  64. IList<ExamPlan> examPlanList = new List<ExamPlan>();
  65. examPlanList.Add(examPlan);
  66. ExamResultService ers = new ExamResultService();
  67. object[] obj = ers.searchExamResult(examPlanList, int.MaxValue, 1);
  68. if (obj[1] != null) {
  69. IList<ExamResult> examResultList = (IList<ExamResult>)obj[1];
  70. foreach (ExamResult er in examResultList)
  71. {
  72. ers.del(er);
  73. }
  74. }
  75. Student student = new Student();
  76. IList<Profession> professionList = new List<Profession>();
  77. professionList.Add(examPlan.Profession);
  78. student.ProfessionList = professionList;
  79. StudentService ss = new StudentService();
  80. object[] studentObjArr = ss.getStudentList(student, int.MaxValue, 1);
  81. if (studentObjArr[1] != null)
  82. {
  83. IList<Student> studentList = (IList<Student>)studentObjArr[1];
  84. foreach (Student s in studentList)
  85. {
  86. ExamResult examResult = new ExamResult();
  87. examResult.ExamPlan = examPlan;
  88. examResult.Student = s;
  89. ers.save(examPlan);
  90. IDictionary<string,string> map = new Dictionary<string,string>();
  91. foreach (Coures c in examPlan.CouresSet)
  92. {
  93. map.Add(c.Name, "0");
  94. }
  95. examResult.CouresScoreMap = map;
  96. ers.save(examResult);
  97. }
  98. }
  99. context.Response.Write("1");
  100. }
  101. catch (Exception e)
  102. {
  103. context.Response.Write("0");
  104. }
  105. }
  106. private void deleteExamPlan()
  107. {
  108. try
  109. {
  110. string ExamPlanID = context.Request.Form.Get("ExamPlanID");
  111. PlanService planService = new PlanService();
  112. ExamPlan examPlan = planService.getExamPlanByID(ExamPlanID);
  113. examPlan.CouresSet = null;
  114. planService.save(examPlan);
  115. planService.del(examPlan);
  116. context.Response.Write("1");
  117. }
  118. catch (Exception e)
  119. {
  120. context.Response.Write("0");
  121. }
  122. }
  123. private void saveCoures()
  124. {
  125. try
  126. {
  127. string ProfessionID = context.Request.Form.Get("Profession");
  128. string FacultyID = context.Request.Form.Get("Faculty");
  129. DepartmentService ds = new DepartmentService();
  130. Profession profession = ds.getProfessionByID(ProfessionID);
  131. Faculty faculty = ds.getFacultyByID(FacultyID);
  132. if (profession != null && faculty != null)
  133. {
  134. ISet<Coures> couresSet = new HashedSet<Coures>();
  135. string[] couresArr = context.Request.Form.GetValues("Coures");
  136. CouresService cs = new CouresService();
  137. foreach (string c in couresArr) {
  138. Coures coures = cs.getCouresByID(c);
  139. if (coures != null)
  140. couresSet.Add(coures);
  141. }
  142. ExamPlan p = new ExamPlan();
  143. setValue(p, context);
  144. p.Profession = profession;
  145. p.Faculty = faculty;
  146. p.CouresSet = couresSet;
  147. PlanService ps = new PlanService();
  148. ps.save(p);
  149. context.Response.Write("1");
  150. }
  151. }
  152. catch (Exception e)
  153. {
  154. context.Response.Write("0");
  155. }
  156. }
  157. private void searchPlan()
  158. {
  159. try
  160. {
  161. PlanService planService = new PlanService();
  162. DepartmentService ds = new DepartmentService();
  163. IList professionList = new ArrayList();
  164. string ProfessionID = context.Request.Form.Get("ProfessionID");
  165. string YearNo = context.Request.Form.Get("YearNo");
  166. string LevelNo = context.Request.Form.Get("LevelNo");
  167. if (!string.IsNullOrEmpty(ProfessionID)) {
  168. Profession profession = ds.getProfessionByID(ProfessionID);
  169. professionList.Add(profession);
  170. }
  171. int rows = Convert.ToInt32(context.Request.Form["rows"]);
  172. int page = Convert.ToInt32(context.Request.Form["page"]);
  173. object[] data = planService.searchPlan(professionList, YearNo, LevelNo, rows, page);
  174. Hashtable ht = new Hashtable();
  175. ht.Add("total", data[0]);
  176. ht.Add("rows", data[1]);
  177. String json = JsonConvert.SerializeObject(ht);
  178. context.Response.Write(json);
  179. }
  180. catch (Exception e) {
  181. context.Response.Write("0");
  182. }
  183. }
  184. private void getPlanByID()
  185. {
  186. try
  187. {
  188. string ExamPlanID = context.Request.Form.Get("ExamPlanID");
  189. PlanService planService = new PlanService();
  190. ExamPlan examPlan = planService.getExamPlanByID(ExamPlanID);
  191. String json = JsonConvert.SerializeObject(examPlan);
  192. context.Response.Write(json);
  193. }
  194. catch (Exception e) {
  195. context.Response.Write("0");
  196. }
  197. }
  198. public bool IsReusable
  199. {
  200. get
  201. {
  202. return false;
  203. }
  204. }
  205. public Object setValue(Object o, HttpContext context)
  206. {
  207. string[] keys = context.Request.Form.AllKeys;
  208. foreach (string s in keys)
  209. {
  210. try
  211. {
  212. PropertyInfo property = o.GetType().GetProperty(s);
  213. if (property == null)
  214. {
  215. continue;
  216. }
  217. if (property.PropertyType == typeof(DateTime))
  218. {
  219. property.SetValue(o, Convert.ToDateTime(context.Request.Form.Get(s)), null);
  220. }
  221. else if (property.PropertyType == typeof(string))
  222. {
  223. property.SetValue(o, context.Request.Form.Get(s), null);
  224. }
  225. else if (property.PropertyType == typeof(int))
  226. {
  227. property.SetValue(o, Convert.ToInt32(context.Request.Form.Get(s)), null);
  228. }
  229. }
  230. catch (Exception e)
  231. {
  232. Console.Write(e.Message);
  233. }
  234. }
  235. return o;
  236. }
  237. }
  238. }