ExaminationSubjectController.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.ViewModel.ExaminationApply;
  7. using EMIS.CommonLogic.ExaminationApply;
  8. using EMIS.ViewModel;
  9. using EMIS.Web.Controls;
  10. using Bowin.Common.Data;
  11. using Bowin.Common.Utility;
  12. using Bowin.Common.Exceptions;
  13. using Bowin.Web.Controls.Mvc;
  14. namespace EMIS.Web.Controllers.ExaminationApply
  15. {
  16. [Authorization]
  17. public class ExaminationSubjectController : Controller
  18. {
  19. public IExaminationSubjectServices ExaminationSubjectServices { get; set; }
  20. /// <summary>
  21. /// 考试科目页面
  22. /// </summary>
  23. /// <returns></returns>
  24. public ActionResult List()
  25. {
  26. return View();
  27. }
  28. public ActionResult Edit(Guid? ExaminationSubjectID)
  29. {
  30. ExaminationSubjectView examinationSubjectView = new ExaminationSubjectView();
  31. if (ExaminationSubjectID != null && ExaminationSubjectID != Guid.Empty)
  32. {
  33. examinationSubjectView = ExaminationSubjectServices.GetExaminationSubjectViewInfo(ExaminationSubjectID);
  34. }
  35. ViewBag.ID = ExaminationSubjectID;
  36. return View(examinationSubjectView);
  37. }
  38. /// <summary>
  39. /// 列表查询
  40. /// </summary>
  41. /// <param name="pararms"></param>
  42. /// <returns></returns>
  43. [HttpPost]
  44. public ActionResult List(QueryParamsModel pararms)
  45. {
  46. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  47. var examinationTypeID = pararms.getExtraGuid("ExaminationTypeDropdown");
  48. var schoolYearID = pararms.getExtraGuid("SchoolYearDropdown");
  49. var examinationSubjectID = pararms.getExtraGuid("ExaminationSubjectDropdown");
  50. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  51. return base.Json(ExaminationSubjectServices.GetExaminationSubjectViewList(configuretView, examinationTypeID,examinationSubjectID,schoolYearID, (int)pararms.page, (int)pararms.rows));
  52. }
  53. [HttpPost]
  54. public ActionResult Excel()
  55. {
  56. NpoiExcelHelper neh = new NpoiExcelHelper();
  57. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  58. var examinationTypeID = Request.Form["ExaminationTypeDropdown"].ParseStrTo<Guid>();
  59. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  60. var dt = ExaminationSubjectServices.GetExaminationSubjectViewList(configuretView, examinationTypeID, null).Select(x => new
  61. {
  62. x.Name,
  63. ExaminationDate = (x.ExaminationDate.HasValue ? x.ExaminationDate.Value.ToString("yyyy-MM-dd") : ""),
  64. x.ExaminationTypeName,
  65. x.ExaminationFormName,
  66. x.PeopleNumLimit,
  67. x.SchoolyearCode
  68. }).ToTable();
  69. string[] liststring = { "考试科目", "考试日期", "考试类型", "考试类别", "最大报名人数", "考试学年学期" };
  70. neh.Export(dt, liststring, "考试科目信息");
  71. return RedirectToAction("MsgShow", "Common", new
  72. {
  73. msg = "导出成功!",
  74. url = Url.Content("~/ExaminationSubject/List").AddMenuParameter()
  75. });
  76. }
  77. /// <summary>
  78. /// 删除
  79. /// </summary>
  80. /// <param name="roleID"></param>
  81. /// <returns></returns>
  82. [HttpPost]
  83. public ActionResult Delete(string examinationSubjectIDs)
  84. {
  85. try
  86. {
  87. var examinationSubjectIDList = examinationSubjectIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
  88. ExaminationSubjectServices.Delete(examinationSubjectIDList);
  89. return base.Json("删除成功");
  90. }
  91. catch (Exception ex)
  92. {
  93. string mge = ex.Message;
  94. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  95. if (num != null)
  96. {
  97. if (num.Number == 547)
  98. mge = "请先删除所有关联的数据,如:要求通过科目为该考试科目的数据、或者考场安排等";
  99. }
  100. return base.Json("删除失败,原因:" + mge + "!");
  101. }
  102. }
  103. /// <summary>
  104. /// 修改
  105. /// </summary>
  106. /// <returns></returns>
  107. [HttpPost]
  108. public ActionResult Edit(ExaminationSubjectView examinationSubjectView)
  109. {
  110. try
  111. {
  112. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  113. ExaminationSubjectServices.Save(examinationSubjectView);
  114. return Json(new ReturnMessage()
  115. {
  116. IsSuccess = true,
  117. Message = "保存成功!"
  118. });
  119. }
  120. catch (Exception ex)
  121. {
  122. return Json(new ReturnMessage()
  123. {
  124. IsSuccess = false,
  125. Message = "保存失败:" + ex.Message
  126. });
  127. }
  128. }
  129. [HttpPost]
  130. public ActionResult DropdownList(DropdownListBindType? bindType, Guid? examinationTypeID,Guid? examinationSubjectID)
  131. {
  132. List<DropdownListItem> list = ExaminationSubjectServices.GetExaminationSubjectViewList(new ConfiguretView(), examinationTypeID, examinationSubjectID)
  133. .Select(x => new DropdownListItem { Text = x.Name, Value = x.ExaminationSubjectID.ToString() }).ToList();
  134. DropdownListBindType dbt = bindType == null ? DropdownListBindType.PleaseSelect : bindType.Value;
  135. Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, list);
  136. return base.Json(list);
  137. }
  138. [HttpPost]
  139. public ActionResult DropdownExaminationSubjectNameList(QueryParamsModel pararms)
  140. {
  141. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  142. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  143. var list = ExaminationSubjectServices.GetExaminationSubjectNameViewList(configuretView, (int)pararms.page, (int)pararms.rows);
  144. return base.Json(list);
  145. }
  146. public ActionResult Validation(string ExaminationTypeIDs, string SchoolyearIDs,string ExaminationFormIDs, string names)
  147. {
  148. List<Guid?> list = new List<Guid?>();
  149. foreach (var i in ExaminationTypeIDs.Split(','))
  150. {
  151. list.Add(new Guid(i));
  152. }
  153. List<Guid?> list1 = new List<Guid?>();
  154. foreach (var i in SchoolyearIDs.Split(','))
  155. {
  156. list1.Add(new Guid(i));
  157. }
  158. List<int?> list2 = new List<int?>();
  159. foreach (var i in ExaminationFormIDs.Split(','))
  160. {
  161. list2.Add(Convert.ToInt32(i));
  162. }
  163. List<string> list3 = new List<string>();
  164. foreach (var i in names.Split(','))
  165. {
  166. list3.Add(i);
  167. }
  168. string[] result = ExaminationSubjectServices.Validation(list, list1, list2, list3);
  169. return Json(new ReturnMessage()
  170. {
  171. IsSuccess = result[0] == "true" ? true : false,
  172. Message = result[1]
  173. });
  174. }
  175. }
  176. }