ExaminationTypeController.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 dt = ExaminationTypeServices.GetExaminationTypeViewList(configuretView).Select(x => new
  56. {
  57. x.Name,
  58. x.IsTimesLimitDesc
  59. }).ToTable();
  60. string[] liststring = { "考试类型", "是否要求次数限定" };
  61. neh.Export(dt, liststring, "考试类型信息");
  62. return RedirectToAction("MsgShow", "Common", new
  63. {
  64. msg = "导出成功!",
  65. url = Url.Content("~/ExaminationType/List").AddMenuParameter()
  66. });
  67. }
  68. /// <summary>
  69. /// 删除
  70. /// </summary>
  71. /// <param name="roleID"></param>
  72. /// <returns></returns>
  73. [HttpPost]
  74. public ActionResult Delete(string examinationTypeIDs)
  75. {
  76. try
  77. {
  78. var examinationTypeIDList = examinationTypeIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
  79. ExaminationTypeServices.Delete(examinationTypeIDList);
  80. return base.Json("删除成功");
  81. }
  82. catch (Exception ex)
  83. {
  84. string mge = ex.Message;
  85. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  86. if (num != null)
  87. {
  88. if (num.Number == 547)
  89. mge = "请先删除所有关联的数据,如:考试科目、考场安排等";
  90. }
  91. return base.Json("删除失败,原因:" + mge + "!");
  92. }
  93. }
  94. /// <summary>
  95. /// 修改
  96. /// </summary>
  97. /// <returns></returns>
  98. [HttpPost]
  99. public ActionResult Edit(ExaminationTypeView examinationTypeView)
  100. {
  101. try
  102. {
  103. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  104. ExaminationTypeServices.Save(examinationTypeView);
  105. return Json(new ReturnMessage()
  106. {
  107. IsSuccess = true,
  108. Message = "保存成功!"
  109. });
  110. }
  111. catch (Exception ex)
  112. {
  113. return Json(new ReturnMessage()
  114. {
  115. IsSuccess = false,
  116. Message = "保存失败:" + ex.Message
  117. });
  118. }
  119. }
  120. [HttpPost]
  121. public ActionResult DropdownList(DropdownListBindType? bindType)
  122. {
  123. List<DropdownListItem> list = ExaminationTypeServices.GetExaminationTypeViewList(new ConfiguretView())
  124. .Select(x => new DropdownListItem { Text = x.Name, Value = x.ExaminationTypeID.ToString() }).ToList();
  125. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  126. Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, list);
  127. return base.Json(list);
  128. }
  129. }
  130. }