ActivitieController.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 ActivitieController : Controller
  20. {
  21. public IActivitieServices ActivitieServices { 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(ActivitieServices.GetActivitieViewGrid(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. ActivitieView activitieView = new ActivitieView();
  51. if (activitiesID != null && activitiesID != Guid.Empty)
  52. activitieView = ActivitieServices.GetActivitieView(activitiesID);
  53. return View(activitieView);
  54. }
  55. /// <summary>
  56. /// 新增或更新
  57. /// </summary>
  58. /// <param name="activitieView"></param>
  59. /// <returns></returns>
  60. [HttpPost]
  61. public ActionResult Edit(ActivitieView activitieView)
  62. {
  63. try
  64. {
  65. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  66. if (!activitieView.ActivitiesID.HasValue || activitieView.ActivitiesID == Guid.Empty)
  67. {
  68. ActivitieServices.ActivitiesAdd(activitieView);
  69. }
  70. else
  71. {
  72. ActivitieServices.ActivitiesUpdate(activitieView);
  73. }
  74. return Json(new ReturnMessage()
  75. {
  76. IsSuccess = true,
  77. Message = "保存成功!"
  78. });
  79. }
  80. catch (Exception ex)
  81. {
  82. return Json(new ReturnMessage()
  83. {
  84. IsSuccess = false,
  85. Message = "保存失败:" + ex.Message
  86. });
  87. }
  88. }
  89. /// <summary>
  90. /// 删除
  91. /// </summary>
  92. /// <param name="activitiesIDs"></param>
  93. /// <returns></returns>
  94. [HttpPost]
  95. public ActionResult Delete(string activitiesIDs)
  96. {
  97. try
  98. {
  99. List<Guid> list = new List<Guid>();
  100. for (int i = 0; i < activitiesIDs.Split(',').Length; i++)
  101. {
  102. string id = activitiesIDs.Split(',')[i];
  103. if (!string.IsNullOrEmpty(id))
  104. {
  105. Guid activitiesID = new Guid(id);
  106. list.Add(activitiesID);
  107. }
  108. }
  109. ActivitieServices.ActivitiesDelete(list);
  110. return base.Json("删除成功!");
  111. }
  112. catch (Exception ex)
  113. {
  114. string mge = ex.Message;
  115. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  116. if (num != null)
  117. {
  118. if (num.Number == 547)
  119. mge = "请先删除所有关联的数据";
  120. }
  121. return base.Json("删除失败,原因:" + mge + "!");
  122. }
  123. }
  124. /// <summary>
  125. /// 导出Excel
  126. /// </summary>
  127. /// <param name="pararms"></param>
  128. /// <returns></returns>
  129. [HttpPost]
  130. public ActionResult Excel()
  131. {
  132. try
  133. {
  134. NpoiExcelHelper neh = new NpoiExcelHelper();
  135. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  136. var activitiesType = Request.Form["ActivitiesTypeDropdown"].ParseStrTo<int>();
  137. var timesSegment = Request.Form["TimesSegmentDropdown"].ParseStrTo<int>();
  138. var dt = ActivitieServices.GetActivitieViewList(configuretView, activitiesType, timesSegment).Select(x => new
  139. {
  140. x.Name,
  141. x.ActivitiesTime,
  142. x.TimesSegmentName,
  143. x.ActivitiesTypeName,
  144. x.ActivitiesContent
  145. }).ToTable();
  146. string[] liststring = { "活动名称", "月日", "时间段", "活动类型", "活动内容" };
  147. neh.Export(dt, liststring, "固定活动信息");
  148. return RedirectToAction("MsgShow", "Common", new
  149. {
  150. msg = "导出成功!",
  151. url = Url.Content("~/Activitie/List").AddMenuParameter()
  152. });
  153. }
  154. catch (Exception ex)
  155. {
  156. return RedirectToAction("MsgShow", "Common", new
  157. {
  158. msg = "导出失败,原因:" + ex.Message + "!",
  159. url = Url.Content("~/Activitie/List").AddMenuParameter()
  160. });
  161. }
  162. }
  163. /// <summary>
  164. /// 活动类型下拉绑定数据
  165. /// </summary>
  166. /// <param name="pararms"></param>
  167. /// <returns></returns>
  168. [HttpPost]
  169. public ActionResult ActivitiesTypeDropdownListBanid(DropdownListBindType? bindType)
  170. {
  171. List<DropdownListItem> list = DictionaryHelper.GetDictionaryValue("CF_ActivitiesType").Select(x => new DropdownListItem { Text = x.Name, Value = x.Value }).ToList();
  172. DropdownList.FormatDropdownItemList(bindType.Value, list);
  173. return base.Json(list);
  174. }
  175. /// <summary>
  176. ///时间段下拉绑定数据
  177. /// </summary>
  178. /// <param name="pararms"></param>
  179. /// <returns></returns>
  180. [HttpPost]
  181. public ActionResult TimesSegmentDropdownListBanid(DropdownListBindType? bindType)
  182. {
  183. List<DropdownListItem> list = DictionaryHelper.GetDictionaryValue("CF_TimesSegment").Select(x => new DropdownListItem { Text = x.Name, Value = x.Value }).ToList();
  184. DropdownList.FormatDropdownItemList(bindType.Value, list);
  185. return base.Json(list);
  186. }
  187. }
  188. }