RecipeLayoutViewModel.cs 68 KB

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