ResRecipeViewModel.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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 PunkHPX8_Core;
  7. using PunkHPX8_MainPages.PMs;
  8. using PunkHPX8_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 PunkHPX8_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. [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. SaveAsRecipeCommand = new DelegateCommand<object>(SaveAsAction);
  137. DIReplenEnableTrueCommand = new DelegateCommand<object>(EnableTrueAction);
  138. DIReplenEnableFalseCommand = new DelegateCommand<object>(EnableFalseAction);
  139. ANDIReplenEnableTrueCommand = new DelegateCommand<object>(ANEnableTrueAction);
  140. ANDIReplenEnableFalseCommand = new DelegateCommand<object>(ANEnableFalseAction);
  141. TimeBasedTrueCommand = new DelegateCommand<object>(TimeBasedTrueAction);
  142. TimeBasedFalseCommand = new DelegateCommand<object>(TimeBasedFalseAction);
  143. CurrentBasedTrueCommand = new DelegateCommand<object>(CurrentBasedTrueAction);
  144. CurrentBasedFalseCommand = new DelegateCommand<object>(CurrentBasedFalseAction);
  145. InitializeProprtyValidResultDictionary();
  146. string chemistryContent = QueryDataClient.Instance.Service.GetConfig($"System.ChemistryList").ToString();
  147. if (!string.IsNullOrEmpty(chemistryContent))
  148. {
  149. ChemistryLst = chemistryContent.Split(',').ToList();
  150. }
  151. }
  152. private void InitializeProprtyValidResultDictionary()
  153. {
  154. PropertyValidResultDic["DIReplenTimeRate"] = false;
  155. PropertyValidResultDic["DIReplenCurrentRate"] = false;
  156. PropertyValidResultDic["PHErrorLow"] = false;
  157. PropertyValidResultDic["PHErrorHigh"] = false;
  158. PropertyValidResultDic["CALevelErrorHigh"] = false;
  159. PropertyValidResultDic["CALevelErrorLow"] = false;
  160. PropertyValidResultDic["ReservoirCALevel"] = false;
  161. PropertyValidResultDic["CAFlowSetPoint"] = false;
  162. PropertyValidResultDic["CAFlowRateWarningLow"] = false;
  163. PropertyValidResultDic["CAFlowRateErrorLow"] = false;
  164. PropertyValidResultDic["TemperatureErrorHigh"] = false;
  165. PropertyValidResultDic["TemperatureErrorLow"] = false;
  166. PropertyValidResultDic["TemperatureSetPoint"] = false;
  167. PropertyValidResultDic["TemperatureWarningHigh"] = false;
  168. PropertyValidResultDic["TemperatureWarningLow"] = false;
  169. PropertyValidResultDic["ANDIReplenCurrentRate"] = false;
  170. PropertyValidResultDic["ANDIReplenTimeRate"] = false;
  171. PropertyValidResultDic["ANFlowRateErrorLow"] = false;
  172. PropertyValidResultDic["ANFlowRateWarningLow"] = false;
  173. PropertyValidResultDic["ANFlowSetPoint"] = false;
  174. PropertyValidResultDic["ANLevelErrorHigh"] = false;
  175. PropertyValidResultDic["ANLevelErrorLow"] = false;
  176. PropertyValidResultDic["ANLevelWarningLow"] = false;
  177. PropertyValidResultDic["ReservoirANLevel"] = false;
  178. PropertyValidResultDic["BurnInTime"] = false;
  179. PropertyValidResultDic["BurnInCurrent"] = false;
  180. PropertyValidResultDic["BurnInCycles"] = false;
  181. PropertyValidResultDic["BurnInMinCurrentLimit"] = false;
  182. PropertyValidResultDic["CMMCurrentSetPoint"] = false;
  183. PropertyValidResultDic["CMMCurrentFaultPercent"] = false;
  184. PropertyValidResultDic["CMMCurrentWarningPercent"] = false;
  185. PropertyValidResultDic["CMMMinVoltage"] = false;
  186. }
  187. public void LoadRecipeData()
  188. {
  189. RecipeNodes = _uiRecipeManager.GetRecipesByType("res");
  190. _recipeNodeDic.Clear();
  191. InitializeDictionary(RecipeNodes);
  192. }
  193. private void InitializeDictionary(ObservableCollection<RecipeNode> nodes)
  194. {
  195. if (nodes != null)
  196. {
  197. foreach (var node in nodes)
  198. {
  199. if (node.NodeType == RecipeNodeType.File)
  200. {
  201. _recipeNodeDic[node.Name] = node;
  202. }
  203. InitializeDictionary(node.Children);
  204. }
  205. }
  206. }
  207. private void SelectionChangedAction(object param)
  208. {
  209. if (_recipeNodeDic.ContainsKey(param.ToString()))
  210. {
  211. CurrentNode = _recipeNodeDic[param.ToString()];
  212. if (CurrentNode.NodeType == RecipeNodeType.File)
  213. {
  214. if (CurrentNode.RecipeLocation == ENGINEERING)
  215. {
  216. EditEnable = true;
  217. CreateEnable = true;
  218. }
  219. else
  220. {
  221. EditEnable = false;
  222. CreateEnable = false;
  223. }
  224. }
  225. Recipe = _uiRecipeManager.LoadRecipe<ResRecipe>(CurrentNode.RecipeFullFileName);
  226. if (Recipe == null)
  227. {
  228. MessageBox.Show("Invalid Recipe", "Load Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  229. EditEnable = false;
  230. CreateEnable = false;
  231. }
  232. Enable = false;
  233. }
  234. else
  235. {
  236. if (param.ToString() == ENGINEERING)
  237. {
  238. CreateEnable = true;
  239. }
  240. else
  241. {
  242. CreateEnable = false;
  243. }
  244. CurrentNode = null;
  245. Recipe = null;
  246. EditEnable = false;
  247. Enable = false;
  248. }
  249. }
  250. private void CreateAction(object param)
  251. {
  252. RecipeNameDialog recipeNameDialog = new RecipeNameDialog();
  253. if (recipeNameDialog.ShowDialog().Value)
  254. {
  255. if (!CheckNameExist(recipeNameDialog.RecipeName))
  256. {
  257. Recipe = new ResRecipe();
  258. Recipe.CreateDate = DateTime.Now;
  259. Recipe.Ppid = recipeNameDialog.RecipeName;
  260. Recipe.Description = recipeNameDialog.RecipeDescription;
  261. Enable = true;
  262. _isEdit = false;
  263. }
  264. }
  265. }
  266. private void EditAction(object param)
  267. {
  268. Enable = true;
  269. _isEdit = false;
  270. }
  271. private void SaveAction(object param)
  272. {
  273. if (CheckValid(_isEdit))
  274. {
  275. Recipe.SaveDate = DateTime.Now;
  276. try
  277. {
  278. _uiRecipeManager.SaveRecipe<ResRecipe>(ENGINEERING, Recipe.Ppid,"res", Recipe);
  279. LoadRecipeData();
  280. MessageBox.Show("Save Recipe Success", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Information);
  281. Enable = false;
  282. }
  283. catch (Exception ex)
  284. {
  285. MessageBox.Show(ex.Message, "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  286. }
  287. }
  288. }
  289. /// <summary>
  290. /// 另存为
  291. /// </summary>
  292. /// <param name="param"></param>
  293. private void SaveAsAction(object param)
  294. {
  295. if (Recipe == null)
  296. {
  297. MessageBox.Show("Select a Recipe first", "SaveAs Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  298. return;
  299. }
  300. ResRecipe recipe = new ResRecipe();
  301. if (CheckValid(_isEdit))
  302. {
  303. RecipeNameDialog recipeNameDialog = new RecipeNameDialog();
  304. if (recipeNameDialog.ShowDialog().Value)
  305. {
  306. if (!CheckNameExist(recipeNameDialog.RecipeName))
  307. {
  308. recipe = new ResRecipe();
  309. //recipe.IdleTime = Recipe.IdleTime;
  310. //recipe.Charge = Recipe.Charge;
  311. //recipe.Cycles = Recipe.Cycles;
  312. //recipe.StartTime = Recipe.StartTime;
  313. //recipe.ChemistryVendor = Recipe.ChemistryVendor;
  314. //recipe.Metal = Recipe.Metal;
  315. //recipe.DIReplenEnable = Recipe.DIReplenEnable;
  316. //recipe.DIReplenTimeRate = Recipe.DIReplenTimeRate;
  317. //recipe.DIReplenCurrentRate = Recipe.DIReplenCurrentRate;
  318. //recipe.PHErrorLow = Recipe.PHErrorLow;
  319. //recipe.PHErrorHigh = Recipe.PHErrorHigh;
  320. //recipe.CALevelErrorHigh = Recipe.CALevelErrorHigh;
  321. //recipe.CALevelErrorLow = Recipe.CALevelErrorLow;
  322. //recipe.ReservoirCALevel = Recipe.ReservoirCALevel;
  323. //recipe.CAFlowSetPoint = Recipe.CAFlowSetPoint;
  324. //recipe.CAFlowRateWarningLow = Recipe.CAFlowRateWarningLow;
  325. //recipe.CAFlowRateErrorLow = Recipe.CAFlowRateErrorLow;
  326. //recipe.IdleFlowEnable = Recipe.IdleFlowEnable;
  327. //recipe.TemperatureErrorHigh = Recipe.TemperatureErrorHigh;
  328. //recipe.TemperatureErrorLow = Recipe.TemperatureErrorLow;
  329. //recipe.TemperatureSetPoint = Recipe.TemperatureSetPoint;
  330. //recipe.TemperatureWarningHigh = Recipe.TemperatureWarningHigh;
  331. //recipe.TemperatureWarningLow = Recipe.TemperatureWarningLow;
  332. //recipe.ANDIReplenEnable = Recipe.ANDIReplenEnable;
  333. //recipe.ANDIReplenCurrentRate = Recipe.ANDIReplenCurrentRate;
  334. //recipe.ANDIReplenTimeRate = Recipe.ANDIReplenTimeRate;
  335. //recipe.ANFlowRateErrorLow = Recipe.ANFlowRateErrorLow;
  336. //recipe.ANFlowRateWarningLow = Recipe.ANFlowRateWarningLow;
  337. //recipe.ANFlowSetPoint = Recipe.ANFlowSetPoint;
  338. //recipe.ANLevelErrorHigh = Recipe.ANLevelErrorHigh;
  339. //recipe.ANLevelErrorLow = Recipe.ANLevelErrorLow;
  340. //recipe.ANLevelWarningLow = Recipe.ANLevelWarningLow;
  341. //recipe.ReservoirANLevel = Recipe.ReservoirANLevel;
  342. //recipe.CrossDoseCurrentRate = Recipe.CrossDoseCurrentRate;
  343. //recipe.CrossDoseTimeRate = Recipe.CrossDoseTimeRate;
  344. //recipe.CurrentBased = Recipe.CurrentBased;
  345. //recipe.TimeBased = Recipe.TimeBased;
  346. //recipe.BurnInEnable = Recipe.BurnInEnable;
  347. //recipe.BurnInTime = Recipe.BurnInTime;
  348. //recipe.BurnInCurrent = Recipe.BurnInCurrent;
  349. //recipe.BurnInCycles = Recipe.BurnInCycles;
  350. //recipe.BurnInCurrentLimitEnable = Recipe.BurnInCurrentLimitEnable;
  351. //recipe.BurnInMinCurrentLimit = Recipe.BurnInMinCurrentLimit;
  352. //recipe.CMMEnable = Recipe.CMMEnable;
  353. //recipe.CMMCurrentSetPoint = Recipe.CMMCurrentSetPoint;
  354. //recipe.CMMCurrentFaultPercent = Recipe.CMMCurrentFaultPercent;
  355. //recipe.CMMCurrentWarningPercent = Recipe.CMMCurrentWarningPercent;
  356. //recipe.CMMMinVoltage = Recipe.CMMMinVoltage;
  357. //recipe.BurnInStartTime = Recipe.BurnInStartTime; //值类型,不影响Recipe
  358. recipe = (ResRecipe)PropertyUtil.Clone(Recipe);
  359. recipe.CreateDate = DateTime.Now;
  360. recipe.Ppid = recipeNameDialog.RecipeName;
  361. recipe.Description = recipeNameDialog.RecipeDescription;
  362. }
  363. else if (recipeNameDialog.RecipeName != null)
  364. {
  365. MessageBox.Show("Name can not be Null", "Create Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  366. return;
  367. }
  368. else
  369. {
  370. return;
  371. }
  372. }
  373. try
  374. {
  375. _uiRecipeManager.SaveRecipe<ResRecipe>(ENGINEERING, recipe.Ppid, "res", recipe);
  376. LoadRecipeData();
  377. MessageBox.Show("Save As Recipe Success", "SaveAs Recipe", MessageBoxButton.OK, MessageBoxImage.Information);
  378. Enable = false;
  379. }
  380. catch (Exception ex)
  381. {
  382. MessageBox.Show(ex.Message, "Save As Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  383. }
  384. }
  385. }
  386. private void EnableTrueAction(object param)
  387. {
  388. Recipe.DIReplenEnable = true;
  389. }
  390. private void EnableFalseAction(object param)
  391. {
  392. Recipe.DIReplenEnable = false;
  393. }
  394. private void ANEnableTrueAction(object param)
  395. {
  396. Recipe.ANDIReplenEnable = true;
  397. }
  398. private void ANEnableFalseAction(object param)
  399. {
  400. Recipe.ANDIReplenEnable = false;
  401. }
  402. private bool CheckValid(bool editType)
  403. {
  404. foreach (string key in _propertyValidResultDic.Keys)
  405. {
  406. //在DIReplenEnable时跳过检验项
  407. if(Recipe.ANDIReplenEnable == false)
  408. {
  409. bool result = false;
  410. switch (key)
  411. {
  412. case "ANLevelErrorHigh":
  413. result = true; break;
  414. case "ANLevelErrorLow":
  415. result = true; break;
  416. case "ANLevelWarningLow":
  417. result = true; break;
  418. case "ReservoirANLevel":
  419. result = true; break;
  420. case "ANDIReplenTimeRate":
  421. result = true; break;
  422. case "ANDIReplenCurrentRate":
  423. result = true; break;
  424. }
  425. if (result)
  426. {
  427. continue;
  428. }
  429. }
  430. //在ReplenEnable时跳过检验项
  431. if (Recipe.DIReplenEnable == false)
  432. {
  433. bool result = false;
  434. switch (key)
  435. {
  436. case "CALevelErrorHigh":
  437. result = true; break;
  438. case "CALevelErrorLow":
  439. result = true; break;
  440. case "ReservoirCALevel":
  441. result = true; break;
  442. case "DIReplenTimeRate":
  443. result = true; break;
  444. case "DIReplenCurrentRate":
  445. result = true; break;
  446. }
  447. if (result)
  448. {
  449. continue;
  450. }
  451. }
  452. bool valid = _propertyValidResultDic[key];
  453. if (!valid)
  454. {
  455. MessageBox.Show($"{key} data invalid", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  456. return false;
  457. }
  458. }
  459. return true;
  460. }
  461. private bool CheckNameExist(string name)
  462. {
  463. foreach (string item in _recipeNodeDic.Keys)
  464. {
  465. if (item == name)
  466. {
  467. MessageBox.Show($"{name} is exsit", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  468. return true;
  469. }
  470. }
  471. return false;
  472. }
  473. private void CurrentBasedTrueAction(object param)
  474. {
  475. //基于时间和基于电流只能二选一
  476. Recipe.CurrentBased = true;
  477. if (Recipe.TimeBased)
  478. {
  479. Recipe.TimeBased = false;
  480. }
  481. }
  482. private void CurrentBasedFalseAction(object param)
  483. {
  484. Recipe.CurrentBased = false;
  485. }
  486. private void TimeBasedTrueAction(object param)
  487. {
  488. Recipe.TimeBased = true;
  489. //基于时间和基于电流只能二选一
  490. if (Recipe.CurrentBased)
  491. {
  492. Recipe.CurrentBased = false;
  493. }
  494. }
  495. private void TimeBasedFalseAction(object param)
  496. {
  497. Recipe.TimeBased = false;
  498. }
  499. }
  500. }