SequenceRecipeViewModel.cs 22 KB

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