FreeSelectionCouseControlController.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.SelectCourse;
  7. using EMIS.ViewModel;
  8. using EMIS.Web.Controls;
  9. using Bowin.Web.Controls.Mvc;
  10. using EMIS.ViewModel.SelectCourse;
  11. using Bowin.Common.Exceptions;
  12. using Bowin.Common.Utility;
  13. using Bowin.Common.Data;
  14. namespace EMIS.Web.Controllers.SelectCourseManage
  15. {
  16. [Authorization]
  17. public class FreeSelectionCouseControlController : Controller
  18. {
  19. public IOpenControlSettingServices openControlSettingServices { get; set; }
  20. /// <summary>
  21. /// 任选控制页面
  22. /// </summary>
  23. /// <returns></returns>
  24. public ActionResult List()
  25. {
  26. return View();
  27. }
  28. /// <summary>
  29. /// 列表查询
  30. /// </summary>
  31. /// <param name="pararms"></param>
  32. /// <returns></returns>
  33. [HttpPost]
  34. public ActionResult List(QueryParamsModel pararms)
  35. {
  36. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  37. var schoolYearID = pararms.getExtraGuid("SchoolyearDropdown");
  38. var Years = pararms.getExtraInt("SchoolyearDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("SchoolyearDictionaryDropDown");
  39. return this.Json(openControlSettingServices.GetFreeSelectionCouseControlViewGrid(configuretView, schoolYearID, Years, (int)pararms.page, (int)pararms.rows));
  40. }
  41. /// <summary>
  42. /// 编辑
  43. /// </summary>
  44. /// <returns></returns>
  45. public ActionResult Edit(Guid? FreeSelectionCourseGradeYearSettingID)
  46. {
  47. FreeSelectionCouseControlView optionalCourseSettingView = new FreeSelectionCouseControlView();
  48. if (FreeSelectionCourseGradeYearSettingID.HasValue && FreeSelectionCourseGradeYearSettingID != Guid.Empty)
  49. optionalCourseSettingView = openControlSettingServices.GetFreeSelectionCouseControlSettingViewInfo(FreeSelectionCourseGradeYearSettingID);
  50. ViewBag.RecordStatus = optionalCourseSettingView.RecordStatus;
  51. return View(optionalCourseSettingView);
  52. }
  53. /// <summary>
  54. /// 保存修改
  55. /// </summary>
  56. /// <param name="optionalCourseSettingView"></param>
  57. /// <returns></returns>
  58. [HttpPost]
  59. public ActionResult Edit(FreeSelectionCouseControlView optionalCourseSettingView)
  60. {
  61. try
  62. {
  63. openControlSettingServices.FreeSelectionCouseControlSave(optionalCourseSettingView);
  64. return Json(new ReturnMessage()
  65. {
  66. IsSuccess = true,
  67. Message = "保存成功!"
  68. });
  69. }
  70. catch (Exception ex)
  71. {
  72. return Json(new ReturnMessage()
  73. {
  74. IsSuccess = false,
  75. Message = "保存失败:" + ex.Message
  76. });
  77. }
  78. }
  79. /// <summary>
  80. /// 删除
  81. /// </summary>
  82. /// <param name="optionalCourseIDs"></param>
  83. /// <returns></returns>
  84. [HttpPost]
  85. public ActionResult Delete(string freeSelectionCourseGradeYearSettingIDs)
  86. {
  87. try
  88. {
  89. List<Guid?> list = new List<Guid?>();
  90. for (int i = 0; i < freeSelectionCourseGradeYearSettingIDs.Split(',').Length; i++)
  91. {
  92. if (!string.IsNullOrEmpty(freeSelectionCourseGradeYearSettingIDs.Split(',')[i]))
  93. {
  94. Guid optionalCourseSettingID = new Guid(freeSelectionCourseGradeYearSettingIDs.Split(',')[i]);
  95. list.Add(optionalCourseSettingID);
  96. }
  97. }
  98. openControlSettingServices.FreeSelectionCouseControlDelete(list);
  99. return this.Json("删除成功!");
  100. }
  101. catch (Exception ex)
  102. {
  103. string mge = ex.Message;
  104. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  105. if (num != null)
  106. {
  107. if (num.Number == 547)
  108. mge = "请先删除所有关联的数据!";
  109. }
  110. return this.Json("删除失败,原因:" + mge);
  111. }
  112. }
  113. [HttpPost]
  114. public ActionResult Excel()
  115. {
  116. NpoiExcelHelper neh = new NpoiExcelHelper();
  117. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  118. //避开全选值
  119. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  120. var schoolYearID = Request.Form["SchoolYear"].ParseStrTo<Guid>();
  121. var Years = Request.Form["DictionaryGrade"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo<int>();
  122. var dt = openControlSettingServices.GetFreeSelectionCouseControlList(configuretView, schoolYearID, Years)
  123. .Select(x => new
  124. {
  125. x.SchoolyearCode,
  126. x.GradeYear,
  127. x.StartTime,
  128. x.EndTime,
  129. x.MaxSelectCount,
  130. x.MinSelectCount,
  131. x.MaxCredit,
  132. x.MinCredit
  133. }).ToTable();
  134. string[] liststring = { "学年学期",
  135. "年级", "开始时间",
  136. "结束时间",
  137. "门数上限", "门数下限",
  138. "学分上限","学分下限"};
  139. neh.Export(dt, liststring, "任选设定");
  140. return RedirectToAction("MsgShow", "Common", new
  141. {
  142. msg = "导出成功!",
  143. url = Url.Content("~/FreeSelectionCouseControl/List").AddMenuParameter()
  144. });
  145. }
  146. }
  147. }