SequenceRecipeViewModel.cs 21 KB

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