WindStationBlock.xaml.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. using NEIntelligentControl2.Models.Matrix;
  2. using NEIntelligentControl2.Models.Pages;
  3. using NEIntelligentControl2.Models.Station;
  4. using NEIntelligentControl2.Models.Windturbine;
  5. using NEIntelligentControl2.Windows;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  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.Matrix
  20. {
  21. /// <summary>
  22. /// 场站模块
  23. /// </summary>
  24. public partial class WindStationBlock : UserControl, IStationInfo
  25. {
  26. // --------------依赖属性----------------
  27. public static DependencyProperty CountTotalProperty = DependencyProperty.Register("CountTotal", typeof(int), typeof(WindStationBlock));
  28. public static DependencyProperty CountConnectProperty = DependencyProperty.Register("CountConnect", typeof(int), typeof(WindStationBlock));
  29. public static DependencyProperty CountStandbyProperty = DependencyProperty.Register("CountStandby", typeof(int), typeof(WindStationBlock));
  30. public static DependencyProperty CountStoppedProperty = DependencyProperty.Register("CountStopped", typeof(int), typeof(WindStationBlock));
  31. public static DependencyProperty CountMaintainProperty = DependencyProperty.Register("CountMaintain", typeof(int), typeof(WindStationBlock));
  32. public static DependencyProperty CountFaultProperty = DependencyProperty.Register("CountFault", typeof(int), typeof(WindStationBlock));
  33. public static DependencyProperty CountOfflineProperty = DependencyProperty.Register("CountOffline", typeof(int), typeof(WindStationBlock));
  34. /// <summary>
  35. /// 总接入台数
  36. /// </summary>
  37. public int CountTotal { get => (int)GetValue(CountTotalProperty); set => SetValue(CountTotalProperty, value); }
  38. /// <summary>
  39. /// 并网台数
  40. /// </summary>
  41. public int CountConnect { get => (int)GetValue(CountConnectProperty); set => SetValue(CountConnectProperty, value); }
  42. /// <summary>
  43. /// 待机台数
  44. /// </summary>
  45. public int CountStandby { get => (int)GetValue(CountStandbyProperty); set => SetValue(CountStandbyProperty, value); }
  46. /// <summary>
  47. /// 停机台数
  48. /// </summary>
  49. public int CountStopped { get => (int)GetValue(CountStoppedProperty); set => SetValue(CountStoppedProperty, value); }
  50. /// <summary>
  51. /// 维护台数
  52. /// </summary>
  53. public int CountMaintain { get => (int)GetValue(CountMaintainProperty); set => SetValue(CountMaintainProperty, value); }
  54. /// <summary>
  55. /// 故障台数
  56. /// </summary>
  57. public int CountFault { get => (int)GetValue(CountFaultProperty); set => SetValue(CountFaultProperty, value); }
  58. /// <summary>
  59. /// 离线台数
  60. /// </summary>
  61. public int CountOffline { get => (int)GetValue(CountOfflineProperty); set => SetValue(CountOfflineProperty, value); }
  62. /// <summary>
  63. /// 场站信息
  64. /// </summary>
  65. public StationInfo StationInfo { get; set; }
  66. /// <summary>
  67. /// 矩阵块
  68. /// </summary>
  69. private List<WindBlockSmall> _Blocks;
  70. private Service.Windturbine.CacheManager _CacheManager;
  71. public WindStationBlock(Service.Windturbine.CacheManager cm)
  72. {
  73. InitializeComponent();
  74. _CacheManager = cm;
  75. }
  76. /// <summary>
  77. /// 更新数据
  78. /// </summary>
  79. public void UpdateData(object obj)
  80. {
  81. var datas = obj as Dictionary<string, WindturbineInfo>;
  82. if (datas == null) return;
  83. var ls = datas.Values.Where(wi => wi.StationId == StationInfo.Id).ToList();
  84. if (_Blocks == null)
  85. {
  86. InitBlocks(ls);
  87. }
  88. CountTotal = ls.Count;
  89. CountStopped = ls.Where(s => (int)s.Status == 0).ToList().Count;
  90. CountConnect = ls.Where(s => (int)s.Status == 4).ToList().Count;
  91. CountStandby = ls.Where(s => (int)s.Status == 2 || s.Status == 3 || s.Status == 1).ToList().Count;
  92. CountMaintain = ls.Where(s => (int)s.Status == 6).ToList().Count;
  93. CountFault = ls.Where(s => (int)s.Status == 5).ToList().Count;
  94. CountOffline = ls.Where(s => (int)s.Status == 7).ToList().Count;
  95. if (_Blocks == null) return;
  96. var lockInfo = _CacheManager.CustomLockInfos;
  97. foreach (var v in _Blocks)
  98. {
  99. if (!datas.ContainsKey(v.WindturbineId)) continue;
  100. if (lockInfo.ContainsKey(v.WindturbineId))
  101. {
  102. v.CustomLockInfo = lockInfo[v.WindturbineId];
  103. }
  104. else
  105. {
  106. v.CustomLockInfo = null;
  107. }
  108. v.Update(datas[v.WindturbineId]);
  109. }
  110. }
  111. private void InitBlocks(List<WindturbineInfo> ls)
  112. {
  113. _Blocks = new List<WindBlockSmall>();
  114. ls.Sort((x, y) => x.ID - y.ID);
  115. Dispatcher.Invoke(() =>
  116. {
  117. foreach (var v in ls)
  118. {
  119. WindBlockSmall bs = new WindBlockSmall(v) { Title =v.ID.ToString(), WindturbineId = v.WindturbineId };
  120. _Blocks.Add(bs);
  121. _OPUGMain.Add(bs);
  122. }
  123. });
  124. }
  125. private void MenuItem_Click(object sender, RoutedEventArgs e)
  126. {
  127. string tag = ((Control)sender).Tag as string;
  128. switch (tag)
  129. {
  130. case "Start": // 启动
  131. case "Stop": // 停机
  132. case "Reset": // 复位
  133. case "Maintain": // 维护
  134. case "UnMaintain": // 取消维护
  135. SendControl(tag);
  136. break;
  137. case "compar": // 参数对比
  138. Compar();
  139. break;
  140. default: return;
  141. }
  142. }
  143. private void MenuItem_Click_Lock(object sender, RoutedEventArgs e)
  144. {
  145. // lockValue
  146. var type = ((Control)sender).Tag as string;
  147. if (type == null) return;
  148. bool b1 = Enum.TryParse(type, out HungType hungType);
  149. if (!b1) return;
  150. var bks = GetSelectedItems();
  151. if (bks.Count <= 0) return;
  152. string customValue = null;
  153. if(hungType == HungType.CustomerLock)
  154. {
  155. customValue = CustomValueWindow.ShowWindow();
  156. if (customValue == null) return;
  157. }
  158. var w = App.ServiceProvider.GetService(typeof(Windows.ConfirmWindow)) as Windows.ConfirmWindow;
  159. var ls = bks.Select(item => item.Value.WindturbineInfo).ToList();
  160. bool b = w.Show(hungType, ls, customValue);
  161. if (!b) return;
  162. //确认操作后,将所有选中的风机修改为非选中状态
  163. foreach (var item in bks)
  164. {
  165. item.Value.IsSelected = false;
  166. }
  167. }
  168. /// <summary>
  169. /// 参数对比
  170. /// </summary>
  171. private void Compar()
  172. {
  173. var vs = GetSelectedItems();
  174. foreach (var item in vs)
  175. {
  176. item.Value.IsSelected = false;
  177. }
  178. var ws = vs.Select(x=>x.Value.WindturbineInfo).ToList();
  179. Windows.ParameterComparisonWindow.ShowWindow(ws);
  180. }
  181. /// <summary>
  182. /// 发送控制命令
  183. /// </summary>
  184. public void SendControl(string tag)
  185. {
  186. OperateStyle os = (OperateStyle)Enum.Parse(typeof(OperateStyle), tag);
  187. var bks = GetSelectedItems();
  188. if (bks.Count <= 0) return;
  189. var w = App.ServiceProvider.GetService(typeof(Windows.ConfirmWindow)) as Windows.ConfirmWindow;
  190. var ls = bks.Select(item => item.Value.WindturbineInfo).ToList();
  191. bool b = w.Show(os, ls);
  192. if (!b) return;
  193. //确认操作后,将所有选中的风机修改为非选中状态
  194. foreach (var item in bks)
  195. {
  196. item.Value.IsSelected = false;
  197. }
  198. }
  199. /// <summary>
  200. /// 获取控制数据
  201. /// </summary>
  202. private WindBlockInfo GetSendData(WindBlockSmall item)
  203. {
  204. WindBlockInfo data = new WindBlockInfo();
  205. data.OperatedTime = item.OperatedTime;
  206. data.ID = item.WindturbineInfo.WindturbineId;
  207. data.WindturbineId = item.WindturbineInfo.WindturbineId;
  208. data.Status = item.WindturbineInfo.Status;
  209. data.ModelId = item.WindturbineInfo.ModelId;
  210. data.StationId = item.WindturbineInfo.StationId;
  211. data.ProjectId = item.WindturbineInfo.ProjectId;
  212. return data;
  213. }
  214. /// <summary>
  215. /// 获取选中的矩阵
  216. /// </summary>
  217. private Dictionary<string, WindBlockSmall> GetSelectedItems()
  218. {
  219. Dictionary<string, WindBlockSmall> bsw = new Dictionary<string, WindBlockSmall>();
  220. foreach (var v in _Blocks)
  221. {
  222. if (v.IsSelected && v.WindturbineInfo != null && !bsw.ContainsKey(v.WindturbineInfo.WindturbineId))
  223. {
  224. bsw.Add(v.WindturbineInfo.WindturbineId, v);
  225. }
  226. }
  227. return bsw;
  228. }
  229. }
  230. }