ExaminationSubjectsController.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 ExaminationSubjectsController : Controller
  18. {
  19. public IExaminationSubjectsServices ExaminationSubjectServices { get; set; }
  20. //
  21. // GET: /ExaminationSubjects/
  22. public ActionResult List()
  23. {
  24. return View();
  25. }
  26. /// <summary>
  27. /// 列表查询
  28. /// </summary>
  29. /// <param name="pararms"></param>
  30. /// <returns></returns>
  31. [HttpPost]
  32. public ActionResult List(QueryParamsModel pararms)
  33. {
  34. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  35. var examinationFormID = pararms.getExtraInt("ExaminationFormDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ExaminationFormDropdown"); ;
  36. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  37. return base.Json(ExaminationSubjectServices.GetExaminationSubjectViewList(configuretView, examinationFormID, (int)pararms.page, (int)pararms.rows));
  38. }
  39. public ActionResult Edit(Guid? ExaminationSubjectID)
  40. {
  41. ExaminationSubjectView examinationSubjectView = new ExaminationSubjectView();
  42. if (ExaminationSubjectID != null && ExaminationSubjectID != Guid.Empty)
  43. {
  44. examinationSubjectView = ExaminationSubjectServices.GetExaminationSubjectViewInfo(ExaminationSubjectID);
  45. }
  46. ViewBag.ID = ExaminationSubjectID;
  47. return View(examinationSubjectView);
  48. }
  49. /// <summary>
  50. /// 修改
  51. /// </summary>
  52. /// <returns></returns>
  53. [HttpPost]
  54. public ActionResult Edit(ExaminationSubjectView examinationSubjectView)
  55. {
  56. try
  57. {
  58. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  59. ExaminationSubjectServices.Save(examinationSubjectView);
  60. return Json(new ReturnMessage()
  61. {
  62. IsSuccess = true,
  63. Message = "保存成功!"
  64. });
  65. }
  66. catch (Exception ex)
  67. {
  68. return Json(new ReturnMessage()
  69. {
  70. IsSuccess = false,
  71. Message = "保存失败:" + ex.Message
  72. });
  73. }
  74. }
  75. /// <summary>
  76. /// 删除
  77. /// </summary>
  78. /// <param name="roleID"></param>
  79. /// <returns></returns>
  80. [HttpPost]
  81. public ActionResult Delete(string examinationSubjectIDs)
  82. {
  83. try
  84. {
  85. var examinationSubjectIDList = examinationSubjectIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
  86. ExaminationSubjectServices.Delete(examinationSubjectIDList);
  87. return base.Json("删除成功");
  88. }
  89. catch (Exception ex)
  90. {
  91. string mge = ex.Message;
  92. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  93. if (num != null)
  94. {
  95. if (num.Number == 547)
  96. mge = "请先删除所有关联的数据,如:要求通过科目为该考试科目的数据、或者考场安排等";
  97. }
  98. return base.Json("删除失败,原因:" + mge + "!");
  99. }
  100. }
  101. [HttpPost]
  102. public ActionResult Excel()
  103. {
  104. NpoiExcelHelper neh = new NpoiExcelHelper();
  105. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  106. var examinationFormID = Request.Form["ExaminationFormDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["ExaminationFormDropdown"].ParseStrTo<int>(); ;
  107. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  108. var dt = ExaminationSubjectServices.GetExaminationSubjectViewList(configuretView, examinationFormID, null).Select(x => new
  109. {
  110. x.Name,
  111. //ExaminationDate = (x.ExaminationDate.HasValue ? x.ExaminationDate.Value.ToString("yyyy-MM-dd") : ""),
  112. //x.ExaminationTypeName,
  113. x.ExaminationFormName,
  114. //x.PeopleNumLimit,
  115. //x.SchoolyearCode
  116. }).ToTable();
  117. string[] liststring = { "考试科目", "考试性质"};
  118. neh.Export(dt, liststring, "考试科目信息");
  119. return RedirectToAction("MsgShow", "Common", new
  120. {
  121. msg = "导出成功!",
  122. url = Url.Content("~/ExaminationSubjects/List").AddMenuParameter()
  123. });
  124. }
  125. public ActionResult Validation(string ExaminationTypeIDs, string SchoolyearIDs, string ExaminationFormIDs, string names)
  126. {
  127. List<int?> list2 = new List<int?>();
  128. foreach (var i in ExaminationFormIDs.Split(','))
  129. {
  130. list2.Add(Convert.ToInt32(i));
  131. }
  132. List<string> list3 = new List<string>();
  133. foreach (var i in names.Split(','))
  134. {
  135. list3.Add(i);
  136. }
  137. string[] result = ExaminationSubjectServices.Validation(list2, list3);
  138. return Json(new ReturnMessage()
  139. {
  140. IsSuccess = result[0] == "true" ? true : false,
  141. Message = result[1]
  142. });
  143. }
  144. }
  145. }