RecipeJobViewModel.cs 67 KB

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