RoleSettingWindow.xaml.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using ivf_tl_Entity.Entity.AppSetting;
  2. using ivf_tl_Entity.Enums;
  3. using ivf_tl_Manage.Converts;
  4. using ivf_tl_Service.HttpProvider;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Configuration;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Shapes;
  19. namespace ivf_tl_Manage.Win
  20. {
  21. /// <summary>
  22. /// RoleSettingWindow.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class RoleSettingWindow : Window
  25. {
  26. SettingProvider settingProvider;
  27. List<Business> BusinesseList = new List<Business>();
  28. long CurrentRole;
  29. public RoleSettingWindow(SettingProvider provider,long currentRoleId)
  30. {
  31. InitializeComponent();
  32. this.Owner = AppData.Instance.MainWindow;
  33. settingProvider = provider;
  34. CurrentRole = currentRoleId;
  35. BusinesseList = settingProvider.GetAllBusinessAndChildrenApi();
  36. var oldRole = settingProvider.GetRoleSettingApi(currentRoleId);
  37. if (oldRole != null && oldRole.permissions != null)
  38. {
  39. var se = oldRole.permissions.Select(x => x.id).ToList();
  40. foreach (var item in BusinesseList) if (se.Contains(item.id)) item.isChecked = true;
  41. }
  42. this._listBox.ItemsSource = BusinesseList;
  43. this.Closed += (a, b) =>
  44. {
  45. AppData.Instance.MainWindow.Activate();
  46. };
  47. }
  48. private void MessageBoxShow(string mess)
  49. {
  50. this.message.Text = mess;
  51. }
  52. private void ExLog(Exception ex, string name)
  53. {
  54. AppData.Instance.LogService.ExceptionLog(ex, $"RoleSettingWindow.{name}", LogEnum.RunException);
  55. }
  56. private void ErrorLog(string message, LogEnum logType)
  57. {
  58. AppData.Instance.LogService.TLLog($"RoleSettingWindow.{message}", logType);
  59. }
  60. private void Cancel_Click(object sender, RoutedEventArgs e)
  61. {
  62. this.DialogResult = false;
  63. return;
  64. }
  65. private void _listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  66. {
  67. if (!(this._listBox.SelectedItem is Business business)) return;
  68. foreach (var item in BusinesseList)
  69. {
  70. if (item.id == business.id)
  71. {
  72. item.isOpen = 1;
  73. }
  74. else
  75. {
  76. item.isOpen = 0;
  77. }
  78. }
  79. this._children.ItemsSource = business.children;
  80. }
  81. private void Rectangle_MouseUp(object sender, MouseButtonEventArgs e)
  82. {
  83. if (!(sender is Image source)) return;
  84. if(source.Tag.ToString() == "0")
  85. {
  86. source.Tag = "1";
  87. source.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/SettingSubIcon.png", UriKind.Absolute));
  88. }
  89. else
  90. {
  91. source.Tag = "0";
  92. source.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/SettingAddIcon.png", UriKind.Absolute));
  93. }
  94. }
  95. private void Ok_Click(object sender, RoutedEventArgs e)
  96. {
  97. try
  98. {
  99. if (CurrentRole == null)
  100. {
  101. //MessageBoxShow("未获取到当前角色");
  102. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0290"));
  103. return;
  104. }
  105. var ids = BusinesseList.Where(x => x.isChecked).Select(x => x.id).ToList();
  106. string error = settingProvider.RoleSettingApi(CurrentRole, ids);
  107. if (!string.IsNullOrEmpty(error))
  108. {
  109. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
  110. return;
  111. }
  112. new ToastWindow(AppData.Instance.MainWindow, 1920, 65, true).Show();
  113. this.DialogResult = true;
  114. return;
  115. }
  116. catch (Exception ex)
  117. {
  118. ExLog(ex, "Ok_Click");
  119. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0291")}:{ex.Message}");
  120. }
  121. }
  122. private void Rectangle_MouseDown(object sender, MouseButtonEventArgs e)
  123. {
  124. if (!(sender is Image source)) return;
  125. if (!(source.Tag is Business business)) return;
  126. if (this._listBox.SelectedItem == business)
  127. {
  128. if (business.isOpen == 1)
  129. {
  130. business.isOpen = 0;
  131. this._children.ItemsSource = null;
  132. }
  133. else
  134. {
  135. business.isOpen = 1;
  136. this._children.ItemsSource = business.children;
  137. }
  138. }
  139. else
  140. {
  141. this._listBox.SelectedItem = business;
  142. }
  143. e.Handled = true;
  144. }
  145. }
  146. }