WindturbineDetails.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using NEIntelligentControl2.Models.Windturbine;
  2. using NEIntelligentControl2.Models.WinForms;
  3. using NEIntelligentControl2.Service.Windturbine;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Controls.Primitives;
  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.Infos
  20. {
  21. /// <summary>
  22. /// 风机测点详情
  23. /// </summary>
  24. public partial class WindturbineDetails : UserControl
  25. {
  26. private InfoManager _InfoManager;
  27. private Dictionary<string,GroupBox> _GroupBoxs;
  28. private List<PointTag> _PointTags;
  29. private IList<UniformCodeInfo> _UniformCodeInfos;
  30. public WindturbineInfo WindturbineInfo { get; set; }
  31. private bool _IsActived;
  32. private bool _IsLoaded;
  33. public WindturbineDetails()
  34. {
  35. InitializeComponent();
  36. _InfoManager = App.ServiceProvider.GetService(typeof(InfoManager)) as InfoManager;
  37. InitGroupBox();
  38. }
  39. private void InitGroupBox()
  40. {
  41. _GroupBoxs = new Dictionary<string, GroupBox>();
  42. foreach(var v in _GdMain.Children)
  43. {
  44. var gd = v as Grid;
  45. if (gd == null) continue;
  46. foreach(var vv in gd.Children)
  47. {
  48. GroupBox gb = vv as GroupBox;
  49. if(gb == null) continue;
  50. _GroupBoxs.Add(gb.Tag as string, gb);
  51. }
  52. }
  53. }
  54. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  55. {
  56. _IsActived = true;
  57. InitTags();
  58. Task.Run(RefreshData);
  59. }
  60. private async void RefreshData()
  61. {
  62. if (_UniformCodeInfos == null) return;
  63. string[] ucs = _UniformCodeInfos.Select(u => u.UniformCode).ToArray();
  64. while (_IsActived)
  65. {
  66. try
  67. {
  68. var vs = _InfoManager.GetPointDatas(WindturbineInfo.WindturbineId, ucs);
  69. Dispatcher.Invoke(() =>
  70. {
  71. foreach(var v in _PointTags)
  72. {
  73. v.UpdateData(vs);
  74. }
  75. });
  76. }
  77. catch { }
  78. await Task.Delay(2000);
  79. }
  80. }
  81. private void InitTags()
  82. {
  83. if (_IsLoaded) return;
  84. _PointTags = new List<PointTag>();
  85. var vs = _InfoManager.GetUniformCode(WindturbineInfo.StationId, WindturbineInfo.ModelId);
  86. if (vs == null) return;
  87. _UniformCodeInfos = vs;
  88. foreach (var v in vs)
  89. {
  90. if (!_GroupBoxs.ContainsKey(v.PartIndex)) continue;
  91. UniformGrid ug = _GroupBoxs[v.PartIndex].Content as UniformGrid;
  92. PointTag pt = new PointTag(v, WindturbineInfo.WindturbineId);
  93. ug.Children.Add(pt);
  94. _PointTags.Add(pt);
  95. }
  96. _IsLoaded = true;
  97. }
  98. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  99. {
  100. _IsActived = false;
  101. }
  102. }
  103. }