CoursesTimeController.cs 8.3 KB

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