DictionaryItemController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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="pararms"></param>
  49. /// <returns></returns>
  50. [HttpPost]
  51. public ActionResult DictionItemList(QueryParamsModel pararms)
  52. {
  53. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  54. //类型名称
  55. var dictionaryCode = Request.QueryString["DictionaryDropdown"];
  56. //可否编辑
  57. var isEditable = pararms.getExtraInt("DictionaryIsEditable") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsEditable");
  58. //可否显示
  59. var isVisible = pararms.getExtraInt("DictionaryIsVisible") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsVisible");
  60. return base.Json(DictionaryItemServices.Value.GetDictionaryItemViewGird(configuretView, dictionaryCode,
  61. isEditable, isVisible, (int)pararms.page, (int)pararms.rows));
  62. }
  63. /// <summary>
  64. /// 复制新增
  65. /// </summary>
  66. /// <param name="dictionaryItemID"></param>
  67. /// <returns></returns>
  68. public ActionResult CopyAdd(Guid dictionaryItemID)
  69. {
  70. DictionaryItemView dictionaryItemView = new DictionaryItemView();
  71. dictionaryItemView = DictionaryItemServices.Value.GetDictionaryItemView(dictionaryItemID);
  72. return View("Edit", dictionaryItemView);
  73. }
  74. /// <summary>
  75. /// 复制新增
  76. /// </summary>
  77. /// <param name="dictionaryItemView"></param>
  78. /// <returns></returns>
  79. [HttpPost]
  80. public ActionResult CopyAdd(DictionaryItemView dictionaryItemView)
  81. {
  82. dictionaryItemView.DictionaryItemID = Guid.Empty;
  83. return this.Edit(dictionaryItemView);
  84. }
  85. /// <summary>
  86. /// 编辑(新增、修改,业务主键:类型代码、元素值-Value)
  87. /// </summary>
  88. /// <param name="dictionaryItemID"></param>
  89. /// <returns></returns>
  90. [HttpGet]
  91. public ActionResult Edit(Guid? dictionaryItemID)
  92. {
  93. ViewBag.Type = Request.Params["Type"];//临时性加参数控制、屏蔽列表进入无保存按钮权限
  94. DictionaryItemView dictionaryItemView = new DictionaryItemView();
  95. if (dictionaryItemID.HasValue && dictionaryItemID != Guid.Empty)
  96. {
  97. dictionaryItemView = DictionaryItemServices.Value.GetDictionaryItemView(dictionaryItemID);
  98. }
  99. else
  100. {
  101. dictionaryItemView.IsEditable = true;
  102. dictionaryItemView.IsVisible = true;
  103. }
  104. return View(dictionaryItemView);
  105. }
  106. /// <summary>
  107. /// 编辑(新增、修改,业务主键:类型代码、元素值-Value)
  108. /// </summary>
  109. /// <param name="dictionaryItemView"></param>
  110. /// <returns></returns>
  111. [HttpPost]
  112. public ActionResult Edit(DictionaryItemView dictionaryItemView)
  113. {
  114. try
  115. {
  116. DictionaryItemServices.Value.DictionaryItemEdit(dictionaryItemView);
  117. return Json(new ReturnMessage()
  118. {
  119. IsSuccess = true,
  120. Message = "保存成功。"
  121. });
  122. }
  123. catch (Exception ex)
  124. {
  125. return Json(new ReturnMessage()
  126. {
  127. IsSuccess = false,
  128. Message = "保存失败,原因:" + ex.Message
  129. });
  130. }
  131. }
  132. /// <summary>
  133. /// 删除(只可删除可编辑的信息)
  134. /// </summary>
  135. /// <param name="dictionaryItemIDs"></param>
  136. /// <returns></returns>
  137. [HttpPost]
  138. public ActionResult Delete(string dictionaryItemIDs)
  139. {
  140. try
  141. {
  142. List<Guid?> list = dictionaryItemIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  143. .Select(x => (Guid?)new Guid(x)).ToList();
  144. DictionaryItemServices.Value.DictionaryItemDelete(list);
  145. return Json(new ReturnMessage()
  146. {
  147. IsSuccess = true,
  148. Message = "删除成功。"
  149. });
  150. }
  151. catch (Exception ex)
  152. {
  153. return Json(new ReturnMessage()
  154. {
  155. IsSuccess = false,
  156. Message = "删除失败,原因:" + ex.Message
  157. });
  158. }
  159. }
  160. /// <summary>
  161. /// 数据字典下拉列表
  162. /// </summary>
  163. /// <param name="pararms"></param>
  164. /// <param name="dictionaryCode"></param>
  165. /// <returns></returns>
  166. [HttpPost]
  167. public ActionResult ComboGridList(QueryParamsModel pararms, string dictionaryCode = null)
  168. {
  169. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  170. //避开全选值
  171. if (string.IsNullOrEmpty(dictionaryCode))
  172. {
  173. dictionaryCode = pararms.getExtraString("DictionaryDropdown");
  174. }
  175. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString())
  176. {
  177. configuretView.Attribute = "";
  178. }
  179. return base.Json(DictionaryItemServices.Value.GetDictionaryViewComboGrid(configuretView,
  180. dictionaryCode, (int)pararms.page, (int)pararms.rows));
  181. }
  182. /// <summary>
  183. /// 数据字典下拉列表(市)
  184. /// </summary>
  185. /// <param name="pararms"></param>
  186. /// <returns></returns>
  187. [HttpPost]
  188. public ActionResult CityComboGridList(QueryParamsModel pararms)
  189. {
  190. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  191. var proviceCode = pararms.getExtraString("ProviceCode");
  192. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString())
  193. {
  194. configuretView.Attribute = "";
  195. }
  196. return base.Json(DictionaryItemServices.Value.GetCityComboGrid(configuretView,
  197. (int)pararms.page, (int)pararms.rows, proviceCode));
  198. }
  199. /// <summary>
  200. /// 数据字典下拉列表(县、区)
  201. /// </summary>
  202. /// <param name="pararms"></param>
  203. /// <returns></returns>
  204. [HttpPost]
  205. public ActionResult DistrictComboGridList(QueryParamsModel pararms)
  206. {
  207. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  208. var cityCode = pararms.getExtraString("CityCode");
  209. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString())
  210. {
  211. configuretView.Attribute = "";
  212. }
  213. return base.Json(DictionaryItemServices.Value.GetDistrictComboGrid(configuretView,
  214. (int)pararms.page, (int)pararms.rows, cityCode));
  215. }
  216. /// <summary>
  217. /// Excel导出
  218. /// </summary>
  219. /// <returns></returns>
  220. [HttpPost]
  221. public ActionResult Excel()
  222. {
  223. NpoiExcelHelper neh = new NpoiExcelHelper();
  224. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  225. //类型名称
  226. var dictionaryCode = Request.Form["DictionaryDropdown"].ToString();
  227. //可否编辑
  228. var isEditable = Request.Form["DictionaryIsEditable"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEditable"].ParseStrTo<int>();
  229. //可否显示
  230. var isVisible = Request.Form["DictionaryIsVisible"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsVisible"].ParseStrTo<int>();
  231. var dt = DictionaryItemServices.Value.GetDictionaryItemViewList(configuretView, dictionaryCode, isEditable, isVisible)
  232. .Select(x => new
  233. {
  234. x.DictionaryCode,
  235. x.DictionaryName,
  236. x.OrderNo,
  237. x.Code,
  238. x.Name,
  239. x.Value,
  240. x.IsEditableName,
  241. x.IsVisibleName
  242. }).ToTable();
  243. string[] liststring = {
  244. "类型代码 ", "类型名称 ", "序号 ", "元素代码 ",
  245. "元素名称 ", "元素值 ", "可否编辑", "可否显示"
  246. };
  247. neh.Export(dt, liststring, "数据字典信息" + DateTime.Now.ToString("yyyyMMdd"));
  248. return Json(new ReturnMessage()
  249. {
  250. IsSuccess = true,
  251. Message = "导出成功。"
  252. });
  253. }
  254. }
  255. }