DictionaryItemController.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.ViewModel;
  7. using EMIS.Web.Controls;
  8. using Bowin.Web.Controls.Mvc;
  9. using EMIS.CommonLogic.SystemSetting;
  10. using EMIS.ViewModel.SystemView;
  11. using Bowin.Common.Utility;
  12. using Bowin.Common.Data;
  13. namespace EMIS.Web.Controllers.SystemManage.SystemSetting
  14. {
  15. [Authorization]
  16. public class DictionaryItemController : Controller
  17. {
  18. public Lazy<IDictionaryItemServices> DictionaryItemServices { get; set; }
  19. /// <summary>
  20. /// 数据字典(字典元素)页面
  21. /// </summary>
  22. /// <returns></returns>
  23. public ActionResult List()
  24. {
  25. return View();
  26. }
  27. /// <summary>
  28. /// 数据字典列表查询
  29. /// </summary>
  30. /// <param name="pararms"></param>
  31. /// <returns></returns>
  32. [HttpPost]
  33. public ActionResult List(QueryParamsModel pararms)
  34. {
  35. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  36. //类型名称
  37. var dictionaryCode = pararms.getExtraString("DictionaryDropdown");
  38. //可否编辑
  39. var isEditable = pararms.getExtraInt("DictionaryIsEditable") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsEditable");
  40. //可否显示
  41. var isVisible = pararms.getExtraInt("DictionaryIsVisible") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsVisible");
  42. return base.Json(DictionaryItemServices.Value.GetDictionaryItemViewGird(configuretView, dictionaryCode,
  43. isEditable, isVisible, (int)pararms.page, (int)pararms.rows));
  44. }
  45. /// <summary>
  46. /// 复制新增
  47. /// </summary>
  48. /// <param name="dictionaryItemID"></param>
  49. /// <returns></returns>
  50. public ActionResult CopyAdd(Guid dictionaryItemID)
  51. {
  52. DictionaryItemView dictionaryItemView = new DictionaryItemView();
  53. dictionaryItemView = DictionaryItemServices.Value.GetDictionaryItemView(dictionaryItemID);
  54. return View("Edit", dictionaryItemView);
  55. }
  56. /// <summary>
  57. /// 复制新增
  58. /// </summary>
  59. /// <param name="dictionaryItemView"></param>
  60. /// <returns></returns>
  61. [HttpPost]
  62. public ActionResult CopyAdd(DictionaryItemView dictionaryItemView)
  63. {
  64. dictionaryItemView.DictionaryItemID = Guid.Empty;
  65. return this.Edit(dictionaryItemView);
  66. }
  67. /// <summary>
  68. /// 编辑(新增、修改,业务主键:类型代码、元素值-Value)
  69. /// </summary>
  70. /// <param name="dictionaryItemID"></param>
  71. /// <returns></returns>
  72. [HttpGet]
  73. public ActionResult Edit(Guid? dictionaryItemID)
  74. {
  75. ViewBag.Type = Request.Params["Type"];//临时性加参数控制、屏蔽列表进入无保存按钮权限
  76. DictionaryItemView dictionaryItemView = new DictionaryItemView();
  77. if (dictionaryItemID.HasValue && dictionaryItemID != Guid.Empty)
  78. {
  79. dictionaryItemView = DictionaryItemServices.Value.GetDictionaryItemView(dictionaryItemID);
  80. }
  81. else
  82. {
  83. dictionaryItemView.IsEditable = true;
  84. dictionaryItemView.IsVisible = true;
  85. }
  86. return View(dictionaryItemView);
  87. }
  88. /// <summary>
  89. /// 编辑(新增、修改,业务主键:类型代码、元素值-Value)
  90. /// </summary>
  91. /// <param name="dictionaryItemView"></param>
  92. /// <returns></returns>
  93. [HttpPost]
  94. public ActionResult Edit(DictionaryItemView dictionaryItemView)
  95. {
  96. try
  97. {
  98. DictionaryItemServices.Value.DictionaryItemEdit(dictionaryItemView);
  99. return Json(new ReturnMessage()
  100. {
  101. IsSuccess = true,
  102. Message = "保存成功。"
  103. });
  104. }
  105. catch (Exception ex)
  106. {
  107. return Json(new ReturnMessage()
  108. {
  109. IsSuccess = false,
  110. Message = "保存失败,原因:" + ex.Message
  111. });
  112. }
  113. }
  114. /// <summary>
  115. /// 删除(只可删除可编辑的信息)
  116. /// </summary>
  117. /// <param name="dictionaryItemIDs"></param>
  118. /// <returns></returns>
  119. [HttpPost]
  120. public ActionResult Delete(string dictionaryItemIDs)
  121. {
  122. try
  123. {
  124. List<Guid?> list = dictionaryItemIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  125. .Select(x => (Guid?)new Guid(x)).ToList();
  126. DictionaryItemServices.Value.DictionaryItemDelete(list);
  127. return Json(new ReturnMessage()
  128. {
  129. IsSuccess = true,
  130. Message = "删除成功。"
  131. });
  132. }
  133. catch (Exception ex)
  134. {
  135. return Json(new ReturnMessage()
  136. {
  137. IsSuccess = false,
  138. Message = "删除失败,原因:" + ex.Message
  139. });
  140. }
  141. }
  142. /// <summary>
  143. /// 数据字典下拉列表
  144. /// </summary>
  145. /// <param name="pararms"></param>
  146. /// <param name="dictionaryCode"></param>
  147. /// <returns></returns>
  148. [HttpPost]
  149. public ActionResult ComboGridList(QueryParamsModel pararms, string dictionaryCode = null)
  150. {
  151. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  152. //避开全选值
  153. if (string.IsNullOrEmpty(dictionaryCode))
  154. {
  155. dictionaryCode = pararms.getExtraString("DictionaryDropdown");
  156. }
  157. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString())
  158. {
  159. configuretView.Attribute = "";
  160. }
  161. return base.Json(DictionaryItemServices.Value.GetDictionaryViewComboGrid(configuretView, dictionaryCode, (int)pararms.page, (int)pararms.rows));
  162. }
  163. /// <summary>
  164. /// 数据字典下拉列表(市)
  165. /// </summary>
  166. /// <param name="pararms"></param>
  167. /// <returns></returns>
  168. [HttpPost]
  169. public ActionResult CityComboGridList(QueryParamsModel pararms)
  170. {
  171. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  172. var proviceCode = pararms.getExtraString("ProviceCode");
  173. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString())
  174. {
  175. configuretView.Attribute = "";
  176. }
  177. return base.Json(DictionaryItemServices.Value.GetCityComboGrid(configuretView,
  178. (int)pararms.page, (int)pararms.rows, proviceCode));
  179. }
  180. /// <summary>
  181. /// 数据字典下拉列表(县、区)
  182. /// </summary>
  183. /// <param name="pararms"></param>
  184. /// <returns></returns>
  185. [HttpPost]
  186. public ActionResult DistrictComboGridList(QueryParamsModel pararms)
  187. {
  188. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  189. var cityCode = pararms.getExtraString("CityCode");
  190. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString())
  191. {
  192. configuretView.Attribute = "";
  193. }
  194. return base.Json(DictionaryItemServices.Value.GetDistrictComboGrid(configuretView,
  195. (int)pararms.page, (int)pararms.rows, cityCode));
  196. }
  197. /// <summary>
  198. /// Excel导出
  199. /// </summary>
  200. /// <returns></returns>
  201. [HttpPost]
  202. public ActionResult Excel()
  203. {
  204. NpoiExcelHelper neh = new NpoiExcelHelper();
  205. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  206. //类型名称
  207. var dictionaryCode = Request.Form["DictionaryDropdown"].ToString();
  208. //可否编辑
  209. var isEditable = Request.Form["DictionaryIsEditable"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEditable"].ParseStrTo<int>();
  210. //可否显示
  211. var isVisible = Request.Form["DictionaryIsVisible"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsVisible"].ParseStrTo<int>();
  212. var dt = DictionaryItemServices.Value.GetDictionaryItemViewList(configuretView, dictionaryCode, isEditable, isVisible)
  213. .Select(x => new
  214. {
  215. x.DictionaryCode,
  216. x.DictionaryName,
  217. x.OrderNo,
  218. x.Code,
  219. x.Name,
  220. x.Value,
  221. x.IsEditableName,
  222. x.IsVisibleName
  223. }).ToTable();
  224. string[] liststring = {
  225. "类型代码 ", "类型名称 ", "序号 ", "元素代码 ",
  226. "元素名称 ", "元素值 ", "可否编辑", "可否显示"
  227. };
  228. neh.Export(dt, liststring, "数据字典信息" + DateTime.Now.ToString("yyyyMMdd"));
  229. return Json(new ReturnMessage()
  230. {
  231. IsSuccess = true,
  232. Message = "导出成功。"
  233. });
  234. }
  235. }
  236. }