ResRecipeViewModel.cs 21 KB

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