RecipeJobViewModel.cs 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. using Aitex.Core.RT.Log;
  2. using Caliburn.Micro;
  3. using Caliburn.Micro.Core;
  4. using MECF.Framework.Common.DataCenter;
  5. using MECF.Framework.UI.Client.CenterViews.Editors;
  6. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  7. using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
  8. using MECF.Framework.UI.Client.ClientBase;
  9. using OpenSEMI.ClientBase;
  10. using OpenSEMI.ClientBase.Command;
  11. using RecipeEditorLib.RecipeModel.Params;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Collections.ObjectModel;
  15. using System.Linq;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Input;
  19. using System.Windows.Media;
  20. using FurnaceUI.Models;
  21. using FurnaceUI.Views.Editors;
  22. using SciChart.Core.Extensions;
  23. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  24. using FurnaceUI.Common;
  25. using FurnaceUI.Views.Jobs;
  26. namespace FurnaceUI.Views.Recipes
  27. {
  28. public class RecipeJobViewModel : FurnaceUIViewModelBase
  29. {
  30. public bool IsPermission { get => this.Permission == 3; }//&& RtStatus != "AutoRunning";
  31. private ICommand _RenameFolderCommand;
  32. public ICommand RenameFolderCommand
  33. {
  34. get
  35. {
  36. if (this._RenameFolderCommand == null)
  37. this._RenameFolderCommand = new BaseCommand(() => this.RenameFolder());
  38. return this._RenameFolderCommand;
  39. }
  40. }
  41. private ICommand _DeleteFolderCommand;
  42. public ICommand DeleteFolderCommand
  43. {
  44. get
  45. {
  46. if (this._DeleteFolderCommand == null)
  47. this._DeleteFolderCommand = new BaseCommand(() => this.DeleteFolder());
  48. return this._DeleteFolderCommand;
  49. }
  50. }
  51. private ICommand _NewFolderCommand;
  52. public ICommand NewFolderCommand
  53. {
  54. get
  55. {
  56. if (this._NewFolderCommand == null)
  57. this._NewFolderCommand = new BaseCommand(() => this.NewFolder());
  58. return this._NewFolderCommand;
  59. }
  60. }
  61. private ICommand _NewFolderRootCommand;
  62. public ICommand NewFolderRootCommand
  63. {
  64. get
  65. {
  66. if (this._NewFolderRootCommand == null)
  67. this._NewFolderRootCommand = new BaseCommand(() => this.NewFolderRoot());
  68. return this._NewFolderRootCommand;
  69. }
  70. }
  71. private ICommand _NewRecipeCommand;
  72. public ICommand NewRecipeCommand
  73. {
  74. get
  75. {
  76. if (this._NewRecipeCommand == null)
  77. this._NewRecipeCommand = new BaseCommand(() => this.NewRecipe());
  78. return this._NewRecipeCommand;
  79. }
  80. }
  81. private ICommand _NewRecipeRootCommand;
  82. public ICommand NewRecipeRootCommand
  83. {
  84. get
  85. {
  86. if (this._NewRecipeRootCommand == null)
  87. this._NewRecipeRootCommand = new BaseCommand(() => this.NewRecipeRoot());
  88. return this._NewRecipeRootCommand;
  89. }
  90. }
  91. private ICommand _RenameRecipeCommand;
  92. public ICommand RenameRecipeCommand
  93. {
  94. get
  95. {
  96. if (this._RenameRecipeCommand == null)
  97. this._RenameRecipeCommand = new BaseCommand(() => this.RenameRecipe());
  98. return this._RenameRecipeCommand;
  99. }
  100. }
  101. private ICommand _DeleteRecipeCommand;
  102. public ICommand DeleteRecipeCommand
  103. {
  104. get
  105. {
  106. if (this._DeleteRecipeCommand == null)
  107. this._DeleteRecipeCommand = new BaseCommand(() => this.DeleteRecipe());
  108. return this._DeleteRecipeCommand;
  109. }
  110. }
  111. private ICommand _SaveAsRecipeCommand;
  112. public ICommand SaveAsRecipeCommand
  113. {
  114. get
  115. {
  116. if (this._SaveAsRecipeCommand == null)
  117. this._SaveAsRecipeCommand = new BaseCommand(() => this.SaveAsRecipe());
  118. return this._SaveAsRecipeCommand;
  119. }
  120. }
  121. private ICommand _EditRecipeCommand;
  122. public ICommand EditRecipeCommand
  123. {
  124. get
  125. {
  126. if (this._EditRecipeCommand == null)
  127. this._EditRecipeCommand = new BaseCommand(() => this.EditRecipe());
  128. return this._EditRecipeCommand;
  129. }
  130. }
  131. private ICommand _SelectRecipeTypeCommand;
  132. public ICommand SelectRecipeTypeCommand
  133. {
  134. get
  135. {
  136. if (this._SelectRecipeTypeCommand == null)
  137. this._SelectRecipeTypeCommand = new BaseCommand(() => this.SelectRecipeType());
  138. return this._SelectRecipeTypeCommand;
  139. }
  140. }
  141. private ICommand _ViewRecipeCommand;
  142. public ICommand ViewRecipeCommand
  143. {
  144. get
  145. {
  146. if (this._ViewRecipeCommand == null)
  147. this._ViewRecipeCommand = new BaseCommand(() => this.ViewRecipe());
  148. return this._ViewRecipeCommand;
  149. }
  150. }
  151. private ICommand _ChangePermission;
  152. public ICommand ChangePermission
  153. {
  154. get
  155. {
  156. if (this._ChangePermission == null)
  157. this._ChangePermission = new BaseCommand(() => this.SavePermission());
  158. return this._ChangePermission;
  159. }
  160. }
  161. public ObservableCollection<ProcessTypeFileItem> ProcessTypeFileList { get; set; }
  162. public RecipeDataJob CurrentRecipe { get; private set; }
  163. public RecipeDataJob CurrentRecipeJob { get; set; } = new RecipeDataJob();
  164. public FileNode CurrentFileNode { get; set; }
  165. public bool IsCurrentNodePath { get => CurrentFileNode != null && !CurrentFileNode.IsFile; }
  166. public bool IsCurrentNodeFile { get => CurrentFileNode != null && CurrentFileNode.IsFile; }
  167. private bool _isReadAndWritePermission;
  168. public bool IsReadAndWritePermission
  169. {
  170. get
  171. {
  172. _isReadAndWritePermission = IsSelectPermission && CurrentFileNode.Permission != "Read";
  173. return _isReadAndWritePermission;
  174. }
  175. set
  176. {
  177. _isReadAndWritePermission = value;
  178. }
  179. }
  180. private bool _isFreePermission;
  181. public bool IsFreePermission
  182. {
  183. get
  184. {
  185. _isFreePermission = IsSelectPermission;
  186. //_isFreePermission = IsSelectPermission && CurrentFileNode.Permission == "Free";
  187. return _isFreePermission;
  188. }
  189. set
  190. {
  191. _isFreePermission = value;
  192. }
  193. }
  194. private bool _isSelectPermission;
  195. public bool IsSelectPermission
  196. {
  197. get
  198. {
  199. _isSelectPermission = LevelDisplay != "LEVEL1" && IsCurrentNodeFile;
  200. return _isSelectPermission;
  201. }
  202. set
  203. {
  204. _isSelectPermission = value;
  205. }
  206. }
  207. private bool IsChanged
  208. {
  209. get
  210. {
  211. return editMode == EditMode.Edit;// || CurrentRecipe.IsChanged;
  212. }
  213. }
  214. private RecipeFormatBuilder _columnBuilder = new RecipeFormatBuilder();
  215. private EditMode editMode;
  216. private RecipeProvider _recipeProvider = new RecipeProvider();
  217. public ObservableCollection<string> ChamberType { get; set; }
  218. public int ChamberTypeIndexSelection { get; set; }
  219. private int _ProcessTypeIndexSelection;
  220. public int ProcessTypeIndexSelection
  221. {
  222. get
  223. {
  224. return _ProcessTypeIndexSelection;
  225. }
  226. set
  227. {
  228. _ProcessTypeIndexSelection = value;
  229. NotifyOfPropertyChange(nameof(ProcessTypeIndexSelection));
  230. }
  231. }
  232. public string CurrentChamberType
  233. {
  234. get
  235. {
  236. return ChamberType[ChamberTypeIndexSelection];
  237. }
  238. }
  239. public string CurrentProcessType
  240. {
  241. get
  242. {
  243. return ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  244. }
  245. }
  246. public Visibility MultiChamberVisibility
  247. {
  248. get;
  249. set;
  250. }
  251. public Visibility ToleranceVisibility
  252. {
  253. get;
  254. set;
  255. }
  256. public ObservableCollection<string> Chambers { get; set; }
  257. public string SelectedChamber { get; set; }
  258. public object View { get; set; }
  259. public string SelectLayoutRecipeType { get; set; }
  260. private string _SelectRecipeTypeName;
  261. public string SelectRecipeTypeName
  262. {
  263. get
  264. {
  265. return _SelectRecipeTypeName;
  266. }
  267. set
  268. {
  269. _SelectRecipeTypeName = value;
  270. NotifyOfPropertyChange(nameof(SelectRecipeTypeName));
  271. }
  272. }
  273. protected override void OnInitialize()
  274. {
  275. base.OnInitialize();
  276. var chamberType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedChamberType");
  277. if (chamberType == null)
  278. {
  279. ChamberType = new ObservableCollection<string>() { "Default" };
  280. }
  281. else
  282. {
  283. ChamberType = new ObservableCollection<string>(((string)(chamberType)).Split(','));
  284. }
  285. ChamberTypeIndexSelection = 0;
  286. //Etch:Process,Clean,Chuck,Dechuck;CVD:Process,Clean;
  287. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{CurrentMenuID}");
  288. if (processType == null)
  289. {
  290. processType = CurrentMenuID;
  291. }
  292. ProcessTypeFileList = new ObservableCollection<ProcessTypeFileItem>();
  293. string[] recipeProcessType = ((string)processType).Split(',');
  294. for (int i = 0; i < recipeProcessType.Length; i++)
  295. {
  296. var type = new ProcessTypeFileItem();
  297. type.ProcessType = recipeProcessType[i];
  298. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{recipeProcessType[i]}";
  299. var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  300. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  301. ProcessTypeFileList.Add(type);
  302. }
  303. if (ProcessTypeFileList[0].FileListByProcessType.Count > 0)
  304. CurrentFileNode = ProcessTypeFileList[0].FileListByProcessType[ProcessTypeFileList[0].FileListByProcessType.Count - 1];
  305. SelectRecipeTypeName = processType + " Recipe";
  306. UpdateRecipeFormat();
  307. if (CurrentFileNode != null && CurrentFileNode.IsFile)
  308. {
  309. this.LoadData(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath);
  310. }
  311. }
  312. protected override void OnActivate()
  313. {
  314. base.OnActivate();
  315. InitialPathFlag(ProcessTypeFileList[0].FileListByProcessType);
  316. }
  317. protected override void OnDeactivate(bool close)
  318. {
  319. base.OnDeactivate(close);
  320. if (this.IsChanged)
  321. {
  322. if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} content is changed, do you want to save it?") == DialogButton.Yes)
  323. {
  324. this.SaveRecipe();
  325. }
  326. }
  327. }
  328. public void TabSelectionChanged()
  329. {
  330. UpdateRecipeFormat();
  331. OnViewLoaded(View);
  332. }
  333. public void UpdateRecipeFormat()
  334. {
  335. this.CurrentRecipe = new RecipeDataJob();
  336. CurrentRecipe.RecipeChamberType = _columnBuilder.RecipeChamberType;
  337. CurrentRecipe.RecipeVersion = _columnBuilder.RecipeVersion;
  338. this.editMode = EditMode.None;
  339. var chamber = QueryDataClient.Instance.Service.GetConfig("System.Recipe.ChamberModules");
  340. if (chamber == null)
  341. {
  342. chamber = "PM1";
  343. }
  344. Chambers = new ObservableCollection<string>(((string)chamber).Split(','));
  345. SelectedChamber = Chambers[0];
  346. MultiChamberVisibility = Chambers.Count > 1 ? Visibility.Visible : Visibility.Collapsed;
  347. ToleranceVisibility =Visibility.Collapsed;// CurrentRecipe.ToleranceEnable ? Visibility.Visible :
  348. }
  349. public void TreeSelectChanged(FileNode node)
  350. {
  351. if (IsChanged)
  352. {
  353. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No,
  354. DialogType.CONFIRM,
  355. $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  356. if (selection == DialogButton.Yes)
  357. {
  358. //this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  359. //this.CurrentRecipe.ReviseTime = DateTime.Now;
  360. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  361. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  362. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  363. // this.Save(this.CurrentRecipe, false);
  364. }
  365. }
  366. CurrentFileNode = node;
  367. NotifyOfPropertyChange(nameof(IsCurrentNodeFile));
  368. NotifyOfPropertyChange(nameof(IsCurrentNodePath));
  369. NotifyOfPropertyChange(nameof(IsSelectPermission));
  370. NotifyOfPropertyChange(nameof(IsReadAndWritePermission));
  371. NotifyOfPropertyChange(nameof(IsFreePermission));
  372. if (node != null && node.IsFile)
  373. {
  374. this.LoadData(node.PrefixPath, node.FullPath);
  375. }
  376. else
  377. {
  378. this.ClearData();
  379. this.editMode = EditMode.None;
  380. }
  381. this.UpdateView();
  382. }
  383. #region folder
  384. public void SelectRecipeType()
  385. {
  386. var windowManager = IoC.Get<IWindowManager>();
  387. JobRecipeSelectTypeViewModel jobRecipeSelectTypeViewModel = new JobRecipeSelectTypeViewModel();
  388. (windowManager as WindowManager)?.ShowDialogWithTitle(jobRecipeSelectTypeViewModel, null, "Select Recipe Type");
  389. SelectLayoutRecipeType = jobRecipeSelectTypeViewModel.SelectRecipeType;
  390. if (jobRecipeSelectTypeViewModel.SelectRecipeType != null)
  391. {
  392. var selectRecipeType = jobRecipeSelectTypeViewModel.SelectRecipeType;
  393. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{selectRecipeType}");
  394. if (processType == null)
  395. {
  396. processType = selectRecipeType;
  397. }
  398. ProcessTypeFileList = new ObservableCollection<ProcessTypeFileItem>();
  399. string[] recipeProcessType = ((string)processType).Split(',');
  400. for (int i = 0; i < recipeProcessType.Length; i++)
  401. {
  402. var type = new ProcessTypeFileItem();
  403. type.ProcessType = recipeProcessType[i];
  404. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{recipeProcessType[i]}";
  405. var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  406. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  407. ProcessTypeFileList.Add(type);
  408. InitialPathFlag(type.FileListByProcessType);
  409. }
  410. SelectRecipeTypeName = processType + " Recipe";
  411. this.NotifyOfPropertyChange("ProcessTypeFileList");
  412. ProcessTypeIndexSelection = 0;
  413. }
  414. }
  415. private void InitialPathFlag(IEnumerable<FileNode> fileNodes)
  416. {
  417. foreach (var recipe in fileNodes)
  418. {
  419. if (recipe.IsFile)
  420. {
  421. RecipeDataJob job = GetJob(recipe.PrefixPath, recipe.FullPath);
  422. Visibility visibility = Visibility.Hidden;
  423. if (UIGlobalVariable.Instance.LayoutModifiedRecipe.ContainsKey(job?.LayoutRecipe ?? "")) visibility = Visibility.Visible;
  424. if (UIGlobalVariable.Instance.ProcessModifiedRecipe.ContainsKey(job?.ProcessRecipe ?? "")) visibility = Visibility.Visible;
  425. if (recipe.IsVisiable != visibility) recipe.IsVisiable = visibility;
  426. }
  427. else InitialPathFlag(recipe.Files);
  428. }
  429. }
  430. public void NewFolder()
  431. {
  432. if (IsChanged)
  433. {
  434. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  435. if (selection == DialogButton.Cancel)
  436. return;
  437. if (selection == DialogButton.Yes)
  438. {
  439. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  440. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  441. this.CurrentRecipe.RecipeLevel = this.LevelDisplay;
  442. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  443. }
  444. }
  445. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType);
  446. dialog.FileName = "new folder";
  447. WindowManager wm = new WindowManager();
  448. bool? dialogReturn = wm.ShowDialog(dialog);
  449. if (!dialogReturn.HasValue || !dialogReturn.Value)
  450. return;
  451. string name = dialog.FileName.Trim();
  452. if (string.IsNullOrEmpty(name))
  453. {
  454. DialogBox.ShowWarning("Folder name should not be empty");
  455. return;
  456. }
  457. string prefix = ChamberType[ChamberTypeIndexSelection] + "\\" + ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  458. string processType = string.Empty;
  459. string newFolder = string.Empty;
  460. if (CurrentFileNode != null)
  461. {
  462. prefix = CurrentFileNode.PrefixPath;
  463. string folder = CurrentFileNode.FullPath;
  464. if (CurrentFileNode.IsFile)
  465. {
  466. folder = folder.Substring(0, folder.LastIndexOf("\\") + 1);
  467. if (!string.IsNullOrEmpty(folder))
  468. newFolder = folder;
  469. }
  470. else
  471. {
  472. newFolder = folder + "\\";
  473. }
  474. }
  475. newFolder = newFolder + name;
  476. if (IsExist(newFolder, false))
  477. {
  478. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder with the same name already exist.");
  479. return;
  480. }
  481. if (newFolder.Length > 200)
  482. {
  483. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder name too long, should be less 200.");
  484. return;
  485. }
  486. _recipeProvider.CreateRecipeFolder(prefix, newFolder);
  487. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, newFolder, true);
  488. }
  489. public void NewFolderRoot()
  490. {
  491. if (IsChanged)
  492. {
  493. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  494. if (selection == DialogButton.Cancel)
  495. return;
  496. if (selection == DialogButton.Yes)
  497. {
  498. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  499. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  500. this.CurrentRecipe.RecipeLevel = this.LevelDisplay;
  501. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  502. }
  503. }
  504. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType);
  505. dialog.FileName = "new folder";
  506. WindowManager wm = new WindowManager();
  507. bool? dialogReturn = wm.ShowDialog(dialog);
  508. if (!dialogReturn.HasValue || !dialogReturn.Value)
  509. return;
  510. string name = dialog.FileName.Trim();
  511. if (string.IsNullOrEmpty(name))
  512. {
  513. DialogBox.ShowWarning("Folder name should not be empty");
  514. return;
  515. }
  516. if (IsExist(name, false))
  517. {
  518. DialogBox.ShowWarning($"Can not create folder {name}, Folder with the same name already exist.");
  519. return;
  520. }
  521. if (name.Length > 200)
  522. {
  523. DialogBox.ShowWarning($"Can not create folder {name}, Folder name too long, should be less 200.");
  524. return;
  525. }
  526. string prefix = ChamberType[ChamberTypeIndexSelection] + "\\" + ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  527. _recipeProvider.CreateRecipeFolder(prefix, name);
  528. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, name, true);
  529. }
  530. public void DeleteFolder()
  531. {
  532. if (CurrentFileNode == null || CurrentFileNode.IsFile)
  533. return;
  534. if (CurrentFileNode.Files.Count > 0)
  535. {
  536. DialogBox.ShowWarning($"Can not delete non-empty folder, Remove the files or folders under \r\n{CurrentFileNode.FullPath}.");
  537. return;
  538. }
  539. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  540. $"Are you sure you want to delete \r\n {CurrentFileNode.FullPath}?");
  541. if (selection == DialogButton.No)
  542. return;
  543. string nextFocus = CurrentFileNode.Parent.FullPath;
  544. bool isFolder = true;
  545. if (CurrentFileNode.Parent.Files.Count > 1)
  546. {
  547. for (int i = 0; i < CurrentFileNode.Parent.Files.Count; i++)
  548. {
  549. if (CurrentFileNode.Parent.Files[i] == CurrentFileNode)
  550. {
  551. if (i == 0)
  552. {
  553. nextFocus = CurrentFileNode.Parent.Files[i + 1].FullPath;
  554. isFolder = !CurrentFileNode.Parent.Files[i + 1].IsFile;
  555. }
  556. else
  557. {
  558. nextFocus = CurrentFileNode.Parent.Files[i - 1].FullPath;
  559. isFolder = !CurrentFileNode.Parent.Files[i - 1].IsFile;
  560. }
  561. }
  562. }
  563. }
  564. _recipeProvider.DeleteRecipeFolder(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath);
  565. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, nextFocus, isFolder);
  566. }
  567. public void RenameFolder()
  568. {
  569. if (CurrentFileNode == null || CurrentFileNode.IsFile)
  570. return;
  571. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType, "", Visibility.Hidden);
  572. dialog.FileName = CurrentFileNode.Name;
  573. WindowManager wm = new WindowManager();
  574. bool? dialogReturn = wm.ShowDialog(dialog);
  575. if (!dialogReturn.HasValue || !dialogReturn.Value)
  576. return;
  577. string name = dialog.FileName.Trim();
  578. if (string.IsNullOrEmpty(name))
  579. return;
  580. string newFolder = CurrentFileNode.FullPath.Substring(0, CurrentFileNode.FullPath.LastIndexOf("\\") + 1);
  581. if (!string.IsNullOrEmpty(newFolder))
  582. newFolder = newFolder + name;
  583. else
  584. newFolder = name;
  585. if (newFolder == CurrentFileNode.FullPath)
  586. return;
  587. if (IsExist(newFolder, false))
  588. {
  589. DialogBox.ShowWarning($"Can not rename to {newFolder}, Folder with the same name already exist.");
  590. return;
  591. }
  592. if (newFolder.Length > 200)
  593. {
  594. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder name too long, should be less 200.");
  595. return;
  596. }
  597. _recipeProvider.RenameFolder(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath, newFolder);
  598. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, newFolder, true);
  599. }
  600. #endregion
  601. #region recipe
  602. public void NewRecipe()
  603. {
  604. if (IsChanged)
  605. {
  606. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  607. if (selection == DialogButton.Cancel)
  608. return;
  609. if (selection == DialogButton.Yes)
  610. {
  611. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  612. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  613. this.CurrentRecipe.RecipeLevel = this.LevelDisplay;
  614. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  615. }
  616. }
  617. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description);
  618. dialog.FileName = (string)QueryDataClient.Instance.Service.GetConfig($"System.Recipe.DefaultJobRecipeName");
  619. WindowManager wm = new WindowManager();
  620. bool? dialogReturn = wm.ShowDialog(dialog);
  621. if (!dialogReturn.HasValue || !dialogReturn.Value)
  622. return;
  623. string recipeName = dialog.FileName.Trim();
  624. string filepath = dialog.FilePath;
  625. string description = dialog.Comment;
  626. if (string.IsNullOrEmpty(dialog.FileName))
  627. {
  628. DialogBox.ShowWarning("Recipe file name should not be empty");
  629. return;
  630. }
  631. string prefix = CurrentChamberType + "\\" + CurrentProcessType + "\\" + filepath;
  632. if (CurrentFileNode != null)
  633. {
  634. if (CurrentFileNode.IsFile)
  635. {
  636. filepath = filepath.Substring(0, filepath.LastIndexOf("\\") + 1);
  637. //if (!string.IsNullOrEmpty(folder))
  638. // folder = folder;
  639. }
  640. else
  641. {
  642. filepath = filepath + "\\";
  643. }
  644. }
  645. if (IsExist(recipeName.ToLower(), true))
  646. {
  647. DialogBox.ShowWarning($"Can not create {recipeName}, Recipe with the same name already exist.");
  648. return;
  649. }
  650. if ((prefix + recipeName).Length > 200)
  651. {
  652. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  653. return;
  654. }
  655. RecipeDataBase recipe = new RecipeDataBase();
  656. recipe.Name = recipeName;
  657. recipe.PrefixPath = prefix;
  658. recipe.Creator = BaseApp.Instance.UserContext.LoginName;
  659. recipe.CreateTime = DateTime.Now;
  660. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  661. recipe.ReviseTime = DateTime.Now;
  662. recipe.Description = description;
  663. recipe.RecipeLevel = LevelDisplay;
  664. recipe.RecipePermission = "Free";
  665. if (!Save(recipe, true))
  666. return;
  667. var types = prefix.Split('\\');
  668. ReloadRecipeFileList(types[0], types[1], recipeName, false);
  669. }
  670. public void NewRecipeRoot()
  671. {
  672. if (IsChanged)
  673. {
  674. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  675. if (selection == DialogButton.Cancel)
  676. return;
  677. if (selection == DialogButton.Yes)
  678. {
  679. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  680. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  681. this.CurrentRecipe.RecipeLevel = this.LevelDisplay;
  682. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  683. }
  684. }
  685. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description);
  686. dialog.FileName = "new recipe";
  687. WindowManager wm = new WindowManager();
  688. bool? dialogReturn = wm.ShowDialog(dialog);
  689. if (!dialogReturn.HasValue || !dialogReturn.Value)
  690. return;
  691. string recipeName = dialog.FileName.Trim();
  692. string description = dialog.Comment;
  693. if (string.IsNullOrEmpty(dialog.FileName))
  694. {
  695. DialogBox.ShowWarning("Recipe file name should not be empty");
  696. return;
  697. }
  698. if (IsExist(recipeName, true))
  699. {
  700. DialogBox.ShowWarning($"Can not create {recipeName}, Recipe with the same name already exist.");
  701. return;
  702. }
  703. if (recipeName.Length > 200)
  704. {
  705. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  706. return;
  707. }
  708. RecipeDataBase recipe = new RecipeDataBase();
  709. recipe.Name = recipeName;
  710. recipe.PrefixPath = CurrentChamberType + "\\" + CurrentProcessType;
  711. recipe.Creator = BaseApp.Instance.UserContext.LoginName;
  712. recipe.CreateTime = DateTime.Now;
  713. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  714. recipe.ReviseTime = DateTime.Now;
  715. recipe.Description = description;
  716. recipe.RecipeLevel = LevelDisplay;
  717. recipe.RecipePermission = "Free";
  718. if (!Save(recipe, true))
  719. return;
  720. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  721. }
  722. private void ReloadRecipeFileList(string chamberType, string processType, string selectedFile, bool selectionIsFolder)
  723. {
  724. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == processType);
  725. if (item == null)
  726. {
  727. LOG.Write("error reload recipe file list, type = " + processType);
  728. }
  729. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}";
  730. var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  731. item.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  732. InitialPathFlag(item.FileListByProcessType);
  733. item.InvokePropertyChanged();
  734. }
  735. private bool IsExist(string fullPath, bool isFile)
  736. {
  737. for (int i = 0; i < ProcessTypeFileList.Count; i++)
  738. {
  739. if (ProcessTypeFileList[i].ProcessType == CurrentProcessType)
  740. {
  741. if (ProcessTypeFileList[i].FileListByProcessType.Count == 0)
  742. return false;
  743. return FindFile(fullPath, ProcessTypeFileList[i].FileListByProcessType[0].Parent, isFile);
  744. }
  745. }
  746. return true;
  747. }
  748. private bool FindFile(string path, FileNode root, bool isFile)
  749. {
  750. if (root.FullPath.ToLower() == path && !isFile)
  751. {
  752. return true;
  753. }
  754. foreach (var node in root.Files)
  755. {
  756. if (isFile && node.IsFile && node.FullPath.ToLower() == path)
  757. return true;
  758. if (!node.IsFile && FindFile(path, node, isFile))
  759. return true;
  760. }
  761. return false;
  762. }
  763. public void SaveAsRecipe()
  764. {
  765. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  766. return;
  767. if (IsChanged)
  768. {
  769. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  770. if (selection == DialogButton.Cancel)
  771. return;
  772. if (selection == DialogButton.Yes)
  773. {
  774. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  775. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  776. this.CurrentRecipe.RecipeLevel = this.LevelDisplay;
  777. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  778. }
  779. }
  780. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType);
  781. dialog.FileName = CurrentFileNode.Name;
  782. WindowManager wm = new WindowManager();
  783. bool? dialogReturn = wm.ShowDialog(dialog);
  784. if (!dialogReturn.HasValue || !dialogReturn.Value)
  785. return;
  786. string recipeName = dialog.FileName.Trim();
  787. string filepath = dialog.FilePath;
  788. FileNode selectNode = dialog.SelectNode;
  789. if (string.IsNullOrEmpty(dialog.FileName))
  790. {
  791. DialogBox.ShowWarning("Recipe file name should not be empty");
  792. return;
  793. }
  794. string prefix = CurrentChamberType + "\\" + CurrentProcessType;// + "\\" + filepath;
  795. string processType = string.Empty;
  796. // string folder = CurrentFileNode.FullPath;
  797. // string folder = filepath.Substring(filepath.LastIndexOf("\\") + 1);
  798. string folder = filepath.Replace($"{prefix}\\", "");
  799. //if (!string.IsNullOrEmpty(folder))
  800. // recipeName = folder + "\\" + recipeName;
  801. // var newPrefix = GetPrefix(CurrentChamberType + "\\" + CurrentProcessType, selectNode);
  802. if (!string.IsNullOrEmpty(folder))
  803. {
  804. recipeName = $"{folder}\\{recipeName}";
  805. }
  806. if (IsExist(prefix + "\\" + recipeName, true))
  807. {
  808. DialogBox.ShowWarning($"Can not copy to {recipeName}, Recipe with the same name already exist.");
  809. return;
  810. }
  811. if (recipeName.Length > 200)
  812. {
  813. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  814. return;
  815. }
  816. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  817. CurrentRecipe.CreateTime = DateTime.Now.ToString();
  818. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString();
  819. CurrentRecipe.Description = CurrentRecipe.Description + ". Renamed from " + CurrentFileNode.Name;
  820. CurrentRecipe.CreateTime = DateTime.Now.ToString();
  821. // CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  822. // CurrentRecipe.ReviseTime = DateTime.Now.ToString();
  823. CurrentRecipe.Description = CurrentRecipe.Description + ". Renamed from " + CurrentFileNode.Name;
  824. _recipeProvider.SaveAsRecipe(prefix, recipeName, CurrentRecipe.GetXmlString());
  825. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  826. // string recipeName = dialog.FileName.Trim();
  827. // string filepath = dialog.FilePath;
  828. // if (string.IsNullOrEmpty(dialog.FileName))
  829. // {
  830. // DialogBox.ShowWarning("Recipe file name should not be empty");
  831. // return;
  832. // }
  833. // string prefix = CurrentChamberType + "\\" + CurrentProcessType + "\\" + filepath;
  834. // string processType = string.Empty;
  835. // string folder = CurrentFileNode.FullPath;
  836. // if (CurrentFileNode.IsFile)
  837. // {
  838. // folder = folder.Substring(0, folder.LastIndexOf("\\") + 1);
  839. // }
  840. // if (!string.IsNullOrEmpty(folder))
  841. // recipeName = folder + "\\" + recipeName;
  842. // if (CurrentFileNode.FullPath == recipeName)
  843. // return;
  844. // if (IsExist(recipeName, true))
  845. // {
  846. // DialogBox.ShowWarning($"Can not copy to {recipeName}, Recipe with the same name already exist.");
  847. // return;
  848. // }
  849. // if (recipeName.Length > 200)
  850. // {
  851. // DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  852. // return;
  853. // }
  854. //// CurrentRecipe.Creator = BaseApp.Instance.UserContext.LoginName;
  855. // CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  856. // CurrentRecipe.CreateTime = DateTime.Now.ToString();
  857. // // CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  858. // CurrentRecipe.LastRevisionTime = DateTime.Now.ToString();
  859. // CurrentRecipe.Description = CurrentRecipe.Description + ". Renamed from " + CurrentFileNode.Name;
  860. // _recipeProvider.SaveAsRecipe(prefix, recipeName, CurrentRecipe.GetXmlString());
  861. // ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  862. }
  863. public void RenameRecipe()
  864. {
  865. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  866. return;
  867. if (IsChanged)
  868. {
  869. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  870. if (selection == DialogButton.Cancel)
  871. return;
  872. if (selection == DialogButton.Yes)
  873. {
  874. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  875. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  876. this.CurrentRecipe.RecipeLevel = this.LevelDisplay;
  877. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  878. }
  879. }
  880. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description, Visibility.Hidden);
  881. dialog.FileName = CurrentFileNode.Name;
  882. WindowManager wm = new WindowManager();
  883. bool? dialogReturn = wm.ShowDialog(dialog);
  884. if (!dialogReturn.HasValue || !dialogReturn.Value)
  885. return;
  886. string recipeName = dialog.FileName.Trim();
  887. if (string.IsNullOrEmpty(dialog.FileName))
  888. {
  889. DialogBox.ShowWarning("Recipe file name should not be empty");
  890. return;
  891. }
  892. string prefix = CurrentChamberType + "\\" + CurrentProcessType;
  893. string processType = string.Empty;
  894. string newName = CurrentFileNode.FullPath.Substring(0, CurrentFileNode.FullPath.LastIndexOf("\\") + 1);
  895. if (!string.IsNullOrEmpty(newName))
  896. newName = newName + recipeName;
  897. else
  898. newName = recipeName;
  899. if (newName == CurrentFileNode.FullPath)
  900. return;
  901. if (IsExist(newName.ToLower(), true))
  902. {
  903. DialogBox.ShowWarning($"Can not rename to {newName}, Recipe with the same name already exist.");
  904. return;
  905. }
  906. if (newName.Length > 200)
  907. {
  908. DialogBox.ShowWarning($"Can not create folder {newName}, Folder name too long, should be less 200.");
  909. return;
  910. }
  911. CurrentRecipeJob.RecipeChamberType = "OriginChamber";
  912. var recipeContent = _recipeProvider.LoadRecipe(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath);
  913. CurrentRecipeJob.InitData(CurrentRecipe.PrefixPath, CurrentRecipe.Name, recipeContent, "PM1");
  914. _recipeProvider.RenameRecipe(prefix, CurrentFileNode.FullPath, newName);
  915. CurrentRecipeJob.Name = dialog.FileName;
  916. CurrentRecipeJob.Description = dialog.Comment;
  917. CurrentRecipeJob.RecipeLevel = CurrentFileNode.Level;
  918. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, newName, CurrentRecipeJob.GetXmlString());
  919. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, newName, false);
  920. }
  921. private void LoadData()
  922. {
  923. // CurrentRecipe.InitData(CurrentRecipe.PrefixPath, CurrentRecipe.Name, recipeContent, "PM1");
  924. //if (SystemConfigProvider.Instance.GetValueByName($"PM1.RecipeEditParameter.CoolTime.{CurrentRecipe.CoolTime}").Length > 0)
  925. // CoolTime = CurrentRecipe.CoolTime + ":" + SystemConfigProvider.Instance.GetValueByName($"PM1.RecipeEditParameter.CoolTime.{CurrentRecipe.CoolTime}");
  926. //else
  927. // CoolTime = "Value:" + CurrentRecipe.CoolTime;
  928. }
  929. public void DeleteRecipe()
  930. {
  931. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  932. return;
  933. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  934. $"Are you sure you want to delete \r\n {CurrentFileNode.FullPath}?");
  935. if (selection == DialogButton.No)
  936. return;
  937. string nextFocus = CurrentFileNode.Parent.FullPath;
  938. bool isFolder = true;
  939. if (CurrentFileNode.Parent.Files.Count > 1)
  940. {
  941. for (int i = 0; i < CurrentFileNode.Parent.Files.Count; i++)
  942. {
  943. if (CurrentFileNode.Parent.Files[i] == CurrentFileNode)
  944. {
  945. if (i == 0)
  946. {
  947. nextFocus = CurrentFileNode.Parent.Files[i + 1].FullPath;
  948. isFolder = !CurrentFileNode.Parent.Files[i + 1].IsFile;
  949. }
  950. else
  951. {
  952. nextFocus = CurrentFileNode.Parent.Files[i - 1].FullPath;
  953. isFolder = !CurrentFileNode.Parent.Files[i - 1].IsFile;
  954. }
  955. }
  956. }
  957. }
  958. _recipeProvider.DeleteRecipe(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath);
  959. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, nextFocus, isFolder);
  960. }
  961. public void ReloadRecipe()
  962. {
  963. if (this.editMode == EditMode.Normal || this.editMode == EditMode.Edit)
  964. {
  965. this.LoadData(CurrentRecipe.PrefixPath, CurrentRecipe.Name);
  966. this.UpdateView();
  967. }
  968. }
  969. public void ViewRecipe()
  970. {
  971. CGlobal.RecipeJobEditViewEnable = false;
  972. PopupPage();
  973. }
  974. public void EditRecipe()
  975. {
  976. CGlobal.RecipeJobEditViewEnable = true;
  977. bool? isSave= PopupPage();
  978. CurrentFileNode.IsChecked = true;
  979. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, CurrentFileNode.FullPath, false);
  980. if (isSave == true && CurrentFileNode.IsVisiable != Visibility.Hidden)
  981. {
  982. CurrentFileNode.IsVisiable = Visibility.Hidden;
  983. if(UIGlobalVariable.Instance.ProcessModifiedRecipe.ContainsKey(CurrentRecipe.ProcessRecipe))
  984. UIGlobalVariable.Instance.ProcessModifiedRecipe.Remove(CurrentRecipe.ProcessRecipe);
  985. if (UIGlobalVariable.Instance.LayoutModifiedRecipe.ContainsKey(CurrentRecipe.LayoutRecipe))
  986. UIGlobalVariable.Instance.LayoutModifiedRecipe.Remove(CurrentRecipe.LayoutRecipe);
  987. }
  988. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, CurrentFileNode.FullPath, false);
  989. this.UpdateView();
  990. }
  991. public void SavePermission()
  992. {
  993. RecipePermissionSelectViewModel dialog = new RecipePermissionSelectViewModel("Save recipe and permission", CurrentFileNode.Permission, CurrentRecipe.Description);
  994. WindowManager wm = new WindowManager();
  995. bool? dialogReturn = wm.ShowDialog(dialog);
  996. if (!dialogReturn.HasValue || !dialogReturn.Value)
  997. return;
  998. CurrentRecipe.RecipePermission = dialog.RecipePermission;
  999. CurrentRecipe.Description = dialog.Comment;
  1000. // this.Save(CurrentRecipe, false);
  1001. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  1002. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, CurrentFileNode.FullPath, false);
  1003. }
  1004. #endregion
  1005. #region Steps
  1006. public void SaveRecipe()
  1007. {
  1008. if (this.IsChanged)
  1009. {
  1010. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  1011. }
  1012. }
  1013. public bool Save(RecipeDataBase recipe, bool createNew)
  1014. {
  1015. bool result = false;
  1016. if (string.IsNullOrEmpty(recipe.Name))
  1017. {
  1018. MessageBox.Show("Recipe name can't be empty");
  1019. return false;
  1020. }
  1021. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1022. recipe.ReviseTime = DateTime.Now;
  1023. result = this._recipeProvider.SaveRecipe(recipe.PrefixPath, recipe.Name, recipe.GetXmlString());
  1024. if (result)
  1025. {
  1026. this.editMode = EditMode.Normal;
  1027. this.UpdateView();
  1028. }
  1029. else
  1030. {
  1031. MessageBox.Show("Save failed!");
  1032. }
  1033. return result;
  1034. }
  1035. private TreeViewItem GetParentObjectEx<TreeViewItem>(DependencyObject obj) where TreeViewItem : FrameworkElement
  1036. {
  1037. DependencyObject parent = VisualTreeHelper.GetParent(obj);
  1038. while (parent != null)
  1039. {
  1040. if (parent is TreeViewItem)
  1041. {
  1042. return (TreeViewItem)parent;
  1043. }
  1044. parent = VisualTreeHelper.GetParent(parent);
  1045. }
  1046. return null;
  1047. }
  1048. public void TreeRightMouseDown(MouseButtonEventArgs e)
  1049. {
  1050. var item = GetParentObjectEx<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
  1051. if (item != null)
  1052. {
  1053. item.Focus();
  1054. }
  1055. }
  1056. #endregion
  1057. private void ClearData()
  1058. {
  1059. this.editMode = EditMode.None;
  1060. this.CurrentRecipe.Clear();
  1061. this.CurrentRecipe.Name = string.Empty;
  1062. this.CurrentRecipe.Description = string.Empty;
  1063. }
  1064. private void LoadData(string prefixPath, string recipeName)
  1065. {
  1066. CurrentRecipe.Clear();
  1067. var recipeContent = _recipeProvider.LoadRecipe(prefixPath, recipeName);
  1068. if (string.IsNullOrEmpty(recipeContent))
  1069. {
  1070. MessageBox.Show($"{prefixPath}\\{recipeName} is empty, please confirm the file is valid.");
  1071. return;
  1072. }
  1073. // CurrentRecipe.RecipeChamberType = "OriginChamber";
  1074. CurrentRecipe.RecipeVersion = _columnBuilder.RecipeVersion;
  1075. CurrentRecipe.RecipeChamberType = "OriginChamber";
  1076. CurrentRecipe.PrefixPath = prefixPath;
  1077. CurrentRecipe.Name = recipeName;
  1078. CurrentRecipe.InitData(CurrentRecipe.PrefixPath, CurrentRecipe.Name, recipeContent, "PM1");
  1079. // CurrentRecipe.InitData(prefixPath, recipeName, recipeContent, SelectedChamber);
  1080. this.editMode = EditMode.Normal;
  1081. }
  1082. private RecipeDataJob GetJob(string prefixPath, string recipeName)
  1083. {
  1084. RecipeDataJob job=new RecipeDataJob();
  1085. var recipeContent = _recipeProvider.LoadRecipe(prefixPath, recipeName);
  1086. if (string.IsNullOrEmpty(recipeContent))
  1087. {
  1088. MessageBox.Show($"{prefixPath}\\{recipeName} is empty, please confirm the file is valid.");
  1089. return null;
  1090. }
  1091. job.RecipeVersion = _columnBuilder.RecipeVersion;
  1092. job.RecipeChamberType = "OriginChamber";
  1093. job.PrefixPath = prefixPath;
  1094. job.Name = recipeName;
  1095. job.InitData(prefixPath, job.Name, recipeContent, "PM1");
  1096. return job;
  1097. }
  1098. private void UpdateView()
  1099. {
  1100. bool isFileSelected = CurrentFileNode != null && CurrentFileNode.IsFile;
  1101. this.NotifyOfPropertyChange("CurrentRecipe");
  1102. }
  1103. private bool? PopupPage()
  1104. {
  1105. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1106. return null;
  1107. var windowManager = IoC.Get<IWindowManager>();
  1108. if (string.IsNullOrEmpty(CurrentRecipe.PrefixPath))
  1109. {
  1110. DialogBox.ShowWarning("Please select a file first");
  1111. return null;
  1112. }
  1113. RecipeJobEditViewModel recipeJobEditViewModel = new RecipeJobEditViewModel(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentFileNode.Permission);
  1114. recipeJobEditViewModel.SelectRecipeType = SelectLayoutRecipeType;
  1115. return(windowManager as WindowManager)?.ShowDialogWithTitle(recipeJobEditViewModel, null, "Job Recipe Edit");
  1116. }
  1117. }
  1118. }