ReservoirsViewModel.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. using Aitex.Core.UI.MVVM;
  2. using CyberX8_Core;
  3. using CyberX8_MainPages.Model;
  4. using CyberX8_Themes.CustomControls;
  5. using ExcelLibrary.BinaryFileFormat;
  6. using MECF.Framework.Common.CommonData.Metal;
  7. using MECF.Framework.Common.CommonData.Reservoir;
  8. using MECF.Framework.Common.DataCenter;
  9. using MECF.Framework.Common.Device.Safety;
  10. using MECF.Framework.Common.OperationCenter;
  11. using MECF.Framework.Common.Persistent.Reservoirs;
  12. using MECF.Framework.Common.RecipeCenter;
  13. using MECF.Framework.Common.Utilities;
  14. using Prism.Mvvm;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Collections.ObjectModel;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows.Input;
  22. using System.Windows.Threading;
  23. namespace CyberX8_MainPages.ViewModels
  24. {
  25. public class ReservoirsViewModel : BindableBase
  26. {
  27. #region 常量
  28. private const string RESERVOIRS_DATA = "ReservoirsData";
  29. private const string RESERVOIRS = "reservoirs";
  30. private const string PERSISTENT_VALUE = "PersistentValue";
  31. #endregion
  32. #region 内部变量
  33. private string _module;
  34. private string _recipeContent;
  35. private string _state;
  36. private List<string> _rtDataKeys = new List<string>();
  37. DispatcherTimer _timer;
  38. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  39. private ObservableCollection<RecipeNode> _recipeNodes;
  40. private string _currentRecipeFileName;
  41. private string _recipeType;
  42. private ResRecipe _currentRecipe;
  43. private SafetyData _safetyData;
  44. private double _aNFlow;
  45. private bool _isCAHighLevel;
  46. private bool _isCALowLevel;
  47. private bool _isANHighLevel;
  48. private bool _isANLowLevel;
  49. private bool _isCASafetyHighLevel;
  50. private bool _filterPurgeEnable;
  51. private double _avgANLevel;
  52. private double _avgCALevel;
  53. /// <summary>
  54. /// Persistent
  55. /// </summary>
  56. private ReservoirsPersistentValue _reservoirsPersistent;
  57. /// <summary>
  58. /// Reservoir数据
  59. /// </summary>
  60. private CompactMembranReservoirData _reservoirData;
  61. /// <summary>
  62. /// CellModuleName集合
  63. /// </summary>
  64. private ObservableCollection<string> _cellModuleNameCollection = new ObservableCollection<string>();
  65. /// <summary>
  66. /// Cell A面Flow集合
  67. /// </summary>
  68. private ObservableCollection<double> _cellModuleNameSideAFlowCollection = new ObservableCollection<double>();
  69. /// <summary>
  70. /// Cell B面Flow集合
  71. /// </summary>
  72. private ObservableCollection<double> _cellModuleNameSideBFlowCollection = new ObservableCollection<double>();
  73. /// <summary>
  74. /// MetalData
  75. /// </summary>
  76. private ObservableCollection<CompactMembranMetalDeviceData> _metalDatas = new ObservableCollection<CompactMembranMetalDeviceData>();
  77. /// <summary>
  78. /// 页面功能启用
  79. /// </summary>
  80. private bool _isEnabled;
  81. /// <summary>
  82. /// 是否error
  83. /// </summary>
  84. private bool _isError;
  85. /// <summary>
  86. /// AutoMode页面功能启用
  87. /// </summary>
  88. private bool _isAutoEnabled;
  89. /// <summary>
  90. /// Meatl UI数据
  91. /// </summary>
  92. private ObservableCollection<ReservoirsUIData> _reservoirsUIDatas = new ObservableCollection<ReservoirsUIData>();
  93. #endregion
  94. #region 属性
  95. public double AvgANLevel
  96. {
  97. get { return _avgANLevel; }
  98. set { SetProperty(ref _avgANLevel, value); }
  99. }
  100. public double AvgCALevel
  101. {
  102. get { return _avgCALevel; }
  103. set { SetProperty(ref _avgCALevel, value); }
  104. }
  105. public bool IsCAHighLevel
  106. {
  107. get { return _isCAHighLevel; }
  108. set { SetProperty(ref _isCAHighLevel, value); }
  109. }
  110. public bool IsCALowLevel
  111. {
  112. get { return _isCALowLevel; }
  113. set { SetProperty(ref _isCALowLevel, value); }
  114. }
  115. public bool IsANHighLevel
  116. {
  117. get { return _isANHighLevel; }
  118. set { SetProperty(ref _isANHighLevel, value); }
  119. }
  120. public bool IsANLowLevel
  121. {
  122. get { return _isANLowLevel; }
  123. set { SetProperty(ref _isANLowLevel, value); }
  124. }
  125. public string CurrentRecipeFileName
  126. {
  127. get { return _currentRecipeFileName; }
  128. set { SetProperty(ref _currentRecipeFileName, value); }
  129. }
  130. public ObservableCollection<RecipeNode> RecipeNodes
  131. {
  132. get { return _recipeNodes; }
  133. set { SetProperty(ref _recipeNodes, value); }
  134. }
  135. public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
  136. public string ReservoirRecipeContent
  137. {
  138. get { return _recipeContent; }
  139. set { SetProperty(ref _recipeContent, value); }
  140. }
  141. public string State
  142. {
  143. get { return _state; }
  144. set { SetProperty(ref _state, value); }
  145. }
  146. public ResRecipe CurrentRecipe
  147. {
  148. get { return _currentRecipe; }
  149. set { SetProperty(ref _currentRecipe, value); }
  150. }
  151. /// <summary>
  152. /// Safety数据
  153. /// </summary>
  154. public SafetyData CommonSafetyData
  155. {
  156. get { return _safetyData; }
  157. set { SetProperty(ref _safetyData, value); }
  158. }
  159. public string RecipeType
  160. {
  161. get { return _recipeType; }
  162. set { SetProperty(ref _recipeType, value); }
  163. }
  164. /// <summary>
  165. /// Threshold
  166. /// </summary>
  167. public ReservoirsPersistentValue ReservoirsPersistent
  168. {
  169. get { return _reservoirsPersistent; }
  170. set { SetProperty(ref _reservoirsPersistent, value); }
  171. }
  172. /// <summary>
  173. /// CellModuleName集合
  174. /// </summary>
  175. public ObservableCollection<string> CellModuleNameCollection
  176. {
  177. get { return _cellModuleNameCollection; }
  178. set { SetProperty(ref _cellModuleNameCollection, value); }
  179. }
  180. /// <summary>
  181. /// 模块A面Flow集合
  182. /// </summary>
  183. public ObservableCollection<double> CellModuleNameSideAFlowCollection
  184. {
  185. get { return _cellModuleNameSideAFlowCollection; }
  186. set { SetProperty(ref _cellModuleNameSideAFlowCollection, value); }
  187. }
  188. /// <summary>
  189. /// 模块B面Flow集合
  190. /// </summary>
  191. public ObservableCollection<double> CellModuleNameSideBFlowCollection
  192. {
  193. get { return _cellModuleNameSideBFlowCollection; }
  194. set { SetProperty(ref _cellModuleNameSideBFlowCollection, value); }
  195. }
  196. /// <summary>
  197. /// Reservoir 数据
  198. /// </summary>
  199. public CompactMembranReservoirData ReservoirData
  200. {
  201. get { return _reservoirData; }
  202. set { SetProperty(ref _reservoirData, value); }
  203. }
  204. public bool IsCASafetyHighLevel
  205. {
  206. get { return _isCASafetyHighLevel; }
  207. set { SetProperty(ref _isCASafetyHighLevel, value); }
  208. }
  209. /// <summary>
  210. /// MetalData
  211. /// </summary>
  212. public ObservableCollection<CompactMembranMetalDeviceData> MetalDatas
  213. {
  214. get { return _metalDatas; }
  215. set { SetProperty(ref _metalDatas, value); }
  216. }
  217. public double ANFlow
  218. {
  219. get { return _aNFlow; }
  220. set { SetProperty(ref _aNFlow, value); }
  221. }
  222. /// <summary>
  223. /// 页面功能启用
  224. /// </summary>
  225. public bool IsEnabled
  226. {
  227. get { return _isEnabled; }
  228. set { SetProperty(ref _isEnabled, value); }
  229. }
  230. /// <summary>
  231. /// 是否Error
  232. /// </summary>
  233. public bool IsError
  234. {
  235. get { return _isError; }
  236. set { SetProperty(ref _isError, value); }
  237. }
  238. /// <summary>
  239. /// AutoMode页面功能启用
  240. /// </summary>
  241. public bool IsAutoEnabled
  242. {
  243. get { return _isAutoEnabled; }
  244. set { SetProperty(ref _isAutoEnabled, value); }
  245. }
  246. /// <summary>
  247. /// FilterPurgeEnable
  248. /// </summary>
  249. public bool FilterPurgeEnable
  250. {
  251. get { return _filterPurgeEnable; }
  252. set { SetProperty(ref _filterPurgeEnable, value); }
  253. }
  254. /// <summary>
  255. /// metal ui数据
  256. /// </summary>
  257. public ObservableCollection<ReservoirsUIData> ReservoirsUIDatas
  258. {
  259. get { return _reservoirsUIDatas; }
  260. set { SetProperty(ref _reservoirsUIDatas, value); }
  261. }
  262. #endregion
  263. #region 命令
  264. public ICommand InitializeCommand { get; set; }
  265. public ICommand GotoPMCounterCommand { get; set; }
  266. public ICommand JumpAnolyteCommand { get; set; }
  267. public ICommand JumpCatholyteCommand { get; set; }
  268. public ICommand FilterPurgeEnableCommand { get; set; }
  269. #endregion
  270. public ReservoirsViewModel()
  271. {
  272. InitializeCommand = new DelegateCommand<object>(InitializeAction);
  273. GotoPMCounterCommand = new DelegateCommand<object>(GotoPMCounterAction);
  274. JumpAnolyteCommand = new DelegateCommand<object>(JumpAnolyteAction);
  275. JumpCatholyteCommand = new DelegateCommand<object>(JumpCatholyteAction);
  276. FilterPurgeEnableCommand = new DelegateCommand<object>(FilterPurgeEnableAction);
  277. }
  278. public void LoadData(string systemName)
  279. {
  280. RecipeType = "res";
  281. Module = systemName;
  282. _rtDataKeys.Clear();
  283. _rtDataKeys.Add($"{Module}.Metals");
  284. MetalDatas.Clear();
  285. ReservoirsUIDatas.Clear();
  286. CellModuleNameSideAFlowCollection.Clear();
  287. CellModuleNameSideBFlowCollection.Clear();
  288. Dictionary<string, object> tmpMetals = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  289. if (tmpMetals != null)
  290. {
  291. List<string> strMetals = CommonFunction.GetValue<List<string>>(tmpMetals, $"{Module}.Metals");
  292. int cellsCount = strMetals.Count;
  293. if (strMetals != null)
  294. {
  295. CellModuleNameCollection.Clear();
  296. for (int i = 0; i < cellsCount; i++)
  297. {
  298. CellModuleNameCollection.Add(strMetals[i]);
  299. MetalDatas.Add(null);
  300. ReservoirsUIData reservoirsUIData = new ReservoirsUIData();
  301. reservoirsUIData.Name = strMetals[i];
  302. ReservoirsUIDatas.Add(reservoirsUIData);
  303. CellModuleNameSideAFlowCollection.Add(0);
  304. CellModuleNameSideBFlowCollection.Add(0);
  305. }
  306. }
  307. }
  308. _rtDataKeys.Clear();
  309. if (_timer == null)
  310. {
  311. _timer = new DispatcherTimer();
  312. _timer.Interval = TimeSpan.FromMilliseconds(200);
  313. _timer.Tick += Timer_Tick;
  314. }
  315. _rtDataKeys.Clear();
  316. for (int i = 0; i < CellModuleNameCollection.Count; i++)
  317. {
  318. _rtDataKeys.Add($"{CellModuleNameCollection[i]}.MetalData");
  319. _rtDataKeys.Add($"{CellModuleNameCollection[i]}.SideAFlow");
  320. _rtDataKeys.Add($"{CellModuleNameCollection[i]}.SideAFlowStatus");
  321. _rtDataKeys.Add($"{CellModuleNameCollection[i]}.SideBFlow");
  322. _rtDataKeys.Add($"{CellModuleNameCollection[i]}.SideBFlowStatus");
  323. }
  324. _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
  325. _rtDataKeys.Add($"{Module}.ReservoirData");
  326. _rtDataKeys.Add($"{Module}.CurrentRecipe");
  327. _rtDataKeys.Add($"{Module}.IsCAHighLevel");
  328. _rtDataKeys.Add($"{Module}.IsCALowLevel");
  329. _rtDataKeys.Add($"{Module}.IsANHighLevel");
  330. _rtDataKeys.Add($"{Module}.IsANLowLevel");
  331. _rtDataKeys.Add($"Safety.SafetyData");
  332. _rtDataKeys.Add($"{Module}.FsmState");
  333. _rtDataKeys.Add($"System.Facilities.FilterPurgeEnable");
  334. _rtDataKeys.Add($"{Module}.ReservoirAverageANLevel");
  335. _rtDataKeys.Add($"{Module}.ReservoirAverageCALevel");
  336. _timer.Start();
  337. }
  338. private void Timer_Tick(object sender, EventArgs e)
  339. {
  340. ANFlow = 0.0;
  341. if (_rtDataKeys.Count != 0)
  342. {
  343. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  344. if (_rtDataValueDic != null)
  345. {
  346. State = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.FsmState");
  347. IsError = "Error".Equals(State) ? true : false;
  348. ReservoirData = CommonFunction.GetValue<CompactMembranReservoirData>(_rtDataValueDic, $"{Module}.ReservoirData");
  349. ReservoirsPersistent = CommonFunction.GetValue<ReservoirsPersistentValue>(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}");
  350. CurrentRecipe = CommonFunction.GetValue<ResRecipe>(_rtDataValueDic, $"{Module}.CurrentRecipe");
  351. CommonSafetyData = CommonFunction.GetValue<SafetyData>(_rtDataValueDic, $"Safety.SafetyData");
  352. FilterPurgeEnable = CommonFunction.GetValue<bool>(_rtDataValueDic, $"System.Facilities.FilterPurgeEnable");
  353. IsCASafetyHighLevel = CommonSafetyData.ReservoirHighLevel;
  354. //计算总的ANFlow
  355. for (int i = 0; i < CellModuleNameCollection.Count; i++)
  356. {
  357. MetalDatas[i] = CommonFunction.GetValue<CompactMembranMetalDeviceData>(_rtDataValueDic, $"{CellModuleNameCollection[i]}.MetalData");
  358. CellModuleNameSideAFlowCollection[i] = CommonFunction.GetValue<double>(_rtDataValueDic, $"{CellModuleNameCollection[i]}.SideAFlow");
  359. CellModuleNameSideBFlowCollection[i] = CommonFunction.GetValue<double>(_rtDataValueDic, $"{CellModuleNameCollection[i]}.SideBFlow");
  360. ANFlow += CellModuleNameSideAFlowCollection[i] + CellModuleNameSideBFlowCollection[i];
  361. }
  362. IsANHighLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsANHighLevel");
  363. IsANLowLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsANLowLevel");
  364. IsCAHighLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCAHighLevel");
  365. IsCALowLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCALowLevel");
  366. if ("Manual".Equals(ReservoirsPersistent.OperatingMode))
  367. {
  368. IsEnabled = true;
  369. IsAutoEnabled = true;
  370. }
  371. else if ("Auto".Equals(ReservoirsPersistent.OperatingMode))
  372. {
  373. IsAutoEnabled = true;
  374. IsEnabled = false;
  375. }
  376. else
  377. {
  378. State = "Stopped";
  379. IsEnabled = false;
  380. IsAutoEnabled = false;
  381. }
  382. AvgANLevel = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.ReservoirAverageANLevel");
  383. AvgCALevel = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.ReservoirAverageCALevel");
  384. }
  385. }
  386. }
  387. #region 命令方法
  388. /// <summary>
  389. /// 初始化
  390. /// </summary>
  391. /// <param name="param"></param>
  392. private void InitializeAction(object param)
  393. {
  394. InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll");
  395. }
  396. /// <summary>
  397. /// 进入PMCounter页面
  398. /// </summary>
  399. /// <param name="param"></param>
  400. private void GotoPMCounterAction(object param)
  401. {
  402. GlobalEvents.OnSwitchFixedChildSubItem(Module, $"PMCounter{Module.Substring(9, 1)}");
  403. }
  404. private void JumpAnolyteAction(object param)
  405. {
  406. GlobalEvents.OnSwitchFixedChildSubItem(Module, $"Anolyte{Module.Substring(9, 1)}");
  407. }
  408. private void JumpCatholyteAction(object param)
  409. {
  410. GlobalEvents.OnSwitchFixedChildSubItem(Module, $"Catholyte{Module.Substring(9, 1)}");
  411. }
  412. private void FilterPurgeEnableAction(object param)
  413. {
  414. CommonValveControl commonValveControl = (CommonValveControl)param;
  415. if (commonValveControl.IsCanEdit == true)
  416. {
  417. if (!commonValveControl.Status)
  418. {
  419. commonValveControl.Status = !commonValveControl.Status;
  420. InvokeClient.Instance.Service.DoOperation($"System.Facilities.FilterPurgeEnable");
  421. }
  422. else
  423. {
  424. commonValveControl.Status = !commonValveControl.Status;
  425. InvokeClient.Instance.Service.DoOperation($"System.Facilities.FilterPurgeDisable");
  426. }
  427. }
  428. }
  429. #endregion
  430. }
  431. }