SequenceRecipeViewModel.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. using Aitex.Core.UI.MVVM;
  2. using Aitex.Core.Utilities;
  3. using MECF.Framework.Common.DataCenter;
  4. using MECF.Framework.Common.RecipeCenter;
  5. using CyberX8_MainPages.PMs;
  6. using CyberX8_Themes.UserControls;
  7. using Prism.Mvvm;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.ComponentModel;
  12. using System.Linq;
  13. using System.Windows;
  14. using System.Windows.Input;
  15. namespace CyberX8_MainPages.ViewModels
  16. {
  17. public class SequenceRecipeViewModel : BindableBase
  18. {
  19. #region 常量
  20. private const string ENGINEERING = "Engineering";
  21. private const string SEQUENCE = "seq";
  22. public enum PlatType
  23. {
  24. notch,
  25. flat
  26. }
  27. #endregion
  28. #region 内部变量
  29. /// <summary>
  30. /// Recipe节点字典
  31. /// </summary>
  32. private Dictionary<string, RecipeNode> _recipeNodeDic = new Dictionary<string, RecipeNode>();
  33. /// <summary>
  34. /// 可用RecipeType字典(key-ListBox内容,value-recipeType)
  35. /// </summary>
  36. private Dictionary<string, string> _aviableNodeTypeDic = new Dictionary<string, string>();
  37. /// <summary>
  38. /// Recipe节点集合
  39. /// </summary>
  40. private ObservableCollection<RecipeNode> _recipeNodes;
  41. /// <summary>
  42. /// 子Recipe节点集合
  43. /// </summary>
  44. private ObservableCollection<string> _subRecipeNodes;
  45. /// <summary>
  46. /// uiRecipeManager
  47. /// </summary>
  48. private UiRecipeManager _uiRecipeManager = new UiRecipeManager();
  49. /// <summary>
  50. /// recipe
  51. /// </summary>
  52. private SequenceRecipe _recipe;
  53. /// <summary>
  54. /// 编辑可用性
  55. /// </summary>
  56. private bool _editEnable;
  57. /// <summary>
  58. /// 创建可用性
  59. /// </summary>
  60. private bool _createEnable;
  61. /// <summary>
  62. /// 当前节点
  63. /// </summary>
  64. private RecipeNode _currentNode;
  65. /// <summary>
  66. /// 可用Recipe集合
  67. /// </summary>
  68. private List<string> _avaibleRecipeTypeLst;
  69. /// <summary>
  70. /// Process Recipe集合
  71. /// </summary>
  72. private ObservableCollection<string> _processRecipes;
  73. /// <summary>
  74. /// 选中可用RecipeType
  75. /// </summary>
  76. private string _selectAvaibleRecipeType;
  77. /// <summary>
  78. /// 选中子Recipe
  79. /// </summary>
  80. private string _selectSubRecipe;
  81. /// <summary>
  82. /// 选中索引
  83. /// </summary>
  84. private int _selectedProcessRecipeIndex;
  85. /// <summary>
  86. /// 选中Process Recipe
  87. /// </summary>
  88. private string _selectedProcessRecipe;
  89. /// <summary>
  90. /// <summary>
  91. /// csr 类型集合
  92. /// </summary>
  93. private List<string> _crsTypeLst = null;
  94. /// <summary>
  95. /// <summary>
  96. /// PlatType类型集合
  97. /// </summary>
  98. private List<PlatType> _platTypeLst = null;
  99. /// <summary>
  100. /// Wafer尺寸集合
  101. /// </summary>
  102. private List<int> _waferSizeLst = null;
  103. /// <summary>
  104. /// 是否可用
  105. /// </summary>
  106. private bool _enable = false;
  107. /// <summary>
  108. /// 是否为编辑
  109. /// </summary>
  110. private bool _editAction = false;
  111. /// <summary>
  112. /// 是否为编辑(true-Edit,false-add)
  113. /// </summary>
  114. private bool _isEdit = false;
  115. /// <summary>
  116. /// 属性检验结果字典
  117. /// </summary>
  118. private Dictionary<string, bool> _propertyValidResultDic = new Dictionary<string, bool>();
  119. /// <summary>
  120. /// Selected Flat Type
  121. /// </summary>
  122. private PlatType _selectedPlatType;
  123. /// <summary>
  124. /// Selected CrsType
  125. /// </summary>
  126. private string _selectedCrsType = "";
  127. #endregion
  128. #region 属性
  129. public ObservableCollection<RecipeNode> RecipeNodes
  130. {
  131. get { return _recipeNodes; }
  132. set { SetProperty(ref _recipeNodes, value); }
  133. }
  134. /// <summary>
  135. /// 子Recipe集合
  136. /// </summary>
  137. public ObservableCollection<string> SubRecipeNodes
  138. {
  139. get { return _subRecipeNodes; }
  140. set { SetProperty(ref _subRecipeNodes, value); }
  141. }
  142. /// <summary>
  143. /// Recipe
  144. /// </summary>
  145. public SequenceRecipe Recipe
  146. {
  147. get { return _recipe; }
  148. set { SetProperty(ref _recipe, value); }
  149. }
  150. /// <summary>
  151. /// 创建可用性
  152. /// </summary>
  153. public bool CreateEnable
  154. {
  155. get { return _createEnable; }
  156. set { SetProperty(ref _createEnable, value);}
  157. }
  158. /// <summary>
  159. /// 编辑可用性
  160. /// </summary>
  161. public bool EditEnable
  162. {
  163. get { return _editEnable; }
  164. set { SetProperty(ref _editEnable, value);}
  165. }
  166. /// <summary>
  167. /// 当前节点
  168. /// </summary>
  169. public RecipeNode CurrentNode
  170. {
  171. get { return _currentNode; }
  172. set { SetProperty(ref _currentNode, value);}
  173. }
  174. /// <summary>
  175. /// 可用集合
  176. /// </summary>
  177. public List<string> AvaibleRecipeTypeLst
  178. {
  179. get { return _avaibleRecipeTypeLst; }
  180. set { SetProperty(ref _avaibleRecipeTypeLst, value);}
  181. }
  182. /// <summary>
  183. /// 选中
  184. /// </summary>
  185. public string SelectedAvaibleRecipeType
  186. {
  187. get { return _selectAvaibleRecipeType; }
  188. set
  189. {
  190. SetProperty(ref _selectAvaibleRecipeType, value);
  191. LoadSubRecipeNodes(value);
  192. }
  193. }
  194. /// <summary>
  195. /// 选中子Recipe
  196. /// </summary>
  197. public string SelectedSubRecipe
  198. {
  199. get { return _selectSubRecipe; }
  200. set { SetProperty(ref _selectSubRecipe, value);}
  201. }
  202. /// <summary>
  203. /// 选中Process Recipe索引
  204. /// </summary>
  205. public int SelectedProcessRecipeIndex
  206. {
  207. get { return _selectedProcessRecipeIndex; }
  208. set { SetProperty(ref _selectedProcessRecipeIndex, value); }
  209. }
  210. /// <summary>
  211. /// 选中Process Recipe
  212. /// </summary>
  213. public string SelectedProcessRecipe
  214. {
  215. get { return _selectedProcessRecipe; }
  216. set { SetProperty(ref _selectedProcessRecipe, value); }
  217. }
  218. /// <summary>
  219. /// Process Recipe集合
  220. /// </summary>
  221. public ObservableCollection<string> ProcessRecipes
  222. {
  223. get { return _processRecipes; }
  224. set { SetProperty(ref _processRecipes,value); }
  225. }
  226. /// <summary>
  227. /// crs类型集合
  228. /// </summary>
  229. public List<string> CrsTypeLst
  230. {
  231. get { return _crsTypeLst; }
  232. set { SetProperty(ref _crsTypeLst, value); }
  233. }
  234. /// <summary>
  235. /// PlatType集合
  236. /// </summary>
  237. public List<PlatType> PlatTypeLst
  238. {
  239. get { return _platTypeLst; }
  240. set { SetProperty(ref _platTypeLst, value); }
  241. }
  242. /// <summary>
  243. /// Wafer 尺寸集合
  244. /// </summary>
  245. public List<int> WaferSizeLst
  246. {
  247. get { return _waferSizeLst; }
  248. set { SetProperty(ref _waferSizeLst, value); }
  249. }
  250. /// <summary>
  251. /// 可用性
  252. /// </summary>
  253. public bool Enable
  254. {
  255. get { return _enable; }
  256. set { SetProperty(ref _enable, value); }
  257. }
  258. /// <summary>
  259. /// 属性数据检验结果
  260. /// </summary>
  261. public Dictionary<string, bool> PropertyValidResultDic
  262. {
  263. get { return _propertyValidResultDic; }
  264. set { SetProperty(ref _propertyValidResultDic, value); }
  265. }
  266. /// <summary>
  267. /// Selected Plat Type
  268. /// </summary>
  269. public PlatType SelectedPlatType
  270. {
  271. get { return _selectedPlatType; }
  272. set { SetProperty(ref _selectedPlatType, value); }
  273. }
  274. /// <summary>
  275. /// SelecteCrsType
  276. /// </summary>
  277. public string SelectedCrsType
  278. {
  279. get { return _selectedCrsType; }
  280. set { SetProperty(ref _selectedCrsType, value); }
  281. }
  282. #endregion
  283. #region 指令
  284. [IgnorePropertyChange]
  285. public ICommand OperationCommand
  286. {
  287. get;
  288. private set;
  289. }
  290. [IgnorePropertyChange]
  291. public ICommand CreateCommand { get; private set; }
  292. [IgnorePropertyChange]
  293. public ICommand EditCommand { get; private set; }
  294. [IgnorePropertyChange]
  295. public ICommand AddRecipeCommand { get; private set; }
  296. [IgnorePropertyChange]
  297. public ICommand RemoveRecipeCommand { get; private set; }
  298. [IgnorePropertyChange]
  299. public ICommand MoveUpCommand { get; private set; }
  300. [IgnorePropertyChange]
  301. public ICommand MoveDownCommand { get; private set; }
  302. [IgnorePropertyChange]
  303. public ICommand SaveRecipeCommand { get; private set; }
  304. [IgnorePropertyChange]
  305. public ICommand SaveAsRecipeCommand { get; private set; }
  306. #endregion
  307. /// <summary>
  308. /// 构造函数
  309. /// </summary>
  310. public SequenceRecipeViewModel()
  311. {
  312. OperationCommand = new DelegateCommand<object>(SelectionChangedAction);
  313. CreateCommand = new DelegateCommand<object>(CreateAction);
  314. EditCommand = new DelegateCommand<object>(EditAction);
  315. AddRecipeCommand=new DelegateCommand<object>(AddRecipeAction);
  316. RemoveRecipeCommand = new DelegateCommand<object>(RemoveRecipeAction);
  317. MoveUpCommand=new DelegateCommand<object>(MoveUpAction);
  318. MoveDownCommand=new DelegateCommand<object>(MoveDownAction);
  319. SaveRecipeCommand = new DelegateCommand<object>(SaveAction);
  320. GetAvaibleRecipeType();
  321. GetComboxLst();
  322. InitializeProprtyValidResultDictionary();
  323. }
  324. /// <summary>
  325. /// 初始化属性数据检验结果字典
  326. /// </summary>
  327. private void InitializeProprtyValidResultDictionary()
  328. {
  329. }
  330. /// <summary>
  331. /// 加载下拉框集合
  332. /// </summary>
  333. private void GetComboxLst()
  334. {
  335. //Wafer尺寸集合
  336. WaferSizeLst = new List<int>();
  337. WaferSizeLst.Add(100);
  338. WaferSizeLst.Add(150);
  339. WaferSizeLst.Add(200);
  340. WaferSizeLst.Add(300);
  341. string crstypeContent = QueryDataClient.Instance.Service.GetConfig($"System.LSType").ToString();
  342. if (!string.IsNullOrEmpty(crstypeContent))
  343. {
  344. CrsTypeLst = crstypeContent.Split(',').ToList();
  345. }
  346. PlatTypeLst = new List<PlatType>();
  347. PlatTypeLst.Add(PlatType.notch);
  348. PlatTypeLst.Add(PlatType.flat);
  349. }
  350. /// <summary>
  351. /// 加载数据
  352. /// </summary>
  353. public void LoadRecipeData()
  354. {
  355. RecipeNodes = _uiRecipeManager.GetRecipesByType(SEQUENCE);
  356. _recipeNodeDic.Clear();
  357. InitializeDictionary(RecipeNodes);
  358. }
  359. /// <summary>
  360. /// 初始化字典
  361. /// </summary>
  362. /// <param name="nodes"></param>
  363. private void InitializeDictionary(ObservableCollection<RecipeNode> nodes)
  364. {
  365. if (nodes != null)
  366. {
  367. foreach (var node in nodes)
  368. {
  369. if (node.NodeType == RecipeNodeType.File)
  370. {
  371. _recipeNodeDic[node.Name] = node;
  372. }
  373. InitializeDictionary(node.Children);
  374. }
  375. }
  376. }
  377. /// <summary>
  378. /// 操作
  379. /// </summary>
  380. /// <param name="param"></param>
  381. private void SelectionChangedAction(object param)
  382. {
  383. if(_recipeNodeDic.ContainsKey(param.ToString()))
  384. {
  385. CurrentNode = _recipeNodeDic[param.ToString()];
  386. if(CurrentNode.NodeType==RecipeNodeType.File)
  387. {
  388. if (CurrentNode.RecipeLocation == ENGINEERING)
  389. {
  390. EditEnable = true;
  391. CreateEnable = true;
  392. }
  393. else
  394. {
  395. EditEnable= false;
  396. CreateEnable = false;
  397. }
  398. }
  399. Recipe =_uiRecipeManager.LoadRecipe<SequenceRecipe>(CurrentNode.RecipeFullFileName);
  400. if (Recipe != null)
  401. {
  402. ProcessRecipes = new ObservableCollection<string>();
  403. if (Recipe.Recipes != null && Recipe.Recipes.Count != 0)
  404. {
  405. ProcessRecipes.AddRange(Recipe.Recipes);
  406. }
  407. SelectedPlatType = (PlatType)Recipe.PlatType;
  408. SelectedCrsType = CrsTypeLst.FirstOrDefault(O => O.Contains(Recipe.CrsType));
  409. }
  410. else
  411. {
  412. MessageBox.Show("Invalid Recipe", "Load Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  413. EditEnable = false;
  414. CreateEnable = false;
  415. }
  416. Enable = false;
  417. }
  418. else
  419. {
  420. if(param.ToString()==ENGINEERING)
  421. {
  422. CreateEnable= true;
  423. }
  424. else
  425. {
  426. CreateEnable = false;
  427. }
  428. CurrentNode = null;
  429. Recipe = null;
  430. ProcessRecipes = null;
  431. EditEnable = false;
  432. Enable = false;
  433. }
  434. _editAction = false;
  435. }
  436. #region Action
  437. /// <summary>
  438. /// 创建
  439. /// </summary>
  440. /// <param name="param"></param>
  441. private void CreateAction(object param)
  442. {
  443. RecipeNameDialog recipeNameDialog = new RecipeNameDialog();
  444. if (recipeNameDialog.ShowDialog().Value)
  445. {
  446. if (!CheckNameExist(recipeNameDialog.RecipeName))
  447. {
  448. Recipe = new SequenceRecipe();
  449. Recipe.CreateDate = DateTime.Now;
  450. Recipe.Ppid = recipeNameDialog.RecipeName;
  451. ProcessRecipes = new ObservableCollection<string>();
  452. Enable = true;
  453. _editAction = false;
  454. }
  455. }
  456. }
  457. /// <summary>
  458. /// 编辑
  459. /// </summary>
  460. /// <param name="param"></param>
  461. private void EditAction(object param)
  462. {
  463. Enable = true;
  464. _editAction= true;
  465. }
  466. /// <summary>
  467. /// 增加Recipe
  468. /// </summary>
  469. /// <param name="param"></param>
  470. private void AddRecipeAction(object param)
  471. {
  472. if (!string.IsNullOrEmpty(SelectedSubRecipe))
  473. {
  474. string[] strAry = SelectedSubRecipe.Split('.');
  475. if(strAry.Length>=3)
  476. {
  477. string str = $"{strAry[1]}.{strAry[2]}";
  478. if (strAry[1].ToLower() != "dep" && strAry[1].ToLower() != "qdr")
  479. {
  480. string first = ProcessRecipes.FirstOrDefault(O => O.Contains(str));
  481. if (!string.IsNullOrEmpty(first))
  482. {
  483. MessageBox.Show("Already exist same Recipe type", "Add Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  484. return;
  485. }
  486. }
  487. else if(strAry[1].ToLower() == "dep")
  488. {
  489. string containResult = ProcessRecipes.FirstOrDefault(O => O == SelectedSubRecipe);
  490. if (!string.IsNullOrEmpty(containResult))
  491. {
  492. MessageBox.Show($"{SelectedSubRecipe} already exist", "Add Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  493. return;
  494. }
  495. }
  496. }
  497. ProcessRecipes.Add(SelectedSubRecipe);
  498. }
  499. }
  500. /// <summary>
  501. /// 移除Recipe
  502. /// </summary>
  503. /// <param name="param"></param>
  504. private void RemoveRecipeAction(object param)
  505. {
  506. if(!string.IsNullOrEmpty(SelectedProcessRecipe)&&ProcessRecipes.Contains(SelectedProcessRecipe))
  507. {
  508. ProcessRecipes.Remove(SelectedProcessRecipe);
  509. }
  510. }
  511. /// <summary>
  512. /// 上移
  513. /// </summary>
  514. /// <param name="param"></param>
  515. private void MoveUpAction(object param)
  516. {
  517. int tmpIndex = SelectedProcessRecipeIndex;
  518. if(SelectedProcessRecipeIndex>0)
  519. {
  520. string up = ProcessRecipes[SelectedProcessRecipeIndex - 1];
  521. ProcessRecipes[SelectedProcessRecipeIndex - 1] = SelectedProcessRecipe;
  522. ProcessRecipes[SelectedProcessRecipeIndex] = up;
  523. SelectedProcessRecipeIndex = tmpIndex - 1;
  524. }
  525. }
  526. /// <summary>
  527. /// 下移
  528. /// </summary>
  529. /// <param name="param"></param>
  530. private void MoveDownAction(object param)
  531. {
  532. int tmpIndex = SelectedProcessRecipeIndex;
  533. if (SelectedProcessRecipeIndex <ProcessRecipes.Count-1)
  534. {
  535. string up = ProcessRecipes[SelectedProcessRecipeIndex + 1];
  536. ProcessRecipes[SelectedProcessRecipeIndex + 1] = SelectedProcessRecipe;
  537. ProcessRecipes[SelectedProcessRecipeIndex] = up;
  538. SelectedProcessRecipeIndex = tmpIndex + 1;
  539. }
  540. }
  541. /// <summary>
  542. /// 保存
  543. /// </summary>
  544. /// <param name="param"></param>
  545. private void SaveAction(object param)
  546. {
  547. if (CheckValid(_isEdit))
  548. {
  549. Recipe.Recipes = new List<string>();
  550. Recipe.Recipes.AddRange(ProcessRecipes);
  551. Recipe.SaveDate = DateTime.Now;
  552. Recipe.PlatType = (int)SelectedPlatType;
  553. Recipe.CrsType = SelectedCrsType;
  554. try
  555. {
  556. _uiRecipeManager.SaveRecipe<SequenceRecipe>(ENGINEERING, Recipe.Ppid, "seq",Recipe);
  557. if (!_editAction)
  558. {
  559. LoadRecipeData();
  560. }
  561. MessageBox.Show("Save Recipe Success", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Information);
  562. Enable = false;
  563. }
  564. catch (Exception ex)
  565. {
  566. MessageBox.Show(ex.Message, "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  567. }
  568. }
  569. }
  570. /// <summary>
  571. /// 检验合法性
  572. /// </summary>
  573. /// <param name="editType"></param>
  574. /// <returns></returns>
  575. private bool CheckValid(bool editType)
  576. {
  577. foreach (string key in _propertyValidResultDic.Keys)
  578. {
  579. bool valid = _propertyValidResultDic[key];
  580. if (!valid)
  581. {
  582. MessageBox.Show($"{key} data invalid", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  583. return false;
  584. }
  585. }
  586. return true;
  587. }
  588. /// <summary>
  589. /// 检验名称是否已经存在
  590. /// </summary>
  591. /// <param name="name"></param>
  592. /// <returns></returns>
  593. private bool CheckNameExist(string name)
  594. {
  595. foreach (string item in _recipeNodeDic.Keys)
  596. {
  597. if (item == name)
  598. {
  599. MessageBox.Show($"{name} is exsit", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
  600. return true;
  601. }
  602. }
  603. return false;
  604. }
  605. #endregion
  606. /// <summary>
  607. /// 选择可用RecipeType
  608. /// </summary>
  609. private void GetAvaibleRecipeType()
  610. {
  611. AvaibleRecipeTypeLst = new List<string>();
  612. ActiveRecipeType[] values=(ActiveRecipeType[]) Enum.GetValues(typeof(ActiveRecipeType));
  613. foreach (var item in values)
  614. {
  615. object[] objAttrs = item.GetType().GetField(item.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
  616. if (objAttrs != null &&objAttrs.Length > 0)
  617. {
  618. DescriptionAttribute descAttr = objAttrs[0] as DescriptionAttribute;
  619. AvaibleRecipeTypeLst.Add($"{item}({descAttr.Description})");
  620. _aviableNodeTypeDic.Add($"{item}({descAttr.Description})", item.ToString());
  621. }
  622. }
  623. }
  624. /// <summary>
  625. /// 加载子Recipe集合
  626. /// </summary>
  627. /// <param name="selectedRecipeType"></param>
  628. private void LoadSubRecipeNodes(string selectedRecipeType)
  629. {
  630. if(_aviableNodeTypeDic.ContainsKey(selectedRecipeType))
  631. {
  632. SubRecipeNodes = new ObservableCollection<string>();
  633. string recipeType = _aviableNodeTypeDic[selectedRecipeType].ToLower();
  634. ObservableCollection<RecipeNode> tmpRecipeNodes = _uiRecipeManager.GetEngineeringRecipesByType(recipeType);
  635. foreach(RecipeNode item in tmpRecipeNodes)
  636. {
  637. SubRecipeNodes.Add(item.FileName);
  638. }
  639. }
  640. }
  641. }
  642. }