BusSettingWindow.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using ivf_tl_CustomControls;
  2. using ivf_tl_Entity.Entity.AppSetting;
  3. using ivf_tl_Entity.Enums;
  4. using ivf_tl_Manage.Converts;
  5. using ivf_tl_Service.HttpProvider;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Data.SqlTypes;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Shapes;
  21. namespace ivf_tl_Manage.Win
  22. {
  23. /// <summary>
  24. /// BusSettingWindow.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class BusSettingWindow : Window
  27. {
  28. private SettingProvider settingProvider;
  29. private long ParentId { get; set; } = 0;
  30. public BusSettingWindow(SettingProvider settingProvider, long id,string name)
  31. {
  32. InitializeComponent();
  33. this.Owner = AppData.Instance.MainWindow;
  34. ParentId = id;
  35. this.settingProvider = settingProvider;
  36. //this._title_TextBlock.Text = $"{name}业务功能关联";
  37. this._title_TextBlock.Text = $"{name}{KeyToStringConvert.GetLanguageStringByKey("0307")}";
  38. NoSelectedBus = new ObservableCollection<Business>(settingProvider.GetUnassignedFuncApi());
  39. SelectedBus = new ObservableCollection<Business>(settingProvider.GetBusByIdApi(id));
  40. Closed += (s, e) => AppData.Instance.MainWindow.Activate();
  41. }
  42. private void MessageBoxShow(string mess)
  43. {
  44. //this.message.Text = mess;
  45. }
  46. private void ExLog(Exception ex, string name)
  47. {
  48. AppData.Instance.LogService.ExceptionLog(ex, $"BusSettingWindow.{name}", LogEnum.RunException);
  49. }
  50. private void ErrorLog(string message, LogEnum logType)
  51. {
  52. AppData.Instance.LogService.TLLog($"BusSettingWindow.{message}", logType);
  53. }
  54. public ObservableCollection<Business> NoSelectedBus
  55. {
  56. get { return (ObservableCollection<Business>)GetValue(NoSelectedBusProperty); }
  57. set { SetValue(NoSelectedBusProperty, value); }
  58. }
  59. // Using a DependencyProperty as the backing store for NoSelectedBus. This enables animation, styling, binding, etc...
  60. public static readonly DependencyProperty NoSelectedBusProperty =
  61. DependencyProperty.Register("NoSelectedBus", typeof(ObservableCollection<Business>), typeof(BusSettingWindow), new PropertyMetadata(new ObservableCollection<Business>()));
  62. public ObservableCollection<Business> SelectedBus
  63. {
  64. get { return (ObservableCollection<Business>)GetValue(SelectedBusProperty); }
  65. set { SetValue(SelectedBusProperty, value); }
  66. }
  67. // Using a DependencyProperty as the backing store for SelectedBus. This enables animation, styling, binding, etc...
  68. public static readonly DependencyProperty SelectedBusProperty =
  69. DependencyProperty.Register("SelectedBus", typeof(ObservableCollection<Business>), typeof(BusSettingWindow), new PropertyMetadata(new ObservableCollection<Business>()));
  70. private void CheckBoxContent_Checked(object sender, RoutedEventArgs e)
  71. {
  72. if (!(sender is CheckBoxContent sourcre)) return;
  73. if (!sourcre.IsLoaded) return;
  74. if (!(sourcre.Tag is Business bus)) return;
  75. NoSelectedBus.Remove(bus);
  76. if (SelectedBus == null) SelectedBus = new ObservableCollection<Business>();
  77. SelectedBus.Add(bus);
  78. }
  79. private void CheckBoxContent_Unchecked(object sender, RoutedEventArgs e)
  80. {
  81. if (!(sender is CheckBoxContent sourcre)) return;
  82. if (!sourcre.IsLoaded) return;
  83. if (!(sourcre.Tag is Business bus)) return;
  84. SelectedBus.Remove(bus);
  85. if (bus.state == 0) return;
  86. if (NoSelectedBus == null) NoSelectedBus = new ObservableCollection<Business>();
  87. NoSelectedBus.Add(bus);
  88. }
  89. private void Cancel_MouseUp(object sender, MouseButtonEventArgs e)
  90. {
  91. this.DialogResult = false;
  92. return;
  93. }
  94. private void Cancel_Click(object sender, RoutedEventArgs e)
  95. {
  96. this.DialogResult = false;
  97. return;
  98. }
  99. private void Ok_Click(object sender, RoutedEventArgs e)
  100. {
  101. try
  102. {
  103. var checkedIds = SelectedBus.Select(x => x.id).ToList();
  104. var uncheckedIds = NoSelectedBus.Select(x => x.id).ToList();
  105. string error = settingProvider.BusSettingApi(ParentId, checkedIds, uncheckedIds);
  106. if (!string.IsNullOrEmpty(error))
  107. {
  108. //MessageBoxShow($"操作失败,{error}");
  109. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
  110. return;
  111. }
  112. this.DialogResult = true;
  113. return;
  114. }
  115. catch (Exception ex)
  116. {
  117. ExLog(ex, "Ok_Click");
  118. //MessageBoxShow($"操作失败:{ex.Message}");
  119. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0291")},{ex.Message}");
  120. }
  121. }
  122. }
  123. }