DutyController.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Bowin.Common.Exceptions;
  7. using Bowin.Common.Utility;
  8. using Bowin.Common.Data;
  9. using Bowin.Web.Controls.Mvc;
  10. using EMIS.Utility;
  11. using EMIS.Web.Controls;
  12. using EMIS.Entities;
  13. using EMIS.ViewModel;
  14. using EMIS.ViewModel.CalendarManage;
  15. using EMIS.CommonLogic.CalendarManage;
  16. using EMIS.CommonLogic.UniversityManage.AdministrativeOrgan;
  17. namespace EMIS.Web.Controllers.CalendarManage
  18. {
  19. [Authorization]
  20. public class DutyController : Controller
  21. {
  22. public IDutyServices DutyServices { get; set; }
  23. public IDepartmentServices DepartmentServices { 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 campusID = pararms.getExtraGuid("CampusDropdown");
  42. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  43. var departmentID = pararms.getExtraGuid("DepartmentDropdown");
  44. var timesSegment = pararms.getExtraInt("TimesSegmentDropdown");
  45. return base.Json(DutyServices.GetDutyViewGrid(configuretView, campusID, collegeID, departmentID, timesSegment, (int)pararms.page, (int)pararms.rows));
  46. }
  47. /// <summary>
  48. /// 编辑页面
  49. /// </summary>
  50. /// <returns></returns>
  51. [HttpGet]
  52. public ActionResult Edit(Guid? dutyID)
  53. {
  54. DutyView dutyView = new DutyView();
  55. if (dutyID != null && dutyID != Guid.Empty)
  56. dutyView = DutyServices.GetDutyView(dutyID);
  57. return View(dutyView);
  58. }
  59. /// <summary>
  60. /// 新增或更新
  61. /// </summary>
  62. /// <param name="dutyView"></param>
  63. /// <returns></returns>
  64. [HttpPost]
  65. public ActionResult Edit(DutyView dutyView)
  66. {
  67. try
  68. {
  69. if (!dutyView.DutyID.HasValue || dutyView.DutyID == Guid.Empty)
  70. {
  71. DutyServices.DutyAdd(dutyView);
  72. }
  73. else
  74. {
  75. DutyServices.DutyUpdate(dutyView);
  76. }
  77. return Json(new ReturnMessage()
  78. {
  79. IsSuccess = true,
  80. Message = "保存成功!"
  81. });
  82. }
  83. catch (Exception ex)
  84. {
  85. return Json(new ReturnMessage()
  86. {
  87. IsSuccess = false,
  88. Message = "保存失败:" + ex.Message
  89. });
  90. }
  91. }
  92. /// <summary>
  93. /// 删除
  94. /// </summary>
  95. /// <param name="activitiesIDs"></param>
  96. /// <returns></returns>
  97. [HttpPost]
  98. public ActionResult Delete(string dutyIDs)
  99. {
  100. try
  101. {
  102. List<Guid> list = new List<Guid>();
  103. for (int i = 0; i < dutyIDs.Split(',').Length; i++)
  104. {
  105. string id = dutyIDs.Split(',')[i];
  106. if (!string.IsNullOrEmpty(id))
  107. {
  108. Guid dutyID = new Guid(id);
  109. list.Add(dutyID);
  110. }
  111. }
  112. DutyServices.DutyDelete(list);
  113. return base.Json("删除成功!");
  114. }
  115. catch (Exception ex)
  116. {
  117. string mge = ex.Message;
  118. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  119. if (num != null)
  120. {
  121. if (num.Number == 547)
  122. mge = "请先删除所有关联的数据";
  123. }
  124. return base.Json("删除失败,原因:" + mge + "!");
  125. }
  126. }
  127. /// <summary>
  128. /// 导出Excel
  129. /// </summary>
  130. /// <param name="pararms"></param>
  131. /// <returns></returns>
  132. [HttpPost]
  133. public ActionResult Excel()
  134. {
  135. try
  136. {
  137. NpoiExcelHelper neh = new NpoiExcelHelper();
  138. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  139. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  140. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  141. var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo<Guid>();
  142. var timesSegment = Request.Form["TimesSegmentDropdown"].ParseStrTo<int>();
  143. var dt = DutyServices.GetDutyViewList(configuretView, campusID, collegeID, departmentID, timesSegment).Select(x => new
  144. {
  145. x.LoginID,
  146. x.UserName,
  147. DutyTime = x.DutyTime.Value.ToString("yyyy-MM-dd"),
  148. x.StartDate,
  149. x.EndDate,
  150. x.Description,
  151. x.TimesSegmentName,
  152. x.DepartmentName
  153. }).ToTable();
  154. string[] liststring = { "工作证号", "值班人名", "值班日期", "开始时间", "结束时间", "任务描述", "时间段", "教研室" };
  155. neh.Export(dt, liststring, "值班管理信息");
  156. return RedirectToAction("MsgShow", "Common", new
  157. {
  158. msg = "导出成功!",
  159. url = Url.Content("~/Duty/List").AddMenuParameter()
  160. });
  161. }
  162. catch (Exception ex)
  163. {
  164. return RedirectToAction("MsgShow", "Common", new
  165. {
  166. msg = "导出失败,原因:" + ex.Message + "!",
  167. url = Url.Content("~/Duty/List").AddMenuParameter()
  168. });
  169. }
  170. }
  171. }
  172. }