PVStationBlock.xaml.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using NEIntelligentControl2.Models.Matrix;
  2. using NEIntelligentControl2.Models.PV;
  3. using NEIntelligentControl2.Models.Station;
  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.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace NEIntelligentControl2.Views.Matrix
  19. {
  20. /// <summary>
  21. /// 光伏模块
  22. /// </summary>
  23. public partial class PVStationBlock : UserControl, IStationInfo
  24. {
  25. // --------------依赖属性----------------
  26. public static DependencyProperty CountTotalProperty = DependencyProperty.Register("CountTotal", typeof(int), typeof(PVStationBlock));
  27. public static DependencyProperty CountConnectProperty = DependencyProperty.Register("CountConnect", typeof(int), typeof(PVStationBlock));
  28. public static DependencyProperty CountStandbyProperty = DependencyProperty.Register("CountStandby", typeof(int), typeof(PVStationBlock));
  29. public static DependencyProperty CountPowerRestrictionProperty = DependencyProperty.Register("CountPowerRestriction", typeof(int), typeof(PVStationBlock));
  30. public static DependencyProperty CountMaintainProperty = DependencyProperty.Register("CountMaintain", typeof(int), typeof(PVStationBlock));
  31. public static DependencyProperty CountFaultProperty = DependencyProperty.Register("CountFault", typeof(int), typeof(PVStationBlock));
  32. public static DependencyProperty CountOfflineProperty = DependencyProperty.Register("CountOffline", typeof(int), typeof(PVStationBlock));
  33. /// <summary>
  34. /// 总接入台数
  35. /// </summary>
  36. public int CountTotal { get => (int)GetValue(CountTotalProperty); set => SetValue(CountTotalProperty, value); }
  37. /// <summary>
  38. /// 并网台数
  39. /// </summary>
  40. public int CountConnect { get => (int)GetValue(CountConnectProperty); set => SetValue(CountConnectProperty, value); }
  41. /// <summary>
  42. /// 待机台数
  43. /// </summary>
  44. public int CountStandby { get => (int)GetValue(CountStandbyProperty); set => SetValue(CountStandbyProperty, value); }
  45. /// <summary>
  46. /// 限电台数
  47. /// </summary>
  48. public int CountPowerRestriction { get => (int)GetValue(CountPowerRestrictionProperty); set => SetValue(CountPowerRestrictionProperty, value); }
  49. /// <summary>
  50. /// 维护台数
  51. /// </summary>
  52. public int CountMaintain { get => (int)GetValue(CountMaintainProperty); set => SetValue(CountMaintainProperty, value); }
  53. /// <summary>
  54. /// 故障台数
  55. /// </summary>
  56. public int CountFault { get => (int)GetValue(CountFaultProperty); set => SetValue(CountFaultProperty, value); }
  57. /// <summary>
  58. /// 离线台数
  59. /// </summary>
  60. public int CountOffline { get => (int)GetValue(CountOfflineProperty); set => SetValue(CountOfflineProperty, value); }
  61. /// <summary>
  62. /// 场站信息
  63. /// </summary>
  64. public StationInfo StationInfo { get; set; }
  65. private List<PVBlock> _PVBlocks;
  66. public PVStationBlock()
  67. {
  68. InitializeComponent();
  69. }
  70. public void UpdateData(object obj)
  71. {
  72. var datas = obj as Dictionary<string, PVInfo>;
  73. if (datas == null) return;
  74. var ls = datas.Values.Where(wi => wi.Station == StationInfo.Id).ToList();
  75. if (_PVBlocks == null)
  76. {
  77. InitBlocks(ls);
  78. }
  79. CountTotal = ls.Count;
  80. CountPowerRestriction = ls.Where(s => s.State == PVState.Restriction|| s.State==PVState.RestrictionShutdown).ToList().Count;
  81. CountConnect = ls.Where(s => s.State == PVState.GridConnected).ToList().Count;
  82. CountStandby = ls.Where(s => s.State == PVState.Standby).ToList().Count;
  83. CountMaintain = ls.Where(s => s.State == PVState.Maintain).ToList().Count;
  84. CountFault = ls.Where(s => s.State == PVState.Malfunction).ToList().Count;
  85. CountOffline = ls.Where(s => s.State == PVState.Offline).ToList().Count;
  86. if (_PVBlocks == null) return;
  87. foreach (var v in _PVBlocks)
  88. {
  89. if (!datas.ContainsKey(v.Id))
  90. {
  91. continue;
  92. }
  93. v.Update(datas[v.Id]);
  94. }
  95. }
  96. private void InitBlocks(List<PVInfo> ls)
  97. {
  98. _PVBlocks = new List<PVBlock>();
  99. ls.Sort((x, y) => x.Index - y.Index);
  100. Dispatcher.Invoke(() =>
  101. {
  102. foreach (var v in ls)
  103. {
  104. PVBlock pb = new PVBlock() { Id = v.Id, IsSmallModel = true };
  105. _PVBlocks.Add(pb);
  106. _UGMain.Children.Add(pb);
  107. }
  108. });
  109. }
  110. }
  111. }