RecipeLayoutViewModel.cs 66 KB

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