BaseClass.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using MySystem.Models.Bs;
  4. using System.Data;
  5. namespace MySystem
  6. {
  7. /// <summary>
  8. /// 基础功能方法
  9. /// </summary>
  10. public class BaseClass
  11. {
  12. public Models.Bs.WebCMSEntities bsdb = new Models.Bs.WebCMSEntities();
  13. #region
  14. public string GetRightJson()
  15. {
  16. string result = "[";
  17. List<RightDic> list = bsdb.RightDic.ToList();
  18. List<RightDic> Level1 = list.Where(m => m.RightLevel == 1).ToList();
  19. foreach (RightDic sub1 in Level1)
  20. {
  21. result += "{title: '" + sub1.Name + "', id: '" + sub1.Id + "', spread: false, children: [";
  22. List<RightDic> Level2 = list.Where(m => m.RightLevel == 2 && m.Id.StartsWith(sub1.Id)).ToList();
  23. if (Level2.Count > 0)
  24. {
  25. foreach (RightDic sub2 in Level2)
  26. {
  27. result += "{title: '" + sub2.Name + "', id: '" + sub2.Id + "', spread: false, children: [";
  28. List<RightDic> Level3 = list.Where(m => m.RightLevel == 3 && m.Id.StartsWith(sub2.Id)).ToList();
  29. if (Level3.Count > 0)
  30. {
  31. foreach (RightDic sub3 in Level3)
  32. {
  33. result += "{title: '" + sub3.Name + "', id: '" + sub3.Id + "', spread: false, children: [";
  34. string rightString = ForOperateRight(sub3.Id);
  35. if (!string.IsNullOrEmpty(rightString))
  36. {
  37. result += rightString;
  38. }
  39. else
  40. {
  41. result += "{title: '基本权限', id: '" + sub3.Id + "_base'}";
  42. }
  43. result += "]},";
  44. }
  45. result = result.TrimEnd(',');
  46. }
  47. else
  48. {
  49. string rightString = ForOperateRight(sub2.Id);
  50. if (!string.IsNullOrEmpty(rightString))
  51. {
  52. result += rightString;
  53. }
  54. else
  55. {
  56. result += "{title: '基本权限', id: '" + sub2.Id + "_base'}";
  57. }
  58. }
  59. result += "]},";
  60. }
  61. result = result.TrimEnd(',');
  62. }
  63. else
  64. {
  65. result += ForOperateRight(sub1.Id);
  66. string rightString = ForOperateRight(sub1.Id);
  67. if (!string.IsNullOrEmpty(rightString))
  68. {
  69. result += rightString;
  70. }
  71. else
  72. {
  73. result += "{title: '基本权限', id: '" + sub1.Id + "_base'}";
  74. }
  75. }
  76. result += "]},";
  77. }
  78. result = result.TrimEnd(',');
  79. result += "]";
  80. return result;
  81. }
  82. //读取当前菜单有哪些权限
  83. public string ForOperateRight(string Id)
  84. {
  85. string result = "";
  86. List<MenuRight> rights = bsdb.MenuRight.Where(m => m.MenuId.StartsWith(Id)).OrderBy(m => m.MenuId).ToList();
  87. foreach (MenuRight right in rights)
  88. {
  89. result += "{title: '" + right.Name + "', id: '" + right.MenuId + "'},";
  90. }
  91. RightDic rightDic = bsdb.RightDic.FirstOrDefault(m => m.Id == Id) ?? new RightDic();
  92. if (!string.IsNullOrEmpty(rightDic.OtherRight))
  93. {
  94. string[] OtherRightList = rightDic.OtherRight.Split('\n');
  95. foreach (string SubOtherRight in OtherRightList)
  96. {
  97. string[] SubOtherRightData = SubOtherRight.Split('_');
  98. result += "{title: '" + SubOtherRightData[1] + "', id: '" + Id + "_" + SubOtherRightData[0] + "'},";
  99. }
  100. }
  101. result = result.TrimEnd(',');
  102. return result;
  103. }
  104. #endregion
  105. }
  106. }