AlarmSettingViewNew.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using ivf_tl_CustomControls;
  2. using ivf_tl_Entity.Entity.Alarm;
  3. using ivf_tl_Manage.ViewModels;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace ivf_tl_Manage.Views
  19. {
  20. /// <summary>
  21. /// AlarmSettingViewNew.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class AlarmSettingViewNew : UserControl
  24. {
  25. AlarmSettingNewViewModel vm;
  26. public AlarmSettingViewNew()
  27. {
  28. InitializeComponent();
  29. Loaded += (a, b) => {
  30. vm = (AlarmSettingNewViewModel)this.DataContext; };
  31. }
  32. private void ListBox_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
  33. {
  34. e.Handled = true;
  35. }
  36. bool isMuteChanged = false;
  37. private void Mute_Checked(object sender, RoutedEventArgs e)
  38. {
  39. if (isMuteChanged || vm == null || !this.IsLoaded) return;
  40. if (!(sender is CheckBox checkBox)) return;
  41. if (!vm.EditAlarmType(checkBox.Tag as AlarmTypeEntity, -1, -1))
  42. {
  43. isMuteChanged = true;
  44. checkBox.IsChecked = false;
  45. isMuteChanged = false;
  46. }
  47. }
  48. private void Mute_Unchecked(object sender, RoutedEventArgs e)
  49. {
  50. if (isMuteChanged || vm == null || !this.IsLoaded) return;
  51. if (!(sender is CheckBox checkBox)) return;
  52. if (!vm.EditAlarmType(checkBox.Tag as AlarmTypeEntity, -1, -1))
  53. {
  54. isMuteChanged = true;
  55. checkBox.IsChecked = true;
  56. isMuteChanged = false;
  57. }
  58. }
  59. private void AddPersonne_Click(object sender, RoutedEventArgs e)
  60. {
  61. if (vm != null) vm.AddAlarmPersonne();
  62. }
  63. private void Del_Click(object sender, RoutedEventArgs e)
  64. {
  65. if (vm == null) return;
  66. if (!(sender is ButtonImage buttonImage)) return;
  67. vm.DelAlarmPersonne(buttonImage.Tag as AlarmPersonne);
  68. }
  69. private void Edit_Click(object sender, RoutedEventArgs e)
  70. {
  71. if (vm == null) return;
  72. if (!(sender is ButtonImage buttonImage)) return;
  73. vm.EditAlarmPersonne(buttonImage.Tag as AlarmPersonne);
  74. }
  75. private void IntervalTime_SelectionChanged(object sender, SelectionChangedEventArgs e)
  76. {
  77. if (vm == null || !this.IsLoaded) return;
  78. if (!(sender is ComBoxCustom1 comBoxCustom)) return;
  79. AlarmTypeEntity alarmTypeEntity = comBoxCustom.Tag as AlarmTypeEntity;
  80. if (alarmTypeEntity == null) return;
  81. if (alarmTypeEntity.intervalTime == alarmTypeEntity.SelectedTime.Key) return;
  82. if (!vm.EditAlarmType(alarmTypeEntity, alarmTypeEntity.SelectedTime.Key, -1))
  83. {
  84. alarmTypeEntity.SelectedTime = alarmTypeEntity.TimeSource.FirstOrDefault(x => x.Key == alarmTypeEntity.intervalTime);
  85. }
  86. else
  87. {
  88. alarmTypeEntity.intervalTime = alarmTypeEntity.SelectedTime.Key;
  89. }
  90. }
  91. private void AlarmLevel_SelectionChanged(object sender, SelectionChangedEventArgs e)
  92. {
  93. if (vm == null || !this.IsLoaded) return;
  94. if (!(sender is ComBoxCustom1 comBoxCustom)) return;
  95. AlarmTypeEntity alarmTypeEntity = comBoxCustom.Tag as AlarmTypeEntity;
  96. if (alarmTypeEntity == null) return;
  97. if (alarmTypeEntity.alarmLevel == alarmTypeEntity.SelectedLevel.Key) return;
  98. if (!vm.EditAlarmType(alarmTypeEntity, -1, alarmTypeEntity.SelectedLevel.Key))
  99. {
  100. alarmTypeEntity.SelectedLevel = alarmTypeEntity.LevelSource.FirstOrDefault(x => x.Key == alarmTypeEntity.alarmLevel);
  101. }
  102. else
  103. {
  104. alarmTypeEntity.alarmLevel = alarmTypeEntity.SelectedLevel.Key;
  105. }
  106. }
  107. private void AlarmSetting_Click(object sender, RoutedEventArgs e)
  108. {
  109. if (vm == null) return;
  110. vm.SetAlarmSetting();
  111. }
  112. }
  113. }