SCalendarController.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 SCalendarController : Controller
  20. {
  21. public ISCalendarServices SCalendarServices { 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 activitiesType = pararms.getExtraInt("ActivitiesTypeDropdown");
  40. var timesSegment = pararms.getExtraInt("TimesSegmentDropdown");
  41. return base.Json(SCalendarServices.GetSCalendarViewGrid(configuretView, activitiesType, timesSegment, (int)pararms.page, (int)pararms.rows));
  42. }
  43. /// <summary>
  44. /// 编辑页面
  45. /// </summary>
  46. /// <returns></returns>
  47. [HttpGet]
  48. public ActionResult Edit(Guid? activitiesID)
  49. {
  50. SCalendarView scalendarView = new SCalendarView();
  51. if (activitiesID != null && activitiesID != Guid.Empty)
  52. scalendarView = SCalendarServices.GetSCalendarView(activitiesID);
  53. return View(scalendarView);
  54. }
  55. /// <summary>
  56. /// 新增或更新
  57. /// </summary>
  58. /// <param name="scalendarView"></param>
  59. /// <returns></returns>
  60. [HttpPost]
  61. public ActionResult Edit(SCalendarView scalendarView)
  62. {
  63. try
  64. {
  65. if (!scalendarView.ActivitiesID.HasValue || scalendarView.ActivitiesID == Guid.Empty)
  66. {
  67. SCalendarServices.SCalendarAdd(scalendarView);
  68. }
  69. else
  70. {
  71. SCalendarServices.SCalendarUpdate(scalendarView);
  72. }
  73. return Json(new ReturnMessage()
  74. {
  75. IsSuccess = true,
  76. Message = "保存成功!"
  77. });
  78. }
  79. catch (Exception ex)
  80. {
  81. return Json(new ReturnMessage()
  82. {
  83. IsSuccess = false,
  84. Message = "保存失败:" + ex.Message
  85. });
  86. }
  87. }
  88. /// <summary>
  89. /// 删除
  90. /// </summary>
  91. /// <param name="activitiesIDs"></param>
  92. /// <returns></returns>
  93. [HttpPost]
  94. public ActionResult Delete(string activitiesIDs)
  95. {
  96. try
  97. {
  98. List<Guid> list = new List<Guid>();
  99. for (int i = 0; i < activitiesIDs.Split(',').Length; i++)
  100. {
  101. string id = activitiesIDs.Split(',')[i];
  102. if (!string.IsNullOrEmpty(id))
  103. {
  104. Guid activitiesID = new Guid(id);
  105. list.Add(activitiesID);
  106. }
  107. }
  108. SCalendarServices.SCalendarDelete(list);
  109. return base.Json("删除成功!");
  110. }
  111. catch (Exception ex)
  112. {
  113. string mge = ex.Message;
  114. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  115. if (num != null)
  116. {
  117. if (num.Number == 547)
  118. mge = "请先删除所有关联的数据";
  119. }
  120. return base.Json("删除失败,原因:" + mge + "!");
  121. }
  122. }
  123. /// <summary>
  124. /// 导出Excel
  125. /// </summary>
  126. /// <param name="pararms"></param>
  127. /// <returns></returns>
  128. [HttpPost]
  129. public ActionResult Excel()
  130. {
  131. try
  132. {
  133. NpoiExcelHelper neh = new NpoiExcelHelper();
  134. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  135. var activitiesType = Request.Form["ActivitiesTypeDropdown"].ParseStrTo<int>();
  136. var timesSegment = Request.Form["TimesSegmentDropdown"].ParseStrTo<int>();
  137. var dt = SCalendarServices.GetSCalendarViewList(configuretView, activitiesType, timesSegment).Select(x => new
  138. {
  139. x.Name,
  140. ActivitiesTime = x.ActivitiesTime.Value.ToString("yyyy-MM-dd"),
  141. x.TimesSegmentName,
  142. x.ActivitiesTypeName,
  143. x.ActivitiesContent
  144. }).ToTable();
  145. string[] liststring = { "活动名称", "活动日期", "时间段", "活动类型", "活动内容" };
  146. neh.Export(dt, liststring, "校历管理信息");
  147. return RedirectToAction("MsgShow", "Common", new
  148. {
  149. msg = "导出成功!",
  150. url = Url.Content("~/SCalendar/List").AddMenuParameter()
  151. });
  152. }
  153. catch (Exception ex)
  154. {
  155. return RedirectToAction("MsgShow", "Common", new
  156. {
  157. msg = "导出失败,原因:" + ex.Message + "!",
  158. url = Url.Content("~/SCalendar/List").AddMenuParameter()
  159. });
  160. }
  161. }
  162. }
  163. }