ExaminationTypeController.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.CommonLogic.ExaminationApply;
  7. using EMIS.ViewModel;
  8. using EMIS.Web.Controls;
  9. using Bowin.Web.Controls.Mvc;
  10. using Bowin.Common.Utility;
  11. using Bowin.Common.Data;
  12. using EMIS.ViewModel.ExaminationApply;
  13. using Bowin.Common.Exceptions;
  14. namespace EMIS.Web.Controllers.ExaminationApply
  15. {
  16. [Authorization]
  17. public class ExaminationTypeController : Controller
  18. {
  19. public IExaminationTypeServices ExaminationTypeServices { get; set; }
  20. /// <summary>
  21. /// 考试类型页面
  22. /// </summary>
  23. /// <returns></returns>
  24. public ActionResult List()
  25. {
  26. return View();
  27. }
  28. public ActionResult Edit(Guid? ExaminationTypeID)
  29. {
  30. ExaminationTypeView examinationTypeView = new ExaminationTypeView();
  31. if (ExaminationTypeID != null && ExaminationTypeID != Guid.Empty)
  32. {
  33. examinationTypeView = ExaminationTypeServices.GetExaminationTypeViewInfo(ExaminationTypeID);
  34. }
  35. return View(examinationTypeView);
  36. }
  37. /// <summary>
  38. /// 列表查询
  39. /// </summary>
  40. /// <param name="pararms"></param>
  41. /// <returns></returns>
  42. [HttpPost]
  43. public ActionResult List(QueryParamsModel pararms)
  44. {
  45. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  46. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  47. return base.Json(ExaminationTypeServices.GetExaminationTypeViewList(configuretView, (int)pararms.page, (int)pararms.rows));
  48. }
  49. [HttpPost]
  50. public ActionResult Excel()
  51. {
  52. NpoiExcelHelper neh = new NpoiExcelHelper();
  53. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  54. if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  55. var query = ExaminationTypeServices.GetExaminationTypeViewList(configuretView);
  56. var SelectedID = Request.Form["SelectedID"];
  57. List<Guid?> selectIDlist = new List<Guid?>();
  58. if (SelectedID != "" && SelectedID != null)
  59. {
  60. selectIDlist = SelectedID.SplitIDString();
  61. query = query.Where(x => selectIDlist.Contains(x.ExaminationTypeID)).ToList();
  62. }
  63. var dt = query.Select(x => new
  64. {
  65. x.Name,
  66. x.IsTimesLimitDesc
  67. }).ToTable();
  68. string[] liststring = { "考试类型", "是否要求次数限定" };
  69. neh.Export(dt, liststring, "考试类型信息");
  70. return RedirectToAction("MsgShow", "Common", new
  71. {
  72. msg = "导出成功!",
  73. url = Url.Content("~/ExaminationType/List").AddMenuParameter()
  74. });
  75. }
  76. /// <summary>
  77. /// 删除
  78. /// </summary>
  79. /// <param name="roleID"></param>
  80. /// <returns></returns>
  81. [HttpPost]
  82. public ActionResult Delete(string examinationTypeIDs)
  83. {
  84. try
  85. {
  86. var examinationTypeIDList = examinationTypeIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
  87. ExaminationTypeServices.Delete(examinationTypeIDList);
  88. return base.Json("删除成功");
  89. }
  90. catch (Exception ex)
  91. {
  92. string mge = ex.Message;
  93. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  94. if (num != null)
  95. {
  96. if (num.Number == 547)
  97. mge = "请先删除所有关联的数据,如:考试科目、考场安排等";
  98. }
  99. return base.Json("删除失败,原因:" + mge + "!");
  100. }
  101. }
  102. /// <summary>
  103. /// 修改
  104. /// </summary>
  105. /// <returns></returns>
  106. [HttpPost]
  107. public ActionResult Edit(ExaminationTypeView examinationTypeView)
  108. {
  109. try
  110. {
  111. //同一类型需作唯一性判断
  112. var model = ExaminationTypeServices.GetView(x => x.Name == examinationTypeView.Name && x.ExaminationTypeID != examinationTypeView.ExaminationTypeID);
  113. if (model != null)
  114. {
  115. return Json(new ReturnMessage()
  116. {
  117. IsSuccess = false,
  118. Message = "类型不允许相同!"
  119. });
  120. }
  121. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  122. ExaminationTypeServices.Save(examinationTypeView);
  123. return Json(new ReturnMessage()
  124. {
  125. IsSuccess = true,
  126. Message = "保存成功!"
  127. });
  128. }
  129. catch (Exception ex)
  130. {
  131. return Json(new ReturnMessage()
  132. {
  133. IsSuccess = false,
  134. Message = "保存失败:" + ex.Message
  135. });
  136. }
  137. }
  138. [HttpPost]
  139. public ActionResult DropdownList(DropdownListBindType? bindType)
  140. {
  141. List<DropdownListItem> list = ExaminationTypeServices.GetExaminationTypeViewList(new ConfiguretView())
  142. .Select(x => new DropdownListItem { Text = x.Name, Value = x.ExaminationTypeID.ToString() }).ToList();
  143. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  144. Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, list);
  145. return base.Json(list);
  146. }
  147. }
  148. }