RecipeJobViewModel.cs 67 KB

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