RealTimeFalutInfoView.xaml.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using NEIntelligentControl2.Models.Alarm;
  2. using NEIntelligentControl2.Service.Alarm;
  3. using NEIntelligentControl2.Windows.Alarm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace NEIntelligentControl2.Views.Alarm
  20. {
  21. /// <summary>
  22. /// 实时故障视图
  23. /// </summary>
  24. public partial class RealTimeFalutInfoView : UserControl
  25. {
  26. // ------------依赖属性--------------
  27. public static DependencyProperty IsFixedProperty = DependencyProperty.Register("IsFixed", typeof(bool), typeof(RealTimeFalutInfoView));
  28. public static DependencyProperty IsFaultProperty = DependencyProperty.Register("IsFault", typeof(bool), typeof(RealTimeFalutInfoView));
  29. public static DependencyProperty IsOpenedProperty = DependencyProperty.Register("IsOpened", typeof(bool), typeof(RealTimeFalutInfoView));
  30. /// <summary>
  31. /// 是否固定
  32. /// </summary>
  33. public bool IsFixed { get => (bool)GetValue(IsFixedProperty); set => SetValue(IsFixedProperty, value); }
  34. /// <summary>
  35. /// 是否是故障
  36. /// </summary>
  37. public bool IsFault { get => (bool)GetValue(IsFaultProperty); set => SetValue(IsFaultProperty, value); }
  38. /// <summary>
  39. /// 是否打开
  40. /// </summary>
  41. public bool IsOpened { get => (bool)GetValue(IsOpenedProperty); set => SetValue(IsOpenedProperty, value); }
  42. private ObservableCollection<FaultInfoModel> _FaultList;
  43. private HashSet<long> _FaultIds;
  44. private ObservableCollection<AlarmInfo> _AlarmList;
  45. private HashSet<long> _AlarmIds;
  46. private AlarmManager _AlarmManager;
  47. public RealTimeFalutInfoView()
  48. {
  49. InitializeComponent();
  50. IsFault = true;
  51. _FaultList = new ObservableCollection<FaultInfoModel>();
  52. _GDFault.ItemsSource = _FaultList;
  53. _AlarmList = new ObservableCollection<AlarmInfo>();
  54. _GDAlarm.ItemsSource = _AlarmList;
  55. _AlarmIds = new HashSet<long>();
  56. _FaultIds = new HashSet<long>();
  57. _AlarmManager = App.ServiceProvider.GetService(typeof(AlarmManager)) as AlarmManager;
  58. _AlarmManager.OnFaultCount += OnFaultCount;
  59. _AlarmManager.OnAlarmCount += OnAlarmCount;
  60. }
  61. private void OnAlarmCount(List<AlarmInfo> obj)
  62. {
  63. var ls = obj.Select(f => f.Id).ToList();
  64. var removed = _AlarmList.Where(f => !ls.Contains(f.Id)).ToList();
  65. Dispatcher.Invoke(() =>
  66. {
  67. for (int i = obj.Count - 1; i >= 0; i--)
  68. {
  69. var v = obj[i];
  70. if (_AlarmIds.Contains(v.Id)) continue;
  71. _AlarmList.Insert(0, v);
  72. _AlarmIds.Add(v.Id);
  73. }
  74. foreach (var v in removed)
  75. {
  76. _AlarmList.Remove(v);
  77. _AlarmIds.Remove(v.Id);
  78. }
  79. });
  80. }
  81. private void OnFaultCount(List<FaultInfoModel> obj)
  82. {
  83. var ls = obj.Select(f => f.FaultInfo.Id).ToList();
  84. var removed = _FaultList.Where(f => !ls.Contains(f.FaultInfo.Id)).ToList();
  85. Dispatcher.Invoke(() =>
  86. {
  87. for (int i = obj.Count - 1; i >= 0; i--)
  88. {
  89. var v = obj[i];
  90. if (_FaultIds.Contains(v.FaultInfo.Id)) continue;
  91. _FaultList.Insert(0, v);
  92. _FaultIds.Add(v.FaultInfo.Id);
  93. }
  94. foreach (var v in removed)
  95. {
  96. _FaultList.Remove(v);
  97. _FaultIds.Remove(v.FaultInfo.Id);
  98. }
  99. });
  100. }
  101. private void cc_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  102. {
  103. IsFixed = !IsFixed;
  104. }
  105. private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  106. {
  107. var v = ((FrameworkElement)sender).DataContext as FaultInfoModel;
  108. if (v == null || v.FaultInfo == null) return;
  109. Windows.Alarm.DeviceDetailAlarmWindow.Show(v.FaultInfo);
  110. IsOpened = false;
  111. }
  112. private void Button_Click(object sender, RoutedEventArgs e)
  113. {
  114. switch (((Control)sender).Tag)
  115. {
  116. case "fault": // 报警故障切换
  117. IsFault = !IsFault;
  118. break;
  119. case "rtalarm":// 实时报警
  120. RealTimeAlarm();
  121. break;
  122. case "hisalarm": // 历史报警
  123. HistoryAlarm();
  124. break;
  125. case "hisfault": // 历史故障
  126. HistoryFault();
  127. break;
  128. default:return;
  129. }
  130. }
  131. /// <summary>
  132. /// 历史故障
  133. /// </summary>
  134. private void HistoryFault()
  135. {
  136. HistoryFaultWindow.ShowWindow();
  137. }
  138. /// <summary>
  139. /// 历史报警
  140. /// </summary>
  141. private void HistoryAlarm()
  142. {
  143. HistoryAlarmWindow.ShowWindow();
  144. }
  145. /// <summary>
  146. /// 实时报警
  147. /// </summary>
  148. private void RealTimeAlarm()
  149. {
  150. RealTimeAlarmWindow.ShowWindow();
  151. }
  152. }
  153. }