PointDetails.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using NEIntelligentControl2.Models.Datas;
  2. using NEIntelligentControl2.Models.Messages;
  3. using NEIntelligentControl2.Models.Windturbine;
  4. using NEIntelligentControl2.Service.Windturbine;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Configuration;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Text.Json.Serialization;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace NEIntelligentControl2.Views.Infos
  23. {
  24. /// <summary>
  25. /// 测点详情
  26. /// </summary>
  27. public partial class PointDetails : UserControl
  28. {
  29. private bool _IsActived;
  30. private List<PointInfo> _AIPoints;
  31. private List<PointInfo> _DIPoints;
  32. private InfoManager _InfoManager;
  33. public WindturbineInfo WindturbineInfo { get; set; }
  34. public PointDetails()
  35. {
  36. InitializeComponent();
  37. _InfoManager = App.ServiceProvider.GetService(typeof(InfoManager)) as InfoManager;
  38. }
  39. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  40. {
  41. _IsActived = false;
  42. }
  43. private async void UserControl_Loaded(object sender, RoutedEventArgs e)
  44. {
  45. _IsActived = true;
  46. await InitPointTags();
  47. Task.Run(RefreshData);
  48. }
  49. private async void RefreshData()
  50. {
  51. var aiks = _AIPoints.Select(p => p.TagName).ToArray();
  52. var diks = _DIPoints.Select(p => p.TagName).ToArray();
  53. while (_IsActived)
  54. {
  55. try
  56. {
  57. var vsai = _InfoManager.GetPointDatasByTags(aiks);
  58. var vsdi = _InfoManager.GetPointDatasByTags(diks);
  59. Dispatcher.Invoke(() =>
  60. {
  61. UpdateData(vsai, _AIPoints);
  62. UpdateData(vsdi, _DIPoints);
  63. });
  64. }
  65. catch (Exception e)
  66. {
  67. Console.WriteLine(e.ToString());
  68. }
  69. await Task.Delay(2000);
  70. }
  71. }
  72. private void UpdateData(Dictionary<string, TsData> vs, List<PointInfo> ps)
  73. {
  74. foreach(var v in ps)
  75. {
  76. if (!vs.ContainsKey(v.TagName)) continue;
  77. v.PointValue = vs[v.TagName].Value;
  78. }
  79. }
  80. private Task InitPointTags()
  81. {
  82. return Task.Run(() =>
  83. {
  84. if (_AIPoints != null && _AIPoints.Count > 0) return;
  85. try
  86. {
  87. _AIPoints = _InfoManager.GetAIPoints(WindturbineInfo.WindturbineId);
  88. _DIPoints = _InfoManager.GetDIPoints(WindturbineInfo.WindturbineId);
  89. Dispatcher.Invoke(() =>
  90. {
  91. _DGAI.ItemsSource = _AIPoints;
  92. _DGDI.ItemsSource = _DIPoints;
  93. });
  94. }
  95. catch { }
  96. });
  97. }
  98. private void TextBox_KeyDown(object sender, KeyEventArgs e)
  99. {
  100. if (e.Key != Key.Enter) return;
  101. Search();
  102. }
  103. private void Button_Click(object sender, RoutedEventArgs e)
  104. {
  105. switch (((Control)sender).Tag)
  106. {
  107. case "ok":
  108. Search();
  109. break;
  110. default:return;
  111. }
  112. }
  113. private void Search()
  114. {
  115. string s = _TBSerach.Text;
  116. if (string.IsNullOrWhiteSpace(s))
  117. {
  118. _DGAI.ItemsSource = _AIPoints;
  119. _DGDI.ItemsSource = _DIPoints;
  120. return;
  121. }
  122. Task.Run(() =>
  123. {
  124. var vs1 = _AIPoints.Where(p => p.PointName.Contains(s)).ToList();
  125. var vs2 = _DIPoints.Where(p => p.PointName.Contains(s)).ToList();
  126. Dispatcher.Invoke(() =>
  127. {
  128. _DGAI.ItemsSource = vs1;
  129. _DGDI.ItemsSource = vs2;
  130. });
  131. });
  132. }
  133. }
  134. }