SequenceRecipeViewModel.cs 25 KB

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