ModuleButtonController.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using LeaRun.Application.Busines.AuthorizeManage;
  2. using LeaRun.Application.Entity.AuthorizeManage;
  3. using LeaRun.Util;
  4. using LeaRun.Util.WebControl;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Web.Mvc;
  8. namespace LeaRun.Application.Web.Areas.AuthorizeManage.Controllers
  9. {
  10. /// <summary>
  11. /// 版 本 6.1
  12. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  13. /// 创建人:佘赐雄
  14. /// 日 期:2015.08.01 14:00
  15. /// 描 述:系统按钮
  16. /// </summary>
  17. public class ModuleButtonController : MvcControllerBase
  18. {
  19. private ModuleButtonBLL moduleButtonBLL = new ModuleButtonBLL();
  20. #region 视图功能
  21. /// <summary>
  22. /// 按钮表单
  23. /// </summary>
  24. /// <returns></returns>
  25. [HttpGet]
  26. public ActionResult Form()
  27. {
  28. return View();
  29. }
  30. /// <summary>
  31. /// 选择系统功能
  32. /// </summary>
  33. /// <returns></returns>
  34. [HttpGet]
  35. public ActionResult OptionModule()
  36. {
  37. return View();
  38. }
  39. #endregion
  40. #region 获取数据
  41. /// <summary>
  42. /// 按钮列表
  43. /// </summary>
  44. /// <returns>返回列表Json</returns>
  45. [HttpGet]
  46. public ActionResult GetListJson(string moduleId)
  47. {
  48. var data = moduleButtonBLL.GetList(moduleId);
  49. return Content(data.ToJson());
  50. }
  51. /// <summary>
  52. /// 按钮列表
  53. /// </summary>
  54. /// <returns>返回树形列表Json</returns>
  55. [HttpGet]
  56. public ActionResult GetTreeListJson(string moduleId)
  57. {
  58. var data = moduleButtonBLL.GetList(moduleId);
  59. if (data != null)
  60. {
  61. var TreeList = new List<TreeGridEntity>();
  62. foreach (ModuleButtonEntity item in data)
  63. {
  64. TreeGridEntity tree = new TreeGridEntity();
  65. bool hasChildren = data.Count(t => t.ParentId == item.ModuleButtonId) == 0 ? false : true;
  66. tree.id = item.ModuleButtonId;
  67. tree.parentId = item.ParentId;
  68. tree.expanded = true;
  69. tree.hasChildren = hasChildren;
  70. tree.entityJson = item.ToJson();
  71. TreeList.Add(tree);
  72. }
  73. return Content(TreeList.TreeJson());
  74. }
  75. return null;
  76. }
  77. #endregion
  78. #region 提交数据
  79. /// <summary>
  80. /// 按钮列表Json转换按钮树形Json
  81. /// </summary>
  82. /// <param name="moduleButtonJson">按钮列表</param>
  83. /// <returns>返回树形Json</returns>
  84. [HttpPost]
  85. public ActionResult ListToTreeJson(string moduleButtonJson)
  86. {
  87. var data = from items in moduleButtonJson.ToList<ModuleButtonEntity>() orderby items.SortCode select items;
  88. var treeList = new List<TreeEntity>();
  89. foreach (ModuleButtonEntity item in data)
  90. {
  91. TreeEntity tree = new TreeEntity();
  92. bool hasChildren = data.Count(t => t.ParentId == item.ModuleButtonId) == 0 ? false : true;
  93. tree.id = item.ModuleButtonId;
  94. tree.text = item.FullName;
  95. tree.value = item.ModuleId;
  96. tree.isexpand = true;
  97. tree.complete = true;
  98. tree.hasChildren = hasChildren;
  99. tree.parentId = item.ParentId;
  100. treeList.Add(tree);
  101. }
  102. return Content(treeList.TreeToJson());
  103. }
  104. /// <summary>
  105. /// 按钮列表Json转换按钮树形Json
  106. /// </summary>
  107. /// <param name="moduleButtonJson">按钮列表</param>
  108. /// <returns>返回树形列表Json</returns>
  109. [HttpPost]
  110. public ActionResult ListToListTreeJson(string moduleButtonJson)
  111. {
  112. var data = from items in moduleButtonJson.ToList<ModuleButtonEntity>() orderby items.SortCode select items;
  113. var TreeList = new List<TreeGridEntity>();
  114. foreach (ModuleButtonEntity item in data)
  115. {
  116. TreeGridEntity tree = new TreeGridEntity();
  117. bool hasChildren = data.Count(t => t.ParentId == item.ModuleButtonId) == 0 ? false : true;
  118. tree.id = item.ModuleButtonId;
  119. tree.parentId = item.ParentId;
  120. tree.expanded = true;
  121. tree.hasChildren = hasChildren;
  122. tree.entityJson = item.ToJson();
  123. TreeList.Add(tree);
  124. }
  125. return Content(TreeList.TreeJson());
  126. }
  127. /// <summary>
  128. /// 复制按钮
  129. /// </summary>
  130. /// <param name="keyValue">主键</param>
  131. /// <param name="moduleId">功能主键</param>
  132. /// <returns></returns>
  133. [HttpPost]
  134. public ActionResult CopyForm(string keyValue, string moduleId)
  135. {
  136. moduleButtonBLL.CopyForm(keyValue, moduleId);
  137. return Content(new AjaxResult { type = ResultType.success, message = "复制成功。" }.ToJson());
  138. }
  139. #endregion
  140. }
  141. }