StatusBar.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using NEIntelligentControl2.Service.Alarm;
  2. using NEIntelligentControl2.Service.Windturbine;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace NEIntelligentControl2.Views.MainWindow
  18. {
  19. /// <summary>
  20. /// 状态栏
  21. /// </summary>
  22. public partial class StatusBar : UserControl
  23. {
  24. // --------依赖属性-----------
  25. public static readonly DependencyProperty IsMenuOpendProperty = DependencyProperty.Register("IsMenuOpen", typeof(bool), typeof(StatusBar));
  26. // ------------事件-------------
  27. public event RoutedEventHandler ItemClick { add { _MWMMain.ItemClick += value; } remove { _MWMMain.ItemClick -= value; } }
  28. /// <summary>
  29. /// 菜单是否弹出
  30. /// </summary>
  31. public bool IsMenuOpen { get => (bool)GetValue(IsMenuOpendProperty); set => SetValue(IsMenuOpendProperty, value); }
  32. private AlarmManager _AlarmManager;
  33. private SuggestionManager _SuggestionManager;
  34. public StatusBar()
  35. {
  36. InitializeComponent();
  37. _AlarmManager = App.ServiceProvider.GetService(typeof(AlarmManager)) as AlarmManager;
  38. _AlarmManager.OnFaultCount += OnFaultCount;
  39. _SuggestionManager = App.ServiceProvider.GetService(typeof(SuggestionManager)) as SuggestionManager;
  40. _SuggestionManager.OnCountChanged = OnSuggestionCount;
  41. }
  42. private void OnSuggestionCount(int obj)
  43. {
  44. Dispatcher.Invoke(() => _TBSCount.Text = obj.ToString());
  45. }
  46. private void OnFaultCount(List<Models.Alarm.FaultInfoModel> fims)
  47. {
  48. if (fims == null || fims.Count <= 0) return;
  49. var info = fims.FirstOrDefault();
  50. Dispatcher.Invoke(() =>
  51. {
  52. _TBAlarmTime.Text = info.FaultInfo.LastUpdateTime?.ToString("HH:mm:ss");
  53. _TBAlarmName.Text = info.FaultInfo.ObjectName;
  54. _TBAlarmText.Text = info.FaultInfo.AlertText;
  55. _TBAlarmType.Text = info.FaultInfo.MessageType == 3 ? "[解除]" : "";
  56. });
  57. }
  58. private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  59. {
  60. switch (((FrameworkElement)sender).Tag)
  61. {
  62. case "menu":// 主菜单
  63. IsMenuOpen = !IsMenuOpen;
  64. break;
  65. case "track":// 控制跟踪
  66. Track();
  67. break;
  68. default:return;
  69. }
  70. }
  71. private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  72. {
  73. switch (((FrameworkElement)sender).Tag)
  74. {
  75. case "recomend":// 推荐
  76. Recomend();
  77. break;
  78. default: return;
  79. }
  80. }
  81. /// <summary>
  82. /// 控制跟踪
  83. /// </summary>
  84. private void Track()
  85. {
  86. Windows.ControlTrackWindow.ShowWindow();
  87. //WinForms.TrackForm tf = new WinForms.TrackForm();
  88. //tf.Show();
  89. }
  90. /// <summary>
  91. /// 控制推荐
  92. /// </summary>
  93. private void Recomend()
  94. {
  95. Windows.RecomendWindow.ShowWindow();
  96. }
  97. private void Popup_MouseLeave(object sender, MouseEventArgs e) => IsMenuOpen = false;
  98. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  99. {
  100. _PAlarm.IsOpen = true;
  101. }
  102. private void gdalarm_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  103. {
  104. _RFIVMain.IsOpened = !_RFIVMain.IsOpened;
  105. }
  106. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  107. {
  108. Task.Factory.StartNew(async () => {
  109. while (true)
  110. {
  111. this.Dispatcher.Invoke(() => time.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  112. await Task.Delay(1000);
  113. }
  114. },TaskCreationOptions.LongRunning);
  115. }
  116. }
  117. }