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. ProcessTypeFileList[0].FileListByProcessType.ForEachDo(a =>
  495. {
  496. a.IsSelected = false;
  497. if (a.Name == node.Name)
  498. {
  499. a.IsSelected = true;
  500. a.Files.ForEachDo(e => e.IsSelected = false);
  501. return;
  502. }
  503. });
  504. RecipeFileList = RecipeSequenceTreeBuilder.GetFileNodeParameterList(node.FullPath).ToList();
  505. }
  506. CurrentFileNode = node;
  507. IsFreePermission = true;
  508. IsReadAndWritePermission = true;
  509. NotifyOfPropertyChange(nameof(IsCurrentNodeFile));
  510. NotifyOfPropertyChange(nameof(IsCurrentNodePath));
  511. NotifyOfPropertyChange(nameof(IsSelectPermission));
  512. NotifyOfPropertyChange(nameof(IsSingleSelectPermission));
  513. NotifyOfPropertyChange(nameof(IsEnabledFolderPermission));
  514. if (node != null && node.IsFile)
  515. {
  516. if (CurrentRecipe != null)
  517. {
  518. CurrentRecipe.Name = node.Name;
  519. CurrentRecipe.PrefixPath = node.PrefixPath;
  520. }
  521. // this.LoadData(node.PrefixPath, node.FullPath);
  522. }
  523. else
  524. {
  525. this.ClearData();
  526. this.editMode = EditMode.None;
  527. }
  528. this.UpdateView();
  529. GetIsEnabledNewRecipe();
  530. }
  531. private void GetIsEnabledNewRecipe()
  532. {
  533. if (!IsSingleFile && ProcessTypeFileList != null && ProcessTypeFileList.FirstOrDefault() != null && ProcessTypeFileList.FirstOrDefault().FileListByProcessType != null && ProcessTypeFileList.FirstOrDefault().FileListByProcessType.Count > 0)
  534. {
  535. IsEnabledNewRecipe = true;
  536. }
  537. else
  538. {
  539. IsEnabledNewRecipe = false;
  540. }
  541. }
  542. #region folder
  543. public void SelectRecipeType()
  544. {
  545. var windowManager = IoC.Get<IWindowManager>();
  546. RecipeSelectRecipeTypeViewModel recipeSelectRecipeTypeViewModel = new RecipeSelectRecipeTypeViewModel();
  547. (windowManager as WindowManager)?.ShowDialogWithTitle(recipeSelectRecipeTypeViewModel, null, "Select Recipe Type");
  548. if (recipeSelectRecipeTypeViewModel.SelectRecipeType != null)
  549. {
  550. var selectRecipeType = recipeSelectRecipeTypeViewModel.SelectRecipeType;
  551. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{selectRecipeType}");
  552. if (processType == null)
  553. {
  554. processType = selectRecipeType;
  555. }
  556. ProcessTypeFileList = new List<ProcessTypeFileItem>();
  557. string[] recipeProcessType = ((string)processType).Split(',');
  558. for (int i = 0; i < recipeProcessType.Length; i++)
  559. {
  560. var type = new ProcessTypeFileItem();
  561. type.ProcessType = recipeProcessType[i];
  562. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{recipeProcessType[i]}";
  563. // var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  564. type.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefix);// RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  565. ProcessTypeFileList.Add(type);
  566. }
  567. SelectRecipeTypeName = processType + " Recipe";
  568. this.NotifyOfPropertyChange("ProcessTypeFileList");
  569. if (ProcessTypeFileList[0].FileListByProcessType.Count > 0)
  570. CurrentFileNode = ProcessTypeFileList[0].FileListByProcessType[ProcessTypeFileList[0].FileListByProcessType.Count - 1];
  571. NotifyOfPropertyChange(nameof(IsCurrentNodeFile));
  572. NotifyOfPropertyChange(nameof(IsCurrentNodePath));
  573. NotifyOfPropertyChange(nameof(IsSelectPermission));
  574. NotifyOfPropertyChange(nameof(IsReadAndWritePermission));
  575. // NotifyOfPropertyChange(nameof(IsFreePermission));
  576. ProcessTypeIndexSelection = 0;
  577. }
  578. }
  579. public void NewFolder()
  580. {
  581. if (IsChanged)
  582. {
  583. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  584. if (selection == DialogButton.Cancel)
  585. return;
  586. if (selection == DialogButton.Yes)
  587. {
  588. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  589. this.CurrentRecipe.ReviseTime = DateTime.Now;
  590. // this.Save(this.CurrentRecipe, false);
  591. }
  592. }
  593. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType, "", Visibility.Visible, Visibility.Collapsed);
  594. // dialog.FileName = "new folder";
  595. WindowManager wm = new WindowManager();
  596. bool? dialogReturn = wm.ShowDialog(dialog);
  597. if (!dialogReturn.HasValue || !dialogReturn.Value)
  598. return;
  599. if (string.IsNullOrWhiteSpace(dialog.FileName))
  600. {
  601. DialogBox.ShowWarning("Folder name should not be empty");
  602. }
  603. else
  604. {
  605. string name = dialog.FileName.Trim();
  606. FileNode selectNode = dialog.SelectNode;
  607. string prefix = ChamberType[ChamberTypeIndexSelection] + "\\" + ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  608. string newFolder = string.Empty;
  609. string folder = string.Empty;
  610. if (selectNode != null)
  611. {
  612. prefix = selectNode.PrefixPath;
  613. folder = selectNode.FullPath.Replace($"{prefix}\\", "");
  614. newFolder = $"{folder}\\{name}";
  615. }
  616. else
  617. {
  618. newFolder = name;
  619. }
  620. if (IsExist(newFolder, false))
  621. {
  622. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder with the same name already exist.");
  623. return;
  624. }
  625. if (newFolder.Length > 200)
  626. {
  627. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder name too long, should be less 200.");
  628. return;
  629. }
  630. prefix = GetPrefix(prefix, selectNode);
  631. _recipeProvider.CreateRecipeFolder(prefix, name);
  632. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  633. if (item == null)
  634. {
  635. LOG.Write("error reload recipe file list, type = " + CurrentProcessType);
  636. }
  637. //var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  638. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  639. FindSelectedFile(item.FileListByProcessType, $"{prefix}\\{newFolder}");
  640. item.InvokePropertyChanged();
  641. TreeSelectChanged(CurrentFileNode);
  642. }
  643. }
  644. private string GetPrefix(string prefix, FileNode CurrentFileNode)
  645. {
  646. string temppreFix = prefix;
  647. if (CurrentFileNode != null)
  648. {
  649. if (string.IsNullOrEmpty(CurrentFileNode.AllParentPath))
  650. {
  651. if (CurrentFileNode.IsFile)
  652. {
  653. return temppreFix;
  654. }
  655. else
  656. {
  657. temppreFix = CurrentFileNode.FullPath;
  658. }
  659. }
  660. else
  661. {
  662. if (CurrentFileNode.IsFile)
  663. {
  664. if (temppreFix.EndsWith("\\"))
  665. {
  666. temppreFix = $"{temppreFix}{CurrentFileNode.AllParentPath}";
  667. }
  668. else
  669. {
  670. temppreFix = $"{temppreFix}\\{CurrentFileNode.AllParentPath}";
  671. }
  672. }
  673. else
  674. {
  675. temppreFix = $"{temppreFix}\\{CurrentFileNode.AllParentPath}\\{CurrentFileNode.Name}";
  676. }
  677. }
  678. }
  679. return temppreFix;
  680. }
  681. public void NewFolderRoot()
  682. {
  683. if (IsChanged)
  684. {
  685. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  686. if (selection == DialogButton.Cancel)
  687. return;
  688. if (selection == DialogButton.Yes)
  689. {
  690. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  691. this.CurrentRecipe.ReviseTime = DateTime.Now;
  692. // this.Save(this.CurrentRecipe, false);
  693. }
  694. }
  695. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType);
  696. dialog.FileName = "new folder";
  697. WindowManager wm = new WindowManager();
  698. bool? dialogReturn = wm.ShowDialog(dialog);
  699. if (!dialogReturn.HasValue || !dialogReturn.Value)
  700. return;
  701. string name = dialog.FileName.Trim();
  702. if (string.IsNullOrEmpty(name))
  703. {
  704. DialogBox.ShowWarning("Folder name should not be empty");
  705. return;
  706. }
  707. if (IsExist(name, false))
  708. {
  709. DialogBox.ShowWarning($"Can not create folder {name}, Folder with the same name already exist.");
  710. return;
  711. }
  712. if (name.Length > 200)
  713. {
  714. DialogBox.ShowWarning($"Can not create folder {name}, Folder name too long, should be less 200.");
  715. return;
  716. }
  717. string prefix = ChamberType[ChamberTypeIndexSelection] + "\\" + ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  718. _recipeProvider.CreateRecipeFolder(prefix, name);
  719. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, name, true);
  720. }
  721. public void DeleteFolder()
  722. {
  723. if (CurrentFileNode == null || CurrentFileNode.IsFile)
  724. return;
  725. if (CurrentFileNode.Files.Count > 0)
  726. {
  727. DialogBox.ShowWarning($"Can not delete non-empty folder, Remove the files or folders under \r\n{CurrentFileNode.FullPath}.");
  728. return;
  729. }
  730. var prefix = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  731. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  732. $"Are you sure you want to delete \r\n {prefix}?");
  733. if (selection == DialogButton.No)
  734. return;
  735. //string nextFocus = CurrentFileNode.Parent.FullPath;
  736. //bool isFolder = true;
  737. //if (CurrentFileNode.Parent!=null&&CurrentFileNode.Parent.Files.Count > 1)
  738. //{
  739. // for (int i = 0; i < CurrentFileNode.Parent.Files.Count; i++)
  740. // {
  741. // if (CurrentFileNode.Parent.Files[i] == CurrentFileNode)
  742. // {
  743. // if (i == 0)
  744. // {
  745. // nextFocus = CurrentFileNode.Parent.Files[i + 1].FullPath;
  746. // isFolder = !CurrentFileNode.Parent.Files[i + 1].IsFile;
  747. // }
  748. // else
  749. // {
  750. // nextFocus = CurrentFileNode.Parent.Files[i - 1].FullPath;
  751. // isFolder = !CurrentFileNode.Parent.Files[i - 1].IsFile;
  752. // }
  753. // }
  754. // }
  755. //}
  756. prefix = prefix.Replace($"\\{CurrentFileNode.Name}", "");
  757. _recipeProvider.DeleteRecipeFolder(prefix, CurrentFileNode.Name);
  758. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, "", false, true);
  759. GetIsEnabledNewRecipe();
  760. }
  761. public void RenameFolder()
  762. {
  763. if (CurrentFileNode == null || CurrentFileNode.IsFile)
  764. return;
  765. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType, "", Visibility.Hidden, Visibility.Collapsed);
  766. dialog.FileName = CurrentFileNode.Name;
  767. WindowManager wm = new WindowManager();
  768. bool? dialogReturn = wm.ShowDialog(dialog);
  769. if (!dialogReturn.HasValue || !dialogReturn.Value)
  770. return;
  771. string name = dialog.FileName.Trim();
  772. if (string.IsNullOrEmpty(name))
  773. return;
  774. string newFolder = CurrentFileNode.FullPath.Substring(0, CurrentFileNode.FullPath.LastIndexOf("\\") + 1);
  775. if (!string.IsNullOrEmpty(newFolder))
  776. newFolder = newFolder + name;
  777. else
  778. newFolder = name;
  779. if (newFolder == CurrentFileNode.FullPath)
  780. return;
  781. if (IsExist(newFolder, false))
  782. {
  783. DialogBox.ShowWarning($"Can not rename to {newFolder}, Folder with the same name already exist.");
  784. return;
  785. }
  786. if (newFolder.Length > 200)
  787. {
  788. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder name too long, should be less 200.");
  789. return;
  790. }
  791. if (_recipeProvider.RenameFolder(CurrentFileNode.PrefixPath, CurrentFileNode.Name, name))
  792. {
  793. foreach (var node in CurrentFileNode.Files)
  794. {
  795. UIGlobalVariable.Instance.ProcessModifiedRecipe[node.FullPath] = $"Folder Rename from [{CurrentFileNode.FullPath}] to [{name}] {DateTime.Now}";
  796. }
  797. }
  798. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, name, true, true);
  799. }
  800. #endregion
  801. #region recipe
  802. public void NewRecipe()
  803. {
  804. if (IsChanged)
  805. {
  806. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  807. if (selection == DialogButton.Cancel)
  808. return;
  809. if (selection == DialogButton.Yes)
  810. {
  811. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  812. this.CurrentRecipe.ReviseTime = DateTime.Now;
  813. this.Save(this.CurrentRecipe, false);
  814. }
  815. }
  816. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, "");
  817. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  818. //dialog.FileName = (string)QueryDataClient.Instance.Service.GetConfig($"System.Recipe.DefaultProcessRecipeName");
  819. WindowManager wm = new WindowManager();
  820. bool? dialogReturn = wm.ShowDialog(dialog);
  821. if (!dialogReturn.HasValue || !dialogReturn.Value)
  822. return;
  823. if (string.IsNullOrEmpty(dialog.FileName))
  824. {
  825. DialogBox.ShowWarning("Recipe file name should not be empty");
  826. return;
  827. }
  828. string recipeName = dialog.FileName.Trim();
  829. string filepath = dialog.FilePath;
  830. string description = dialog.Comment;
  831. string prefix;
  832. if (filepath.Contains("\\"))
  833. {
  834. prefix = filepath;
  835. }
  836. else
  837. {
  838. prefix = CurrentChamberType + "\\" + CurrentProcessType + "\\" + filepath;
  839. if (CurrentFileNode != null)
  840. {
  841. //获取目录
  842. prefix = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  843. }
  844. }
  845. if (RecipeFileList != null && RecipeFileList.Find(a => a.Name == recipeName.ToLower()) != null)
  846. {
  847. DialogBox.ShowWarning($"Can not create {recipeName}, Recipe with the same name already exist.");
  848. return;
  849. }
  850. if ((prefix + recipeName).Length > 200)
  851. {
  852. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  853. return;
  854. }
  855. RecipeDataLayout recipe = new RecipeDataLayout();
  856. recipe.Name = recipeName;
  857. recipe.PrefixPath = prefix;
  858. recipe.Creator = BaseApp.Instance.UserContext.LoginName;
  859. recipe.CreateTime = DateTime.Now;
  860. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  861. recipe.ReviseTime = DateTime.Now;
  862. recipe.Description = description;
  863. recipe.RecipeLevel = LevelDisplay;
  864. recipe.RecipePermission = "Free";
  865. if (!Save(recipe, true))
  866. return;
  867. var types = prefix.Split('\\');
  868. string newfile = string.Empty;
  869. if (types.Length > 2)
  870. {
  871. newfile = $"{string.Join("\\", types.Skip(2))}\\{recipeName}";
  872. }
  873. else
  874. {
  875. newfile = recipeName;
  876. }
  877. //ReloadRecipeFileList(types[0], types[1], newfile, false);
  878. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == types[1]);
  879. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  880. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{newfile}");
  881. TreeSelectChanged(CurrentFileNode);
  882. item.FileListByProcessType.ForEachDo(a =>
  883. {
  884. a.IsSelected = false;
  885. if (a.FullPath == prefix)
  886. {
  887. a.IsSelected = true;
  888. RecipeFileList = a.Files.ToList();
  889. return;
  890. }
  891. });
  892. }
  893. public void NewRecipeRoot()
  894. {
  895. if (IsChanged)
  896. {
  897. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  898. if (selection == DialogButton.Cancel)
  899. return;
  900. if (selection == DialogButton.Yes)
  901. {
  902. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  903. this.CurrentRecipe.ReviseTime = DateTime.Now;
  904. this.Save(this.CurrentRecipe, false);
  905. }
  906. }
  907. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description);
  908. dialog.FileName = "new recipe";
  909. WindowManager wm = new WindowManager();
  910. bool? dialogReturn = wm.ShowDialog(dialog);
  911. if (!dialogReturn.HasValue || !dialogReturn.Value)
  912. return;
  913. string recipeName = dialog.FileName.Trim();
  914. string description = dialog.Comment;
  915. if (string.IsNullOrEmpty(dialog.FileName))
  916. {
  917. DialogBox.ShowWarning("Recipe file name should not be empty");
  918. return;
  919. }
  920. if (IsExist(recipeName, true))
  921. {
  922. DialogBox.ShowWarning($"Can not create {recipeName}, Recipe with the same name already exist.");
  923. return;
  924. }
  925. if (recipeName.Length > 200)
  926. {
  927. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  928. return;
  929. }
  930. }
  931. private void ReloadRecipeFileList(string chamberType, string processType, string selectedFile, bool selectionIsFolder, bool isRefreshFlod = false)
  932. {
  933. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == processType);
  934. if (item == null)
  935. {
  936. LOG.Write("error reload recipe file list, type = " + processType);
  937. }
  938. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}";
  939. //var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  940. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefix);// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  941. FindSelectedFile(item.FileListByProcessType, $"{prefix}\\{selectedFile}");
  942. if (isRefreshFlod)
  943. item.InvokePropertyChanged();
  944. }
  945. private bool FindSelectedFile(ObservableCollection<FileNode> nodes, string selectedFile)
  946. {
  947. foreach (var recipe in nodes)
  948. {
  949. recipe.IsSelected = false;
  950. if (!recipe.IsFile)
  951. {
  952. if (recipe.FullPath == selectedFile && recipe.Files.Count == 0)
  953. {
  954. recipe.IsSelected = true;
  955. CurrentFileNode = recipe;
  956. return true;
  957. }
  958. else
  959. {
  960. if (FindSelectedFile(recipe.Files, selectedFile)) return true;
  961. }
  962. }
  963. else
  964. {
  965. string filepath = string.Empty;
  966. if (string.IsNullOrEmpty(recipe.AllParentPath))
  967. {
  968. filepath = recipe.Name;
  969. }
  970. else
  971. {
  972. filepath = recipe.AllParentPath + "\\" + recipe.Name;
  973. }
  974. if (filepath == selectedFile.Replace($"{recipe.PrefixPath}\\", ""))
  975. {
  976. recipe.IsSelected = true;
  977. CurrentFileNode = recipe;
  978. return true;
  979. }
  980. }
  981. }
  982. return false;
  983. }
  984. public void SavePermission()
  985. {
  986. CurrentRecipe.Clear();
  987. var recipeContent = _recipeProvider.LoadRecipe(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath);
  988. if (string.IsNullOrEmpty(recipeContent))
  989. {
  990. MessageBox.Show($"{CurrentRecipe.PrefixPath}\\{CurrentRecipe.Name} is empty, please confirm the file is valid.");
  991. return;
  992. }
  993. CurrentRecipe.InitData(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath, recipeContent, _columnBuilder.Configs, SelectedChamber);
  994. CurrentRecipe.RecipeLevel = CurrentFileNode.Level;
  995. RecipePermissionSelectViewModel dialog = new RecipePermissionSelectViewModel("Save recipe and permission", CurrentFileNode.Permission, CurrentRecipe.Description);
  996. WindowManager wm = new WindowManager();
  997. bool? dialogReturn = wm.ShowDialog(dialog);
  998. if (!dialogReturn.HasValue || !dialogReturn.Value)
  999. return;
  1000. CurrentRecipe.RecipePermission = dialog.RecipePermission;
  1001. CurrentRecipe.Description = dialog.RecipeComment;
  1002. CurrentRecipe.RecipeLevel = CurrentFileNode.Level;
  1003. this.Save(CurrentRecipe, false);
  1004. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1005. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1006. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{CurrentFileNode.FullPath}");
  1007. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  1008. item.FileListByProcessType.ForEachDo(a =>
  1009. {
  1010. a.IsSelected = false;
  1011. if (a.FullPath == prefixPath)
  1012. {
  1013. a.IsSelected = true;
  1014. RecipeFileList = a.Files.ToList();
  1015. return;
  1016. }
  1017. });
  1018. }
  1019. private bool IsExist(string fullPath, bool isFile)
  1020. {
  1021. for (int i = 0; i < ProcessTypeFileList.Count; i++)
  1022. {
  1023. if (ProcessTypeFileList[i].ProcessType == CurrentProcessType)
  1024. {
  1025. if (ProcessTypeFileList[i].FileListByProcessType.Count == 0)
  1026. return false;
  1027. foreach (var item in ProcessTypeFileList[i].FileListByProcessType)
  1028. {
  1029. if (FindFile(fullPath, item, isFile))
  1030. {
  1031. return true;
  1032. }
  1033. }
  1034. return false;
  1035. }
  1036. }
  1037. return true;
  1038. }
  1039. private bool FindFile(string path, FileNode root, bool isFile)
  1040. {
  1041. if (root.FullPath.ToLower() == path && !isFile)
  1042. {
  1043. return true;
  1044. }
  1045. if (root.IsFile && isFile)
  1046. {
  1047. return root.FullPath.ToLower().Equals(path);
  1048. }
  1049. else if (!root.IsFile && isFile)
  1050. {
  1051. foreach (var node in root.Files)
  1052. {
  1053. if (isFile && node.IsFile && node.FullPath.ToLower() == path)
  1054. return true;
  1055. if (!node.IsFile && FindFile(path, node, isFile))
  1056. return true;
  1057. }
  1058. }
  1059. return false;
  1060. }
  1061. public void SaveAsRecipe()
  1062. {
  1063. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1064. return;
  1065. if (IsChanged)
  1066. {
  1067. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  1068. if (selection == DialogButton.Cancel)
  1069. return;
  1070. if (selection == DialogButton.Yes)
  1071. {
  1072. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1073. this.CurrentRecipe.ReviseTime = DateTime.Now;
  1074. this.Save(this.CurrentRecipe, false);
  1075. }
  1076. }
  1077. this.LoadData(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath);
  1078. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description, Visibility.Hidden);
  1079. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  1080. dialog.FileName = CurrentFileNode.Name;
  1081. WindowManager wm = new WindowManager();
  1082. bool? dialogReturn = wm.ShowDialog(dialog);
  1083. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1084. return;
  1085. string recipeName = dialog.FileName.Trim();
  1086. string filepath = dialog.FilePath;
  1087. FileNode selectNode = dialog.SelectNode;
  1088. if (string.IsNullOrEmpty(dialog.FileName))
  1089. {
  1090. DialogBox.ShowWarning("Recipe file name should not be empty");
  1091. return;
  1092. }
  1093. string prefix = CurrentChamberType + "\\" + CurrentProcessType;// + "\\" + filepath;
  1094. string processType = string.Empty;
  1095. // string folder = CurrentFileNode.FullPath;
  1096. // string folder = filepath.Substring(filepath.LastIndexOf("\\") + 1);
  1097. string folder = filepath.Replace($"{prefix}\\", "");
  1098. //if (!string.IsNullOrEmpty(folder))
  1099. // recipeName = folder + "\\" + recipeName;
  1100. // var newPrefix = GetPrefix(CurrentChamberType + "\\" + CurrentProcessType, selectNode);
  1101. if (!string.IsNullOrEmpty(folder))
  1102. {
  1103. recipeName = $"{folder}\\{recipeName}";
  1104. }
  1105. if (IsExist(prefix + "\\" + recipeName, true))
  1106. {
  1107. DialogBox.ShowWarning($"Can not copy to {recipeName}, Recipe with the same name already exist.");
  1108. return;
  1109. }
  1110. if (recipeName.Length > 200)
  1111. {
  1112. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  1113. return;
  1114. }
  1115. CurrentRecipe.Creator = BaseApp.Instance.UserContext.LoginName;
  1116. CurrentRecipe.CreateTime = DateTime.Now;
  1117. CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1118. CurrentRecipe.ReviseTime = DateTime.Now;
  1119. CurrentRecipe.Description = CurrentRecipe.Description + ". Renamed from " + CurrentFileNode.Name;
  1120. _recipeProvider.SaveAsRecipe(prefix, recipeName, CurrentRecipe.GetXmlString());
  1121. prefix = GetPrefix(prefix, CurrentFileNode);
  1122. if (selectNode.Name == prefix)
  1123. {
  1124. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  1125. }
  1126. else
  1127. {
  1128. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1129. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1130. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{recipeName}");
  1131. item.FileListByProcessType.ForEachDo(a =>
  1132. {
  1133. a.IsSelected = false;
  1134. if (a.FullPath == prefix)
  1135. {
  1136. a.IsSelected = true;
  1137. RecipeFileList = a.Files.ToList();
  1138. return;
  1139. }
  1140. });
  1141. }
  1142. }
  1143. public void RenameRecipe()
  1144. {
  1145. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1146. return;
  1147. if (IsChanged)
  1148. {
  1149. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  1150. if (selection == DialogButton.Cancel)
  1151. return;
  1152. if (selection == DialogButton.Yes)
  1153. {
  1154. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1155. this.CurrentRecipe.ReviseTime = DateTime.Now;
  1156. this.Save(this.CurrentRecipe, false);
  1157. }
  1158. }
  1159. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description, Visibility.Hidden);
  1160. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  1161. dialog.FileName = CurrentFileNode.Name;
  1162. WindowManager wm = new WindowManager();
  1163. bool? dialogReturn = wm.ShowDialog(dialog);
  1164. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1165. return;
  1166. string recipeName = dialog.FileName.Trim();
  1167. if (string.IsNullOrEmpty(dialog.FileName))
  1168. {
  1169. DialogBox.ShowWarning("Recipe file name should not be empty");
  1170. return;
  1171. }
  1172. string prefix = CurrentChamberType + "\\" + CurrentProcessType;
  1173. string processType = string.Empty;
  1174. string newName = CurrentFileNode.FullPath.Substring(0, CurrentFileNode.FullPath.LastIndexOf("\\") + 1);
  1175. if (!string.IsNullOrEmpty(newName))
  1176. newName = newName + recipeName;
  1177. else
  1178. newName = recipeName;
  1179. if (newName == CurrentFileNode.FullPath)
  1180. return;
  1181. if (IsExist(newName, true))
  1182. {
  1183. DialogBox.ShowWarning($"Can not rename to {newName}, Recipe with the same name already exist.");
  1184. return;
  1185. }
  1186. if (newName.Length > 200)
  1187. {
  1188. DialogBox.ShowWarning($"Can not create folder {newName}, Folder name too long, should be less 200.");
  1189. return;
  1190. }
  1191. prefix = dialog.FilePath;
  1192. if (_recipeProvider.RenameRecipe(dialog.FilePath, CurrentFileNode.Name, recipeName))
  1193. {
  1194. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Rename Recipe from [{CurrentFileNode.FullPath}] to [{recipeName}] {DateTime.Now}";
  1195. }
  1196. CurrentRecipe.Name = newName;
  1197. CurrentRecipe.Description = dialog.Comment;
  1198. CurrentRecipe.ReviseTime = DateTime.Now;
  1199. CurrentRecipe.PrefixPath = CurrentChamberType + "\\" + CurrentProcessType;
  1200. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, newName, false);
  1201. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1202. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1203. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{newName}");
  1204. TreeSelectChanged(CurrentFileNode);
  1205. item.FileListByProcessType.ForEachDo(a =>
  1206. {
  1207. a.IsSelected = false;
  1208. if (a.FullPath == dialog.FilePath)
  1209. {
  1210. a.IsSelected = true;
  1211. RecipeFileList = a.Files.ToList();
  1212. return;
  1213. }
  1214. });
  1215. }
  1216. public void DeleteRecipe()
  1217. {
  1218. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1219. return;
  1220. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  1221. $"Are you sure you want to delete \r\n {CurrentFileNode.FullPath}?");
  1222. if (selection == DialogButton.No)
  1223. return;
  1224. //string nextFocus = CurrentFileNode.Parent.FullPath;
  1225. //bool isFolder = true;
  1226. //if (CurrentFileNode.Parent.Files.Count > 1)
  1227. //{
  1228. // for (int i = 0; i < CurrentFileNode.Parent.Files.Count; i++)
  1229. // {
  1230. // if (CurrentFileNode.Parent.Files[i] == CurrentFileNode)
  1231. // {
  1232. // if (i == 0)
  1233. // {
  1234. // nextFocus = CurrentFileNode.Parent.Files[i + 1].FullPath;
  1235. // isFolder = !CurrentFileNode.Parent.Files[i + 1].IsFile;
  1236. // }
  1237. // else
  1238. // {
  1239. // nextFocus = CurrentFileNode.Parent.Files[i - 1].FullPath;
  1240. // isFolder = !CurrentFileNode.Parent.Files[i - 1].IsFile;
  1241. // }
  1242. // }
  1243. // }
  1244. //}
  1245. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  1246. if (_recipeProvider.DeleteRecipe(prefixPath, CurrentFileNode.Name))
  1247. {
  1248. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Delet Recipe from [{CurrentFileNode.FullPath}] {DateTime.Now}";
  1249. }
  1250. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, "", false);
  1251. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1252. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1253. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{""}");
  1254. item.FileListByProcessType.ForEachDo(a =>
  1255. {
  1256. a.IsSelected = false;
  1257. if (a.FullPath == prefixPath)
  1258. {
  1259. a.IsSelected = true;
  1260. CurrentFileNode = a;
  1261. RecipeFileList = a.Files.ToList();
  1262. return;
  1263. }
  1264. });
  1265. }
  1266. public void ReloadRecipe()
  1267. {
  1268. if (this.editMode == EditMode.Normal || this.editMode == EditMode.Edit)
  1269. {
  1270. this.LoadData(CurrentRecipe.PrefixPath, CurrentRecipe.Name);
  1271. this.UpdateView();
  1272. }
  1273. }
  1274. public void SaveToAll()
  1275. {
  1276. if (!CurrentRecipe.IsCompatibleWithCurrentFormat)
  1277. {
  1278. DialogBox.ShowWarning($"Save failed, {CurrentRecipe.Name} is not a valid recipe file");
  1279. return;
  1280. }
  1281. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No,
  1282. DialogType.CONFIRM, $"Do you want to save to all? \r\n This will replace all the other chamber recipe content");
  1283. if (selection == DialogButton.No)
  1284. return;
  1285. CurrentRecipe.SaveTo(Chambers.ToArray());
  1286. Save(this.CurrentRecipe, false);
  1287. }
  1288. public void SaveTo()
  1289. {
  1290. if (!CurrentRecipe.IsCompatibleWithCurrentFormat)
  1291. {
  1292. DialogBox.ShowWarning($"Save failed, {CurrentRecipe.Name} is not a valid recipe file");
  1293. return;
  1294. }
  1295. SaveToDialogViewModel dialog = new SaveToDialogViewModel("Select which chamber to copy to", SelectedChamber, Chambers.ToList());
  1296. WindowManager wm = new WindowManager();
  1297. bool? dialogReturn = wm.ShowDialog(dialog);
  1298. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1299. return;
  1300. List<string> chambers = new List<string>();
  1301. foreach (var dialogChamber in dialog.Chambers)
  1302. {
  1303. if (dialogChamber.IsEnabled && dialogChamber.IsChecked)
  1304. chambers.Add(dialogChamber.Name);
  1305. }
  1306. if (chambers.Count == 0)
  1307. return;
  1308. CurrentRecipe.SaveTo(chambers.ToArray());
  1309. Save(this.CurrentRecipe, false);
  1310. }
  1311. public void EditRecipe()
  1312. {
  1313. CGlobal.RecipeProcessEditViewEnable = true;
  1314. MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = true;
  1315. if (PopupPage())
  1316. {
  1317. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Edit {DateTime.Now}";
  1318. this.editMode = EditMode.Normal;
  1319. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  1320. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1321. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1322. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{CurrentFileNode.FullPath}");
  1323. TreeSelectChanged(CurrentFileNode);
  1324. item.FileListByProcessType.ForEachDo(a =>
  1325. {
  1326. a.IsSelected = false;
  1327. if (a.FullPath == prefixPath)
  1328. {
  1329. a.IsSelected = true;
  1330. RecipeFileList = a.Files.ToList();
  1331. return;
  1332. }
  1333. });
  1334. }
  1335. }
  1336. public void ViewRecipe()
  1337. {
  1338. CGlobal.RecipeProcessEditViewEnable = false;
  1339. MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = false;
  1340. if (PopupPage())
  1341. {
  1342. this.editMode = EditMode.Normal;
  1343. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, CurrentFileNode.FullPath, false);
  1344. this.UpdateView();
  1345. }
  1346. }
  1347. private string GetTimeFormat(string value)
  1348. {
  1349. try
  1350. {
  1351. if (value != null && value.Length > 1 && value.Split(':').Length > 2)
  1352. {
  1353. var timeH = value.Split(':')[0];
  1354. var timeM = value.Split(':')[1];
  1355. var timeS = value.Split(':')[2];
  1356. if (timeS.Contains('.'))
  1357. {
  1358. var timesArray = timeS.Split('.');
  1359. return $"{timeH}:{timeM.PadLeft(2, '0')}:{timesArray[0].PadLeft(2, '0')}.{timesArray[1].Substring(0, 1)}";
  1360. }
  1361. else
  1362. {
  1363. return $"{timeH}:{timeM.PadLeft(2, '0')}:{timeS.PadLeft(2, '0')}.0";
  1364. }
  1365. }
  1366. else
  1367. {
  1368. return value;
  1369. }
  1370. }
  1371. catch
  1372. {
  1373. return value;
  1374. }
  1375. }
  1376. public void SaveRecipe()
  1377. {
  1378. if (this.IsChanged)
  1379. {
  1380. this.Save(this.CurrentRecipe, false);
  1381. }
  1382. }
  1383. public bool Save(RecipeDataLayout recipe, bool createNew)
  1384. {
  1385. bool result = false;
  1386. if (string.IsNullOrEmpty(recipe.Name))
  1387. {
  1388. MessageBox.Show("Recipe name can't be empty");
  1389. return false;
  1390. }
  1391. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1392. recipe.ReviseTime = DateTime.Now;
  1393. result = this._recipeProvider.SaveRecipe(recipe.PrefixPath, recipe.Name, recipe.GetXmlString());
  1394. if (result)
  1395. {
  1396. //recipe.DataSaved();
  1397. this.editMode = EditMode.Normal;
  1398. this.UpdateView();
  1399. }
  1400. else
  1401. {
  1402. MessageBox.Show("Save failed!");
  1403. }
  1404. return result;
  1405. }
  1406. #endregion
  1407. private void ClearData()
  1408. {
  1409. this.editMode = EditMode.None;
  1410. this.CurrentRecipe.Clear();
  1411. this.CurrentRecipe.Name = string.Empty;
  1412. this.CurrentRecipe.Description = string.Empty;
  1413. }
  1414. private void LoadData(string prefixPath, string recipeName)
  1415. {
  1416. CurrentRecipe.Clear();
  1417. var recipeContent = _recipeProvider.LoadRecipe(prefixPath, recipeName);
  1418. if (string.IsNullOrEmpty(recipeContent))
  1419. {
  1420. MessageBox.Show($"{prefixPath}\\{recipeName} is empty, please confirm the file is valid.");
  1421. return;
  1422. }
  1423. CurrentRecipe.RecipeChamberType = "OriginChamber";
  1424. CurrentRecipe.RecipeVersion = _columnBuilder.RecipeVersion;
  1425. _columnBuilder.Build(CurrentProcessType);
  1426. CurrentRecipe.InitData(prefixPath, recipeName, recipeContent, _columnBuilder.Configs, SelectedChamber);
  1427. this.editMode = EditMode.Normal;
  1428. }
  1429. private void UpdateView()
  1430. {
  1431. bool isFileSelected = CurrentFileNode != null && CurrentFileNode.IsFile;
  1432. this.NotifyOfPropertyChange("CurrentRecipe");
  1433. }
  1434. private string oldPrefix { get; set; }
  1435. private string oldName { get; set; }
  1436. private string oldStepName { get; set; }
  1437. private bool PopupPage()
  1438. {
  1439. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1440. return false;
  1441. var windowManager = IoC.Get<IWindowManager>();
  1442. var currentProcessType = CurrentProcessType;
  1443. if (CurrentProcessType == "Expert Layout")
  1444. {
  1445. RecipeLayoutExpertEditViewModel recipeLayoutExpertEditViewModel = new RecipeLayoutExpertEditViewModel(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath, CurrentFileNode.Permission);
  1446. return (windowManager as WindowManager)?.ShowDialogWithTitle(recipeLayoutExpertEditViewModel, null, "Layout Setting") == true;
  1447. }
  1448. else
  1449. {
  1450. try
  1451. {
  1452. var permission = "PM1";
  1453. var waferNumberAll = (int)QueryDataClient.Instance.Service.GetConfig("Boat.SlotCount");
  1454. var layoutRecipe = new RecipeDataLayout();
  1455. layoutRecipe.PrefixPath = CurrentRecipe.PrefixPath;
  1456. layoutRecipe.Name = CurrentFileNode.FullPath;
  1457. layoutRecipe.RecipePermission = permission;
  1458. var recipeContent = _recipeProvider.LoadRecipe(layoutRecipe.PrefixPath, layoutRecipe.Name);
  1459. if (string.IsNullOrEmpty(recipeContent))
  1460. {
  1461. System.Windows.MessageBox.Show($"{layoutRecipe.PrefixPath}\\{layoutRecipe.Name} is empty, please confirm the file is valid.");
  1462. return false;
  1463. }
  1464. layoutRecipe.RecipeChamberType = "OriginChamber";
  1465. layoutRecipe.InitData(layoutRecipe.PrefixPath, layoutRecipe.Name, recipeContent, _columnBuilder.Configs, permission);
  1466. if (layoutRecipe.ExpertSteps != null && layoutRecipe.ExpertSteps.Count > 0 && layoutRecipe.ExpertSteps[0].Items != null && layoutRecipe.ExpertSteps[0].Items.Count != waferNumberAll)
  1467. {
  1468. DialogBox.ShowWarning($"layoutRecipe slot:{layoutRecipe.ExpertSteps[0].Items.Count} not match boatSlotConfig:{waferNumberAll}");
  1469. return false;
  1470. }
  1471. else
  1472. {
  1473. RecipeLayoutEditViewModel sdSettingViewModel = new RecipeLayoutEditViewModel(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath, _columnBuilder, CurrentFileNode.Permission);
  1474. return (windowManager as WindowManager)?.ShowDialogWithTitle(sdSettingViewModel, null, "Layout Setting") == true;
  1475. }
  1476. }
  1477. catch (Exception ex)
  1478. {
  1479. RecipeLayoutEditViewModel sdSettingViewModel = new RecipeLayoutEditViewModel(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath, _columnBuilder, CurrentFileNode.Permission);
  1480. return (windowManager as WindowManager)?.ShowDialogWithTitle(sdSettingViewModel, null, "Layout Setting") == true;
  1481. }
  1482. }
  1483. }
  1484. }
  1485. }