RecipeLayoutViewModel.cs 68 KB

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