CoursesTimeController.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Bowin.Web.Controls.Mvc;
  7. using EMIS.Utility;
  8. using EMIS.ViewModel;
  9. using EMIS.Web.Controls;
  10. using EMIS.CommonLogic.CalendarManage;
  11. using EMIS.ViewModel.CalendarManage;
  12. using EMIS.Entities;
  13. using Bowin.Common.Exceptions;
  14. using Bowin.Common.Utility;
  15. using Bowin.Common.Data;
  16. using EMIS.CommonLogic.EducationSchedule;
  17. namespace EMIS.Web.Controllers.CalendarManage
  18. {
  19. [Authorization]
  20. public class CoursesTimeController : Controller
  21. {
  22. public ICoursesTimeServices CoursesTimeServices { get; set; }
  23. public IScheduleServices scheduleServices { get; set; }
  24. //public EducationSchedulingDAL EducationSchedulingDAL { get; set; }
  25. /// <summary>
  26. /// 节次时间页面
  27. /// </summary>
  28. /// <returns></returns>
  29. public ActionResult List()
  30. {
  31. return View();
  32. }
  33. /// <summary>
  34. /// 列表查询
  35. /// </summary>
  36. /// <param name="pararms"></param>
  37. /// <returns></returns>
  38. [HttpPost]
  39. public ActionResult List(QueryParamsModel pararms)
  40. {
  41. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  42. var timesSegment = pararms.getExtraInt("TimesSegmentDropdown");
  43. return base.Json(CoursesTimeServices.GetCoursesTimeViewGrid(configuretView, timesSegment, (int)pararms.page, (int)pararms.rows));
  44. }
  45. /// <summary>
  46. /// 编辑页面
  47. /// </summary>
  48. /// <returns></returns>
  49. [HttpGet]
  50. public ActionResult Edit(Guid? coursesTimeID)
  51. {
  52. CoursesTimeView coursesTimeView = new CoursesTimeView();
  53. if (coursesTimeID != null && coursesTimeID != Guid.Empty)
  54. coursesTimeView = CoursesTimeServices.GetCoursesTimeView(coursesTimeID);
  55. return View(coursesTimeView);
  56. }
  57. /// <summary>
  58. /// 新增或更新
  59. /// </summary>
  60. /// <param name="coursesTimeView"></param>
  61. /// <returns></returns>
  62. [HttpPost]
  63. public ActionResult Edit(CoursesTimeView coursesTimeView)
  64. {
  65. try
  66. {
  67. if (!coursesTimeView.CoursesTimeID.HasValue || coursesTimeView.CoursesTimeID == Guid.Empty)
  68. {
  69. CoursesTimeServices.CoursesTimeAdd(coursesTimeView);
  70. }
  71. else
  72. {
  73. CoursesTimeServices.CoursesTimeUpdate(coursesTimeView);
  74. }
  75. return Json(new ReturnMessage()
  76. {
  77. IsSuccess = true,
  78. Message = "保存成功!"
  79. });
  80. }
  81. catch (Exception ex)
  82. {
  83. return Json(new ReturnMessage()
  84. {
  85. IsSuccess = false,
  86. Message = "保存失败:" + ex.Message
  87. });
  88. }
  89. }
  90. /// <summary>
  91. /// 删除
  92. /// </summary>
  93. /// <param name="coursesTimeIDs"></param>
  94. /// <returns></returns>
  95. [HttpPost]
  96. public ActionResult Delete(string coursesTimeIDs)
  97. {
  98. try
  99. {
  100. List<Guid> list = new List<Guid>();
  101. for (int i = 0; i < coursesTimeIDs.Split(',').Length; i++)
  102. {
  103. string id = coursesTimeIDs.Split(',')[i];
  104. if (!string.IsNullOrEmpty(id))
  105. {
  106. Guid coursesTimeID = new Guid(id);
  107. list.Add(coursesTimeID);
  108. }
  109. }
  110. CoursesTimeServices.CoursesTimeDelete(list);
  111. return base.Json("删除成功!");
  112. }
  113. catch (Exception ex)
  114. {
  115. string mge = ex.Message;
  116. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  117. if (num != null)
  118. {
  119. if (num.Number == 547)
  120. mge = "请先删除所有关联的数据";
  121. }
  122. return base.Json("删除失败,原因:" + mge + "!");
  123. }
  124. }
  125. /// <summary>
  126. /// 导出Excel
  127. /// </summary>
  128. /// <param name="pararms"></param>
  129. /// <returns></returns>
  130. [HttpPost]
  131. public ActionResult Excel()
  132. {
  133. try
  134. {
  135. NpoiExcelHelper neh = new NpoiExcelHelper();
  136. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  137. var timesSegment = Request.Form["TimesSegmentDropdown"].ParseStrTo<int>();
  138. var dt = CoursesTimeServices.GetCoursesTimeViewList(configuretView, timesSegment).Select(x => new
  139. {
  140. TimeGroupName = (x.StartTimes == x.EndTimes) ? x.StartTimes.Value.ToString() : x.StartTimes.Value.ToString() + "-" + x.EndTimes.Value.ToString(),
  141. x.TimesSegmentName,
  142. x.StartDate,
  143. x.EndDate
  144. }).ToTable();
  145. string[] liststring = { "节次", "时间段", "开始时间", "结束时间" };
  146. neh.Export(dt, liststring, "课程时间信息");
  147. return RedirectToAction("MsgShow", "Common", new
  148. {
  149. msg = "导出成功!",
  150. url = Url.Content("~/CoursesTime/List").AddMenuParameter()
  151. });
  152. }
  153. catch (Exception ex)
  154. {
  155. return RedirectToAction("MsgShow", "Common", new
  156. {
  157. msg = "导出失败,原因:" + ex.Message + "!",
  158. url = Url.Content("~/CoursesTime/List").AddMenuParameter()
  159. });
  160. }
  161. }
  162. /// <summary>
  163. /// 列表查询
  164. /// </summary>
  165. /// <param name="pararms"></param>
  166. /// <returns></returns>
  167. [HttpPost]
  168. public ActionResult ListAll()
  169. {
  170. return base.Json(CoursesTimeServices.GetCoursesTimeViewList(new ConfiguretView(), null));
  171. }
  172. /// <summary>
  173. /// 列表查询
  174. /// </summary>
  175. /// <param name="pararms"></param>
  176. /// <returns></returns>
  177. [HttpPost]
  178. public ActionResult DropDown(DropdownListBindType? bindType)
  179. {
  180. var coursesTimeViewList = CoursesTimeServices.GetCoursesTimeViewList(new ConfiguretView(), null);
  181. List<DropdownListItem> list = coursesTimeViewList
  182. .Select(x => new DropdownListItem { Text = x.StartDate + "-" + x.EndDate, Value = x.CoursesTimeID.ToString() }).ToList();
  183. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  184. DropdownList.FormatDropdownItemList(dbt, list);
  185. return base.Json(list);
  186. }
  187. /// <summary>
  188. /// 列表查询
  189. /// </summary>
  190. /// <param name="pararms"></param>
  191. /// <returns></returns>
  192. [HttpPost]
  193. public ActionResult DropDownForSegment(DropdownListBindType? bindType)
  194. {
  195. var coursesTimeViewList = CoursesTimeServices.GetCoursesTimeViewList(new ConfiguretView(), null);
  196. List<DropdownListItem> list = coursesTimeViewList
  197. .Select(x => new DropdownListItem { Text = string.Format("第{0}-{1}节", x.StartTimes, x.EndTimes), Value = x.CoursesTimeID.ToString() }).ToList();
  198. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  199. DropdownList.FormatDropdownItemList(dbt, list);
  200. return base.Json(list);
  201. }
  202. /// <summary>
  203. /// 列表查询
  204. /// </summary>
  205. /// <param name="pararms"></param>
  206. /// <returns></returns>
  207. [HttpPost]
  208. public ActionResult DropDownFuture(DropdownListBindType? bindType, string educationSchedulingIDs, int? weekNum, int? weekday, Guid? teacherID, Guid? schoolyearID)
  209. {
  210. var educationSchedulingWeekNumIDList = educationSchedulingIDs.Split(',')
  211. .Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  212. var coursesTimeViewList = CoursesTimeServices.GetCoursesTimeViewFutureList(educationSchedulingWeekNumIDList, weekNum, weekday);
  213. //var coursesTimeViewList = scheduleServices.GetNotUseCoursesTimeViewListForBatchAdjustment(schoolyearID, weekday, weekNum, teacherID, educationSchedulingWeekNumIDList);
  214. List<DropdownListItem> list = coursesTimeViewList
  215. .Select(x => new DropdownListItem { Text = x.StartDate + "-" + x.EndDate, Value = x.CoursesTimeID.ToString() }).ToList();
  216. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  217. DropdownList.FormatDropdownItemList(dbt, list);
  218. return base.Json(list);
  219. }
  220. /// <summary>
  221. /// 列表查询
  222. /// </summary>
  223. /// <param name="pararms"></param>
  224. /// <returns></returns>
  225. [HttpPost]
  226. public ActionResult DropDownForAdjustmentBatch(DropdownListBindType? bindType, string educationSchedulingIDs, int? weekNum, int? weekday, Guid? teacherID, Guid? schoolyearID)
  227. {
  228. var educationSchedulingWeekNumIDList = educationSchedulingIDs.Split(',')
  229. .Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  230. var coursesTimeViewList = scheduleServices.GetNotUseCoursesTimeViewListForBatchAdjustment(schoolyearID, weekday, weekNum, teacherID, educationSchedulingWeekNumIDList);
  231. List<DropdownListItem> list = coursesTimeViewList
  232. .Select(x => new DropdownListItem { Text = x.StartDate + "-" + x.EndDate, Value = x.CoursesTimeID.ToString() }).ToList();
  233. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  234. DropdownList.FormatDropdownItemList(dbt, list);
  235. return base.Json(list);
  236. }
  237. }
  238. }