RecipeLayoutViewModel.cs 65 KB

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