VpwRecipeViewModel.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. using Aitex.Core.UI.MVVM;
  2. using Aitex.Core.Utilities;
  3. using MECF.Framework.Common.RecipeCenter;
  4. using MECF.Framework.Common.Utilities;
  5. using Prism.Mvvm;
  6. using PunkHPX8_MainPages.PMs;
  7. using PunkHPX8_Themes.UserControls;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Input;
  16. namespace PunkHPX8_MainPages.ViewModels
  17. {
  18. public class VpwRecipeViewModel : BindableBase
  19. {
  20. private const string ENGINEERING = "Engineering";
  21. #region 内部变量
  22. private Dictionary<string, RecipeNode> _recipeNodeDic = new Dictionary<string, RecipeNode>();
  23. private ObservableCollection<RecipeNode> _recipeNodes;
  24. private UiRecipeManager _uiRecipeManager = new UiRecipeManager();
  25. private Dictionary<string, bool> _propertyValidResultDic = new Dictionary<string, bool>();
  26. private VpwRecipe _recipe;
  27. private bool _editEnable;
  28. private bool _createEnable;
  29. private RecipeNode _currentNode;
  30. private bool _enable = false;
  31. private bool _isEdit = false;
  32. /// <summary>
  33. /// Wafer尺寸集合
  34. /// </summary>
  35. private List<int> _waferSizeLst = null;
  36. /// <summary>
  37. /// Vacuum Prewet step选择索引
  38. /// </summary>
  39. private int _selectedVacuumPrewetIndex = -1;
  40. /// <summary>
  41. /// Extend Clean step选择索引
  42. /// </summary>
  43. private int _selectedExtendCleanIndex = -1;
  44. /// <summary>
  45. /// Vent Prewet step选择索引
  46. /// </summary>
  47. private int _selectedVentPrewetIndex = -1;
  48. #endregion
  49. #region 属性
  50. public ObservableCollection<RecipeNode> RecipeNodes
  51. {
  52. get { return _recipeNodes; }
  53. set { SetProperty(ref _recipeNodes, value); }
  54. }
  55. public Dictionary<string, bool> PropertyValidResultDic
  56. {
  57. get { return _propertyValidResultDic; }
  58. set { SetProperty(ref _propertyValidResultDic, value); }
  59. }
  60. public RecipeNode CurrentNode
  61. {
  62. get { return _currentNode; }
  63. set { SetProperty(ref _currentNode, value); }
  64. }
  65. public bool Enable
  66. {
  67. get { return _enable; }
  68. set { SetProperty(ref _enable, value); }
  69. }
  70. public bool EditEnable
  71. {
  72. get { return _editEnable; }
  73. set { SetProperty(ref _editEnable, value); }
  74. }
  75. public bool CreateEnable
  76. {
  77. get { return _createEnable; }
  78. set { SetProperty(ref _createEnable, value); }
  79. }
  80. public VpwRecipe Recipe
  81. {
  82. get { return _recipe; }
  83. set { SetProperty(ref _recipe, value); }
  84. }
  85. /// <summary>
  86. /// Wafer 尺寸集合
  87. /// </summary>
  88. public List<int> WaferSizeLst
  89. {
  90. get { return _waferSizeLst; }
  91. set { SetProperty(ref _waferSizeLst, value); }
  92. }
  93. /// <summary>
  94. /// Vacuum Prewet step选择索引
  95. /// </summary>
  96. public int SelectedVacuumPrewetIndex
  97. {
  98. get { return _selectedVacuumPrewetIndex; }
  99. set { SetProperty(ref _selectedVacuumPrewetIndex, value); }
  100. }
  101. /// <summary>
  102. /// SelectedExtendCleanIndex选择索引
  103. /// </summary>
  104. public int SelectedExtendCleanIndex
  105. {
  106. get { return _selectedExtendCleanIndex; }
  107. set { SetProperty(ref _selectedExtendCleanIndex, value); }
  108. }
  109. /// <summary>
  110. /// SelectedVentPrewetIndex选择索引
  111. /// </summary>
  112. public int SelectedVentPrewetIndex
  113. {
  114. get { return _selectedVentPrewetIndex; }
  115. set { SetProperty(ref _selectedVentPrewetIndex, value); }
  116. }
  117. #region 指令
  118. public ICommand OperationCommand
  119. {
  120. get;
  121. private set;
  122. }
  123. [IgnorePropertyChange]
  124. public ICommand CreateCommand { get; private set; }
  125. [IgnorePropertyChange]
  126. public ICommand EditCommand { get; private set; }
  127. [IgnorePropertyChange]
  128. public ICommand SaveRecipeCommand { get; private set; }
  129. [IgnorePropertyChange]
  130. public ICommand SaveAsRecipeCommand { get; private set; }
  131. [IgnorePropertyChange]
  132. public ICommand IsSprayBarRetractFalseCommand { get; private set; }
  133. #endregion
  134. public VpwRecipeViewModel()
  135. {
  136. OperationCommand = new DelegateCommand<object>(SelectionChangedAction);
  137. CreateCommand = new DelegateCommand<object>(CreateAction);
  138. EditCommand = new DelegateCommand<object>(EditAction);
  139. SaveRecipeCommand = new DelegateCommand<object>(SaveAction);
  140. SaveAsRecipeCommand = new DelegateCommand<object>(SaveAsAction);
  141. IsSprayBarRetractFalseCommand = new DelegateCommand<object>(IsSprayBarRetractFalseAction);
  142. //Wafer尺寸集合
  143. WaferSizeLst = new List<int>();
  144. WaferSizeLst.Add(100);
  145. WaferSizeLst.Add(150);
  146. WaferSizeLst.Add(200);
  147. WaferSizeLst.Add(300);
  148. InitializeProprtyValidResultDictionary();
  149. }
  150. #endregion
  151. private void InitializeProprtyValidResultDictionary()
  152. {
  153. //需要检验的参数
  154. PropertyValidResultDic["VacuumTarget"] = false;
  155. PropertyValidResultDic["DryHoldTime"] = false;
  156. PropertyValidResultDic["DiwLoopDoSet"] = false;
  157. PropertyValidResultDic["SpinSpeed"] = false;
  158. PropertyValidResultDic["SpinTime"] = false;
  159. }
  160. public void LoadRecipeData()
  161. {
  162. RecipeNodes = _uiRecipeManager.GetRecipesByType("vpw");
  163. _recipeNodeDic.Clear();
  164. InitializeDictionary(RecipeNodes);
  165. }
  166. private void InitializeDictionary(ObservableCollection<RecipeNode> nodes)
  167. {
  168. if (nodes != null)
  169. {
  170. foreach (var node in nodes)
  171. {
  172. if (node.NodeType == RecipeNodeType.File)
  173. {
  174. _recipeNodeDic[node.Name] = node;
  175. }
  176. InitializeDictionary(node.Children);
  177. }
  178. }
  179. }
  180. private void SelectionChangedAction(object param)
  181. {
  182. if (_recipeNodeDic.ContainsKey(param.ToString()))
  183. {
  184. CurrentNode = _recipeNodeDic[param.ToString()];
  185. if (CurrentNode.NodeType == RecipeNodeType.File)
  186. {
  187. if (CurrentNode.RecipeLocation == ENGINEERING)
  188. {
  189. EditEnable = true;
  190. CreateEnable = true;
  191. }
  192. else
  193. {
  194. EditEnable = false;
  195. CreateEnable = false;
  196. }
  197. }
  198. Recipe = _uiRecipeManager.LoadRecipe<VpwRecipe>(CurrentNode.RecipeFullFileName);
  199. if (Recipe == null)
  200. {
  201. MessageBox.Show("Invalid Recipe", "Load Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  202. EditEnable = false;
  203. CreateEnable = false;
  204. }
  205. Enable = false;
  206. }
  207. else
  208. {
  209. if (param.ToString() == ENGINEERING)
  210. {
  211. CreateEnable = true;
  212. }
  213. else
  214. {
  215. CreateEnable = false;
  216. }
  217. CurrentNode = null;
  218. Recipe = null;
  219. EditEnable = false;
  220. Enable = false;
  221. }
  222. }
  223. private void CreateAction(object param)
  224. {
  225. RecipeNameDialog recipeNameDialog = new RecipeNameDialog();
  226. if (recipeNameDialog.ShowDialog().Value)
  227. {
  228. if (!CheckNameExist(recipeNameDialog.RecipeName))
  229. {
  230. Recipe = new VpwRecipe();
  231. Recipe.CreateDate = DateTime.Now;
  232. Recipe.Ppid = recipeNameDialog.RecipeName;
  233. Recipe.Description = recipeNameDialog.RecipeDescription;
  234. Enable = true;
  235. _isEdit = false;
  236. }
  237. }
  238. }
  239. private void EditAction(object param)
  240. {
  241. Enable = true;
  242. _isEdit = false;
  243. }
  244. private void SaveAction(object param)
  245. {
  246. if (CheckValid(_isEdit))
  247. {
  248. Recipe.SaveDate = DateTime.Now;
  249. try
  250. {
  251. _uiRecipeManager.SaveRecipe<VpwRecipe>(ENGINEERING, Recipe.Ppid, "vpw", Recipe);
  252. LoadRecipeData();
  253. MessageBox.Show("Save Recipe Success", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Information);
  254. Enable = false;
  255. }
  256. catch (Exception ex)
  257. {
  258. MessageBox.Show(ex.Message, "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  259. }
  260. }
  261. }
  262. /// <summary>
  263. /// 另存为
  264. /// </summary>
  265. /// <param name="param"></param>
  266. private void SaveAsAction(object param)
  267. {
  268. if (Recipe == null)
  269. {
  270. MessageBox.Show("Select a Recipe first", "SaveAs Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  271. return;
  272. }
  273. VpwRecipe recipe = new VpwRecipe();
  274. if (CheckValid(_isEdit))
  275. {
  276. RecipeNameDialog recipeNameDialog = new RecipeNameDialog();
  277. if (recipeNameDialog.ShowDialog().Value)
  278. {
  279. if (!CheckNameExist(recipeNameDialog.RecipeName))
  280. {
  281. recipe = new VpwRecipe();
  282. recipe = (VpwRecipe)PropertyUtil.Clone(Recipe);
  283. recipe.CreateDate = DateTime.Now;
  284. recipe.Ppid = recipeNameDialog.RecipeName;
  285. recipe.Description = recipeNameDialog.RecipeDescription;
  286. }
  287. else if (recipeNameDialog.RecipeName != null)
  288. {
  289. MessageBox.Show("Name can not be Null", "Create Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  290. return;
  291. }
  292. else
  293. {
  294. return;
  295. }
  296. }
  297. try
  298. {
  299. _uiRecipeManager.SaveRecipe<RdsRecipe>(ENGINEERING, recipe.Ppid, "vpw", recipe);
  300. LoadRecipeData();
  301. MessageBox.Show("Save As Recipe Success", "SaveAs Recipe", MessageBoxButton.OK, MessageBoxImage.Information);
  302. Enable = false;
  303. }
  304. catch (Exception ex)
  305. {
  306. MessageBox.Show(ex.Message, "Save As Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  307. }
  308. }
  309. }
  310. private bool CheckNameExist(string name)
  311. {
  312. foreach (string item in _recipeNodeDic.Keys)
  313. {
  314. if (item == name)
  315. {
  316. MessageBox.Show($"{name} is exsit", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  317. return true;
  318. }
  319. }
  320. return false;
  321. }
  322. private bool CheckValid(bool editType)
  323. {
  324. foreach (string key in _propertyValidResultDic.Keys)
  325. {
  326. bool valid = _propertyValidResultDic[key];
  327. if (!valid)
  328. {
  329. MessageBox.Show($"{key} data invalid", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  330. return false;
  331. }
  332. }
  333. return true;
  334. }
  335. private void IsSprayBarRetractFalseAction(object param)
  336. {
  337. Recipe.IsSprayBarRetract = false;
  338. }
  339. #region Vacuum prewet按钮
  340. /// <summary>
  341. /// 增加
  342. /// </summary>
  343. /// <param name="param"></param>
  344. private void AddBelowAction(object param)
  345. {
  346. if (Recipe != null)
  347. {
  348. VpwRinseStep currentRinseSteps = new VpwRinseStep();
  349. Recipe.VacuumRinseStep.Insert(SelectedVacuumPrewetIndex + 1, currentRinseSteps);
  350. SelectedVacuumPrewetIndex++;
  351. }
  352. }
  353. /// <summary>
  354. /// 增加
  355. /// </summary>
  356. /// <param name="param"></param>
  357. private void AddAboveAction(object param)
  358. {
  359. if (Recipe != null)
  360. {
  361. VpwRinseStep currentRinseSteps = new VpwRinseStep();
  362. if (SelectedVacuumPrewetIndex == -1)
  363. {
  364. Recipe.VacuumRinseStep.Add(currentRinseSteps);
  365. SelectedVacuumPrewetIndex = 0;
  366. }
  367. else
  368. {
  369. Recipe.VacuumRinseStep.Insert(SelectedVacuumPrewetIndex, currentRinseSteps);
  370. SelectedVacuumPrewetIndex--;
  371. }
  372. }
  373. }
  374. /// <summary>
  375. /// 上移
  376. /// </summary>
  377. /// <param name="param"></param>
  378. private void MoveUpAction(object param)
  379. {
  380. if (Recipe != null)
  381. {
  382. if (SelectedVacuumPrewetIndex > 0)
  383. {
  384. int currentIndex = SelectedVacuumPrewetIndex;
  385. VpwRinseStep currentRinseSteps = Recipe.VacuumRinseStep[SelectedVacuumPrewetIndex];
  386. Recipe.VacuumRinseStep.RemoveAt(SelectedVacuumPrewetIndex);
  387. Recipe.VacuumRinseStep.Insert(currentIndex - 1, currentRinseSteps);
  388. SelectedVacuumPrewetIndex = currentIndex - 1;
  389. }
  390. }
  391. }
  392. /// <summary>
  393. /// 下移
  394. /// </summary>
  395. /// <param name="param"></param>
  396. private void MoveDownAction(object param)
  397. {
  398. if (Recipe != null)
  399. {
  400. if (SelectedVacuumPrewetIndex >= 0 && SelectedVacuumPrewetIndex < Recipe.VacuumRinseStep.Count - 1 && Recipe.VacuumRinseStep.Count > 1)
  401. {
  402. int currentIndex = SelectedVacuumPrewetIndex;
  403. VpwRinseStep currentRinseSteps = Recipe.VacuumRinseStep[SelectedVacuumPrewetIndex];
  404. Recipe.VacuumRinseStep.RemoveAt(SelectedVacuumPrewetIndex);
  405. Recipe.VacuumRinseStep.Insert(currentIndex + 1, currentRinseSteps);
  406. SelectedVacuumPrewetIndex = currentIndex + 1;
  407. }
  408. }
  409. }
  410. /// <summary>
  411. /// 删除
  412. /// </summary>
  413. /// <param name="param"></param>
  414. private void DeleteAction(object param)
  415. {
  416. if (SelectedVacuumPrewetIndex != -1)
  417. {
  418. if (Recipe != null && Recipe.VacuumRinseStep.Count > SelectedVacuumPrewetIndex)
  419. {
  420. Recipe.VacuumRinseStep.RemoveAt(SelectedVacuumPrewetIndex);
  421. }
  422. }
  423. }
  424. #endregion
  425. #region Vent prewet按钮
  426. /// <summary>
  427. /// 增加
  428. /// </summary>
  429. /// <param name="param"></param>
  430. private void VentPrewetAddBelowAction(object param)
  431. {
  432. if (Recipe != null)
  433. {
  434. VpwRinseStep currentRinseSteps = new VpwRinseStep();
  435. Recipe.VentRinseStep.Insert(SelectedVentPrewetIndex + 1, currentRinseSteps);
  436. SelectedVentPrewetIndex++;
  437. }
  438. }
  439. /// <summary>
  440. /// 增加
  441. /// </summary>
  442. /// <param name="param"></param>
  443. private void VentPrewetAddAboveAction(object param)
  444. {
  445. if (Recipe != null)
  446. {
  447. VpwRinseStep currentRinseSteps = new VpwRinseStep();
  448. if (SelectedVentPrewetIndex == -1)
  449. {
  450. Recipe.VentRinseStep.Add(currentRinseSteps);
  451. SelectedVentPrewetIndex = 0;
  452. }
  453. else
  454. {
  455. Recipe.VentRinseStep.Insert(SelectedVentPrewetIndex, currentRinseSteps);
  456. SelectedVentPrewetIndex--;
  457. }
  458. }
  459. }
  460. /// <summary>
  461. /// 上移
  462. /// </summary>
  463. /// <param name="param"></param>
  464. private void VentPrewetMoveUpAction(object param)
  465. {
  466. if (Recipe != null)
  467. {
  468. if (SelectedVentPrewetIndex > 0)
  469. {
  470. int currentIndex = SelectedVentPrewetIndex;
  471. VpwRinseStep currentRinseSteps = Recipe.VentRinseStep[SelectedVentPrewetIndex];
  472. Recipe.VentRinseStep.RemoveAt(SelectedVentPrewetIndex);
  473. Recipe.VentRinseStep.Insert(currentIndex - 1, currentRinseSteps);
  474. SelectedVentPrewetIndex = currentIndex - 1;
  475. }
  476. }
  477. }
  478. /// <summary>
  479. /// 下移
  480. /// </summary>
  481. /// <param name="param"></param>
  482. private void VentPrewetMoveDownAction(object param)
  483. {
  484. if (Recipe != null)
  485. {
  486. if (SelectedVentPrewetIndex >= 0 && SelectedVentPrewetIndex < Recipe.VentRinseStep.Count - 1 && Recipe.VentRinseStep.Count > 1)
  487. {
  488. int currentIndex = SelectedVentPrewetIndex;
  489. VpwRinseStep currentRinseSteps = Recipe.VentRinseStep[SelectedVentPrewetIndex];
  490. Recipe.VentRinseStep.RemoveAt(SelectedVentPrewetIndex);
  491. Recipe.VentRinseStep.Insert(currentIndex + 1, currentRinseSteps);
  492. SelectedVentPrewetIndex = currentIndex + 1;
  493. }
  494. }
  495. }
  496. /// <summary>
  497. /// 删除
  498. /// </summary>
  499. /// <param name="param"></param>
  500. private void VentPrewetDeleteAction(object param)
  501. {
  502. if (SelectedVentPrewetIndex != -1)
  503. {
  504. if (Recipe != null && Recipe.VentRinseStep.Count > SelectedVentPrewetIndex)
  505. {
  506. Recipe.VentRinseStep.RemoveAt(SelectedVentPrewetIndex);
  507. }
  508. }
  509. }
  510. #endregion
  511. #region Extend Clean按钮
  512. /// <summary>
  513. /// 增加
  514. /// </summary>
  515. /// <param name="param"></param>
  516. private void ExtendCleanAddBelowAction(object param)
  517. {
  518. if (Recipe != null)
  519. {
  520. VpwRinseStep currentRinseSteps = new VpwRinseStep();
  521. Recipe.ExtendCleanRinseStep.Insert(SelectedExtendCleanIndex + 1, currentRinseSteps);
  522. SelectedExtendCleanIndex++;
  523. }
  524. }
  525. /// <summary>
  526. /// 增加
  527. /// </summary>
  528. /// <param name="param"></param>
  529. private void ExtendCleanAddAboveAction(object param)
  530. {
  531. if (Recipe != null)
  532. {
  533. VpwRinseStep currentRinseSteps = new VpwRinseStep();
  534. if (SelectedExtendCleanIndex == -1)
  535. {
  536. Recipe.ExtendCleanRinseStep.Add(currentRinseSteps);
  537. SelectedExtendCleanIndex = 0;
  538. }
  539. else
  540. {
  541. Recipe.ExtendCleanRinseStep.Insert(SelectedExtendCleanIndex, currentRinseSteps);
  542. SelectedExtendCleanIndex--;
  543. }
  544. }
  545. }
  546. /// <summary>
  547. /// 上移
  548. /// </summary>
  549. /// <param name="param"></param>
  550. private void ExtendCleanMoveUpAction(object param)
  551. {
  552. if (Recipe != null)
  553. {
  554. if (SelectedExtendCleanIndex > 0)
  555. {
  556. int currentIndex = SelectedExtendCleanIndex;
  557. VpwRinseStep currentRinseSteps = Recipe.ExtendCleanRinseStep[SelectedExtendCleanIndex];
  558. Recipe.ExtendCleanRinseStep.RemoveAt(SelectedExtendCleanIndex);
  559. Recipe.ExtendCleanRinseStep.Insert(currentIndex - 1, currentRinseSteps);
  560. SelectedExtendCleanIndex = currentIndex - 1;
  561. }
  562. }
  563. }
  564. /// <summary>
  565. /// 下移
  566. /// </summary>
  567. /// <param name="param"></param>
  568. private void ExtendCleanMoveDownAction(object param)
  569. {
  570. if (Recipe != null)
  571. {
  572. if (SelectedExtendCleanIndex >= 0 && SelectedExtendCleanIndex < Recipe.ExtendCleanRinseStep.Count - 1 && Recipe.ExtendCleanRinseStep.Count > 1)
  573. {
  574. int currentIndex = SelectedExtendCleanIndex;
  575. VpwRinseStep currentRinseSteps = Recipe.ExtendCleanRinseStep[SelectedExtendCleanIndex];
  576. Recipe.ExtendCleanRinseStep.RemoveAt(SelectedExtendCleanIndex);
  577. Recipe.ExtendCleanRinseStep.Insert(currentIndex + 1, currentRinseSteps);
  578. SelectedExtendCleanIndex = currentIndex + 1;
  579. }
  580. }
  581. }
  582. /// <summary>
  583. /// 删除
  584. /// </summary>
  585. /// <param name="param"></param>
  586. private void ExtendCleanDeleteAction(object param)
  587. {
  588. if (SelectedExtendCleanIndex != -1)
  589. {
  590. if (Recipe != null && Recipe.ExtendCleanRinseStep.Count > SelectedExtendCleanIndex)
  591. {
  592. Recipe.ExtendCleanRinseStep.RemoveAt(SelectedExtendCleanIndex);
  593. }
  594. }
  595. }
  596. #endregion
  597. }
  598. }