RecipeJobViewModel.cs 66 KB

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