RecipeLayoutViewModel.cs 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  1. using Aitex.Core.RT.Log;
  2. using Caliburn.Micro;
  3. using Caliburn.Micro.Core;
  4. using FurnaceUI.Common;
  5. using FurnaceUI.Models;
  6. using FurnaceUI.Views.Editors;
  7. using MECF.Framework.Common.DataCenter;
  8. using MECF.Framework.UI.Client.CenterViews.Editors;
  9. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  10. using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
  11. using MECF.Framework.UI.Client.ClientBase;
  12. using OpenSEMI.ClientBase;
  13. using OpenSEMI.ClientBase.Command;
  14. using SciChart.Core.Extensions;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Collections.ObjectModel;
  18. using System.Linq;
  19. using System.Windows;
  20. using System.Windows.Input;
  21. namespace FurnaceUI.Views.Recipes
  22. {
  23. public class RecipeLayoutViewModel : FurnaceUIViewModelBase
  24. {
  25. public bool IsPermission { get => this.Permission == 3; }//&& RtStatus != "AutoRunning";
  26. private ICommand _RenameFolderCommand;
  27. public ICommand RenameFolderCommand
  28. {
  29. get
  30. {
  31. if (this._RenameFolderCommand == null)
  32. this._RenameFolderCommand = new BaseCommand(() => this.RenameFolder());
  33. return this._RenameFolderCommand;
  34. }
  35. }
  36. private ICommand _DeleteFolderCommand;
  37. public ICommand DeleteFolderCommand
  38. {
  39. get
  40. {
  41. if (this._DeleteFolderCommand == null)
  42. this._DeleteFolderCommand = new BaseCommand(() => this.DeleteFolder());
  43. return this._DeleteFolderCommand;
  44. }
  45. }
  46. private ICommand _NewFolderCommand;
  47. public ICommand NewFolderCommand
  48. {
  49. get
  50. {
  51. if (this._NewFolderCommand == null)
  52. this._NewFolderCommand = new BaseCommand(() => this.NewFolder());
  53. return this._NewFolderCommand;
  54. }
  55. }
  56. private ICommand _NewFolderRootCommand;
  57. public ICommand NewFolderRootCommand
  58. {
  59. get
  60. {
  61. if (this._NewFolderRootCommand == null)
  62. this._NewFolderRootCommand = new BaseCommand(() => this.NewFolderRoot());
  63. return this._NewFolderRootCommand;
  64. }
  65. }
  66. private ICommand _NewRecipeCommand;
  67. public ICommand NewRecipeCommand
  68. {
  69. get
  70. {
  71. if (this._NewRecipeCommand == null)
  72. this._NewRecipeCommand = new BaseCommand(() => this.NewRecipe());
  73. return this._NewRecipeCommand;
  74. }
  75. }
  76. private ICommand _NewRecipeRootCommand;
  77. public ICommand NewRecipeRootCommand
  78. {
  79. get
  80. {
  81. if (this._NewRecipeRootCommand == null)
  82. this._NewRecipeRootCommand = new BaseCommand(() => this.NewRecipeRoot());
  83. return this._NewRecipeRootCommand;
  84. }
  85. }
  86. private ICommand _RenameRecipeCommand;
  87. public ICommand RenameRecipeCommand
  88. {
  89. get
  90. {
  91. if (this._RenameRecipeCommand == null)
  92. this._RenameRecipeCommand = new BaseCommand(() => this.RenameRecipe());
  93. return this._RenameRecipeCommand;
  94. }
  95. }
  96. private ICommand _DeleteRecipeCommand;
  97. public ICommand DeleteRecipeCommand
  98. {
  99. get
  100. {
  101. if (this._DeleteRecipeCommand == null)
  102. this._DeleteRecipeCommand = new BaseCommand(() => this.DeleteRecipe());
  103. return this._DeleteRecipeCommand;
  104. }
  105. }
  106. private ICommand _SaveAsRecipeCommand;
  107. public ICommand SaveAsRecipeCommand
  108. {
  109. get
  110. {
  111. if (this._SaveAsRecipeCommand == null)
  112. this._SaveAsRecipeCommand = new BaseCommand(() => this.SaveAsRecipe());
  113. return this._SaveAsRecipeCommand;
  114. }
  115. }
  116. private ICommand _EditRecipeCommand;
  117. public ICommand EditRecipeCommand
  118. {
  119. get
  120. {
  121. if (this._EditRecipeCommand == null)
  122. this._EditRecipeCommand = new BaseCommand(() => this.EditRecipe());
  123. return this._EditRecipeCommand;
  124. }
  125. }
  126. private ICommand _SelectRecipeTypeCommand;
  127. public ICommand SelectRecipeTypeCommand
  128. {
  129. get
  130. {
  131. if (this._SelectRecipeTypeCommand == null)
  132. this._SelectRecipeTypeCommand = new BaseCommand(() => this.SelectRecipeType());
  133. return this._SelectRecipeTypeCommand;
  134. }
  135. }
  136. private ICommand _ViewRecipeCommand;
  137. public ICommand ViewRecipeCommand
  138. {
  139. get
  140. {
  141. if (this._ViewRecipeCommand == null)
  142. this._ViewRecipeCommand = new BaseCommand(() => this.ViewRecipe());
  143. return this._ViewRecipeCommand;
  144. }
  145. }
  146. private ICommand _ChangePermission;
  147. public ICommand ChangePermission
  148. {
  149. get
  150. {
  151. if (this._ChangePermission == null)
  152. this._ChangePermission = new BaseCommand(() => this.SavePermission());
  153. return this._ChangePermission;
  154. }
  155. }
  156. private ICommand _ExportRecipeCommand;
  157. public ICommand ExportRecipeCommand
  158. {
  159. get
  160. {
  161. //if (this._ExportRecipeCommand == null)
  162. // this._ExportRecipeCommand = new BaseCommand(() => this.ExportRecipe());
  163. return this._ExportRecipeCommand;
  164. }
  165. }
  166. private ICommand _historyRecipeCommand;
  167. public ICommand HistoryRecipeCommand
  168. {
  169. get
  170. {
  171. //if (this._historyRecipeCommand == null)
  172. // this._historyRecipeCommand = new BaseCommand(() => this.HistoryRecipe());
  173. return this._historyRecipeCommand;
  174. }
  175. }
  176. private List<FileNode> _recipeFileList = new List<FileNode>();
  177. public List<FileNode> RecipeFileList
  178. {
  179. get { return _recipeFileList; }
  180. set { _recipeFileList = value; this.NotifyOfPropertyChange(nameof(RecipeFileList)); }
  181. }
  182. private List<ProcessTypeFileItem> _processTypeFileList = new List<ProcessTypeFileItem>();
  183. public List<ProcessTypeFileItem> ProcessTypeFileList
  184. {
  185. get { return _processTypeFileList; }
  186. set { _processTypeFileList = value; this.NotifyOfPropertyChange(nameof(ProcessTypeFileList)); }
  187. }
  188. public RecipeDataLayout CurrentRecipe { get; private set; }
  189. public FileNode CurrentFileNode { get; set; }
  190. public bool IsCurrentNodePath { get => CurrentFileNode != null; }
  191. public bool IsCurrentNodeFile { get => CurrentFileNode != null && CurrentFileNode.IsFile; }
  192. private bool _isReadAndWritePermission = false;
  193. public bool IsReadAndWritePermission
  194. {
  195. get
  196. {
  197. // _isReadAndWritePermission = IsSelectPermission;
  198. return _isReadAndWritePermission;
  199. }
  200. set
  201. {
  202. _isReadAndWritePermission = value;
  203. NotifyOfPropertyChange(nameof(IsReadAndWritePermission));
  204. }
  205. }
  206. private bool _isFreePermission = false;
  207. public bool IsFreePermission
  208. {
  209. get
  210. {
  211. //_isFreePermission = IsSelectPermission;
  212. return _isFreePermission;
  213. }
  214. set
  215. {
  216. _isFreePermission = value;
  217. NotifyOfPropertyChange(nameof(IsFreePermission));
  218. }
  219. }
  220. private bool _isSelectPermission = false;
  221. public bool IsSelectPermission
  222. {
  223. get
  224. {
  225. _isSelectPermission = LevelDisplay != "LEVEL1" && IsCurrentNodeFile;
  226. return _isSelectPermission;
  227. }
  228. set
  229. {
  230. _isSelectPermission = value;
  231. NotifyOfPropertyChange(nameof(IsSelectPermission));
  232. }
  233. }
  234. public bool IsSingleSelectPermission
  235. {
  236. get => _isSelectPermission && !IsSingleFile;
  237. }
  238. private bool _isEnabledFolderPermission = false;
  239. public bool IsEnabledFolderPermission
  240. {
  241. get
  242. {
  243. _isEnabledFolderPermission = !IsCurrentNodeFile && !IsSingleFile;
  244. return _isEnabledFolderPermission;
  245. }
  246. set
  247. {
  248. _isEnabledFolderPermission = value;
  249. NotifyOfPropertyChange(nameof(IsEnabledFolderPermission));
  250. }
  251. }
  252. private bool _isEnabledNewRecipe = false;
  253. public bool IsEnabledNewRecipe
  254. {
  255. get
  256. {
  257. return _isEnabledNewRecipe;
  258. }
  259. set
  260. {
  261. _isEnabledNewRecipe = value;
  262. NotifyOfPropertyChange(nameof(IsEnabledNewRecipe));
  263. }
  264. }
  265. private bool IsChanged
  266. {
  267. get
  268. {
  269. return editMode == EditMode.Edit || (CurrentRecipe != null && CurrentRecipe.IsChanged);
  270. }
  271. }
  272. private RecipeFormatBuilder _columnBuilder = new RecipeFormatBuilder();
  273. private EditMode editMode;
  274. private RecipeProvider _recipeProvider = new RecipeProvider();
  275. public ObservableCollection<string> ChamberType { get; set; } = new ObservableCollection<string>();
  276. public int ChamberTypeIndexSelection { get; set; }
  277. private int _ProcessTypeIndexSelection;
  278. public int ProcessTypeIndexSelection
  279. {
  280. get
  281. {
  282. return _ProcessTypeIndexSelection;
  283. }
  284. set
  285. {
  286. _ProcessTypeIndexSelection = value;
  287. NotifyOfPropertyChange(nameof(ProcessTypeIndexSelection));
  288. }
  289. }
  290. public string CurrentChamberType
  291. {
  292. get
  293. {
  294. return ChamberType[ChamberTypeIndexSelection];
  295. }
  296. }
  297. public string CurrentProcessType
  298. {
  299. get
  300. {
  301. return ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  302. }
  303. }
  304. public Visibility MultiChamberVisibility
  305. {
  306. get;
  307. set;
  308. }
  309. public Visibility ToleranceVisibility
  310. {
  311. get;
  312. set;
  313. }
  314. public ObservableCollection<string> Chambers { get; set; }
  315. public string SelectedChamber { get; set; }
  316. public object View { get; set; }
  317. private string _SelectRecipeTypeName;
  318. public string SelectRecipeTypeName
  319. {
  320. get
  321. {
  322. return _SelectRecipeTypeName;
  323. }
  324. set
  325. {
  326. _SelectRecipeTypeName = value;
  327. NotifyOfPropertyChange("SelectRecipeTypeName");
  328. }
  329. }
  330. private bool IsSingleFile { get; set; } = false;
  331. protected override void OnInitialize()
  332. {
  333. base.OnInitialize();
  334. InitializeDefault();
  335. }
  336. private void InitializeDefault()
  337. {
  338. var chamberType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedChamberType");
  339. ChamberType.Clear();
  340. if (chamberType == null)
  341. {
  342. ChamberType.Add("Default");
  343. }
  344. else
  345. {
  346. (((string)(chamberType)).Split(',')).ToList().ForEach(x => ChamberType.Add(x));
  347. }
  348. ChamberTypeIndexSelection = 0;
  349. //Etch:Process,Clean,Chuck,Dechuck;CVD:Process,Clean;
  350. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{CurrentMenuID}");
  351. if (processType == null)
  352. {
  353. processType = CurrentMenuID;
  354. }
  355. if (processType == null) processType = "alarm";
  356. string[] recipeProcessType = ((string)processType).Split(',');
  357. for (int i = 0; i < recipeProcessType.Length; i++)
  358. {
  359. var type = new ProcessTypeFileItem();
  360. type.ProcessType = recipeProcessType[i];
  361. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{recipeProcessType[i]}";
  362. // var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  363. type.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefix);// RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  364. ProcessTypeFileList.Add(type);
  365. RecipeFileList = type.FileListByProcessType.FirstOrDefault()?.Files.ToList();
  366. }
  367. //if (ProcessTypeFileList[0].FileListByProcessType.Count > 0)
  368. // CurrentFileNode = ProcessTypeFileList[0].FileListByProcessType[ProcessTypeFileList[0].FileListByProcessType.Count - 1];
  369. SelectRecipeTypeName = processType + " Recipe";
  370. UpdateRecipeFormat();
  371. if (CurrentFileNode != null && CurrentFileNode.IsFile)
  372. {
  373. if (CurrentRecipe != null)
  374. {
  375. CurrentRecipe.PrefixPath = CurrentFileNode.PrefixPath;
  376. CurrentRecipe.Name = CurrentFileNode.FullPath;
  377. }
  378. //this.LoadData(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath);
  379. }
  380. GetRecipeType();
  381. _columnBuilder.Build(CurrentProcessType);
  382. }
  383. private void GetRecipeType()
  384. {
  385. var single = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.SingleRecipeFileType");
  386. if (single != null && !string.IsNullOrEmpty((string)single))
  387. {
  388. string[] singleTypes = ((string)single).ToLower().Split(';');
  389. if (singleTypes != null)
  390. {
  391. int findIndex = Array.IndexOf(singleTypes, CurrentMenuID.ToLower());
  392. if (findIndex != -1)
  393. {
  394. CreateDefaultRecipe();
  395. IsSingleFile = true;
  396. }
  397. }
  398. }
  399. }
  400. private void CreateDefaultRecipe()
  401. {
  402. var defaultFileName = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.DefaultFileName");
  403. string fileName = "default";
  404. if (defaultFileName != null && !string.IsNullOrEmpty((string)defaultFileName))
  405. {
  406. fileName = (string)defaultFileName;
  407. }
  408. string recipeName = fileName.Trim();
  409. string description = "";
  410. string prefix = CurrentChamberType + "\\" + CurrentProcessType;
  411. if (!IsExist(recipeName.ToLower(), true))
  412. {
  413. RecipeDataLayout recipe = new RecipeDataLayout();
  414. recipe.Name = recipeName;
  415. recipe.PrefixPath = prefix;
  416. recipe.Creator = BaseApp.Instance.UserContext.LoginName;
  417. recipe.CreateTime = DateTime.Now;
  418. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  419. recipe.ReviseTime = DateTime.Now;
  420. recipe.Description = description;
  421. recipe.RecipeLevel = LevelDisplay;
  422. recipe.RecipePermission = "Free";
  423. if (!Save(recipe, true))
  424. return;
  425. }
  426. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  427. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  428. var tempFile = item.FileListByProcessType.FirstOrDefault(x => x.Name == fileName);
  429. if (tempFile != null)
  430. {
  431. TreeSelectChanged(tempFile);
  432. }
  433. }
  434. protected override void OnActivate()
  435. {
  436. base.OnActivate();
  437. }
  438. protected override void OnDeactivate(bool close)
  439. {
  440. base.OnDeactivate(close);
  441. if (this.IsChanged)
  442. {
  443. if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} content is changed, do you want to save it?") == DialogButton.Yes)
  444. {
  445. this.SaveRecipe();
  446. }
  447. }
  448. }
  449. public void TabSelectionChanged()
  450. {
  451. UpdateRecipeFormat();
  452. OnViewLoaded(View);
  453. }
  454. public void UpdateRecipeFormat()
  455. {
  456. this.CurrentRecipe = new RecipeDataLayout();
  457. CurrentRecipe.RecipeChamberType = _columnBuilder.RecipeChamberType;
  458. CurrentRecipe.RecipeVersion = _columnBuilder.RecipeVersion;
  459. this.editMode = EditMode.None;
  460. var chamber = QueryDataClient.Instance.Service.GetConfig("System.Recipe.ChamberModules");
  461. if (chamber == null)
  462. {
  463. chamber = "PM1";
  464. }
  465. Chambers = new ObservableCollection<string>(((string)chamber).Split(','));
  466. SelectedChamber = Chambers[0];
  467. MultiChamberVisibility = Chambers.Count > 1 ? Visibility.Visible : Visibility.Collapsed;
  468. ToleranceVisibility = CurrentRecipe.ToleranceEnable ? Visibility.Visible : Visibility.Collapsed;
  469. }
  470. public void TreeSelectChanged(FileNode node)
  471. {
  472. if (IsChanged)
  473. {
  474. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No,
  475. DialogType.CONFIRM,
  476. $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  477. if (selection == DialogButton.Yes)
  478. {
  479. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  480. this.CurrentRecipe.ReviseTime = DateTime.Now;
  481. // this.Save(this.CurrentRecipe, false);
  482. }
  483. }
  484. if (node != null && !node.IsFile)
  485. {
  486. ProcessTypeFileList[0].FileListByProcessType.ForEachDo(a =>
  487. {
  488. a.IsSelected = false;
  489. if (a.Name == node.Name)
  490. {
  491. a.IsSelected = true;
  492. RecipeFileList = a.Files.ToList();
  493. return;
  494. }
  495. });
  496. }
  497. CurrentFileNode = node;
  498. IsFreePermission = true;
  499. IsReadAndWritePermission = true;
  500. NotifyOfPropertyChange(nameof(IsCurrentNodeFile));
  501. NotifyOfPropertyChange(nameof(IsCurrentNodePath));
  502. NotifyOfPropertyChange(nameof(IsSelectPermission));
  503. NotifyOfPropertyChange(nameof(IsSingleSelectPermission));
  504. NotifyOfPropertyChange(nameof(IsEnabledFolderPermission));
  505. if (node != null && node.IsFile)
  506. {
  507. if (CurrentRecipe != null)
  508. {
  509. CurrentRecipe.Name = node.Name;
  510. CurrentRecipe.PrefixPath = node.PrefixPath;
  511. }
  512. // this.LoadData(node.PrefixPath, node.FullPath);
  513. }
  514. else
  515. {
  516. this.ClearData();
  517. this.editMode = EditMode.None;
  518. }
  519. this.UpdateView();
  520. GetIsEnabledNewRecipe();
  521. }
  522. private void GetIsEnabledNewRecipe()
  523. {
  524. if (!IsSingleFile && ProcessTypeFileList != null && ProcessTypeFileList.FirstOrDefault() != null && ProcessTypeFileList.FirstOrDefault().FileListByProcessType != null && ProcessTypeFileList.FirstOrDefault().FileListByProcessType.Count > 0)
  525. {
  526. IsEnabledNewRecipe = true;
  527. }
  528. else
  529. {
  530. IsEnabledNewRecipe = false;
  531. }
  532. }
  533. #region folder
  534. public void SelectRecipeType()
  535. {
  536. var windowManager = IoC.Get<IWindowManager>();
  537. RecipeSelectRecipeTypeViewModel recipeSelectRecipeTypeViewModel = new RecipeSelectRecipeTypeViewModel();
  538. (windowManager as WindowManager)?.ShowDialogWithTitle(recipeSelectRecipeTypeViewModel, null, "Select Recipe Type");
  539. if (recipeSelectRecipeTypeViewModel.SelectRecipeType != null)
  540. {
  541. var selectRecipeType = recipeSelectRecipeTypeViewModel.SelectRecipeType;
  542. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{selectRecipeType}");
  543. if (processType == null)
  544. {
  545. processType = selectRecipeType;
  546. }
  547. ProcessTypeFileList = new List<ProcessTypeFileItem>();
  548. string[] recipeProcessType = ((string)processType).Split(',');
  549. for (int i = 0; i < recipeProcessType.Length; i++)
  550. {
  551. var type = new ProcessTypeFileItem();
  552. type.ProcessType = recipeProcessType[i];
  553. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{recipeProcessType[i]}";
  554. // var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  555. type.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefix);// RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  556. ProcessTypeFileList.Add(type);
  557. }
  558. SelectRecipeTypeName = processType + " Recipe";
  559. this.NotifyOfPropertyChange("ProcessTypeFileList");
  560. if (ProcessTypeFileList[0].FileListByProcessType.Count > 0)
  561. CurrentFileNode = ProcessTypeFileList[0].FileListByProcessType[ProcessTypeFileList[0].FileListByProcessType.Count - 1];
  562. NotifyOfPropertyChange(nameof(IsCurrentNodeFile));
  563. NotifyOfPropertyChange(nameof(IsCurrentNodePath));
  564. NotifyOfPropertyChange(nameof(IsSelectPermission));
  565. NotifyOfPropertyChange(nameof(IsReadAndWritePermission));
  566. // NotifyOfPropertyChange(nameof(IsFreePermission));
  567. ProcessTypeIndexSelection = 0;
  568. }
  569. }
  570. public void NewFolder()
  571. {
  572. if (IsChanged)
  573. {
  574. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  575. if (selection == DialogButton.Cancel)
  576. return;
  577. if (selection == DialogButton.Yes)
  578. {
  579. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  580. this.CurrentRecipe.ReviseTime = DateTime.Now;
  581. // this.Save(this.CurrentRecipe, false);
  582. }
  583. }
  584. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType, "", Visibility.Visible, Visibility.Collapsed);
  585. // dialog.FileName = "new folder";
  586. WindowManager wm = new WindowManager();
  587. bool? dialogReturn = wm.ShowDialog(dialog);
  588. if (!dialogReturn.HasValue || !dialogReturn.Value)
  589. return;
  590. if (string.IsNullOrWhiteSpace(dialog.FileName))
  591. {
  592. DialogBox.ShowWarning("Folder name should not be empty");
  593. }
  594. else
  595. {
  596. string name = dialog.FileName.Trim();
  597. FileNode selectNode = dialog.SelectNode;
  598. string prefix = ChamberType[ChamberTypeIndexSelection] + "\\" + ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  599. string newFolder = string.Empty;
  600. string folder = string.Empty;
  601. if (selectNode != null)
  602. {
  603. prefix = selectNode.PrefixPath;
  604. folder = selectNode.FullPath.Replace($"{prefix}\\", "");
  605. newFolder = $"{folder}\\{name}";
  606. }
  607. else
  608. {
  609. newFolder = name;
  610. }
  611. if (IsExist(newFolder, false))
  612. {
  613. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder with the same name already exist.");
  614. return;
  615. }
  616. if (newFolder.Length > 200)
  617. {
  618. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder name too long, should be less 200.");
  619. return;
  620. }
  621. prefix = GetPrefix(prefix, selectNode);
  622. _recipeProvider.CreateRecipeFolder(prefix, name);
  623. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  624. if (item == null)
  625. {
  626. LOG.Write("error reload recipe file list, type = " + CurrentProcessType);
  627. }
  628. //var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  629. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  630. FindSelectedFile(item.FileListByProcessType, $"{prefix}\\{newFolder}");
  631. item.InvokePropertyChanged();
  632. TreeSelectChanged(CurrentFileNode);
  633. }
  634. }
  635. private string GetPrefix(string prefix, FileNode CurrentFileNode)
  636. {
  637. string temppreFix = prefix;
  638. if (CurrentFileNode != null)
  639. {
  640. if (string.IsNullOrEmpty(CurrentFileNode.AllParentPath))
  641. {
  642. if (CurrentFileNode.IsFile)
  643. {
  644. return temppreFix;
  645. }
  646. else
  647. {
  648. temppreFix = CurrentFileNode.FullPath;
  649. }
  650. }
  651. else
  652. {
  653. if (CurrentFileNode.IsFile)
  654. {
  655. if (temppreFix.EndsWith("\\"))
  656. {
  657. temppreFix = $"{temppreFix}{CurrentFileNode.AllParentPath}";
  658. }
  659. else
  660. {
  661. temppreFix = $"{temppreFix}\\{CurrentFileNode.AllParentPath}";
  662. }
  663. }
  664. else
  665. {
  666. temppreFix = $"{temppreFix}\\{CurrentFileNode.AllParentPath}\\{CurrentFileNode.Name}";
  667. }
  668. }
  669. }
  670. return temppreFix;
  671. }
  672. public void NewFolderRoot()
  673. {
  674. if (IsChanged)
  675. {
  676. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  677. if (selection == DialogButton.Cancel)
  678. return;
  679. if (selection == DialogButton.Yes)
  680. {
  681. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  682. this.CurrentRecipe.ReviseTime = DateTime.Now;
  683. // this.Save(this.CurrentRecipe, false);
  684. }
  685. }
  686. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType);
  687. dialog.FileName = "new folder";
  688. WindowManager wm = new WindowManager();
  689. bool? dialogReturn = wm.ShowDialog(dialog);
  690. if (!dialogReturn.HasValue || !dialogReturn.Value)
  691. return;
  692. string name = dialog.FileName.Trim();
  693. if (string.IsNullOrEmpty(name))
  694. {
  695. DialogBox.ShowWarning("Folder name should not be empty");
  696. return;
  697. }
  698. if (IsExist(name, false))
  699. {
  700. DialogBox.ShowWarning($"Can not create folder {name}, Folder with the same name already exist.");
  701. return;
  702. }
  703. if (name.Length > 200)
  704. {
  705. DialogBox.ShowWarning($"Can not create folder {name}, Folder name too long, should be less 200.");
  706. return;
  707. }
  708. string prefix = ChamberType[ChamberTypeIndexSelection] + "\\" + ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  709. _recipeProvider.CreateRecipeFolder(prefix, name);
  710. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, name, true);
  711. }
  712. public void DeleteFolder()
  713. {
  714. if (CurrentFileNode == null || CurrentFileNode.IsFile)
  715. return;
  716. if (CurrentFileNode.Files.Count > 0)
  717. {
  718. DialogBox.ShowWarning($"Can not delete non-empty folder, Remove the files or folders under \r\n{CurrentFileNode.FullPath}.");
  719. return;
  720. }
  721. var prefix = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  722. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  723. $"Are you sure you want to delete \r\n {prefix}?");
  724. if (selection == DialogButton.No)
  725. return;
  726. //string nextFocus = CurrentFileNode.Parent.FullPath;
  727. //bool isFolder = true;
  728. //if (CurrentFileNode.Parent!=null&&CurrentFileNode.Parent.Files.Count > 1)
  729. //{
  730. // for (int i = 0; i < CurrentFileNode.Parent.Files.Count; i++)
  731. // {
  732. // if (CurrentFileNode.Parent.Files[i] == CurrentFileNode)
  733. // {
  734. // if (i == 0)
  735. // {
  736. // nextFocus = CurrentFileNode.Parent.Files[i + 1].FullPath;
  737. // isFolder = !CurrentFileNode.Parent.Files[i + 1].IsFile;
  738. // }
  739. // else
  740. // {
  741. // nextFocus = CurrentFileNode.Parent.Files[i - 1].FullPath;
  742. // isFolder = !CurrentFileNode.Parent.Files[i - 1].IsFile;
  743. // }
  744. // }
  745. // }
  746. //}
  747. prefix = prefix.Replace($"\\{CurrentFileNode.Name}", "");
  748. _recipeProvider.DeleteRecipeFolder(prefix, CurrentFileNode.Name);
  749. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, "", false, true);
  750. GetIsEnabledNewRecipe();
  751. }
  752. public void RenameFolder()
  753. {
  754. if (CurrentFileNode == null || CurrentFileNode.IsFile)
  755. return;
  756. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType, "", Visibility.Hidden, Visibility.Collapsed);
  757. dialog.FileName = CurrentFileNode.Name;
  758. WindowManager wm = new WindowManager();
  759. bool? dialogReturn = wm.ShowDialog(dialog);
  760. if (!dialogReturn.HasValue || !dialogReturn.Value)
  761. return;
  762. string name = dialog.FileName.Trim();
  763. if (string.IsNullOrEmpty(name))
  764. return;
  765. string newFolder = CurrentFileNode.FullPath.Substring(0, CurrentFileNode.FullPath.LastIndexOf("\\") + 1);
  766. if (!string.IsNullOrEmpty(newFolder))
  767. newFolder = newFolder + name;
  768. else
  769. newFolder = name;
  770. if (newFolder == CurrentFileNode.FullPath)
  771. return;
  772. if (IsExist(newFolder, false))
  773. {
  774. DialogBox.ShowWarning($"Can not rename to {newFolder}, Folder with the same name already exist.");
  775. return;
  776. }
  777. if (newFolder.Length > 200)
  778. {
  779. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder name too long, should be less 200.");
  780. return;
  781. }
  782. if (_recipeProvider.RenameFolder(CurrentFileNode.PrefixPath, CurrentFileNode.Name, name))
  783. {
  784. foreach (var node in CurrentFileNode.Files)
  785. {
  786. UIGlobalVariable.Instance.ProcessModifiedRecipe[node.FullPath] = $"Folder Rename from [{CurrentFileNode.FullPath}] to [{name}] {DateTime.Now}";
  787. }
  788. }
  789. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, name, true, true);
  790. }
  791. #endregion
  792. #region recipe
  793. public void NewRecipe()
  794. {
  795. if (IsChanged)
  796. {
  797. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  798. if (selection == DialogButton.Cancel)
  799. return;
  800. if (selection == DialogButton.Yes)
  801. {
  802. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  803. this.CurrentRecipe.ReviseTime = DateTime.Now;
  804. this.Save(this.CurrentRecipe, false);
  805. }
  806. }
  807. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, "");
  808. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  809. //dialog.FileName = (string)QueryDataClient.Instance.Service.GetConfig($"System.Recipe.DefaultProcessRecipeName");
  810. WindowManager wm = new WindowManager();
  811. bool? dialogReturn = wm.ShowDialog(dialog);
  812. if (!dialogReturn.HasValue || !dialogReturn.Value)
  813. return;
  814. if (string.IsNullOrEmpty(dialog.FileName))
  815. {
  816. DialogBox.ShowWarning("Recipe file name should not be empty");
  817. return;
  818. }
  819. string recipeName = dialog.FileName.Trim();
  820. string filepath = dialog.FilePath;
  821. string description = dialog.Comment;
  822. string prefix;
  823. if (filepath.Contains("\\"))
  824. {
  825. prefix = filepath;
  826. }
  827. else
  828. {
  829. prefix = CurrentChamberType + "\\" + CurrentProcessType + "\\" + filepath;
  830. if (CurrentFileNode != null)
  831. {
  832. //获取目录
  833. prefix = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  834. }
  835. }
  836. if (RecipeFileList.Find(a => a.Name == recipeName.ToLower()) != null)
  837. {
  838. DialogBox.ShowWarning($"Can not create {recipeName}, Recipe with the same name already exist.");
  839. return;
  840. }
  841. if ((prefix + recipeName).Length > 200)
  842. {
  843. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  844. return;
  845. }
  846. RecipeDataLayout recipe = new RecipeDataLayout();
  847. recipe.Name = recipeName;
  848. recipe.PrefixPath = prefix;
  849. recipe.Creator = BaseApp.Instance.UserContext.LoginName;
  850. recipe.CreateTime = DateTime.Now;
  851. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  852. recipe.ReviseTime = DateTime.Now;
  853. recipe.Description = description;
  854. recipe.RecipeLevel = LevelDisplay;
  855. recipe.RecipePermission = "Free";
  856. if (!Save(recipe, true))
  857. return;
  858. var types = prefix.Split('\\');
  859. string newfile = string.Empty;
  860. if (types.Length > 2)
  861. {
  862. newfile = $"{string.Join("\\", types.Skip(2))}\\{recipeName}";
  863. }
  864. else
  865. {
  866. newfile = recipeName;
  867. }
  868. //ReloadRecipeFileList(types[0], types[1], newfile, false);
  869. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == types[1]);
  870. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  871. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{newfile}");
  872. item.FileListByProcessType.ForEachDo(a =>
  873. {
  874. a.IsSelected = false;
  875. if (a.FullPath == prefix)
  876. {
  877. a.IsSelected = true;
  878. CurrentFileNode = a;
  879. RecipeFileList = a.Files.ToList();
  880. return;
  881. }
  882. });
  883. }
  884. public void NewRecipeRoot()
  885. {
  886. if (IsChanged)
  887. {
  888. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  889. if (selection == DialogButton.Cancel)
  890. return;
  891. if (selection == DialogButton.Yes)
  892. {
  893. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  894. this.CurrentRecipe.ReviseTime = DateTime.Now;
  895. this.Save(this.CurrentRecipe, false);
  896. }
  897. }
  898. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description);
  899. dialog.FileName = "new recipe";
  900. WindowManager wm = new WindowManager();
  901. bool? dialogReturn = wm.ShowDialog(dialog);
  902. if (!dialogReturn.HasValue || !dialogReturn.Value)
  903. return;
  904. string recipeName = dialog.FileName.Trim();
  905. string description = dialog.Comment;
  906. if (string.IsNullOrEmpty(dialog.FileName))
  907. {
  908. DialogBox.ShowWarning("Recipe file name should not be empty");
  909. return;
  910. }
  911. if (IsExist(recipeName, true))
  912. {
  913. DialogBox.ShowWarning($"Can not create {recipeName}, Recipe with the same name already exist.");
  914. return;
  915. }
  916. if (recipeName.Length > 200)
  917. {
  918. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  919. return;
  920. }
  921. }
  922. private void ReloadRecipeFileList(string chamberType, string processType, string selectedFile, bool selectionIsFolder, bool isRefreshFlod = false)
  923. {
  924. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == processType);
  925. if (item == null)
  926. {
  927. LOG.Write("error reload recipe file list, type = " + processType);
  928. }
  929. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}";
  930. //var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  931. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefix);// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  932. FindSelectedFile(item.FileListByProcessType, $"{prefix}\\{selectedFile}");
  933. if (isRefreshFlod)
  934. item.InvokePropertyChanged();
  935. }
  936. private bool FindSelectedFile(ObservableCollection<FileNode> nodes, string selectedFile)
  937. {
  938. foreach (var recipe in nodes)
  939. {
  940. recipe.IsSelected = false;
  941. if (!recipe.IsFile)
  942. {
  943. if (recipe.FullPath == selectedFile && recipe.Files.Count == 0)
  944. {
  945. recipe.IsSelected = true;
  946. CurrentFileNode = recipe;
  947. return true;
  948. }
  949. else
  950. {
  951. if (FindSelectedFile(recipe.Files, selectedFile)) return true;
  952. }
  953. }
  954. else
  955. {
  956. string filepath = string.Empty;
  957. if (string.IsNullOrEmpty(recipe.AllParentPath))
  958. {
  959. filepath = recipe.Name;
  960. }
  961. else
  962. {
  963. filepath = recipe.AllParentPath + "\\" + recipe.Name;
  964. }
  965. if (filepath == selectedFile.Replace($"{recipe.PrefixPath}\\", ""))
  966. {
  967. recipe.IsSelected = true;
  968. CurrentFileNode = recipe;
  969. return true;
  970. }
  971. }
  972. }
  973. return false;
  974. }
  975. public void SavePermission()
  976. {
  977. CurrentRecipe.Clear();
  978. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  979. var recipeContent = _recipeProvider.LoadRecipe(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath);
  980. if (string.IsNullOrEmpty(recipeContent))
  981. {
  982. MessageBox.Show($"{CurrentRecipe.PrefixPath}\\{CurrentRecipe.Name} is empty, please confirm the file is valid.");
  983. return;
  984. }
  985. CurrentRecipe.InitData(prefixPath, CurrentRecipe.Name, recipeContent, _columnBuilder.Configs, SelectedChamber);
  986. CurrentRecipe.RecipeLevel = CurrentFileNode.Level;
  987. RecipePermissionSelectViewModel dialog = new RecipePermissionSelectViewModel("Save recipe and permission", CurrentFileNode.Permission, CurrentRecipe.Description);
  988. WindowManager wm = new WindowManager();
  989. bool? dialogReturn = wm.ShowDialog(dialog);
  990. if (!dialogReturn.HasValue || !dialogReturn.Value)
  991. return;
  992. this.LoadData(CurrentRecipe.PrefixPath, CurrentRecipe.Name);
  993. CurrentRecipe.RecipePermission = dialog.RecipePermission;
  994. CurrentRecipe.Description = dialog.RecipeComment;
  995. CurrentRecipe.RecipeLevel = CurrentFileNode.Level;
  996. this.Save(CurrentRecipe, false);
  997. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  998. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  999. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{CurrentFileNode.FullPath}");
  1000. item.FileListByProcessType.ForEachDo(a =>
  1001. {
  1002. a.IsSelected = false;
  1003. if (a.FullPath == CurrentRecipe.PrefixPath)
  1004. {
  1005. a.IsSelected = true;
  1006. RecipeFileList = a.Files.ToList();
  1007. return;
  1008. }
  1009. });
  1010. }
  1011. private bool IsExist(string fullPath, bool isFile)
  1012. {
  1013. for (int i = 0; i < ProcessTypeFileList.Count; i++)
  1014. {
  1015. if (ProcessTypeFileList[i].ProcessType == CurrentProcessType)
  1016. {
  1017. if (ProcessTypeFileList[i].FileListByProcessType.Count == 0)
  1018. return false;
  1019. foreach (var item in ProcessTypeFileList[i].FileListByProcessType)
  1020. {
  1021. if (FindFile(fullPath, item, isFile))
  1022. {
  1023. return true;
  1024. }
  1025. }
  1026. return false;
  1027. }
  1028. }
  1029. return true;
  1030. }
  1031. private bool FindFile(string path, FileNode root, bool isFile)
  1032. {
  1033. if (root.FullPath.ToLower() == path && !isFile)
  1034. {
  1035. return true;
  1036. }
  1037. if (root.IsFile && isFile)
  1038. {
  1039. return root.FullPath.ToLower().Equals(path);
  1040. }
  1041. else if (!root.IsFile && isFile)
  1042. {
  1043. foreach (var node in root.Files)
  1044. {
  1045. if (isFile && node.IsFile && node.FullPath.ToLower() == path)
  1046. return true;
  1047. if (!node.IsFile && FindFile(path, node, isFile))
  1048. return true;
  1049. }
  1050. }
  1051. return false;
  1052. }
  1053. public void SaveAsRecipe()
  1054. {
  1055. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1056. return;
  1057. if (IsChanged)
  1058. {
  1059. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  1060. if (selection == DialogButton.Cancel)
  1061. return;
  1062. if (selection == DialogButton.Yes)
  1063. {
  1064. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1065. this.CurrentRecipe.ReviseTime = DateTime.Now;
  1066. this.Save(this.CurrentRecipe, false);
  1067. }
  1068. }
  1069. this.LoadData(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath);
  1070. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description, Visibility.Hidden);
  1071. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  1072. dialog.FileName = CurrentFileNode.Name;
  1073. WindowManager wm = new WindowManager();
  1074. bool? dialogReturn = wm.ShowDialog(dialog);
  1075. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1076. return;
  1077. string recipeName = dialog.FileName.Trim();
  1078. string filepath = dialog.FilePath;
  1079. FileNode selectNode = dialog.SelectNode;
  1080. if (string.IsNullOrEmpty(dialog.FileName))
  1081. {
  1082. DialogBox.ShowWarning("Recipe file name should not be empty");
  1083. return;
  1084. }
  1085. string prefix = CurrentChamberType + "\\" + CurrentProcessType;// + "\\" + filepath;
  1086. string processType = string.Empty;
  1087. // string folder = CurrentFileNode.FullPath;
  1088. // string folder = filepath.Substring(filepath.LastIndexOf("\\") + 1);
  1089. string folder = filepath.Replace($"{prefix}\\", "");
  1090. //if (!string.IsNullOrEmpty(folder))
  1091. // recipeName = folder + "\\" + recipeName;
  1092. // var newPrefix = GetPrefix(CurrentChamberType + "\\" + CurrentProcessType, selectNode);
  1093. if (!string.IsNullOrEmpty(folder))
  1094. {
  1095. recipeName = $"{folder}\\{recipeName}";
  1096. }
  1097. if (IsExist(prefix + "\\" + recipeName, true))
  1098. {
  1099. DialogBox.ShowWarning($"Can not copy to {recipeName}, Recipe with the same name already exist.");
  1100. return;
  1101. }
  1102. if (recipeName.Length > 200)
  1103. {
  1104. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  1105. return;
  1106. }
  1107. CurrentRecipe.Creator = BaseApp.Instance.UserContext.LoginName;
  1108. CurrentRecipe.CreateTime = DateTime.Now;
  1109. CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1110. CurrentRecipe.ReviseTime = DateTime.Now;
  1111. CurrentRecipe.Description = CurrentRecipe.Description + ". Renamed from " + CurrentFileNode.Name;
  1112. _recipeProvider.SaveAsRecipe(prefix, recipeName, CurrentRecipe.GetXmlString());
  1113. prefix = GetPrefix(prefix, CurrentFileNode);
  1114. if (selectNode.Name == prefix)
  1115. {
  1116. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  1117. }
  1118. else
  1119. {
  1120. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1121. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1122. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{recipeName}");
  1123. item.FileListByProcessType.ForEachDo(a =>
  1124. {
  1125. a.IsSelected = false;
  1126. if (a.FullPath == prefix)
  1127. {
  1128. a.IsSelected = true;
  1129. RecipeFileList = a.Files.ToList();
  1130. return;
  1131. }
  1132. });
  1133. }
  1134. }
  1135. public void RenameRecipe()
  1136. {
  1137. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1138. return;
  1139. if (IsChanged)
  1140. {
  1141. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  1142. if (selection == DialogButton.Cancel)
  1143. return;
  1144. if (selection == DialogButton.Yes)
  1145. {
  1146. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1147. this.CurrentRecipe.ReviseTime = DateTime.Now;
  1148. this.Save(this.CurrentRecipe, false);
  1149. }
  1150. }
  1151. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description, Visibility.Hidden);
  1152. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  1153. dialog.FileName = CurrentFileNode.Name;
  1154. WindowManager wm = new WindowManager();
  1155. bool? dialogReturn = wm.ShowDialog(dialog);
  1156. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1157. return;
  1158. string recipeName = dialog.FileName.Trim();
  1159. if (string.IsNullOrEmpty(dialog.FileName))
  1160. {
  1161. DialogBox.ShowWarning("Recipe file name should not be empty");
  1162. return;
  1163. }
  1164. string prefix = CurrentChamberType + "\\" + CurrentProcessType;
  1165. string processType = string.Empty;
  1166. string newName = CurrentFileNode.FullPath.Substring(0, CurrentFileNode.FullPath.LastIndexOf("\\") + 1);
  1167. if (!string.IsNullOrEmpty(newName))
  1168. newName = newName + recipeName;
  1169. else
  1170. newName = recipeName;
  1171. if (newName == CurrentFileNode.FullPath)
  1172. return;
  1173. if (IsExist(newName, true))
  1174. {
  1175. DialogBox.ShowWarning($"Can not rename to {newName}, Recipe with the same name already exist.");
  1176. return;
  1177. }
  1178. if (newName.Length > 200)
  1179. {
  1180. DialogBox.ShowWarning($"Can not create folder {newName}, Folder name too long, should be less 200.");
  1181. return;
  1182. }
  1183. prefix = GetPrefix(prefix, CurrentFileNode);
  1184. if (_recipeProvider.RenameRecipe(prefix, CurrentFileNode.Name, recipeName))
  1185. {
  1186. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Rename Recipe from [{CurrentFileNode.FullPath}] to [{recipeName}] {DateTime.Now}";
  1187. }
  1188. CurrentRecipe.Name = dialog.FileName;
  1189. CurrentRecipe.Description = dialog.Comment;
  1190. CurrentRecipe.PrefixPath = prefix;
  1191. this.Save(CurrentRecipe, false);
  1192. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, newName, false);
  1193. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1194. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1195. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{newName}");
  1196. item.FileListByProcessType.ForEachDo(a =>
  1197. {
  1198. a.IsSelected = false;
  1199. if (a.FullPath == prefix)
  1200. {
  1201. a.IsSelected = true;
  1202. RecipeFileList = a.Files.ToList();
  1203. return;
  1204. }
  1205. });
  1206. }
  1207. public void DeleteRecipe()
  1208. {
  1209. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1210. return;
  1211. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  1212. $"Are you sure you want to delete \r\n {CurrentFileNode.FullPath}?");
  1213. if (selection == DialogButton.No)
  1214. return;
  1215. //string nextFocus = CurrentFileNode.Parent.FullPath;
  1216. //bool isFolder = true;
  1217. //if (CurrentFileNode.Parent.Files.Count > 1)
  1218. //{
  1219. // for (int i = 0; i < CurrentFileNode.Parent.Files.Count; i++)
  1220. // {
  1221. // if (CurrentFileNode.Parent.Files[i] == CurrentFileNode)
  1222. // {
  1223. // if (i == 0)
  1224. // {
  1225. // nextFocus = CurrentFileNode.Parent.Files[i + 1].FullPath;
  1226. // isFolder = !CurrentFileNode.Parent.Files[i + 1].IsFile;
  1227. // }
  1228. // else
  1229. // {
  1230. // nextFocus = CurrentFileNode.Parent.Files[i - 1].FullPath;
  1231. // isFolder = !CurrentFileNode.Parent.Files[i - 1].IsFile;
  1232. // }
  1233. // }
  1234. // }
  1235. //}
  1236. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  1237. if (_recipeProvider.DeleteRecipe(prefixPath, CurrentFileNode.Name))
  1238. {
  1239. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Delet Recipe from [{CurrentFileNode.FullPath}] {DateTime.Now}";
  1240. }
  1241. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, "", false);
  1242. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1243. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1244. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{""}");
  1245. item.FileListByProcessType.ForEachDo(a =>
  1246. {
  1247. a.IsSelected = false;
  1248. if (a.FullPath == prefixPath)
  1249. {
  1250. a.IsSelected = true;
  1251. RecipeFileList = a.Files.ToList();
  1252. return;
  1253. }
  1254. });
  1255. CurrentFileNode = null;
  1256. }
  1257. public void ReloadRecipe()
  1258. {
  1259. if (this.editMode == EditMode.Normal || this.editMode == EditMode.Edit)
  1260. {
  1261. this.LoadData(CurrentRecipe.PrefixPath, CurrentRecipe.Name);
  1262. this.UpdateView();
  1263. }
  1264. }
  1265. public void SaveToAll()
  1266. {
  1267. if (!CurrentRecipe.IsCompatibleWithCurrentFormat)
  1268. {
  1269. DialogBox.ShowWarning($"Save failed, {CurrentRecipe.Name} is not a valid recipe file");
  1270. return;
  1271. }
  1272. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No,
  1273. DialogType.CONFIRM, $"Do you want to save to all? \r\n This will replace all the other chamber recipe content");
  1274. if (selection == DialogButton.No)
  1275. return;
  1276. CurrentRecipe.SaveTo(Chambers.ToArray());
  1277. Save(this.CurrentRecipe, false);
  1278. }
  1279. public void SaveTo()
  1280. {
  1281. if (!CurrentRecipe.IsCompatibleWithCurrentFormat)
  1282. {
  1283. DialogBox.ShowWarning($"Save failed, {CurrentRecipe.Name} is not a valid recipe file");
  1284. return;
  1285. }
  1286. SaveToDialogViewModel dialog = new SaveToDialogViewModel("Select which chamber to copy to", SelectedChamber, Chambers.ToList());
  1287. WindowManager wm = new WindowManager();
  1288. bool? dialogReturn = wm.ShowDialog(dialog);
  1289. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1290. return;
  1291. List<string> chambers = new List<string>();
  1292. foreach (var dialogChamber in dialog.Chambers)
  1293. {
  1294. if (dialogChamber.IsEnabled && dialogChamber.IsChecked)
  1295. chambers.Add(dialogChamber.Name);
  1296. }
  1297. if (chambers.Count == 0)
  1298. return;
  1299. CurrentRecipe.SaveTo(chambers.ToArray());
  1300. Save(this.CurrentRecipe, false);
  1301. }
  1302. public void EditRecipe()
  1303. {
  1304. CGlobal.RecipeProcessEditViewEnable = true;
  1305. MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = true;
  1306. if (PopupPage())
  1307. {
  1308. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Edit {DateTime.Now}";
  1309. this.editMode = EditMode.Normal;
  1310. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, CurrentFileNode.FullPath, false);
  1311. this.UpdateView();
  1312. }
  1313. }
  1314. public void ViewRecipe()
  1315. {
  1316. CGlobal.RecipeProcessEditViewEnable = false;
  1317. MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = false;
  1318. if (PopupPage())
  1319. {
  1320. this.editMode = EditMode.Normal;
  1321. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, CurrentFileNode.FullPath, false);
  1322. this.UpdateView();
  1323. }
  1324. }
  1325. private string GetTimeFormat(string value)
  1326. {
  1327. try
  1328. {
  1329. if (value != null && value.Length > 1 && value.Split(':').Length > 2)
  1330. {
  1331. var timeH = value.Split(':')[0];
  1332. var timeM = value.Split(':')[1];
  1333. var timeS = value.Split(':')[2];
  1334. if (timeS.Contains('.'))
  1335. {
  1336. var timesArray = timeS.Split('.');
  1337. return $"{timeH}:{timeM.PadLeft(2, '0')}:{timesArray[0].PadLeft(2, '0')}.{timesArray[1].Substring(0, 1)}";
  1338. }
  1339. else
  1340. {
  1341. return $"{timeH}:{timeM.PadLeft(2, '0')}:{timeS.PadLeft(2, '0')}.0";
  1342. }
  1343. }
  1344. else
  1345. {
  1346. return value;
  1347. }
  1348. }
  1349. catch
  1350. {
  1351. return value;
  1352. }
  1353. }
  1354. public void SaveRecipe()
  1355. {
  1356. if (this.IsChanged)
  1357. {
  1358. this.Save(this.CurrentRecipe, false);
  1359. }
  1360. }
  1361. public bool Save(RecipeDataLayout recipe, bool createNew)
  1362. {
  1363. bool result = false;
  1364. if (string.IsNullOrEmpty(recipe.Name))
  1365. {
  1366. MessageBox.Show("Recipe name can't be empty");
  1367. return false;
  1368. }
  1369. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1370. recipe.ReviseTime = DateTime.Now;
  1371. result = this._recipeProvider.SaveRecipe(recipe.PrefixPath, recipe.Name, recipe.GetXmlString());
  1372. if (result)
  1373. {
  1374. //recipe.DataSaved();
  1375. this.editMode = EditMode.Normal;
  1376. this.UpdateView();
  1377. }
  1378. else
  1379. {
  1380. MessageBox.Show("Save failed!");
  1381. }
  1382. return result;
  1383. }
  1384. #endregion
  1385. private void ClearData()
  1386. {
  1387. this.editMode = EditMode.None;
  1388. this.CurrentRecipe.Clear();
  1389. this.CurrentRecipe.Name = string.Empty;
  1390. this.CurrentRecipe.Description = string.Empty;
  1391. }
  1392. private void LoadData(string prefixPath, string recipeName)
  1393. {
  1394. CurrentRecipe.Clear();
  1395. var recipeContent = _recipeProvider.LoadRecipe(prefixPath, recipeName);
  1396. if (string.IsNullOrEmpty(recipeContent))
  1397. {
  1398. MessageBox.Show($"{prefixPath}\\{recipeName} is empty, please confirm the file is valid.");
  1399. return;
  1400. }
  1401. // CurrentRecipe.RecipeChamberType = "OriginChamber";
  1402. CurrentRecipe.RecipeVersion = _columnBuilder.RecipeVersion;
  1403. _columnBuilder.Build(CurrentProcessType);
  1404. CurrentRecipe.InitData(prefixPath, recipeName, recipeContent, _columnBuilder.Configs, SelectedChamber);
  1405. this.editMode = EditMode.Normal;
  1406. }
  1407. private void UpdateView()
  1408. {
  1409. bool isFileSelected = CurrentFileNode != null && CurrentFileNode.IsFile;
  1410. this.NotifyOfPropertyChange("CurrentRecipe");
  1411. }
  1412. private string oldPrefix { get; set; }
  1413. private string oldName { get; set; }
  1414. private string oldStepName { get; set; }
  1415. private bool PopupPage()
  1416. {
  1417. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1418. return false;
  1419. var windowManager = IoC.Get<IWindowManager>();
  1420. var currentProcessType = CurrentProcessType;
  1421. if (CurrentProcessType == "Expert Layout")
  1422. {
  1423. RecipeLayoutExpertEditViewModel recipeLayoutExpertEditViewModel = new RecipeLayoutExpertEditViewModel(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath, CurrentFileNode.Permission);
  1424. return (windowManager as WindowManager)?.ShowDialogWithTitle(recipeLayoutExpertEditViewModel, null, "Layout Setting") == true;
  1425. }
  1426. else
  1427. {
  1428. RecipeLayoutEditViewModel sdSettingViewModel = new RecipeLayoutEditViewModel(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath, _columnBuilder, CurrentFileNode.Permission);
  1429. return (windowManager as WindowManager)?.ShowDialogWithTitle(sdSettingViewModel, null, "Layout Setting") == true;
  1430. }
  1431. }
  1432. }
  1433. }