DataItemDetailController.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using Lottomat.Application.Busines.SystemManage;
  2. using Lottomat.Application.Cache;
  3. using Lottomat.Application.Code;
  4. using Lottomat.Application.Entity.SystemManage;
  5. using Lottomat.Application.Entity.SystemManage.ViewModel;
  6. using Lottomat.Util;
  7. using Lottomat.Util.WebControl;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Web.Mvc;
  11. using Lottomat.Util.Extension;
  12. namespace Lottomat.Application.Admin.Areas.SystemManage.Controllers
  13. {
  14. /// <summary>
  15. /// 版 本 1.0
  16. /// Copyright (c) 2016-2017
  17. /// 创建人:赵轶
  18. /// 日 期:2015.11.17 9:56
  19. /// 描 述:数据字典明细
  20. /// </summary>
  21. public class DataItemDetailController : MvcControllerBase
  22. {
  23. private DataItemDetailBLL dataItemDetailBLL = new DataItemDetailBLL();
  24. private DataItemCache dataItemCache = new DataItemCache();
  25. #region 视图功能
  26. /// <summary>
  27. /// 明细管理
  28. /// </summary>
  29. /// <returns></returns>
  30. [HttpGet]
  31. [HandlerAuthorize(PermissionMode.Enforce)]
  32. public ActionResult Index()
  33. {
  34. return View();
  35. }
  36. /// <summary>
  37. /// 明细表单
  38. /// </summary>
  39. /// <returns></returns>
  40. [HttpGet]
  41. [HandlerAuthorize(PermissionMode.Enforce)]
  42. public ActionResult Form()
  43. {
  44. return View();
  45. }
  46. /// <summary>
  47. /// 明细详细
  48. /// </summary>
  49. /// <returns></returns>
  50. [HttpGet]
  51. [HandlerAuthorize(PermissionMode.Enforce)]
  52. public ActionResult Detail()
  53. {
  54. return View();
  55. }
  56. #endregion
  57. #region 获取数据
  58. /// <summary>
  59. /// 明细列表
  60. /// </summary>
  61. /// <param name="itemId">分类Id</param>
  62. /// <param name="condition">条件</param>
  63. /// <param name="keyword">关键字查询</param>
  64. /// <returns>返回树形列表Json</returns>
  65. [HttpGet]
  66. public ActionResult GetTreeListJson(string itemId, string condition, string keyword)
  67. {
  68. var data = dataItemDetailBLL.GetList(itemId).ToList();
  69. if (!string.IsNullOrEmpty(keyword))
  70. {
  71. #region 多条件查询
  72. switch (condition)
  73. {
  74. case "ItemName": //项目名
  75. data = data.TreeWhere(t => t.ItemName.Contains(keyword), "ItemDetailId");
  76. break;
  77. case "ItemValue": //项目值
  78. data = data.TreeWhere(t => t.ItemValue.Contains(keyword), "ItemDetailId");
  79. break;
  80. case "SimpleSpelling": //拼音
  81. data = data.TreeWhere(t => t.SimpleSpelling.Contains(keyword), "ItemDetailId");
  82. break;
  83. default:
  84. break;
  85. }
  86. #endregion
  87. }
  88. var TreeList = new List<TreeGridEntity>();
  89. foreach (DataItemDetailEntity item in data)
  90. {
  91. TreeGridEntity tree = new TreeGridEntity();
  92. bool hasChildren = data.Count(t => t.ParentId == item.ItemDetailId) != 0;
  93. tree.id = item.ItemDetailId;
  94. tree.parentId = item.ParentId;
  95. tree.expanded = true;
  96. tree.hasChildren = hasChildren;
  97. tree.entityJson = item.ToJson();
  98. TreeList.Add(tree);
  99. }
  100. return Content(TreeList.TreeJson());
  101. }
  102. /// <summary>
  103. /// 明细实体
  104. /// </summary>
  105. /// <param name="keyValue">主键值</param>
  106. /// <returns>返回对象Json</returns>
  107. [HttpGet]
  108. public ActionResult GetFormJson(string keyValue)
  109. {
  110. var data = dataItemDetailBLL.GetEntity(keyValue);
  111. return Content(data.ToJson());
  112. }
  113. /// <summary>
  114. /// 获取数据字典列表(绑定控件)
  115. /// </summary>
  116. /// <param name="EnCode">代码</param>
  117. /// <returns>返回列表树Json</returns>
  118. [HttpGet]
  119. public ActionResult GetDataItemTreeJson(string EnCode)
  120. {
  121. var data = dataItemCache.GetDataItemList(EnCode);
  122. var treeList = new List<TreeEntity>();
  123. foreach (DataItemModel item in data)
  124. {
  125. TreeEntity tree = new TreeEntity();
  126. bool hasChildren = data.Count(t => t.ParentId == item.ItemDetailId) == 0 ? false : true;
  127. tree.id = item.ItemDetailId;
  128. tree.text = item.ItemName;
  129. tree.value = item.ItemValue;
  130. tree.parentId = item.ParentId;
  131. tree.isexpand = true;
  132. tree.complete = true;
  133. tree.hasChildren = hasChildren;
  134. treeList.Add(tree);
  135. }
  136. return Content(treeList.TreeToJson());
  137. }
  138. /// <summary>
  139. /// 获取数据字典列表(绑定控件)
  140. /// </summary>
  141. /// <param name="EnCode">代码</param>
  142. /// <returns>返回列表Json</returns>
  143. [HttpGet]
  144. public ActionResult GetDataItemListJson(string EnCode)
  145. {
  146. var data = dataItemCache.GetDataItemList(EnCode);
  147. return Content(data.ToJson());
  148. }
  149. /// <summary>
  150. /// 获取数据字典子列表(绑定控件)
  151. /// </summary>
  152. /// <param name="EnCode">代码</param>
  153. /// <param name="ItemValue">项目值</param>
  154. /// <returns>返回列表Json</returns>
  155. public ActionResult GetSubDataItemListJson(string EnCode, string ItemValue)
  156. {
  157. var data = dataItemCache.GetSubDataItemList(EnCode, ItemValue);
  158. return Content(data.ToJson());
  159. }
  160. #endregion
  161. #region 验证数据
  162. /// <summary>
  163. /// 项目值不能重复
  164. /// </summary>
  165. /// <param name="ItemValue">项目值</param>
  166. /// <param name="keyValue">主键</param>
  167. /// <param name="itemId">分类Id</param>
  168. /// <returns></returns>
  169. [HttpGet]
  170. public ActionResult ExistItemValue(string ItemValue, string keyValue, string itemId)
  171. {
  172. bool IsOk = dataItemDetailBLL.ExistItemValue(ItemValue, keyValue, itemId);
  173. return Content(IsOk.ToString());
  174. }
  175. /// <summary>
  176. /// 项目名不能重复
  177. /// </summary>
  178. /// <param name="ItemName">项目名</param>
  179. /// <param name="keyValue">主键</param>
  180. /// <param name="itemId">分类Id</param>
  181. /// <returns></returns>
  182. [HttpGet]
  183. public ActionResult ExistItemName(string ItemName, string keyValue, string itemId)
  184. {
  185. bool IsOk = dataItemDetailBLL.ExistItemName(ItemName, keyValue, itemId);
  186. return Content(IsOk.ToString());
  187. }
  188. #endregion
  189. #region 提交数据
  190. /// <summary>
  191. /// 删除明细
  192. /// </summary>
  193. /// <param name="keyValue">主键值</param>
  194. /// <returns></returns>
  195. [HttpPost]
  196. [ValidateAntiForgeryToken]
  197. [AjaxOnly]
  198. public ActionResult RemoveForm(string keyValue)
  199. {
  200. dataItemDetailBLL.RemoveForm(keyValue);
  201. return Success("删除成功。");
  202. }
  203. /// <summary>
  204. /// 保存明细表单(新增、修改)
  205. /// </summary>
  206. /// <param name="keyValue">主键值</param>
  207. /// <param name="dataItemDetailEntity">明细实体</param>
  208. /// <returns></returns>
  209. [HttpPost]
  210. [ValidateAntiForgeryToken]
  211. [AjaxOnly]
  212. public ActionResult SaveForm(string keyValue, DataItemDetailEntity dataItemDetailEntity)
  213. {
  214. dataItemDetailBLL.SaveForm(keyValue, dataItemDetailEntity);
  215. return Success("操作成功。");
  216. }
  217. #endregion
  218. }
  219. }