DosingSystemViewModel.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using MECF.Framework.Common.DataCenter;
  8. using MECF.Framework.Common.Utilities;
  9. using System.Windows.Threading;
  10. using Prism.Commands;
  11. using Prism.Mvvm;
  12. using MECF.Framework.Common.RecipeCenter;
  13. using CyberX8_Core;
  14. using CyberX8_MainPages.PMs;
  15. using MECF.Framework.Common.OperationCenter;
  16. using System.Windows.Input;
  17. using MECF.Framework.Common.Persistent.Reservoirs;
  18. using MECF.Framework.Common.CommonData.Reservoir;
  19. using CyberX8_MainPages.Model;
  20. using System.Collections.ObjectModel;
  21. using OpenSEMI.ClientBase.Command;
  22. namespace CyberX8_MainPages.ViewModels
  23. {
  24. internal class DosingSystemViewModel : BindableBase
  25. {
  26. #region 常量
  27. private const int MAX_REPLEN_NUM = 4;
  28. #endregion
  29. #region 内部变量
  30. #region system
  31. /// <summary>
  32. /// rt查询key
  33. /// </summary>
  34. private List<string> _rtDataKeys = new List<string>();
  35. /// <summary>
  36. /// 时钟
  37. /// </summary>
  38. DispatcherTimer _timer;
  39. /// <summary>
  40. /// rt查询数据
  41. /// </summary>
  42. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  43. #endregion
  44. #region Common
  45. /// <summary>
  46. /// Module
  47. /// </summary>
  48. private string _module;
  49. /// <summary>
  50. /// Operation Mode
  51. /// </summary>
  52. private string _operatingMode;
  53. /// <summary>
  54. /// 状态
  55. /// </summary>
  56. private string _state;
  57. /// <summary>
  58. /// Reservoirs Persistent数据
  59. /// </summary>
  60. private ReservoirsPersistentValue _reservoirsPersistent;
  61. /// <summary>
  62. /// Replens Persistent数据
  63. /// </summary>
  64. private Dictionary<string, ReplenPersistentValue> _replensPersistent = new Dictionary<string, ReplenPersistentValue>();
  65. /// <summary>
  66. /// 页面功能启用
  67. /// </summary>
  68. private bool _isEnabled;
  69. /// <summary>
  70. /// AutoMode页面功能启用
  71. /// </summary>
  72. private bool _isAutoEnabled;
  73. /// <summary>
  74. /// IsManualorAuto
  75. /// </summary>
  76. private bool _isManualorAuto;
  77. /// <summary>
  78. /// Reservoir数据
  79. /// </summary>
  80. private StandardHotReservoirData _reservoirData;
  81. #endregion
  82. #region recipe
  83. /// <summary>
  84. /// 当前的recipe
  85. /// </summary>
  86. private ResRecipe _currentRecipe;
  87. /// <summary>
  88. /// Recipe Mode
  89. /// </summary>
  90. private string _recipeMode;
  91. /// <summary>
  92. /// Selected Recipe Node
  93. /// </summary>
  94. private RecipeNode _selectedRecipeNode;
  95. /// <summary>
  96. /// Recipe Type
  97. /// </summary>
  98. private string _recipeType;
  99. /// <summary>
  100. /// Recipe Manager
  101. /// </summary>
  102. private UiRecipeManager _uiRecipeManager = new UiRecipeManager();
  103. #endregion
  104. #region DosingSystem
  105. /// <summary>
  106. /// Replen Datas
  107. /// </summary>
  108. private ReplenData[] _replenDatas;
  109. /// <summary>
  110. /// Replen Data Collection
  111. /// </summary>
  112. private ObservableCollection<ReplenData> _replenDataCollection;
  113. /// <summary>
  114. /// Replen Items
  115. /// </summary>
  116. private ObservableCollection<bool> _replenEnable = new ObservableCollection<bool>(new bool[MAX_REPLEN_NUM]);
  117. /// <summary>
  118. /// Replen数量
  119. /// </summary>
  120. private int _replenNum;
  121. /// <summary>
  122. /// Replen Persistent数据集合
  123. /// </summary>
  124. private ObservableCollection<ReplenPersistentValue> _replensPersistentCollection;
  125. #endregion
  126. #endregion
  127. #region 属性
  128. #region Common
  129. /// <summary>
  130. /// Module
  131. /// </summary>
  132. public string Module
  133. {
  134. get { return _module; }
  135. set { SetProperty(ref _module, value); }
  136. }
  137. /// <summary>
  138. /// Operation Mode
  139. /// </summary>
  140. public string OperatingMode
  141. {
  142. get { return _operatingMode; }
  143. set { SetProperty(ref _operatingMode, value); }
  144. }
  145. /// <summary>
  146. /// 状态
  147. /// </summary>
  148. public string State
  149. {
  150. get { return _state; }
  151. set { SetProperty(ref _state, value); }
  152. }
  153. /// <summary>
  154. /// Reservoirs Persistent数据
  155. /// </summary>
  156. public ReservoirsPersistentValue ReservoirsPersistent
  157. {
  158. get { return _reservoirsPersistent; }
  159. set { SetProperty(ref _reservoirsPersistent, value); }
  160. }
  161. /// <summary>
  162. /// Replen Persistent数据集合
  163. /// </summary>
  164. public ObservableCollection<ReplenPersistentValue> ReplensPersistentCollection
  165. {
  166. get { return _replensPersistentCollection; }
  167. set { SetProperty(ref _replensPersistentCollection, value); }
  168. }
  169. /// <summary>
  170. /// 页面功能启用
  171. /// </summary>
  172. public bool IsEnabled
  173. {
  174. get { return _isEnabled; }
  175. set { SetProperty(ref _isEnabled, value); }
  176. }
  177. /// <summary>
  178. /// AutoMode页面功能启用
  179. /// </summary>
  180. public bool IsAutoEnabled
  181. {
  182. get { return _isAutoEnabled; }
  183. set { SetProperty(ref _isAutoEnabled, value); }
  184. }
  185. /// <summary>
  186. /// IsManualorAuto
  187. /// </summary>
  188. public bool IsManualorAuto
  189. {
  190. get { return _isManualorAuto; }
  191. set { SetProperty(ref _isManualorAuto, value); }
  192. }
  193. /// <summary>
  194. /// Reservoir数据
  195. /// </summary>
  196. public StandardHotReservoirData ReservoirData
  197. {
  198. get { return _reservoirData; }
  199. set { SetProperty(ref _reservoirData, value); }
  200. }
  201. #endregion
  202. #region recipe
  203. /// <summary>
  204. /// Recipe内容
  205. /// </summary>
  206. public ResRecipe CurrentRecipe
  207. {
  208. get { return _currentRecipe; }
  209. set { SetProperty(ref _currentRecipe, value); }
  210. }
  211. /// <summary>
  212. /// Selected Recipe Node
  213. /// </summary>
  214. public RecipeNode SelectedRecipeNode
  215. {
  216. get { return _selectedRecipeNode; }
  217. set { SetProperty(ref _selectedRecipeNode, value); }
  218. }
  219. /// <summary>
  220. /// Recipe Mode
  221. /// </summary>
  222. public string RecipeMode
  223. {
  224. get { return _recipeMode; }
  225. set { SetProperty(ref _recipeMode, value); }
  226. }
  227. /// <summary>
  228. /// Recipe Type
  229. /// </summary>
  230. public string RecipeType
  231. {
  232. get { return _recipeType; }
  233. set { SetProperty(ref _recipeType, value); }
  234. }
  235. #endregion
  236. #region DosingSystem
  237. /// <summary>
  238. /// Replen 数据
  239. /// </summary>
  240. public ReplenData[] ReplenDatas
  241. {
  242. get { return _replenDatas; }
  243. set { SetProperty(ref _replenDatas, value); }
  244. }
  245. /// <summary>
  246. /// Replen Data集合
  247. /// </summary>
  248. public ObservableCollection<ReplenData> ReplenDataCollection
  249. {
  250. get { return _replenDataCollection; }
  251. set { SetProperty(ref _replenDataCollection, value); }
  252. }
  253. /// <summary>
  254. /// Replen Enable列表
  255. /// </summary>
  256. public ObservableCollection<bool> ReplenEnable
  257. {
  258. get { return _replenEnable; }
  259. set { SetProperty(ref _replenEnable, value); }
  260. }
  261. /// <summary>
  262. /// Replen 数量
  263. /// </summary>
  264. public int ReplenNum
  265. {
  266. get { return _replenNum; }
  267. set { SetProperty(ref _replenNum, value); }
  268. }
  269. #endregion
  270. #endregion
  271. #region 命令
  272. public ICommand InitializeCommand { get; set; }
  273. public ICommand BackCommand { get; set; }
  274. #endregion
  275. /// <summary>
  276. /// 构造函数
  277. /// </summary>
  278. public DosingSystemViewModel()
  279. {
  280. InitializeCommand = new DelegateCommand<object>(InitializeAction);
  281. BackCommand = new DelegateCommand<object>(BackAction);
  282. }
  283. /// <summary>
  284. /// 加载数据
  285. /// </summary>
  286. public void LoadData(string systemName)
  287. {
  288. RecipeType = "rds";
  289. Module = systemName;
  290. _rtDataKeys.Clear();
  291. _rtDataKeys.Add($"{Module}.ReservoirData");
  292. _rtDataKeys.Add($"{Module}.PersistentValue");
  293. _rtDataKeys.Add($"{Module}.ReplenPersistentValue");
  294. _rtDataKeys.Add($"{Module}.ReplenNum");
  295. _rtDataKeys.Add($"{Module}.ReplenDatas");
  296. _rtDataKeys.Add($"{Module}.DosingSystemState");
  297. if (_rtDataKeys.Count != 0)
  298. {
  299. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  300. if (_rtDataValueDic != null)
  301. {
  302. ReplenNum = CommonFunction.GetValue<int>(_rtDataValueDic, $"{Module}.ReplenNum");
  303. for (int i = 0; i < ReplenNum; i++)
  304. {
  305. ReplenEnable[i] = true;
  306. }
  307. }
  308. }
  309. if (ReplenDataCollection == null) ReplenDataCollection = new ObservableCollection<ReplenData>(new ReplenData[ReplenNum]);
  310. if (ReplensPersistentCollection == null) ReplensPersistentCollection = new ObservableCollection<ReplenPersistentValue>(new ReplenPersistentValue[ReplenNum]);
  311. if (_timer == null)
  312. {
  313. _timer = new DispatcherTimer();
  314. _timer.Interval = TimeSpan.FromMilliseconds(200);
  315. _timer.Tick += Timer_Tick;
  316. }
  317. _timer.Start();
  318. }
  319. #region 命令方法
  320. /// <summary>
  321. /// 初始化
  322. /// </summary>
  323. /// <param name="param"></param>
  324. private void InitializeAction(object param)
  325. {
  326. InvokeClient.Instance.Service.DoOperation($"{Module}.DosingInitialize");
  327. }
  328. /// <summary>
  329. /// 回到Reservoir主页面
  330. /// </summary>
  331. /// <param name="param"></param>
  332. private void BackAction(object param)
  333. {
  334. GlobalEvents.OnSwitchFixedChildSubItem(Module, Module);
  335. }
  336. #endregion
  337. /// <summary>
  338. /// 时钟
  339. /// </summary>
  340. /// <param name="sender"></param>
  341. /// <param name="e"></param>
  342. private void Timer_Tick(object sender, EventArgs e)
  343. {
  344. if (_rtDataKeys.Count != 0)
  345. {
  346. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  347. if (_rtDataValueDic != null)
  348. {
  349. State = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.DosingSystemState");
  350. ReservoirsPersistent = CommonFunction.GetValue<ReservoirsPersistentValue>(_rtDataValueDic, $"{Module}.PersistentValue");
  351. _replensPersistent = CommonFunction.GetValue<Dictionary<string, ReplenPersistentValue>>(_rtDataValueDic, $"{Module}.ReplenPersistentValue");
  352. _replenDatas = CommonFunction.GetValue<ReplenData[]>(_rtDataValueDic, $"{Module}.ReplenDatas");
  353. if(_replenDatas != null)
  354. {
  355. for(int i = 0; i < _replenNum;i++)
  356. {
  357. ReplensPersistentCollection[i] = _replensPersistent[_replenDatas[i].ReplenName];
  358. if (_replenDatas[i].IsAutoDosingError)
  359. {
  360. State = "Error";
  361. }
  362. }
  363. }
  364. ReservoirData = CommonFunction.GetValue<StandardHotReservoirData>(_rtDataValueDic, $"{Module}.ReservoirData");
  365. if ("Manual".Equals(ReplensPersistentCollection[0].OperatingMode))
  366. {
  367. IsEnabled = true;
  368. IsAutoEnabled = true;
  369. IsManualorAuto = false;
  370. }
  371. else if ("Auto".Equals(ReplensPersistentCollection[0].OperatingMode))
  372. {
  373. IsAutoEnabled = true;
  374. IsEnabled = false;
  375. IsManualorAuto = true;
  376. }
  377. else
  378. {
  379. State = "Stopped";
  380. IsEnabled = false;
  381. IsAutoEnabled = false;
  382. IsManualorAuto = false;
  383. }
  384. if(ReplenDataCollection != null)
  385. {
  386. ReplenDataCollection.Clear();
  387. for (int i = 0; i < ReplenNum; i++)
  388. {
  389. ReplenDataCollection.Add(_replenDatas[i]);
  390. }
  391. }
  392. }
  393. }
  394. }
  395. /// <summary>
  396. /// 隐藏
  397. /// </summary>
  398. public void Hide()
  399. {
  400. if (_timer != null)
  401. {
  402. _timer.Stop();
  403. }
  404. }
  405. }
  406. }