RecipeJobViewModel.cs 66 KB

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