DictionaryController.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 EMIS.CommonLogic.SystemSetting;
  10. using EMIS.ViewModel;
  11. using EMIS.Web.Controls;
  12. using EMIS.ViewModel.SystemSetting;
  13. namespace EMIS.Web.Controllers.SystemManage.SystemSetting
  14. {
  15. [Authorization]
  16. public class DictionaryController : Controller
  17. {
  18. public Lazy<IDictionaryServices> DictionaryServices { get; set; }
  19. /// <summary>
  20. /// 字典类型页面
  21. /// </summary>
  22. /// <returns></returns>
  23. [HttpGet]
  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. //可否编辑
  38. var isEditable = pararms.getExtraInt("DictionaryIsEditable") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsEditable");
  39. return base.Json(DictionaryServices.Value.GetDictionaryViewGird(configuretView,
  40. isEditable, (int)pararms.page, (int)pararms.rows));
  41. }
  42. /// <summary>
  43. /// 编辑(修改)
  44. /// </summary>
  45. /// <param name="dictionaryCode"></param>
  46. /// <returns></returns>
  47. [HttpGet]
  48. public ActionResult Edit(string dictionaryCode)
  49. {
  50. DictionaryView dictionaryView = new DictionaryView();
  51. if (!string.IsNullOrEmpty(dictionaryCode))
  52. {
  53. dictionaryView = DictionaryServices.Value.GetDictionaryView(dictionaryCode);
  54. }
  55. else
  56. {
  57. dictionaryView.IsEditable = true;
  58. }
  59. return View(dictionaryView);
  60. }
  61. /// <summary>
  62. /// 编辑(修改)
  63. /// </summary>
  64. /// <param name="dictionaryView"></param>
  65. /// <returns></returns>
  66. [HttpPost]
  67. public ActionResult Edit(DictionaryView dictionaryView)
  68. {
  69. try
  70. {
  71. DictionaryServices.Value.DictionaryEdit(dictionaryView);
  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="dictionaryCodes"></param>
  91. /// <returns></returns>
  92. [HttpPost]
  93. public ActionResult Delete(string dictionaryCodes)
  94. {
  95. try
  96. {
  97. var list = dictionaryCodes.Split(',').Where(x => !string.IsNullOrEmpty(x))
  98. .Select(x => x).ToList();
  99. DictionaryServices.Value.DictionaryDelete(list);
  100. return Json(new ReturnMessage()
  101. {
  102. IsSuccess = true,
  103. Message = "删除成功。"
  104. });
  105. }
  106. catch (Exception ex)
  107. {
  108. return Json(new ReturnMessage()
  109. {
  110. IsSuccess = false,
  111. Message = "删除失败:" + ex.Message
  112. });
  113. }
  114. }
  115. /// <summary>
  116. /// Excel导出
  117. /// </summary>
  118. /// <returns></returns>
  119. [HttpPost]
  120. public ActionResult Excel()
  121. {
  122. NpoiExcelHelper neh = new NpoiExcelHelper();
  123. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  124. //可否编辑
  125. var isEditable = Request.Form["DictionaryIsEditable"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEditable"].ParseStrTo<int>();
  126. var dt = DictionaryServices.Value.GetDictionaryViewList(configuretView, isEditable)
  127. .Select(x => new
  128. {
  129. x.OrderNo,
  130. x.DictionaryCode,
  131. x.DictionaryName,
  132. x.IsEditableName
  133. }).ToTable();
  134. string[] liststring = {
  135. "序号 ", "类型代码 ", "类型名称 ", "可否编辑"
  136. };
  137. neh.Export(dt, liststring, "字典类型信息" + DateTime.Now.ToString("yyyyMMdd"));
  138. return Json(new ReturnMessage()
  139. {
  140. IsSuccess = true,
  141. Message = "导出成功。"
  142. });
  143. }
  144. }
  145. }