FreeSelectionCourseController.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 EMIS.Entities;
  12. using Bowin.Common.Exceptions;
  13. using Bowin.Common.Data;
  14. using Bowin.Common.Utility;
  15. using EMIS.Utility;
  16. using EMIS.Utility.FormValidate;
  17. namespace EMIS.Web.Controllers.SelectCourseManage
  18. {
  19. [Authorization]
  20. public class FreeSelectionCourseController : Controller
  21. {
  22. public IFreeSelectionCourseServices FreeSelectionCourseServices { get; set; }
  23. public IFreeSelectionCourseApplyServices FreeSelectionCourseApplyServices { get; set; }
  24. /// <summary>
  25. /// 任选课程页面
  26. /// </summary>
  27. /// <returns></returns>
  28. public ActionResult List()
  29. {
  30. return View();
  31. }
  32. /// <summary>
  33. /// 查询列表
  34. /// </summary>
  35. /// <param name="pararms"></param>
  36. /// <returns></returns>
  37. [HttpPost]
  38. public ActionResult List(QueryParamsModel pararms)
  39. {
  40. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  41. var coursematerialID = pararms.getExtraGuid("CoursematerialIDDropdownGridBo");
  42. var departmentID = pararms.getExtraGuid("DepartmentComboGrid");
  43. var schoolcodeID = pararms.getExtraInt("DictionarySchoolcode") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolcode");
  44. var starttermID = pararms.getExtraInt("DictionaryStartterm") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStartterm");
  45. var isEnable = pararms.getExtraInt("DictionaryIsEnable") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsEnable");
  46. return base.Json(FreeSelectionCourseServices.GetFreeSelectionCourseViewGrid(configuretView, coursematerialID, departmentID,schoolcodeID, starttermID, isEnable, (int)pararms.page, (int)pararms.rows));
  47. }
  48. public ActionResult Edit(Guid? freeSelectionCourseIDs,string type)
  49. {
  50. FreeSelectionCourseView freeSelectionCourseView = new FreeSelectionCourseView();
  51. if (freeSelectionCourseIDs.HasValue)
  52. freeSelectionCourseView = FreeSelectionCourseServices.GetFreeSelectionCourseView(freeSelectionCourseIDs);
  53. else
  54. {
  55. var staff = FreeSelectionCourseApplyServices.GetStaff(CustomPrincipal.Current.UserID);
  56. if (staff != null)
  57. {
  58. freeSelectionCourseView.DepartmentID = staff.DepartmentID;
  59. ViewBag.DepartmentID = staff.DepartmentID;
  60. }
  61. freeSelectionCourseView.ResultTypeID = (int)CF_ResultType.Percentage;
  62. }
  63. //默认启用
  64. freeSelectionCourseView.IsEnable = true;
  65. if (freeSelectionCourseIDs.HasValue && type == "copyAdd")
  66. {
  67. freeSelectionCourseView.FreeSelectionCouseID = Guid.Empty;
  68. }
  69. return View(freeSelectionCourseView);
  70. }
  71. /// <summary>
  72. /// 编辑
  73. /// </summary>
  74. /// <param name="freeSelectionCourseView"></param>
  75. /// <returns></returns>
  76. [HttpPost]
  77. public ActionResult Edit(FreeSelectionCourseView freeSelectionCourseView)
  78. {
  79. try
  80. {
  81. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  82. if (freeSelectionCourseView.FreeSelectionCouseID == null || freeSelectionCourseView.FreeSelectionCouseID == Guid.Empty)
  83. {
  84. FreeSelectionCourseServices.FreeSelectionCourseAdd(freeSelectionCourseView);
  85. }
  86. else
  87. {
  88. FreeSelectionCourseServices.FreeSelectionCourseUpdate(freeSelectionCourseView);
  89. }
  90. return Json(new ReturnMessage()
  91. {
  92. IsSuccess = true,
  93. Message = "保存成功!"
  94. });
  95. }
  96. catch (Exception ex)
  97. {
  98. return Json(new ReturnMessage()
  99. {
  100. IsSuccess = false,
  101. Message = "保存失败:" + ex.Message
  102. });
  103. }
  104. }
  105. /// <summary>
  106. /// 删除
  107. /// </summary>
  108. /// <param name="freeSelectionCourseIDs"></param>
  109. /// <returns></returns>
  110. [HttpPost]
  111. public ActionResult Delete(string freeSelectionCourseIDs)
  112. {
  113. try
  114. {
  115. List<Guid?> list = new List<Guid?>();
  116. for (int i = 0; i < freeSelectionCourseIDs.Split(',').Length; i++)
  117. {
  118. string id = freeSelectionCourseIDs.Split(',')[i];
  119. if (!string.IsNullOrEmpty(id))
  120. {
  121. Guid specialtyCourseID = new Guid(id);
  122. list.Add(specialtyCourseID);
  123. }
  124. }
  125. FreeSelectionCourseServices.FreeSelectionCourseDelete(list);
  126. return base.Json("删除成功!");
  127. }
  128. catch (Exception ex)
  129. {
  130. string mge = ex.Message;
  131. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  132. if (num != null)
  133. {
  134. if (num.Number == 547)
  135. mge = "请先删除所有关联的数据,如:开课申请、任选设定、选课结果等!";
  136. }
  137. return base.Json("删除失败,原因:" + mge);
  138. }
  139. }
  140. /// <summary>
  141. /// 导出Excel
  142. /// </summary>
  143. /// <returns></returns>
  144. [HttpPost]
  145. public ActionResult Excel()
  146. {
  147. NpoiExcelHelper neh = new NpoiExcelHelper();
  148. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  149. var coursematerialID = Request.Form["CoursematerialIDDropdownGridBo"].ParseStrTo<Guid>();
  150. var departmentID = Request.Form["DepartmentComboGrid"].ParseStrTo<Guid>();
  151. var schoolcodeID = Request.Form["DictionarySchoolcode"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolcode"].ParseStrTo<int>();
  152. var starttermID = Request.Form["DictionaryStartterm"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStartterm"].ParseStrTo<int>();
  153. var isEnable = Request.Form["DictionaryIsEnable"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEnable"].ParseStrTo<int>();
  154. var dt = FreeSelectionCourseServices.GetFreeSelectionCourseViewList(configuretView, coursematerialID,departmentID, schoolcodeID, starttermID, isEnable).Select(x => new
  155. {
  156. //x.No,
  157. x.CourseCode,
  158. x.CourseName,
  159. //x.CourseCategoryName,
  160. x.CourseTypeName,
  161. x.CourseQualityName,
  162. x.Credit,
  163. x.Totalhours,
  164. //x.SchoolweeksNum,
  165. //x.SchoolyearNumName,
  166. //x.SchoolcodeName,
  167. //x.StarttermName,
  168. x.TeachingModeName,
  169. x.DepartmentName,
  170. x.IsEnableDesc
  171. }).ToTable();
  172. string[] liststring = { //"选课编号",
  173. "课程代码", "课程名称", //"课程属性",
  174. "课程类型",
  175. "课程性质","学分","总学时",//"上课周数","学年数","学期","开课学期",
  176. "授课方式","教研室","是否启用"};
  177. neh.Export(dt, liststring, "任选课程信息");
  178. return RedirectToAction("MsgShow", "Common", new
  179. {
  180. msg = "导出成功!",
  181. url = Url.Content("~/FreeSelectionCourse/List").AddMenuParameter()
  182. });
  183. }
  184. /// <summary>
  185. /// 获取已经存在在授课方式
  186. /// </summary>
  187. /// <param name="freeSelectionCourseID"></param>
  188. /// <returns></returns>
  189. [HttpPost]
  190. public ActionResult TeachingModeType(Guid? freeSelectionCourseID)
  191. {
  192. List<int> list = new List<int>();
  193. if (freeSelectionCourseID.HasValue && freeSelectionCourseID != Guid.Empty)
  194. list = FreeSelectionCourseServices.GetTeachingModeType(freeSelectionCourseID);
  195. else
  196. list.Add(((int)EMIS.ViewModel.CF_TeachingMode.Theory));
  197. return base.Json(list.ConvertAll(x=>x.ToString()));
  198. }
  199. }
  200. }