DynamicAGCCard.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using NEIntelligentControl2.Models.AGC;
  2. using NEIntelligentControl2.Models.Messages;
  3. using NEIntelligentControl2.Service.AGC;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Configuration;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  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.AGC
  20. {
  21. /// <summary>
  22. /// 动态AGC卡片页面
  23. /// </summary>
  24. public partial class DynamicAGCCard : UserControl
  25. {
  26. private Dictionary<int, AGCCard2> _AGCCardsPairt; // AGC卡片集合
  27. private AGCCard2 _CurrentCard; // 当前卡片
  28. private int _CurrentIndex; // 当前序列
  29. private bool _IsActived; // 是否正在运行
  30. private AGCManager _AGCManager;
  31. private bool _IsLoaded;
  32. public DynamicAGCCard()
  33. {
  34. InitializeComponent();
  35. _AGCCardsPairt = new Dictionary<int, AGCCard2>();
  36. _AGCManager = App.ServiceProvider.GetService(typeof(AGCManager)) as AGCManager;
  37. }
  38. private void InitCard()
  39. {
  40. var agcInfos = _AGCManager.AGCInfos;
  41. if (agcInfos == null) return;
  42. int i = 0;
  43. foreach(var v in agcInfos)
  44. {
  45. AGCCard2 ac = new AGCCard2() { Info = v, Visibility = Visibility.Collapsed };
  46. _GDMain.Children.Add(ac);
  47. _AGCCardsPairt.Add(i, ac);
  48. ++i;
  49. }
  50. _DVMain.Count = agcInfos.Count;
  51. _DVMain.Check(0);
  52. }
  53. /// <summary>
  54. /// 自动刷新AGC图表数据
  55. /// </summary>
  56. private void RefreshLineData()
  57. {
  58. _AGCManager.RefreshLineData(this);
  59. }
  60. /// <summary>
  61. /// 自动刷新AGC数据
  62. /// </summary>
  63. private async void RefreshData()
  64. {
  65. while (_IsActived)
  66. {
  67. _AGCManager.RefreshData(this);
  68. await Task.Delay(2000);
  69. }
  70. }
  71. /// <summary>
  72. /// 自动切换AGC卡片
  73. /// </summary>
  74. private async void AutoCheck()
  75. {
  76. while (_IsActived)
  77. {
  78. await Task.Delay(7000);
  79. Dispatcher.Invoke(() => Button_Click(_BTRight, null));
  80. }
  81. }
  82. public void ChangeCard(int index)
  83. {
  84. if (index < 0 || index >= _DVMain.Count) return;
  85. _CurrentIndex = index;
  86. _DVMain.Check(index);
  87. }
  88. private void Button_Click(object sender, RoutedEventArgs e)
  89. {
  90. int i = ((Control)sender).Tag as string == "leftbutton" ? -1 : 1;
  91. _CurrentIndex += i;
  92. if (_CurrentIndex < 0) _CurrentIndex = _DVMain.Count - 1;
  93. if (_CurrentIndex >= _DVMain.Count) _CurrentIndex = 0;
  94. _DVMain.Check(_CurrentIndex);
  95. }
  96. /// <summary>
  97. /// 小圆点选择改变事件(此处引用虽数然为0,但这个函数处于使用状态,除非您知道在做什么,否则请勿删!)
  98. /// </summary>
  99. private void DotView_Changed(object sender, DotChangedRoutedEventArgs e)
  100. {
  101. if (_CurrentCard != null)
  102. {
  103. _CurrentCard.Visibility = Visibility.Collapsed;
  104. }
  105. if (_AGCCardsPairt.ContainsKey(e.Index))
  106. {
  107. _AGCCardsPairt[e.Index].Visibility = Visibility.Visible;
  108. _CurrentCard = _AGCCardsPairt[e.Index];
  109. _CurrentIndex = e.Index;
  110. }
  111. }
  112. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  113. {
  114. _IsActived = false;
  115. }
  116. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  117. {
  118. _IsActived = true;
  119. if (!_IsLoaded)
  120. {
  121. InitCard();
  122. }
  123. //Task.Factory.StartNew(AutoCheck, TaskCreationOptions.LongRunning); // 自动切换AGC卡片
  124. _IsLoaded = true;
  125. Task.Factory.StartNew(RefreshData, TaskCreationOptions.LongRunning); // 自动刷新AGC数据
  126. Task.Factory.StartNew(RefreshLineData, TaskCreationOptions.LongRunning); // 自动刷新AGC图表数据
  127. }
  128. }
  129. }