PageAGC.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using NEIntelligentControl2.Models;
  2. using NEIntelligentControl2.Models.AGC;
  3. using NEIntelligentControl2.Models.Datas;
  4. using NEIntelligentControl2.Models.Messages;
  5. using NEIntelligentControl2.Models.Pages;
  6. using NEIntelligentControl2.Service.AGC;
  7. using NEIntelligentControl2.Views.AGC;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Configuration;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Data;
  17. using System.Windows.Documents;
  18. using System.Windows.Input;
  19. using System.Windows.Media;
  20. using System.Windows.Media.Imaging;
  21. using System.Windows.Navigation;
  22. using System.Windows.Shapes;
  23. namespace NEIntelligentControl2.Pages.AGC
  24. {
  25. /// <summary>
  26. /// AGC页面
  27. /// </summary>
  28. public partial class PageAGC : Page
  29. {
  30. /// <summary>
  31. /// 页面是否活跃
  32. /// </summary>
  33. private bool _IsActived;
  34. private bool _IsLoaded;
  35. private TagManager _TagManager;
  36. private AGCManager _AGCManager;
  37. public PageAGC(TagManager tm, AGCManager am)
  38. {
  39. InitializeComponent();
  40. _TagManager = tm;
  41. _AGCManager = am;
  42. }
  43. private void Page_Loaded(object sender, RoutedEventArgs e)
  44. {
  45. _TagManager.TagChanged?.Invoke(new List<Models.Station.StationInfo>());
  46. if (!_IsLoaded)
  47. {
  48. InitCards();
  49. _IsLoaded = true;
  50. }
  51. _IsActived = true;
  52. Task.Factory.StartNew(RefreshData, TaskCreationOptions.LongRunning);
  53. Task.Factory.StartNew(RefreshLineData, TaskCreationOptions.LongRunning);
  54. }
  55. /// <summary>
  56. /// 曲线数据刷新
  57. /// </summary>
  58. private async void RefreshLineData()
  59. {
  60. while (_IsLoaded)
  61. {
  62. _AGCManager.RefreshLineData(this);
  63. await Task.Delay(30000);
  64. }
  65. }
  66. /// <summary>
  67. /// 数据刷新
  68. /// </summary>
  69. private async void RefreshData()
  70. {
  71. while (_IsActived)
  72. {
  73. _AGCManager.RefreshData(this);
  74. await Task.Delay(2000);
  75. }
  76. }
  77. private void InitCards()
  78. {
  79. int i = 0;
  80. var agcInfos = _AGCManager.AGCInfos;
  81. if (agcInfos == null) return;
  82. while (i < agcInfos.Count)
  83. {
  84. var vs = agcInfos.Where(ai => ai.Coordinate.X == i).ToList();
  85. if (vs.Count <= 0)
  86. {
  87. break;
  88. }
  89. _GMain.RowDefinitions.Add(new RowDefinition());
  90. Grid gd = new Grid();
  91. foreach (var v in vs)
  92. {
  93. gd.ColumnDefinitions.Add(new ColumnDefinition());
  94. AGCCard2 ac = new AGCCard2() { Info = v };
  95. gd.Children.Add(ac);
  96. Grid.SetColumn(ac, v.Coordinate.Y);
  97. }
  98. if (gd.Children.Count < 3)
  99. {
  100. gd.HorizontalAlignment = HorizontalAlignment.Center;
  101. }
  102. _GMain.Children.Add(gd);
  103. Grid.SetRow(gd, i);
  104. ++i;
  105. }
  106. //_GMain.Height = this.ActualHeight / 2 * i;
  107. }
  108. private void Page_Unloaded(object sender, RoutedEventArgs e)
  109. {
  110. _IsActived = false;
  111. }
  112. private void Button_Click(object sender, RoutedEventArgs e)
  113. {
  114. var bt = sender as Button;
  115. if (bt == null) return;
  116. if (bt.Content.ToString() == "光 伏")
  117. {
  118. bt.Content = "风 机";
  119. _sv.ScrollToEnd();
  120. }
  121. else
  122. {
  123. bt.Content = "光 伏";
  124. _sv.ScrollToTop();
  125. }
  126. }
  127. private void _sv_ScrollChanged(object sender, ScrollChangedEventArgs e)
  128. {
  129. var v = e.VerticalOffset / e.ViewportHeight;
  130. _bt.Content = v <= 0.5 ? "光 伏" : "风 机";
  131. }
  132. }
  133. }