XTMKBuiness.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.Composition;
  4. using System.Linq;
  5. using System.Text;
  6. using PMS.DBService.SysManager;
  7. using PMS.Interface.SysManager;
  8. using QWPlatform.IService;
  9. using QWPlatform.SystemLibrary.Utils;
  10. using QWPlatform.SystemLibrary;
  11. using System.Data;
  12. using PMS.BusinessModels.SysManager;
  13. namespace PMS.BusinessService.SysManager
  14. {
  15. /// <summary>
  16. /// 创 建 人:王海洋
  17. /// 创建日期:2018-12-7
  18. /// 功能描述:系统模块业务层
  19. /// </summary>
  20. public class XTMKBuiness : ISystemModule
  21. {
  22. //数据服务
  23. private XTMKService db_sysMenu = DataServiceBase.Instance<XTMKService>();
  24. #region 系统模块基础操作
  25. //根据用户id获取对应的菜单目录
  26. public string GetTreeMenu(List<string> roleids, bool isAdmin)
  27. {
  28. var list = db_sysMenu.GetSysMenus(roleids, isAdmin);
  29. return Strings.ObjectToJson(list, true);
  30. }
  31. //获取easyui treeGridView
  32. public string GetTreeGridView()
  33. {
  34. var dt = db_sysMenu.GetList();
  35. var column = new string[] { "ID", "上级ID", "名称", "地址", "启用", "图标", "序号", "备注", "首页" };
  36. return dt.ToEasyUITreeGridJson("ID", "上级ID", null, column, "");
  37. //return dt.ToJson();
  38. }
  39. //获取module信息
  40. public DataTable GetModuleInfo(int id)
  41. {
  42. return db_sysMenu.GetInfoById(id);
  43. }
  44. //获取EasyuiTreejson
  45. public string GetEasyUIJson()
  46. {
  47. var dt = db_sysMenu.GetList();
  48. return dt.ToEasyUITreeJson("ID", "名称", "上级ID", null, "");
  49. }
  50. //保存
  51. public bool SaveInfo(form_menu_model model)
  52. {
  53. var emodel = new PMS.EntityModels.SysManager.XTMKModel();
  54. emodel.MC = model.name;
  55. emodel.DZ = model.address;
  56. emodel.QY = model.GetIsActive ? 1 : 0;
  57. emodel.TB = model.icons;
  58. emodel.XH = model.ordnum;
  59. emodel.BZ = model.remark;
  60. emodel.SY = model.ishome == "on" ? 1 : 0;
  61. if (model.parentid > 0)
  62. {//设置为上级ID
  63. emodel.SJID = model.parentid;
  64. }
  65. if (model.id > 0)
  66. {//存在ID,说明是编辑
  67. emodel.ID = model.id;
  68. return db_sysMenu.Update(emodel) > 0;
  69. }
  70. else
  71. {//不存在ID,需要创建一个新记录
  72. return db_sysMenu.Add(emodel) > 0;
  73. }
  74. }
  75. //检查数据库是否重复名称
  76. public bool CheckNameExists(string name, int id)
  77. {
  78. return db_sysMenu.CheckNameExists(name, id);
  79. }
  80. //删除模块
  81. public bool DeleteModule(int id)
  82. {
  83. var model = new EntityModels.SysManager.XTMKModel();
  84. model.ID = id;
  85. return db_sysMenu.Delete(model) > 0;
  86. }
  87. #endregion
  88. #region 系统模块授权操作
  89. //根据ID查询已授权的功能列表
  90. public DataTable GetButtonListByID(int id)
  91. {
  92. return this.db_sysMenu.SelectButtonsByMid(id);
  93. }
  94. //对模块分配按钮
  95. public bool AuthButtons(int id, string buttonids, string group)
  96. {
  97. if (!string.IsNullOrEmpty(buttonids))
  98. {
  99. group = group.Trim();
  100. var btns = buttonids.Split(',');
  101. int orderNum = 0;
  102. foreach (var bid in btns)
  103. {
  104. if (!string.IsNullOrEmpty(bid))
  105. {//按钮id不为空
  106. int buttonId = 0;
  107. if (int.TryParse(bid, out buttonId))
  108. {
  109. orderNum++;
  110. //同一个模块,同一个按钮,同一个分组不能重复
  111. bool r = db_sysMenu.CheckModuleButtonExists(id, group, buttonId);
  112. if (!r)
  113. {//只有不存在时才添加该按钮
  114. db_sysMenu.AddModuleButton(id, group, buttonId, orderNum);
  115. }
  116. }//end if
  117. }//end if
  118. }
  119. return true;
  120. }
  121. return false;
  122. }
  123. //移除指定模块的授权功能
  124. public bool RemoveAuthButtons(string ids)
  125. {
  126. if (!string.IsNullOrEmpty(ids))
  127. {//检查是否为空
  128. var mids = ids.Split(',');
  129. foreach (var id in mids)
  130. {
  131. if (!string.IsNullOrEmpty(id))
  132. {//id不为空,删除
  133. int mid = 0;
  134. if (int.TryParse(id, out mid))
  135. {
  136. db_sysMenu.RemoveModuleButton(mid);
  137. }
  138. }
  139. }
  140. return true;
  141. }
  142. return false;
  143. }
  144. //获取所有的模块授权(已启用的模块)
  145. public string GetActiveTreemenu()
  146. {
  147. //获取模块的列表
  148. var dt = db_sysMenu.GetMenuActiveList();
  149. return dt.ToEasyUITreeJson("ID", "名称", "上级ID", null, null);
  150. }
  151. #endregion
  152. }
  153. }