ChangeReportController.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 Bowin.Common.Utility;
  8. using Bowin.Common.Data;
  9. using Bowin.Common.Exceptions;
  10. using EMIS.Web.Controls;
  11. using EMIS.ViewModel;
  12. using EMIS.ViewModel.StudentManage.StudentChange;
  13. using EMIS.CommonLogic.StudentManage.StudentChange;
  14. namespace EMIS.Web.Controllers.StudentManage.StudentChange
  15. {
  16. [Authorization]
  17. public class ChangeReportController : Controller
  18. {
  19. public IChangeReportServices ChangeReportServices { get; set; }
  20. /// <summary>
  21. /// 异动报表页面
  22. /// </summary>
  23. /// <returns></returns>
  24. public ActionResult List()
  25. {
  26. return View();
  27. }
  28. /// <summary>
  29. /// 异动报表列表查询
  30. /// </summary>
  31. /// <param name="pararms"></param>
  32. /// <returns></returns>
  33. [HttpPost]
  34. public ActionResult List(QueryParamsModel pararms)
  35. {
  36. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  37. return base.Json(ChangeReportServices.GetChangeReportViewGrid(configuretView, (int)pararms.page, (int)pararms.rows));
  38. }
  39. /// <summary>
  40. /// 复制新增
  41. /// </summary>
  42. /// <param name="changeReportID"></param>
  43. /// <returns></returns>
  44. public ActionResult CopyAdd(Guid changeReportID)
  45. {
  46. var changeReportView = new ChangeReportView();
  47. changeReportView = ChangeReportServices.GetChangeReportView(changeReportID);
  48. return View("Edit", changeReportView);
  49. }
  50. /// <summary>
  51. /// 复制新增
  52. /// </summary>
  53. /// <param name="changeReportView"></param>
  54. /// <returns></returns>
  55. [HttpPost]
  56. public ActionResult CopyAdd(ChangeReportView changeReportView)
  57. {
  58. changeReportView.ChangeReportID = Guid.Empty;
  59. return this.Edit(changeReportView);
  60. }
  61. /// <summary>
  62. /// 编辑(新增、修改)
  63. /// </summary>
  64. /// <param name="changeReportID"></param>
  65. /// <returns></returns>
  66. [HttpGet]
  67. public ActionResult Edit(Guid? changeReportID)
  68. {
  69. var changeReportView = new ChangeReportView();
  70. if (changeReportID.HasValue && changeReportID != Guid.Empty)
  71. {
  72. changeReportView = ChangeReportServices.GetChangeReportView(changeReportID);
  73. }
  74. return View(changeReportView);
  75. }
  76. /// <summary>
  77. /// 编辑(新增、修改)
  78. /// </summary>
  79. /// <param name="changeReportView"></param>
  80. /// <returns></returns>
  81. [HttpPost]
  82. public ActionResult Edit(ChangeReportView changeReportView)
  83. {
  84. try
  85. {
  86. ChangeReportServices.ChangeReportEdit(changeReportView);
  87. return Json(new ReturnMessage()
  88. {
  89. IsSuccess = true,
  90. Message = "保存成功。"
  91. });
  92. }
  93. catch (Exception ex)
  94. {
  95. return Json(new ReturnMessage()
  96. {
  97. IsSuccess = false,
  98. Message = "保存失败,原因:" + ex.Message
  99. });
  100. }
  101. }
  102. /// <summary>
  103. /// 删除
  104. /// </summary>
  105. /// <param name="changeReportIDs"></param>
  106. /// <returns></returns>
  107. [HttpPost]
  108. public ActionResult Delete(string changeReportIDs)
  109. {
  110. try
  111. {
  112. List<Guid?> list = changeReportIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  113. ChangeReportServices.ChangeReportDelete(list);
  114. return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
  115. }
  116. catch (Exception ex)
  117. {
  118. string mge = ex.Message;
  119. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  120. if (num != null)
  121. {
  122. if (num.Number == 547)
  123. {
  124. mge = "请先删除与其关联的数据,如:报表类型等。";
  125. }
  126. }
  127. return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge });
  128. }
  129. }
  130. /// <summary>
  131. /// Excel导出
  132. /// </summary>
  133. /// <returns></returns>
  134. [HttpPost]
  135. public ActionResult Excel()
  136. {
  137. NpoiExcelHelper neh = new NpoiExcelHelper();
  138. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  139. var dt = ChangeReportServices.GetChangeReportViewList(configuretView)
  140. .Select(x => new
  141. {
  142. x.Code,
  143. x.Name,
  144. x.Url
  145. }).ToTable();
  146. string[] liststring = {
  147. "报表代码", "报表名称", "报表Url"
  148. };
  149. neh.Export(dt, liststring, "异动报表信息" + DateTime.Now.ToString("yyyyMMdd"));
  150. return Json(new ReturnMessage()
  151. {
  152. IsSuccess = true,
  153. Message = "导出成功。"
  154. });
  155. }
  156. }
  157. }