PageAuthManage.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using BLL.Dto;
  11. using BLL.Dto.AuthDto;
  12. using BLL.Manager;
  13. using Helper;
  14. using HZY.Framework.DependencyInjection;
  15. using Sunny.UI;
  16. namespace Scada.Page
  17. {
  18. public partial class PageAuthManage : UIPage, ISingletonSelfDependency
  19. {
  20. private readonly AuthManager _authManager;
  21. public PageAuthManage(AuthManager authManager)
  22. {
  23. InitializeComponent();
  24. _authManager = authManager;
  25. this.Load += PageAuthManage_Load;
  26. }
  27. private async void PageAuthManage_Load(object sender, EventArgs e)
  28. {
  29. await LoadAuthAynsc(SystemEnums.UserRole.工程师, cbg_Engineer);
  30. await LoadAuthAynsc(SystemEnums.UserRole.访客, cbg_Visitor);
  31. await LoadAuthAynsc(SystemEnums.UserRole.操作员, cbg_Operator);
  32. }
  33. private async Task LoadAuthAynsc(SystemEnums.UserRole role, UICheckBoxGroup cbg)
  34. {
  35. var result = await _authManager.GetAuthAsync(new QueryAuthDto() { Role = role.ToString() });
  36. if (result.Result == SystemEnums.Result.Success)
  37. {
  38. var auths = result.Data[0];
  39. List<int> ints = new List<int>();
  40. if (auths.ControlModule)
  41. {
  42. ints.Add(0);
  43. }
  44. if (auths.MonitorModule)
  45. {
  46. ints.Add(1);
  47. }
  48. if (auths.RecipeModule)
  49. {
  50. ints.Add(2);
  51. }
  52. if (auths.LogModule)
  53. {
  54. ints.Add(3);
  55. }
  56. if (auths.ReportModule)
  57. {
  58. ints.Add(4);
  59. }
  60. if (auths.ChartModule)
  61. {
  62. ints.Add(5);
  63. }
  64. if (auths.ParamModule)
  65. {
  66. ints.Add(6);
  67. }
  68. cbg.SelectedIndexes = ints;
  69. }
  70. else
  71. {
  72. UIMessageBox.ShowError(result.Msg);
  73. }
  74. }
  75. private async void btn_UpdateEngAuth_Click(object sender, EventArgs e)
  76. {
  77. var result =await _authManager.GetAuthAsync(new QueryAuthDto() { Role = SystemEnums.UserRole.工程师.ToString() });
  78. var id = result.Data[0].Id;
  79. await UpdateAuthAsync(SystemEnums.UserRole.工程师,id, cbg_Engineer);
  80. }
  81. private async void btn_UpdateOpAuth_Click(object sender, EventArgs e)
  82. {
  83. var result = await _authManager.GetAuthAsync(new QueryAuthDto() { Role = SystemEnums.UserRole.操作员.ToString() });
  84. var id = result.Data[0].Id;
  85. await UpdateAuthAsync(SystemEnums.UserRole.操作员, id, cbg_Operator);
  86. }
  87. private async void btn_UpdateVisitorAuth_Click(object sender, EventArgs e)
  88. {
  89. var result = await _authManager.GetAuthAsync(new QueryAuthDto() { Role = SystemEnums.UserRole.访客.ToString() });
  90. var id = result.Data[0].Id;
  91. await UpdateAuthAsync(SystemEnums.UserRole.访客, id, cbg_Visitor);
  92. }
  93. private async Task UpdateAuthAsync(SystemEnums.UserRole role,int id, UICheckBoxGroup cbg)
  94. {
  95. var authList = new List<int>();
  96. for(int i =0;i<cbg.Items.Count;i++)
  97. {
  98. if(cbg.SelectedIndexes.Contains(i))
  99. {
  100. authList.Add(i);
  101. }
  102. }
  103. UpdateAuthDto updateAuthDto = new UpdateAuthDto()
  104. {
  105. Id = id,
  106. Role = role.ToString(),
  107. ControlModule = authList.Contains(0),
  108. MonitorModule = authList.Contains(1),
  109. RecipeModule = authList.Contains(2),
  110. LogModule = authList.Contains(3),
  111. ReportModule = authList.Contains(4),
  112. ChartModule = authList.Contains(5),
  113. ParamModule = authList.Contains(6)
  114. };
  115. var result = await _authManager.UpdateAuthAsync(updateAuthDto);
  116. if (result.Result == SystemEnums.Result.Success)
  117. {
  118. UIMessageTip.ShowOk("更新成功");
  119. }
  120. else
  121. {
  122. UIMessageTip.ShowError(result.Msg);
  123. }
  124. }
  125. }
  126. }