SequenceRecipeViewModel.cs 26 KB

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