RecipeLayoutViewModel.cs 65 KB

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