| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- using ivf_tl_Entity.Entity.AppSetting;
- using ivf_tl_Entity.Enums;
- using ivf_tl_Manage.Converts;
- using ivf_tl_Service.HttpProvider;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- namespace ivf_tl_Manage.Win
- {
- /// <summary>
- /// RoleSettingWindow.xaml 的交互逻辑
- /// </summary>
- public partial class RoleSettingWindow : Window
- {
- SettingProvider settingProvider;
- List<Business> BusinesseList = new List<Business>();
- long CurrentRole;
- public RoleSettingWindow(SettingProvider provider,long currentRoleId)
- {
- InitializeComponent();
- this.Owner = AppData.Instance.MainWindow;
- settingProvider = provider;
- CurrentRole = currentRoleId;
- BusinesseList = settingProvider.GetAllBusinessAndChildrenApi();
- var oldRole = settingProvider.GetRoleSettingApi(currentRoleId);
- if (oldRole != null && oldRole.permissions != null)
- {
- var se = oldRole.permissions.Select(x => x.id).ToList();
- foreach (var item in BusinesseList) if (se.Contains(item.id)) item.isChecked = true;
- }
- this._listBox.ItemsSource = BusinesseList;
- this.Closed += (a, b) =>
- {
- AppData.Instance.MainWindow.Activate();
- };
- }
- private void MessageBoxShow(string mess)
- {
- this.message.Text = mess;
- }
- private void ExLog(Exception ex, string name)
- {
- AppData.Instance.LogService.ExceptionLog(ex, $"RoleSettingWindow.{name}", LogEnum.RunException);
- }
- private void ErrorLog(string message, LogEnum logType)
- {
- AppData.Instance.LogService.TLLog($"RoleSettingWindow.{message}", logType);
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- this.DialogResult = false;
- return;
- }
- private void _listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!(this._listBox.SelectedItem is Business business)) return;
- foreach (var item in BusinesseList)
- {
- if (item.id == business.id)
- {
- item.isOpen = 1;
- }
- else
- {
- item.isOpen = 0;
- }
- }
- this._children.ItemsSource = business.children;
- }
- private void Rectangle_MouseUp(object sender, MouseButtonEventArgs e)
- {
- if (!(sender is Image source)) return;
- if(source.Tag.ToString() == "0")
- {
- source.Tag = "1";
- source.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/SettingSubIcon.png", UriKind.Absolute));
- }
- else
- {
- source.Tag = "0";
- source.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/SettingAddIcon.png", UriKind.Absolute));
- }
- }
- private void Ok_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (CurrentRole == null)
- {
- //MessageBoxShow("未获取到当前角色");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0290"));
- return;
- }
- var ids = BusinesseList.Where(x => x.isChecked).Select(x => x.id).ToList();
- string error = settingProvider.RoleSettingApi(CurrentRole, ids);
- if (!string.IsNullOrEmpty(error))
- {
- MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
- return;
- }
- new ToastWindow(AppData.Instance.MainWindow, 1920, 65, true).Show();
- this.DialogResult = true;
- return;
- }
- catch (Exception ex)
- {
- ExLog(ex, "Ok_Click");
- MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0291")}:{ex.Message}");
- }
- }
- private void Rectangle_MouseDown(object sender, MouseButtonEventArgs e)
- {
- if (!(sender is Image source)) return;
- if (!(source.Tag is Business business)) return;
- if (this._listBox.SelectedItem == business)
- {
- if (business.isOpen == 1)
- {
- business.isOpen = 0;
- this._children.ItemsSource = null;
- }
- else
- {
- business.isOpen = 1;
- this._children.ItemsSource = business.children;
- }
- }
- else
- {
- this._listBox.SelectedItem = business;
- }
- e.Handled = true;
- }
- }
- }
|