PageMatrixStation.xaml.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. using NEIntelligentControl2.Models.Matrix;
  2. using NEIntelligentControl2.Models.PV;
  3. using NEIntelligentControl2.Models.Station;
  4. using NEIntelligentControl2.Models.Windturbine;
  5. using NEIntelligentControl2.Service.Windturbine;
  6. using NEIntelligentControl2.Views.Matrix;
  7. using NEIntelligentControl2.Windows;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace NEIntelligentControl2.Pages.Matrix
  23. {
  24. /// <summary>
  25. /// 场站矩阵页面
  26. /// </summary>
  27. public partial class PageMatrixStation : Page, IStationInfo
  28. {
  29. public StationInfo StationInfo { get; set; }
  30. /// <summary>
  31. /// 矩阵块
  32. /// </summary>
  33. private List<WindBlock> _WindBlocks;
  34. /// <summary>
  35. /// 光伏矩阵块
  36. /// </summary>
  37. private List<PVBlock> _PVBlocks;
  38. /// <summary>
  39. /// 缓存
  40. /// </summary>
  41. private CacheManager _CacheManager;
  42. public PageMatrixStation(CacheManager cm)
  43. {
  44. InitializeComponent();
  45. _CacheManager = cm;
  46. }
  47. public void UpdateData(object obj)
  48. {
  49. if (StationInfo.Type == StationType.Wind || StationInfo.Id == "WIND_ALL")
  50. {
  51. UpdateWindturbine(obj);
  52. }
  53. else
  54. {
  55. Dispatcher.Invoke(() => _GDMain.ContextMenu = null);
  56. UpdatePV(obj);
  57. }
  58. }
  59. private void UpdatePV(object obj)
  60. {
  61. var datas = obj as Dictionary<string, PVInfo>;
  62. if (datas == null) return;
  63. var ls = datas.Values.Where(wi => wi.Station == StationInfo.Id).ToList();
  64. if (_PVBlocks == null)
  65. {
  66. InitPVInfo(ls);
  67. return;
  68. }
  69. Dispatcher.Invoke(() =>
  70. {
  71. foreach (var v in _PVBlocks)
  72. {
  73. if (!datas.ContainsKey(v.Id)) continue;
  74. v.Update(datas[v.Id]);
  75. }
  76. });
  77. }
  78. private void InitPVInfo(List<PVInfo> ls)
  79. {
  80. if (ls == null) return;
  81. _PVBlocks = new List<PVBlock>();
  82. ls.Sort((x, y) => x.Index - y.Index);
  83. Dispatcher.Invoke(() =>
  84. {
  85. foreach (var v in ls)
  86. {
  87. PVBlock pb = new PVBlock() { Id = v.Id };
  88. pb.Update(v);
  89. _PVBlocks.Add(pb);
  90. _OPUGMain.Add(pb);
  91. }
  92. });
  93. }
  94. /// <summary>
  95. /// 更新风机数据
  96. /// </summary>
  97. /// <param name="obj"></param>
  98. private void UpdateWindturbine(object obj)
  99. {
  100. var datas = obj as Dictionary<string, WindturbineInfo>;
  101. if (datas == null) return;
  102. var ls = datas.Values.Where(wi => wi.StationId == StationInfo.Id).ToList();
  103. if (_WindBlocks == null)
  104. {
  105. InitWindturbineBlocks(ls);
  106. return;
  107. }
  108. var lockInfo = _CacheManager.CustomLockInfos;
  109. Dispatcher.Invoke(() =>
  110. {
  111. foreach (var v in _WindBlocks)
  112. {
  113. if (!datas.ContainsKey(v.WindturbineId)) continue;
  114. if (lockInfo.ContainsKey(v.WindturbineId))
  115. {
  116. v.CustomLockInfo = lockInfo[v.WindturbineId];
  117. }
  118. else
  119. {
  120. v.CustomLockInfo = null;
  121. }
  122. v.Update(datas[v.WindturbineId]);
  123. }
  124. });
  125. }
  126. /// <summary>
  127. /// 初始化风机矩阵块
  128. /// </summary>
  129. private void InitWindturbineBlocks(List<WindturbineInfo> ls)
  130. {
  131. if (ls == null) return;
  132. _WindBlocks = new List<WindBlock>();
  133. ls.Sort((x, y) => x.ID - y.ID);
  134. Dispatcher.Invoke(() =>
  135. {
  136. foreach (var v in ls)
  137. {
  138. WindBlock bs = new WindBlock(v) { WindturbineId = v.WindturbineId };
  139. bs.Update(v);
  140. _WindBlocks.Add(bs);
  141. _OPUGMain.Add(bs);
  142. }
  143. });
  144. }
  145. private void MenuItem_Click(object sender, RoutedEventArgs e)
  146. {
  147. string tag = ((Control)sender).Tag as string;
  148. switch (tag)
  149. {
  150. case "Start": // 启动
  151. case "Stop": // 停机
  152. case "Reset": // 复位
  153. case "Maintain": // 维护
  154. case "UnMaintain": // 取消维护
  155. SendControl(tag);
  156. break;
  157. case "compar": // 参数对比
  158. Compar();
  159. break;
  160. default: return;
  161. }
  162. }
  163. private void MenuItem_Click_Lock(object sender, RoutedEventArgs e)
  164. {
  165. // lockValue
  166. var type = ((Control)sender).Tag as string;
  167. if (type == null) return;
  168. bool b1 = Enum.TryParse(type, out HungType hungType);
  169. if (!b1) return;
  170. var bks = GetSelectedItems();
  171. if (bks.Count <= 0) return;
  172. string customValue = null;
  173. if (hungType == HungType.CustomerLock)
  174. {
  175. customValue = CustomValueWindow.ShowWindow();
  176. if (customValue == null) return;
  177. }
  178. var w = App.ServiceProvider.GetService(typeof(Windows.ConfirmWindow)) as Windows.ConfirmWindow;
  179. var ls = bks.Select(item => item.Value.WindturbineInfo).ToList();
  180. bool b = w.Show(hungType, ls, customValue);
  181. if (!b) return;
  182. //确认操作后,将所有选中的风机修改为非选中状态
  183. foreach (var item in bks)
  184. {
  185. item.Value.IsSelected = false;
  186. }
  187. }
  188. /// <summary>
  189. /// 参数对比
  190. /// </summary>
  191. private void Compar()
  192. {
  193. var vs = GetSelectedItems();
  194. foreach (var item in vs)
  195. {
  196. item.Value.IsSelected = false;
  197. }
  198. var ws = vs.Select(x => x.Value.WindturbineInfo).ToList();
  199. Windows.ParameterComparisonWindow.ShowWindow(ws);
  200. }
  201. /// <summary>
  202. /// 发送控制命令
  203. /// </summary>
  204. public void SendControl(string tag)
  205. {
  206. OperateStyle os = (OperateStyle)Enum.Parse(typeof(OperateStyle), tag);
  207. //List<WindBlockInfo> dataList = new List<WindBlockInfo>();
  208. var bks = GetSelectedItems();
  209. if (bks.Count <= 0) return;
  210. foreach (var item in bks)
  211. {
  212. WindBlockInfo data = GetSendData(item.Value);
  213. //dataList.Add(data);
  214. }
  215. //if (dataList.Count <= 0) return;
  216. var w = App.ServiceProvider.GetService(typeof(Windows.ConfirmWindow)) as Windows.ConfirmWindow;
  217. var ls = bks.Select(item => item.Value.WindturbineInfo).ToList();
  218. bool b = w.Show(os, ls);
  219. if (!b) return;
  220. //确认操作后,将所有选中的风机修改为非选中状态
  221. foreach (var item in bks)
  222. {
  223. item.Value.IsSelected = false;
  224. }
  225. }
  226. private Dictionary<string, WindBlock> GetSelectedItems()
  227. {
  228. Dictionary<string, WindBlock> bsw = new Dictionary<string, WindBlock>();
  229. foreach (var v in _WindBlocks)
  230. {
  231. if (v.IsSelected && v.WindturbineInfo != null && !bsw.ContainsKey(v.WindturbineInfo.WindturbineId))
  232. {
  233. bsw.Add(v.WindturbineInfo.WindturbineId, v);
  234. }
  235. }
  236. return bsw;
  237. }
  238. /// <summary>
  239. /// 获取控制数据
  240. /// </summary>
  241. private WindBlockInfo GetSendData(WindBlock item)
  242. {
  243. WindBlockInfo data = new WindBlockInfo();
  244. //data.OperatedTime = item.OperatedTime;
  245. data.ID = item.WindturbineInfo.WindturbineId;
  246. data.WindturbineId = item.WindturbineInfo.WindturbineId;
  247. data.Status = item.WindturbineInfo.Status;
  248. data.ModelId = item.WindturbineInfo.ModelId;
  249. data.StationId = item.WindturbineInfo.StationId;
  250. data.ProjectId = item.WindturbineInfo.ProjectId;
  251. return data;
  252. }
  253. private void Page_Loaded(object sender, RoutedEventArgs e)
  254. {
  255. if (StationInfo.Type == StationType.Wind || StationInfo.Id == "WIND_ALL")
  256. {
  257. var ls = _CacheManager.Windturbineinfos?.Values.Where(wi => wi.StationId == StationInfo.Id).ToList();
  258. if (_WindBlocks == null)
  259. {
  260. InitWindturbineBlocks(ls);
  261. }
  262. }
  263. else
  264. {
  265. var ls = _CacheManager.PVInfos?.Values.Where(wi => wi.Station == StationInfo.Id).ToList();
  266. if (ls == null) return;
  267. if (_PVBlocks == null)
  268. {
  269. InitPVInfo(ls);
  270. }
  271. }
  272. }
  273. }
  274. }