RecipeLayoutViewModel.cs 66 KB

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