ExaminationBatchController.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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;
  7. using EMIS.Web.Controls;
  8. using EMIS.CommonLogic.ExamManage;
  9. using Bowin.Common.Utility;
  10. using Bowin.Common.Exceptions;
  11. using Bowin.Common.Data;
  12. using Bowin.Web.Controls.Mvc;
  13. using EMIS.CommonLogic.CalendarManage;
  14. namespace EMIS.Web.Controllers.ExamManage
  15. {
  16. [Authorization]
  17. public class ExaminationBatchController : Controller
  18. {
  19. public IExaminationBatchServices IExaminationBatchService { get; set; }
  20. public ISchoolYearServices ISchoolYearService { get; set; }
  21. //
  22. // GET: /ExaminationBatch/
  23. public ActionResult List()
  24. {
  25. return View();
  26. }
  27. /// <summary>
  28. /// 项目列表查询
  29. /// </summary>
  30. /// <param name="pararms"></param>
  31. /// <returns></returns>
  32. [HttpPost]
  33. public ActionResult GetProjectListViewGrid(QueryParamsModel pararms)
  34. {
  35. List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  36. configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
  37. configuretViews.AddRange(pararms.getConditions());
  38. var StartDate = configuretViews.Where(x => x.Attribute == "StartDate").SingleOrDefault();
  39. if (StartDate != null) StartDate.Condition = ">=";
  40. var EndDate = configuretViews.Where(x => x.Attribute == "EndDate").SingleOrDefault();
  41. if (EndDate != null) EndDate.Condition = "<=";
  42. return base.Json(IExaminationBatchService.GetBatchListGridView((int)pararms.page, (int)pararms.rows, configuretViews.ToArray()));
  43. }
  44. [HttpPost]
  45. public ActionResult DropDownList(DropdownListBindType? bindType, Guid? schoolyearID)
  46. {
  47. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  48. var batchQuery = IExaminationBatchService.GetBatchList(new ConfiguretView());
  49. if (schoolyearID.HasValue)
  50. {
  51. batchQuery = batchQuery.Where(x => x.SchoolyearID == schoolyearID);
  52. }
  53. else
  54. {
  55. var emptyList = new List<DropdownListItem>();
  56. Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, emptyList);
  57. return Json(emptyList);
  58. }
  59. List<DropdownListItem> list = batchQuery
  60. .OrderBy(x => x.Name)
  61. .Select(x => new DropdownListItem { Text = x.Name, Value = x.ExaminationBatchID.ToString() })
  62. .ToList();
  63. Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, list);
  64. return base.Json(list);
  65. }
  66. /// <summary>
  67. /// 设置编辑页
  68. /// </summary>
  69. /// <param name="ExaminationProjectFeeID"></param>
  70. /// <returns></returns>
  71. [HttpGet]
  72. public ActionResult Edit(Guid? ExaminationBatchID)
  73. {
  74. EMIS.ViewModel.ExaminationBatchView projectFeeView = new EMIS.ViewModel.ExaminationBatchView() { ExaminationBatchID = Guid.NewGuid() };
  75. if (ExaminationBatchID.HasValue && ExaminationBatchID != Guid.Empty)
  76. {
  77. projectFeeView = IExaminationBatchService.GetExamBatch(ExaminationBatchID);
  78. }
  79. else
  80. {
  81. var currentYear = ISchoolYearService.GetSchoolYearViewList(new ConfiguretView(), 1).FirstOrDefault();
  82. if (currentYear != null)
  83. {
  84. projectFeeView.SchoolyearID = currentYear.SchoolYearID;
  85. projectFeeView.Schoolyear = currentYear.SchoolcodeName;
  86. }
  87. }
  88. return View(projectFeeView);
  89. }
  90. /// <summary>
  91. /// 设置编辑页提交
  92. /// </summary>
  93. /// <param name="campusView"></param>
  94. /// <returns></returns>
  95. [HttpPost]
  96. public ActionResult Edit(ExaminationBatchView view)
  97. {
  98. try
  99. {
  100. //同一学年学期内批次名称需作唯一性判断
  101. var model = IExaminationBatchService.GetExamBatch(x => x.Name == view.Name && x.SchoolyearID == view.SchoolyearID && x.ExaminationBatchID != view.ExaminationBatchID);
  102. if (model != null)
  103. {
  104. return Json(new ReturnMessage()
  105. {
  106. IsSuccess = false,
  107. Message = "同一学年学期内批次名称不允许相同!"
  108. });
  109. }
  110. view.RecordStatus = (int)EMIS.ViewModel.SYS_STATUS.USABLE;
  111. IExaminationBatchService.Edit(view);
  112. return Json(new ReturnMessage()
  113. {
  114. IsSuccess = true,
  115. Message = "保存成功。"
  116. });
  117. }
  118. catch (Exception ex)
  119. {
  120. return Json(new ReturnMessage()
  121. {
  122. IsSuccess = false,
  123. Message = "保存失败,原因:" + ex.Message
  124. });
  125. }
  126. }
  127. /// <summary>
  128. /// 删除项目设置
  129. /// </summary>
  130. /// <param name="campusIDs"></param>
  131. /// <returns></returns>
  132. [HttpPost]
  133. public JsonResult DeleteBatch(string ExamBatchIDs)
  134. {
  135. try
  136. {
  137. List<Guid?> list = ExamBatchIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  138. .Select(x => (Guid?)new Guid(x)).ToList();
  139. IExaminationBatchService.DeleteBatch(list);
  140. return base.Json("删除成功。");
  141. }
  142. catch (Exception ex)
  143. {
  144. string mge = ex.Message;
  145. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  146. if (num != null)
  147. {
  148. if (num.Number == 547)
  149. {
  150. mge = "请先删除与其有关联的数据";
  151. }
  152. }
  153. return base.Json("删除失败,原因:" + mge);
  154. }
  155. }
  156. [HttpPost]
  157. public ActionResult Excel(QueryParamsModel pararms)
  158. {
  159. List<ConfiguretView> configuretViews = new List<ConfiguretView>();
  160. configuretViews.Add(ConfiguretExtensions.GetConfiguretermsView(pararms));
  161. configuretViews.AddRange(pararms.getConditions());
  162. var StartDate = configuretViews.Where(x => x.Attribute == "StartDate").SingleOrDefault();
  163. if (StartDate != null) StartDate.Condition = ">=";
  164. var EndDate = configuretViews.Where(x => x.Attribute == "EndDate").SingleOrDefault();
  165. if (EndDate != null) EndDate.Condition = "<=";
  166. var query = IExaminationBatchService.GetBatchList(configuretViews.ToArray());
  167. var SelectedID = Request.Form["SelectedID"];
  168. List<Guid?> selectIDlist = new List<Guid?>();
  169. if (SelectedID != "" && SelectedID != null)
  170. {
  171. selectIDlist = SelectedID.SplitIDString();
  172. query = query.Where(x => selectIDlist.Contains(x.ExaminationBatchID));
  173. }
  174. var dt = query.ToList().Select(q =>
  175. new
  176. {
  177. q.Schoolyear,
  178. q.Name,
  179. StartDate = q.StartDate.ToStringEx("yyyy-MM-dd"),
  180. EndDate = q.EndDate.ToStringEx("yyyy-MM-dd"),
  181. q.Remark
  182. }).ToTable();
  183. NpoiExcelHelper neh = new NpoiExcelHelper();
  184. string[] liststring = {
  185. "学年学期","考试批次","报名起始时间","报名结束时间","备注"};
  186. neh.Export(dt, liststring, "考试批次设置列表" + DateTime.Now.ToString("yyyyMMddhhmmss"));
  187. return RedirectToAction("MsgShow", "Common", new
  188. {
  189. msg = "导出成功!",
  190. url = Url.Content("~/ExaminationBatc/List").AddMenuParameter()
  191. });
  192. }
  193. }
  194. }