ResRecipeViewModel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.UI.Dialog;
  3. using Aitex.Core.UI.MVVM;
  4. using Aitex.Core.Utilities;
  5. using Caliburn.Micro.Core;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.RecipeCenter;
  8. using CyberX8_Core;
  9. using CyberX8_MainPages.PMs;
  10. using CyberX8_Themes.UserControls;
  11. using Prism.Mvvm;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Collections.ObjectModel;
  15. using System.ComponentModel;
  16. using System.Linq;
  17. using System.Reflection;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows;
  21. using System.Windows.Documents;
  22. using System.Windows.Input;
  23. namespace CyberX8_MainPages.ViewModels
  24. {
  25. public class ResRecipeViewModel: BindableBase
  26. {
  27. private const string ENGINEERING = "Engineering";
  28. #region 内部变量
  29. private Dictionary<string, RecipeNode> _recipeNodeDic = new Dictionary<string, RecipeNode>();
  30. private ObservableCollection<RecipeNode> _recipeNodes;
  31. private UiRecipeManager _uiRecipeManager = new UiRecipeManager();
  32. private Dictionary<string, bool> _propertyValidResultDic = new Dictionary<string, bool>();
  33. private ResRecipe _recipe;
  34. private bool _editEnable;
  35. private bool _createEnable;
  36. private RecipeNode _currentNode;
  37. private bool _enable = false;
  38. private bool _isEdit = false;
  39. /// <summary>
  40. /// 化学液集合
  41. /// </summary>
  42. private List<string> _chemistryLst = new List<string>();
  43. #endregion
  44. #region 属性
  45. /// <summary>
  46. /// Recipe Nodes
  47. /// </summary>
  48. public ObservableCollection<RecipeNode> RecipeNodes
  49. {
  50. get { return _recipeNodes; }
  51. set { SetProperty(ref _recipeNodes, value); }
  52. }
  53. /// <summary>
  54. /// PropertyValidResultDic
  55. /// </summary>
  56. public Dictionary<string, bool> PropertyValidResultDic
  57. {
  58. get { return _propertyValidResultDic; }
  59. set { SetProperty(ref _propertyValidResultDic, value); }
  60. }
  61. /// <summary>
  62. /// 当前Recipe节点
  63. /// </summary>
  64. public RecipeNode CurrentNode
  65. {
  66. get { return _currentNode; }
  67. set { SetProperty(ref _currentNode, value); }
  68. }
  69. public bool Enable
  70. {
  71. get { return _enable; }
  72. set { SetProperty(ref _enable, value); }
  73. }
  74. public bool EditEnable
  75. {
  76. get { return _editEnable; }
  77. set { SetProperty(ref _editEnable, value); }
  78. }
  79. public bool CreateEnable
  80. {
  81. get { return _createEnable; }
  82. set { SetProperty(ref _createEnable, value); }
  83. }
  84. public ResRecipe Recipe
  85. {
  86. get { return _recipe; }
  87. set { SetProperty(ref _recipe, value); }
  88. }
  89. /// <summary>
  90. /// 化学液集合
  91. /// </summary>
  92. public List<string> ChemistryLst
  93. {
  94. get { return _chemistryLst; }
  95. set { SetProperty(ref _chemistryLst, value); }
  96. }
  97. #endregion
  98. #region 指令
  99. public ICommand OperationCommand
  100. {
  101. get;
  102. private set;
  103. }
  104. #endregion
  105. [IgnorePropertyChange]
  106. public ICommand CreateCommand { get; private set; }
  107. [IgnorePropertyChange]
  108. public ICommand EditCommand { get; private set; }
  109. [IgnorePropertyChange]
  110. public ICommand SaveRecipeCommand { get; private set; }
  111. [IgnorePropertyChange]
  112. public ICommand DIReplenEnableTrueCommand { get; private set; }
  113. [IgnorePropertyChange]
  114. public ICommand DIReplenEnableFalseCommand { get; private set; }
  115. [IgnorePropertyChange]
  116. public ICommand ANDIReplenEnableTrueCommand { get; private set; }
  117. [IgnorePropertyChange]
  118. public ICommand ANDIReplenEnableFalseCommand { get; private set; }
  119. public ICommand IdleFlowEnableTrueCommand { get; private set; }
  120. [IgnorePropertyChange]
  121. public ICommand IdleFlowEnableFalseCommand { get; private set; }
  122. [IgnorePropertyChange]
  123. public ICommand TimeBasedTrueCommand { get; private set; }
  124. [IgnorePropertyChange]
  125. public ICommand TimeBasedFalseCommand { get; private set; }
  126. [IgnorePropertyChange]
  127. public ICommand CurrentBasedTrueCommand { get; private set; }
  128. [IgnorePropertyChange]
  129. public ICommand CurrentBasedFalseCommand { get; private set; }
  130. public ResRecipeViewModel()
  131. {
  132. OperationCommand = new DelegateCommand<object>(SelectionChangedAction);
  133. CreateCommand = new DelegateCommand<object>(CreateAction);
  134. EditCommand = new DelegateCommand<object>(EditAction);
  135. SaveRecipeCommand = new DelegateCommand<object>(SaveAction);
  136. DIReplenEnableTrueCommand = new DelegateCommand<object>(EnableTrueAction);
  137. DIReplenEnableFalseCommand = new DelegateCommand<object>(EnableFalseAction);
  138. ANDIReplenEnableTrueCommand = new DelegateCommand<object>(ANEnableTrueAction);
  139. ANDIReplenEnableFalseCommand = new DelegateCommand<object>(ANEnableFalseAction);
  140. IdleFlowEnableTrueCommand = new DelegateCommand<object>(IdleFlowEnableTrueAction);
  141. IdleFlowEnableFalseCommand = new DelegateCommand<object>(IdleFlowEnableFalseAction);
  142. TimeBasedTrueCommand = new DelegateCommand<object>(TimeBasedTrueAction);
  143. TimeBasedFalseCommand = new DelegateCommand<object>(TimeBasedFalseAction);
  144. CurrentBasedTrueCommand = new DelegateCommand<object>(CurrentBasedTrueAction);
  145. CurrentBasedFalseCommand = new DelegateCommand<object>(CurrentBasedFalseAction);
  146. InitializeProprtyValidResultDictionary();
  147. string chemistryContent = QueryDataClient.Instance.Service.GetConfig($"System.ChemistryList").ToString();
  148. if (!string.IsNullOrEmpty(chemistryContent))
  149. {
  150. ChemistryLst = chemistryContent.Split(',').ToList();
  151. }
  152. }
  153. private void InitializeProprtyValidResultDictionary()
  154. {
  155. PropertyValidResultDic["DIReplenTimeRate"] = false;
  156. PropertyValidResultDic["DIReplenCurrentRate"] = false;
  157. PropertyValidResultDic["PHErrorLow"] = false;
  158. PropertyValidResultDic["PHErrorHigh"] = false;
  159. PropertyValidResultDic["CALevelErrorHigh"] = false;
  160. PropertyValidResultDic["CALevelErrorLow"] = false;
  161. PropertyValidResultDic["ReservoirCALevel"] = false;
  162. PropertyValidResultDic["CAFlowSetPoint"] = false;
  163. PropertyValidResultDic["CAFlowRateWarningLow"] = false;
  164. PropertyValidResultDic["CAFlowRateErrorLow"] = false;
  165. PropertyValidResultDic["TemperatureErrorHigh"] = false;
  166. PropertyValidResultDic["TemperatureErrorLow"] = false;
  167. PropertyValidResultDic["TemperatureSetPoint"] = false;
  168. PropertyValidResultDic["TemperatureWarningHigh"] = false;
  169. PropertyValidResultDic["TemperatureWarningLow"] = false;
  170. PropertyValidResultDic["ANDIReplenCurrentRate"] = false;
  171. PropertyValidResultDic["ANDIReplenTimeRate"] = false;
  172. PropertyValidResultDic["ANFlowRateErrorLow"] = false;
  173. PropertyValidResultDic["ANFlowRateWarningLow"] = false;
  174. PropertyValidResultDic["ANFlowSetPoint"] = false;
  175. PropertyValidResultDic["ANLevelErrorHigh"] = false;
  176. PropertyValidResultDic["ANLevelErrorLow"] = false;
  177. PropertyValidResultDic["ANLevelWarningLow"] = false;
  178. PropertyValidResultDic["ReservoirANLevel"] = false;
  179. PropertyValidResultDic["BurnInTime"] = false;
  180. PropertyValidResultDic["BurnInCurrent"] = false;
  181. PropertyValidResultDic["BurnInCycles"] = false;
  182. PropertyValidResultDic["BurnInMinCurrentLimit"] = false;
  183. PropertyValidResultDic["CMMCurrentSetPoint"] = false;
  184. PropertyValidResultDic["CMMCurrentFaultPercent"] = false;
  185. PropertyValidResultDic["CMMCurrentWarningPercent"] = false;
  186. PropertyValidResultDic["CMMMinVoltage"] = false;
  187. }
  188. public void LoadRecipeData()
  189. {
  190. RecipeNodes = _uiRecipeManager.GetRecipesByType("res");
  191. _recipeNodeDic.Clear();
  192. InitializeDictionary(RecipeNodes);
  193. }
  194. private void InitializeDictionary(ObservableCollection<RecipeNode> nodes)
  195. {
  196. if (nodes != null)
  197. {
  198. foreach (var node in nodes)
  199. {
  200. if (node.NodeType == RecipeNodeType.File)
  201. {
  202. _recipeNodeDic[node.Name] = node;
  203. }
  204. InitializeDictionary(node.Children);
  205. }
  206. }
  207. }
  208. private void SelectionChangedAction(object param)
  209. {
  210. if (_recipeNodeDic.ContainsKey(param.ToString()))
  211. {
  212. CurrentNode = _recipeNodeDic[param.ToString()];
  213. if (CurrentNode.NodeType == RecipeNodeType.File)
  214. {
  215. if (CurrentNode.RecipeLocation == ENGINEERING)
  216. {
  217. EditEnable = true;
  218. CreateEnable = true;
  219. }
  220. else
  221. {
  222. EditEnable = false;
  223. CreateEnable = false;
  224. }
  225. }
  226. Recipe = _uiRecipeManager.LoadRecipe<ResRecipe>(CurrentNode.RecipeFullFileName);
  227. if (Recipe == null)
  228. {
  229. MessageBox.Show("Invalid Recipe", "Load Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  230. EditEnable = false;
  231. CreateEnable = false;
  232. }
  233. Enable = false;
  234. }
  235. else
  236. {
  237. if (param.ToString() == ENGINEERING)
  238. {
  239. CreateEnable = true;
  240. }
  241. else
  242. {
  243. CreateEnable = false;
  244. }
  245. CurrentNode = null;
  246. Recipe = null;
  247. EditEnable = false;
  248. Enable = false;
  249. }
  250. }
  251. private void CreateAction(object param)
  252. {
  253. RecipeNameDialog recipeNameDialog = new RecipeNameDialog();
  254. if (recipeNameDialog.ShowDialog().Value)
  255. {
  256. if (!CheckNameExist(recipeNameDialog.RecipeName))
  257. {
  258. Recipe = new ResRecipe();
  259. Recipe.CreateDate = DateTime.Now;
  260. Recipe.Ppid = recipeNameDialog.RecipeName;
  261. Recipe.Description = recipeNameDialog.RecipeDescription;
  262. Enable = true;
  263. _isEdit = false;
  264. }
  265. }
  266. }
  267. private void EditAction(object param)
  268. {
  269. Enable = true;
  270. _isEdit = false;
  271. }
  272. private void SaveAction(object param)
  273. {
  274. if (CheckValid(_isEdit))
  275. {
  276. Recipe.SaveDate = DateTime.Now;
  277. try
  278. {
  279. _uiRecipeManager.SaveRecipe<ResRecipe>(ENGINEERING, Recipe.Ppid,"res", Recipe);
  280. LoadRecipeData();
  281. MessageBox.Show("Save Recipe Success", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Information);
  282. Enable = false;
  283. }
  284. catch (Exception ex)
  285. {
  286. MessageBox.Show(ex.Message, "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  287. }
  288. }
  289. }
  290. private void EnableTrueAction(object param)
  291. {
  292. Recipe.DIReplenEnable = true;
  293. }
  294. private void EnableFalseAction(object param)
  295. {
  296. Recipe.DIReplenEnable = false;
  297. }
  298. private void ANEnableTrueAction(object param)
  299. {
  300. Recipe.ANDIReplenEnable = true;
  301. }
  302. private void ANEnableFalseAction(object param)
  303. {
  304. Recipe.ANDIReplenEnable = false;
  305. }
  306. private void IdleFlowEnableTrueAction(object param)
  307. {
  308. Recipe.IdleFlowEnable = true;
  309. }
  310. private void IdleFlowEnableFalseAction(object param)
  311. {
  312. Recipe.IdleFlowEnable = false;
  313. }
  314. private bool CheckValid(bool editType)
  315. {
  316. foreach (string key in _propertyValidResultDic.Keys)
  317. {
  318. //在DIReplenEnable时跳过检验项
  319. if(Recipe.ANDIReplenEnable == false)
  320. {
  321. bool result = false;
  322. switch (key)
  323. {
  324. case "ANLevelErrorHigh":
  325. result = true; break;
  326. case "ANLevelErrorLow":
  327. result = true; break;
  328. case "ANLevelWarningLow":
  329. result = true; break;
  330. case "ReservoirANLevel":
  331. result = true; break;
  332. case "ANDIReplenTimeRate":
  333. result = true; break;
  334. case "ANDIReplenCurrentRate":
  335. result = true; break;
  336. }
  337. if (result)
  338. {
  339. continue;
  340. }
  341. }
  342. //在ReplenEnable时跳过检验项
  343. if (Recipe.DIReplenEnable == false)
  344. {
  345. bool result = false;
  346. switch (key)
  347. {
  348. case "CALevelErrorHigh":
  349. result = true; break;
  350. case "CALevelErrorLow":
  351. result = true; break;
  352. case "ReservoirCALevel":
  353. result = true; break;
  354. case "DIReplenTimeRate":
  355. result = true; break;
  356. case "DIReplenCurrentRate":
  357. result = true; break;
  358. }
  359. if (result)
  360. {
  361. continue;
  362. }
  363. }
  364. bool valid = _propertyValidResultDic[key];
  365. if (!valid)
  366. {
  367. MessageBox.Show($"{key} data invalid", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  368. return false;
  369. }
  370. }
  371. return true;
  372. }
  373. private bool CheckNameExist(string name)
  374. {
  375. foreach (string item in _recipeNodeDic.Keys)
  376. {
  377. if (item == name)
  378. {
  379. MessageBox.Show($"{name} is exsit", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  380. return true;
  381. }
  382. }
  383. return false;
  384. }
  385. private void CurrentBasedTrueAction(object param)
  386. {
  387. //基于时间和基于电流只能二选一
  388. Recipe.CurrentBased = true;
  389. if (Recipe.TimeBased)
  390. {
  391. Recipe.TimeBased = false;
  392. }
  393. }
  394. private void CurrentBasedFalseAction(object param)
  395. {
  396. Recipe.CurrentBased = false;
  397. }
  398. private void TimeBasedTrueAction(object param)
  399. {
  400. Recipe.TimeBased = true;
  401. //基于时间和基于电流只能二选一
  402. if (Recipe.CurrentBased)
  403. {
  404. Recipe.CurrentBased = false;
  405. }
  406. }
  407. private void TimeBasedFalseAction(object param)
  408. {
  409. Recipe.TimeBased = false;
  410. }
  411. }
  412. }