ResRecipeViewModel.cs 22 KB

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