PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/website/control/CouresControl.ashx.cs

https://github.com/panmingzhi815/SchoolManagementSystem
C# | 179 lines | 167 code | 9 blank | 3 comment | 17 complexity | ad41a8f2bac89dd7a47f876b74720e78 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 System.Reflection;
  10. using DataService.service.dao;
  11. using Domain.Entities;
  12. using Iesi.Collections;
  13. using System.Collections.Generic;
  14. using Newtonsoft.Json;
  15. namespace Domain.control
  16. {
  17. /// <summary>
  18. /// Summary description for $codebehindclassname$
  19. /// </summary>
  20. [WebService(Namespace = "http://tempuri.org/")]
  21. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  22. public class CouresControl : IHttpHandler
  23. {
  24. public HttpContext context;
  25. public void ProcessRequest(HttpContext context)
  26. {
  27. this.context = context;
  28. context.Response.ContentType = "text/plain";
  29. string method = context.Request.Form.Get("method");
  30. if (method == null)
  31. {
  32. method = context.Request.QueryString["method"];
  33. }
  34. switch (method)
  35. {
  36. case "getCouresByID":
  37. getCouresByID();
  38. break;
  39. case "searchCoures":
  40. searchCoures();
  41. break;
  42. case "saveCoures":
  43. saveCoures();
  44. break;
  45. case "deleteCoures":
  46. deleteCoures();
  47. break;
  48. default:
  49. context.Response.Write("-1");
  50. break;
  51. }
  52. }
  53. private void deleteCoures()
  54. {
  55. try
  56. {
  57. string CouresID = context.Request.Form.Get("CouresID");
  58. CouresService cs = new CouresService();
  59. cs.del(cs.getCouresByID(CouresID));
  60. context.Response.Write("1");
  61. }
  62. catch (Exception e)
  63. {
  64. context.Response.Write("0");
  65. }
  66. }
  67. private void saveCoures()
  68. {
  69. try
  70. {
  71. string professionID = context.Request.Form.Get("profession");
  72. DepartmentService ds = new DepartmentService();
  73. Profession profession = ds.getProfessionByID(professionID);
  74. if (profession != null)
  75. {
  76. Coures c = new Coures();
  77. setValue(c, context);
  78. c.Profession = profession;
  79. ds.save(c);
  80. context.Response.Write("1");
  81. }
  82. }
  83. catch (Exception e) {
  84. context.Response.Write("0");
  85. }
  86. }
  87. private void searchCoures()
  88. {
  89. System.Collections.IList professionList = new ArrayList();
  90. string FacultyID = context.Request.Form.Get("FacultyID");
  91. string ProfessionID = context.Request.Form.Get("ProfessionID");
  92. string YearNo = context.Request.Form.Get("YearNo");
  93. string LevelNo = context.Request.Form.Get("LevelNo");
  94. if (!string.IsNullOrEmpty(ProfessionID)) {
  95. DepartmentService ds = new DepartmentService();
  96. Profession p = ds.getProfessionByID(ProfessionID);
  97. professionList.Add(p);
  98. }else if(!string.IsNullOrEmpty(FacultyID)){
  99. DepartmentService ds = new DepartmentService();
  100. Iesi.Collections.Generic.ISet<Profession> iset = ds.getProfessionSet(FacultyID);
  101. foreach(Profession pf in iset){
  102. professionList.Add(pf);
  103. }
  104. }
  105. CouresService cs = new CouresService();
  106. int rows = Convert.ToInt32(context.Request.Form["rows"]);
  107. int page = Convert.ToInt32(context.Request.Form["page"]);
  108. object[] data = cs.searchCoures(professionList, YearNo, LevelNo, rows, page);
  109. Hashtable ht = new Hashtable();
  110. ht.Add("total", data[0]);
  111. ht.Add("rows", data[1]);
  112. String json = JsonConvert.SerializeObject(ht);
  113. context.Response.Write(json);
  114. }
  115. private void getCouresByID()
  116. {
  117. try
  118. {
  119. string CouresID = context.Request.Form.Get("CouresID");
  120. CouresService cs = new CouresService();
  121. Coures coures = cs.getCouresByID(CouresID);
  122. String json = JsonConvert.SerializeObject(coures);
  123. context.Response.Write(json);
  124. }
  125. catch (Exception e)
  126. {
  127. context.Response.Write("0");
  128. }
  129. }
  130. public Object setValue(Object o, HttpContext context)
  131. {
  132. string[] keys = context.Request.Form.AllKeys;
  133. foreach (string s in keys)
  134. {
  135. try
  136. {
  137. PropertyInfo property = o.GetType().GetProperty(s);
  138. if (property == null)
  139. {
  140. continue;
  141. }
  142. if (property.PropertyType == typeof(DateTime))
  143. {
  144. property.SetValue(o, Convert.ToDateTime(context.Request.Form.Get(s)), null);
  145. }
  146. else if (property.PropertyType == typeof(string))
  147. {
  148. property.SetValue(o, context.Request.Form.Get(s), null);
  149. }
  150. else if (property.PropertyType == typeof(int))
  151. {
  152. property.SetValue(o, Convert.ToInt32(context.Request.Form.Get(s)), null);
  153. }
  154. }
  155. catch (Exception e)
  156. {
  157. Console.Write(e.Message);
  158. }
  159. }
  160. return o;
  161. }
  162. public bool IsReusable
  163. {
  164. get
  165. {
  166. return false;
  167. }
  168. }
  169. }
  170. }