RecipeJobViewModel.cs 68 KB

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