ControlTrackWindow.xaml.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using NEIntelligentControl2.Service.Station;
  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.Shapes;
  16. namespace NEIntelligentControl2.Windows
  17. {
  18. /// <summary>
  19. /// 控制跟踪窗口
  20. /// </summary>
  21. public partial class ControlTrackWindow : Window
  22. {
  23. private ControlManager _ControlManager;
  24. private StationManager _StationManager;
  25. private bool _IsActived;
  26. public ControlTrackWindow(ControlManager cm,StationManager sm)
  27. {
  28. InitializeComponent();
  29. _ControlManager = cm;
  30. _StationManager = sm;
  31. Init();
  32. }
  33. private void Init()
  34. {
  35. _TBStart.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  36. _TBEnd.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  37. var vs = _StationManager.GetStationInfos().Where(s => s.Type == Models.Station.StationType.Wind).ToList();
  38. vs.Insert(0, new Models.Station.StationInfo() { Name = "未选择", Id = "" });
  39. _CBStation.ItemsSource = vs;
  40. _CBStation.SelectedIndex = 0;
  41. }
  42. public static void ShowWindow()
  43. {
  44. ControlTrackWindow ctw = App.ServiceProvider.GetService(typeof(ControlTrackWindow)) as ControlTrackWindow;
  45. ctw.Owner = Application.Current.MainWindow;
  46. ctw.ShowDialog();
  47. }
  48. private void Window_Loaded(object sender, RoutedEventArgs e)
  49. {
  50. _IsActived = true;
  51. Task.Run(RefreshControlLog);
  52. }
  53. private async void RefreshControlLog()
  54. {
  55. while (_IsActived)
  56. {
  57. try
  58. {
  59. var v = _ControlManager.GetControlLog();
  60. Dispatcher.Invoke(() => _TBLog.Text = v);
  61. }
  62. catch { }
  63. await Task.Delay(5000);
  64. }
  65. }
  66. private void Button_Click(object sender, RoutedEventArgs e)
  67. {
  68. switch (((Control)sender).Tag)
  69. {
  70. case "search":
  71. SearchControlLog();
  72. break;
  73. case "close":
  74. this.Close();
  75. break;
  76. default:return;
  77. }
  78. }
  79. /// <summary>
  80. /// 查询操作日志
  81. /// </summary>
  82. private void SearchControlLog()
  83. {
  84. var start = _TBStart.Text;
  85. var end = _TBEnd.Text;
  86. var station = (_CBStation.SelectedItem as Models.Station.StationInfo)?.Id;
  87. Task.Run(() =>
  88. {
  89. try
  90. {
  91. DateTime.TryParse(start, out DateTime startTime);
  92. DateTime.TryParse(end, out DateTime endTime);
  93. string stimestring = $"{startTime.Year}/{startTime.Month}/{startTime.Day} {startTime.Hour}:{startTime.Minute}:{startTime.Second}";
  94. string etimestring = $"{endTime.Year}/{endTime.Month}/{endTime.Day} {endTime.Hour}:{endTime.Minute}:{endTime.Second}";
  95. var v = _ControlManager.GetControlRecord(station, stimestring, etimestring);
  96. if (v == null) return;
  97. foreach(var vv in v.DataList)
  98. {
  99. vv.StationName = _StationManager.GetStatonInfo(vv.StationId)?.FullName;
  100. }
  101. Dispatcher.Invoke(() => _DGControlLog.ItemsSource = v.DataList);
  102. }
  103. catch { }
  104. });
  105. }
  106. private void TextBox_LostFocus(object sender, RoutedEventArgs e)
  107. {
  108. SearchControlLog();
  109. }
  110. private void _CBStation_SelectionChanged(object sender, SelectionChangedEventArgs e)
  111. {
  112. SearchControlLog();
  113. }
  114. private void TabItem_Loaded(object sender, RoutedEventArgs e)
  115. {
  116. SearchControlLog();
  117. }
  118. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  119. {
  120. _IsActived = false;
  121. }
  122. }
  123. }