DataItemDetailController.cs 7.8 KB

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