AlarmViewModel.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. 
  2. namespace HistoryView.ViewModels.Regions;
  3. public partial class AlarmViewModel : ObservableObject
  4. {
  5. public AlarmViewModel(MessageBoxHelper messageBox, UserInformation user, Alarms alarms, Hardwares hardwares, HistoryViewer historyViewer)
  6. {
  7. this._messageBox = messageBox;
  8. this.NoAlarm = alarms.DisplayAlarm.Count switch
  9. {
  10. 0 => Visibility.Visible,
  11. _ => Visibility.Collapsed
  12. };
  13. alarms.DisplayAlarm.PropertyChanged += DisplayAlarm_PropertyChanged;
  14. this.Alarms = alarms;
  15. this.Hardwares = hardwares;
  16. this.UserInfo = user;
  17. this._history = historyViewer;
  18. }
  19. private void DisplayAlarm_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
  20. {
  21. this.Alarms.DisplayAlarm.CollectionChanged += DisplayAlarm_CollectionChanged;
  22. }
  23. private void DisplayAlarm_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  24. {
  25. this.NoAlarm = this.Alarms.DisplayAlarm.Count switch
  26. {
  27. 0 => Visibility.Visible,
  28. _ => Visibility.Collapsed
  29. };
  30. }
  31. private readonly HistoryViewer _history;
  32. private readonly MessageBoxHelper _messageBox;
  33. [ObservableProperty]
  34. private Hardwares _Hardwares;
  35. [ObservableProperty]
  36. private Alarms _Alarms;
  37. [ObservableProperty]
  38. private Visibility _NoAlarm;
  39. [ObservableProperty]
  40. ObservableCollection<AlarmInfo>? _DisplayHistoryAlarms;
  41. [ObservableProperty]
  42. private Mini8Info? _SelectedMini8;
  43. partial void OnSelectedMini8Changed(Mini8Info? value)
  44. {
  45. this.Mini8Channels ??= [];
  46. this.Mini8Channels.Clear();
  47. if (value is null)
  48. return;
  49. //this.Mini8Channels.AddRange(this.Hardwares.Mini8Channels.Where(t => t.Key == value.Index).FirstOrDefault().Value);
  50. }
  51. [ObservableProperty]
  52. public ObservableCollection<Channel>? _Mini8Channels;
  53. [ObservableProperty]
  54. private Channel? _SelectedChannel;
  55. [ObservableProperty]
  56. private UserInformation? _UserInfo;
  57. [RelayCommand]
  58. private void Filter()
  59. {
  60. if (this.Alarms.HistoryAlarms is null)
  61. return;
  62. this.DisplayHistoryAlarms ??= [];
  63. this.DisplayHistoryAlarms.Clear();
  64. List<AlarmInfo> alarms = [];
  65. alarms.AddRange(this.Alarms.HistoryAlarms);
  66. if (this.SelectedMini8 is not null)
  67. alarms = [.. alarms.Where(t => t.Mini8Index == this.SelectedMini8.Index)];
  68. if (this.SelectedChannel is not null)
  69. alarms = [.. alarms.Where(t => t.ChannelIndex == this.SelectedChannel.ChannelIndex)];
  70. this.DisplayHistoryAlarms.AddRange(alarms);
  71. }
  72. [RelayCommand]
  73. private void History()
  74. {
  75. this._history.StartAlarmHistroy();
  76. }
  77. [RelayCommand]
  78. private void ClearFilter()
  79. {
  80. this.SelectedMini8 = null;
  81. this.SelectedChannel = null;
  82. this.DisplayHistoryAlarms ??= [];
  83. this.DisplayHistoryAlarms.Clear();
  84. //this.DisplayHistoryAlarms.AddRange(this.Alarms.HistoryAlarms);
  85. }
  86. [RelayCommand]
  87. private void Clear()
  88. {
  89. IDialogResult result = this._messageBox.ShowAsync((string)App.Current.Resources["ConfirmClearAllAlarm"], MessageBoxButton.YesNo, MessageBoxImage.Question).Result;
  90. if (result.Result != ButtonResult.Yes)
  91. return;
  92. this.Alarms.DisplayAlarm?.Clear();
  93. }
  94. [RelayCommand]
  95. private void ClearSingle(AlarmInfo alarmInfo)
  96. {
  97. if (alarmInfo is null)
  98. return;
  99. if (this.Alarms.DisplayAlarm is null)
  100. return;
  101. if (!this.Alarms.DisplayAlarm.ContainsKey(alarmInfo.Mini8Index))
  102. return;
  103. IDialogResult result = this._messageBox.ShowAsync((string)App.Current.Resources["ConfirmClearThisAlarm"], MessageBoxButton.YesNo, MessageBoxImage.Question).Result;
  104. if (result.Result != ButtonResult.Yes)
  105. return;
  106. this.Alarms.DisplayAlarm.Remove(alarmInfo.Mini8Index);
  107. }
  108. }