RecipeJobViewModel.cs 68 KB

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