RecipeJobViewModel.cs 68 KB

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