RecipeLayoutViewModel.cs 68 KB

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