RecipeJobViewModel.cs 68 KB

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