RecipeJobViewModel.cs 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  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. InitializeDefault(false);
  504. }
  505. if (node != null && !node.IsFile)
  506. {
  507. ProcessTypeFileList[0].FileListByProcessType.ForEachDo(a =>
  508. {
  509. a.IsSelected = false;
  510. if (a.Name == node.Name)
  511. {
  512. a.IsSelected = true;
  513. a.Files.ForEachDo(e => e.IsSelected = false);
  514. RecipeFileList = a.Files.ToList();
  515. return;
  516. }
  517. });
  518. }
  519. CurrentFileNode = node;
  520. IsFreePermission = true;
  521. IsReadAndWritePermission = true;
  522. NotifyOfPropertyChange(nameof(IsCurrentNodeFile));
  523. NotifyOfPropertyChange(nameof(IsCurrentNodePath));
  524. NotifyOfPropertyChange(nameof(IsSelectPermission));
  525. NotifyOfPropertyChange(nameof(IsSingleSelectPermission));
  526. NotifyOfPropertyChange(nameof(IsEnabledFolderPermission));
  527. if (node != null && node.IsFile)
  528. {
  529. if (CurrentRecipe != null)
  530. {
  531. CurrentRecipe.Name = node.Name;
  532. CurrentRecipe.PrefixPath = node.PrefixPath;
  533. }
  534. // this.LoadData(node.PrefixPath, node.FullPath);
  535. }
  536. else
  537. {
  538. this.ClearData();
  539. this.editMode = EditMode.None;
  540. }
  541. this.UpdateView();
  542. GetIsEnabledNewRecipe();
  543. }
  544. private void GetIsEnabledNewRecipe()
  545. {
  546. if (!IsSingleFile && ProcessTypeFileList != null && ProcessTypeFileList.FirstOrDefault() != null && ProcessTypeFileList.FirstOrDefault().FileListByProcessType != null && ProcessTypeFileList.FirstOrDefault().FileListByProcessType.Count > 0)
  547. {
  548. IsEnabledNewRecipe = true;
  549. }
  550. else
  551. {
  552. IsEnabledNewRecipe = false;
  553. }
  554. }
  555. #region folder
  556. public void SelectRecipeType()
  557. {
  558. var windowManager = IoC.Get<IWindowManager>();
  559. RecipeSelectRecipeTypeViewModel recipeSelectRecipeTypeViewModel = new RecipeSelectRecipeTypeViewModel();
  560. (windowManager as WindowManager)?.ShowDialogWithTitle(recipeSelectRecipeTypeViewModel, null, "Select Recipe Type");
  561. if (recipeSelectRecipeTypeViewModel.SelectRecipeType != null)
  562. {
  563. var selectRecipeType = recipeSelectRecipeTypeViewModel.SelectRecipeType;
  564. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{selectRecipeType}");
  565. if (processType == null)
  566. {
  567. processType = selectRecipeType;
  568. }
  569. ProcessTypeFileList = new List<ProcessTypeFileItem>();
  570. string[] recipeProcessType = ((string)processType).Split(',');
  571. for (int i = 0; i < recipeProcessType.Length; i++)
  572. {
  573. var type = new ProcessTypeFileItem();
  574. type.ProcessType = recipeProcessType[i];
  575. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{recipeProcessType[i]}";
  576. // var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  577. type.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefix);// RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  578. ProcessTypeFileList.Add(type);
  579. }
  580. SelectRecipeTypeName = processType + " Recipe";
  581. this.NotifyOfPropertyChange("ProcessTypeFileList");
  582. if (ProcessTypeFileList[0].FileListByProcessType.Count > 0)
  583. CurrentFileNode = ProcessTypeFileList[0].FileListByProcessType[ProcessTypeFileList[0].FileListByProcessType.Count - 1];
  584. NotifyOfPropertyChange(nameof(IsCurrentNodeFile));
  585. NotifyOfPropertyChange(nameof(IsCurrentNodePath));
  586. NotifyOfPropertyChange(nameof(IsSelectPermission));
  587. NotifyOfPropertyChange(nameof(IsReadAndWritePermission));
  588. // NotifyOfPropertyChange(nameof(IsFreePermission));
  589. ProcessTypeIndexSelection = 0;
  590. }
  591. }
  592. public void NewFolder()
  593. {
  594. if (IsChanged)
  595. {
  596. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  597. if (selection == DialogButton.Cancel)
  598. return;
  599. if (selection == DialogButton.Yes)
  600. {
  601. this.CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  602. this.CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  603. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  604. }
  605. }
  606. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType, "", Visibility.Visible, Visibility.Collapsed);
  607. // dialog.FileName = "new folder";
  608. WindowManager wm = new WindowManager();
  609. bool? dialogReturn = wm.ShowDialog(dialog);
  610. if (!dialogReturn.HasValue || !dialogReturn.Value)
  611. return;
  612. if (string.IsNullOrWhiteSpace(dialog.FileName))
  613. {
  614. DialogBox.ShowWarning("Folder name should not be empty");
  615. }
  616. else
  617. {
  618. string name = dialog.FileName.Trim();
  619. FileNode selectNode = dialog.SelectNode;
  620. string prefix = ChamberType[ChamberTypeIndexSelection] + "\\" + ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  621. string newFolder = string.Empty;
  622. string folder = string.Empty;
  623. if (selectNode != null)
  624. {
  625. prefix = selectNode.PrefixPath;
  626. folder = selectNode.FullPath.Replace($"{prefix}\\", "");
  627. newFolder = $"{folder}\\{name}";
  628. }
  629. else
  630. {
  631. newFolder = name;
  632. }
  633. if (IsExist(newFolder, false))
  634. {
  635. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder with the same name already exist.");
  636. return;
  637. }
  638. if (newFolder.Length > 200)
  639. {
  640. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder name too long, should be less 200.");
  641. return;
  642. }
  643. prefix = GetPrefix(prefix, selectNode);
  644. _recipeProvider.CreateRecipeFolder(prefix, name);
  645. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  646. if (item == null)
  647. {
  648. LOG.Write("error reload recipe file list, type = " + CurrentProcessType);
  649. }
  650. //var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  651. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  652. FindSelectedFile(item.FileListByProcessType, $"{prefix}\\{newFolder}");
  653. item.InvokePropertyChanged();
  654. TreeSelectChanged(CurrentFileNode);
  655. }
  656. }
  657. private string GetPrefix(string prefix, FileNode CurrentFileNode)
  658. {
  659. string temppreFix = prefix;
  660. if (CurrentFileNode != null)
  661. {
  662. if (string.IsNullOrEmpty(CurrentFileNode.AllParentPath))
  663. {
  664. if (CurrentFileNode.IsFile)
  665. {
  666. return temppreFix;
  667. }
  668. else
  669. {
  670. temppreFix = CurrentFileNode.FullPath;
  671. }
  672. }
  673. else
  674. {
  675. if (CurrentFileNode.IsFile)
  676. {
  677. if (temppreFix.EndsWith("\\"))
  678. {
  679. temppreFix = $"{temppreFix}{CurrentFileNode.AllParentPath}";
  680. }
  681. else
  682. {
  683. temppreFix = $"{temppreFix}\\{CurrentFileNode.AllParentPath}";
  684. }
  685. }
  686. else
  687. {
  688. temppreFix = $"{temppreFix}\\{CurrentFileNode.AllParentPath}\\{CurrentFileNode.Name}";
  689. }
  690. }
  691. }
  692. return temppreFix;
  693. }
  694. public void NewFolderRoot()
  695. {
  696. if (IsChanged)
  697. {
  698. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  699. if (selection == DialogButton.Cancel)
  700. return;
  701. if (selection == DialogButton.Yes)
  702. {
  703. this.CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  704. this.CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  705. // this.Save(this.CurrentRecipe, false);
  706. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  707. }
  708. }
  709. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType);
  710. dialog.FileName = "new folder";
  711. WindowManager wm = new WindowManager();
  712. bool? dialogReturn = wm.ShowDialog(dialog);
  713. if (!dialogReturn.HasValue || !dialogReturn.Value)
  714. return;
  715. string name = dialog.FileName.Trim();
  716. if (string.IsNullOrEmpty(name))
  717. {
  718. DialogBox.ShowWarning("Folder name should not be empty");
  719. return;
  720. }
  721. if (IsExist(name, false))
  722. {
  723. DialogBox.ShowWarning($"Can not create folder {name}, Folder with the same name already exist.");
  724. return;
  725. }
  726. if (name.Length > 200)
  727. {
  728. DialogBox.ShowWarning($"Can not create folder {name}, Folder name too long, should be less 200.");
  729. return;
  730. }
  731. string prefix = ChamberType[ChamberTypeIndexSelection] + "\\" + ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  732. _recipeProvider.CreateRecipeFolder(prefix, name);
  733. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, name, true);
  734. }
  735. public void DeleteFolder()
  736. {
  737. if (CurrentFileNode == null || CurrentFileNode.IsFile)
  738. return;
  739. if (CurrentFileNode.Files.Count > 0)
  740. {
  741. DialogBox.ShowWarning($"Can not delete non-empty folder, Remove the files or folders under \r\n{CurrentFileNode.FullPath}.");
  742. return;
  743. }
  744. var prefix = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  745. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  746. $"Are you sure you want to delete \r\n {prefix}?");
  747. if (selection == DialogButton.No)
  748. return;
  749. //string nextFocus = CurrentFileNode.Parent.FullPath;
  750. //bool isFolder = true;
  751. //if (CurrentFileNode.Parent!=null&&CurrentFileNode.Parent.Files.Count > 1)
  752. //{
  753. // for (int i = 0; i < CurrentFileNode.Parent.Files.Count; i++)
  754. // {
  755. // if (CurrentFileNode.Parent.Files[i] == CurrentFileNode)
  756. // {
  757. // if (i == 0)
  758. // {
  759. // nextFocus = CurrentFileNode.Parent.Files[i + 1].FullPath;
  760. // isFolder = !CurrentFileNode.Parent.Files[i + 1].IsFile;
  761. // }
  762. // else
  763. // {
  764. // nextFocus = CurrentFileNode.Parent.Files[i - 1].FullPath;
  765. // isFolder = !CurrentFileNode.Parent.Files[i - 1].IsFile;
  766. // }
  767. // }
  768. // }
  769. //}
  770. prefix = prefix.Replace($"\\{CurrentFileNode.Name}", "");
  771. _recipeProvider.DeleteRecipeFolder(prefix, CurrentFileNode.Name);
  772. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, "", false, true);
  773. GetIsEnabledNewRecipe();
  774. }
  775. public void RenameFolder()
  776. {
  777. if (CurrentFileNode == null || CurrentFileNode.IsFile)
  778. return;
  779. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType, "", Visibility.Hidden, Visibility.Collapsed);
  780. dialog.FileName = CurrentFileNode.Name;
  781. WindowManager wm = new WindowManager();
  782. bool? dialogReturn = wm.ShowDialog(dialog);
  783. if (!dialogReturn.HasValue || !dialogReturn.Value)
  784. return;
  785. string name = dialog.FileName.Trim();
  786. if (string.IsNullOrEmpty(name))
  787. return;
  788. string newFolder = CurrentFileNode.FullPath.Substring(0, CurrentFileNode.FullPath.LastIndexOf("\\") + 1);
  789. if (!string.IsNullOrEmpty(newFolder))
  790. newFolder = newFolder + name;
  791. else
  792. newFolder = name;
  793. if (newFolder == CurrentFileNode.FullPath)
  794. return;
  795. if (IsExist(newFolder, false))
  796. {
  797. DialogBox.ShowWarning($"Can not rename to {newFolder}, Folder with the same name already exist.");
  798. return;
  799. }
  800. if (newFolder.Length > 200)
  801. {
  802. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder name too long, should be less 200.");
  803. return;
  804. }
  805. if (_recipeProvider.RenameFolder(CurrentFileNode.PrefixPath, CurrentFileNode.Name, name))
  806. {
  807. foreach (var node in CurrentFileNode.Files)
  808. {
  809. UIGlobalVariable.Instance.ProcessModifiedRecipe[node.FullPath] = $"Folder Rename from [{CurrentFileNode.FullPath}] to [{name}] {DateTime.Now}";
  810. }
  811. }
  812. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, name, true, true);
  813. }
  814. #endregion
  815. #region recipe
  816. public void NewRecipe()
  817. {
  818. if (IsChanged)
  819. {
  820. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  821. if (selection == DialogButton.Cancel)
  822. return;
  823. if (selection == DialogButton.Yes)
  824. {
  825. this.CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  826. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  827. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  828. }
  829. }
  830. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, "");
  831. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  832. //dialog.FileName = (string)QueryDataClient.Instance.Service.GetConfig($"System.Recipe.DefaultProcessRecipeName");
  833. WindowManager wm = new WindowManager();
  834. bool? dialogReturn = wm.ShowDialog(dialog);
  835. if (!dialogReturn.HasValue || !dialogReturn.Value)
  836. return;
  837. if (string.IsNullOrEmpty(dialog.FileName))
  838. {
  839. DialogBox.ShowWarning("Recipe file name should not be empty");
  840. return;
  841. }
  842. string recipeName = dialog.FileName.Trim();
  843. string filepath = dialog.FilePath;
  844. string description = dialog.Comment;
  845. string prefix;
  846. if (filepath.Contains("\\"))
  847. {
  848. prefix = filepath;
  849. }
  850. else
  851. {
  852. prefix = CurrentChamberType + "\\" + CurrentProcessType + "\\" + filepath;
  853. if (CurrentFileNode != null)
  854. {
  855. //获取目录
  856. prefix = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  857. }
  858. }
  859. if (RecipeFileList != null && RecipeFileList.Find(a => a.Name == recipeName.ToLower()) != null)
  860. {
  861. DialogBox.ShowWarning($"Can not create {recipeName}, Recipe with the same name already exist.");
  862. return;
  863. }
  864. if ((prefix + recipeName).Length > 200)
  865. {
  866. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  867. return;
  868. }
  869. RecipeDataBase recipe = new RecipeDataBase();
  870. recipe.Name = recipeName;
  871. recipe.PrefixPath = prefix;
  872. recipe.Creator = BaseApp.Instance.UserContext.LoginName;
  873. recipe.CreateTime = DateTime.Now;
  874. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  875. recipe.ReviseTime = DateTime.Now;
  876. recipe.Description = description;
  877. recipe.RecipeLevel = LevelDisplay;
  878. recipe.RecipePermission = "Free";
  879. if (!Save(recipe, true))
  880. return;
  881. var types = prefix.Split('\\');
  882. string newfile = string.Empty;
  883. if (types.Length > 2)
  884. {
  885. newfile = $"{string.Join("\\", types.Skip(2))}\\{recipeName}";
  886. }
  887. else
  888. {
  889. newfile = recipeName;
  890. }
  891. //ReloadRecipeFileList(types[0], types[1], newfile, false);
  892. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == types[1]);
  893. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  894. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{newfile}");
  895. TreeSelectChanged(CurrentFileNode);
  896. item.FileListByProcessType.ForEachDo(a =>
  897. {
  898. a.IsSelected = false;
  899. if (a.FullPath == prefix)
  900. {
  901. a.IsSelected = true;
  902. RecipeFileList = a.Files.ToList();
  903. return;
  904. }
  905. });
  906. }
  907. public void NewRecipeRoot()
  908. {
  909. if (IsChanged)
  910. {
  911. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  912. if (selection == DialogButton.Cancel)
  913. return;
  914. if (selection == DialogButton.Yes)
  915. {
  916. this.CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  917. this.CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  918. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  919. }
  920. }
  921. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description);
  922. dialog.FileName = "new recipe";
  923. WindowManager wm = new WindowManager();
  924. bool? dialogReturn = wm.ShowDialog(dialog);
  925. if (!dialogReturn.HasValue || !dialogReturn.Value)
  926. return;
  927. string recipeName = dialog.FileName.Trim();
  928. string description = dialog.Comment;
  929. if (string.IsNullOrEmpty(dialog.FileName))
  930. {
  931. DialogBox.ShowWarning("Recipe file name should not be empty");
  932. return;
  933. }
  934. if (IsExist(recipeName, true))
  935. {
  936. DialogBox.ShowWarning($"Can not create {recipeName}, Recipe with the same name already exist.");
  937. return;
  938. }
  939. if (recipeName.Length > 200)
  940. {
  941. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  942. return;
  943. }
  944. RecipeDataBase recipe = new RecipeDataBase();
  945. recipe.Name = recipeName;
  946. recipe.PrefixPath = CurrentChamberType + "\\" + CurrentProcessType;
  947. recipe.Creator = BaseApp.Instance.UserContext.LoginName;
  948. recipe.CreateTime = DateTime.Now;
  949. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  950. recipe.ReviseTime = DateTime.Now;
  951. recipe.Description = string.Empty;
  952. recipe.Description = description;
  953. recipe.RecipeLevel = LevelDisplay;
  954. recipe.RecipePermission = "Free";
  955. if (!Save(recipe, true))
  956. return;
  957. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  958. }
  959. private void ReloadRecipeFileList(string chamberType, string processType, string selectedFile, bool selectionIsFolder, bool isRefreshFlod = false)
  960. {
  961. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == processType);
  962. if (item == null)
  963. {
  964. LOG.Write("error reload recipe file list, type = " + processType);
  965. }
  966. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}";
  967. //var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  968. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefix);// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  969. FindSelectedFile(item.FileListByProcessType, $"{prefix}\\{selectedFile}");
  970. if (isRefreshFlod)
  971. item.InvokePropertyChanged();
  972. }
  973. private bool FindSelectedFile(ObservableCollection<FileNode> nodes, string selectedFile)
  974. {
  975. foreach (var recipe in nodes)
  976. {
  977. recipe.IsSelected = false;
  978. if (!recipe.IsFile)
  979. {
  980. if (recipe.FullPath == selectedFile && recipe.Files.Count == 0)
  981. {
  982. recipe.IsSelected = true;
  983. CurrentFileNode = recipe;
  984. return true;
  985. }
  986. else
  987. {
  988. if (FindSelectedFile(recipe.Files, selectedFile)) return true;
  989. }
  990. }
  991. else
  992. {
  993. string filepath = string.Empty;
  994. if (string.IsNullOrEmpty(recipe.AllParentPath))
  995. {
  996. filepath = recipe.Name;
  997. }
  998. else
  999. {
  1000. filepath = recipe.AllParentPath + "\\" + recipe.Name;
  1001. }
  1002. if (filepath == selectedFile.Replace($"{recipe.PrefixPath}\\", ""))
  1003. {
  1004. recipe.IsSelected = true;
  1005. CurrentFileNode = recipe;
  1006. return true;
  1007. }
  1008. }
  1009. }
  1010. return false;
  1011. }
  1012. private bool IsExist(string fullPath, bool isFile)
  1013. {
  1014. for (int i = 0; i < ProcessTypeFileList.Count; i++)
  1015. {
  1016. if (ProcessTypeFileList[i].ProcessType == CurrentProcessType)
  1017. {
  1018. if (ProcessTypeFileList[i].FileListByProcessType.Count == 0)
  1019. return false;
  1020. foreach (var item in ProcessTypeFileList[i].FileListByProcessType)
  1021. {
  1022. if (FindFile(fullPath, item, isFile))
  1023. {
  1024. return true;
  1025. }
  1026. }
  1027. return false;
  1028. }
  1029. }
  1030. return true;
  1031. }
  1032. private bool FindFile(string path, FileNode root, bool isFile)
  1033. {
  1034. if (root.FullPath.ToLower() == path && !isFile)
  1035. {
  1036. return true;
  1037. }
  1038. if (root.IsFile && isFile)
  1039. {
  1040. return root.FullPath.ToLower().Equals(path);
  1041. }
  1042. else if (!root.IsFile && isFile)
  1043. {
  1044. foreach (var node in root.Files)
  1045. {
  1046. if (isFile && node.IsFile && node.FullPath.ToLower() == path)
  1047. return true;
  1048. if (!node.IsFile && FindFile(path, node, isFile))
  1049. return true;
  1050. }
  1051. }
  1052. return false;
  1053. }
  1054. public void SaveAsRecipe()
  1055. {
  1056. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1057. return;
  1058. if (IsChanged)
  1059. {
  1060. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  1061. if (selection == DialogButton.Cancel)
  1062. return;
  1063. if (selection == DialogButton.Yes)
  1064. {
  1065. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  1066. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1067. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  1068. }
  1069. }
  1070. this.LoadData(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath);
  1071. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description, Visibility.Hidden);
  1072. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  1073. dialog.FileName = CurrentFileNode.Name;
  1074. WindowManager wm = new WindowManager();
  1075. bool? dialogReturn = wm.ShowDialog(dialog);
  1076. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1077. return;
  1078. string recipeName = dialog.FileName.Trim();
  1079. string filepath = dialog.FilePath;
  1080. FileNode selectNode = dialog.SelectNode;
  1081. if (string.IsNullOrEmpty(dialog.FileName))
  1082. {
  1083. DialogBox.ShowWarning("Recipe file name should not be empty");
  1084. return;
  1085. }
  1086. string prefix = CurrentChamberType + "\\" + CurrentProcessType;// + "\\" + filepath;
  1087. string processType = string.Empty;
  1088. // string folder = CurrentFileNode.FullPath;
  1089. // string folder = filepath.Substring(filepath.LastIndexOf("\\") + 1);
  1090. string folder = filepath.Replace($"{prefix}\\", "");
  1091. //if (!string.IsNullOrEmpty(folder))
  1092. // recipeName = folder + "\\" + recipeName;
  1093. // var newPrefix = GetPrefix(CurrentChamberType + "\\" + CurrentProcessType, selectNode);
  1094. if (!string.IsNullOrEmpty(folder))
  1095. {
  1096. recipeName = $"{folder}\\{recipeName}";
  1097. }
  1098. if (IsExist(prefix + "\\" + recipeName, true))
  1099. {
  1100. DialogBox.ShowWarning($"Can not copy to {recipeName}, Recipe with the same name already exist.");
  1101. return;
  1102. }
  1103. if (recipeName.Length > 200)
  1104. {
  1105. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  1106. return;
  1107. }
  1108. CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  1109. CurrentRecipe.CreateTime = DateTime.Now.ToString();
  1110. CurrentRecipe.LastRevisionTime = DateTime.Now.ToString();
  1111. CurrentRecipe.Description = CurrentRecipe.Description + ". Renamed from " + CurrentFileNode.Name;
  1112. CurrentRecipe.CreateTime = DateTime.Now.ToString();
  1113. // CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1114. // CurrentRecipe.ReviseTime = DateTime.Now.ToString();
  1115. CurrentRecipe.Description = CurrentRecipe.Description + ". Renamed from " + CurrentFileNode.Name;
  1116. _recipeProvider.SaveAsRecipe(prefix, recipeName, CurrentRecipe.GetXmlString());
  1117. prefix = GetPrefix(prefix, CurrentFileNode);
  1118. if (selectNode.Name == prefix)
  1119. {
  1120. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  1121. }
  1122. else
  1123. {
  1124. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1125. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1126. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{recipeName}");
  1127. item.FileListByProcessType.ForEachDo(a =>
  1128. {
  1129. a.IsSelected = false;
  1130. if (a.FullPath == prefix)
  1131. {
  1132. a.IsSelected = true;
  1133. RecipeFileList = a.Files.ToList();
  1134. return;
  1135. }
  1136. });
  1137. }
  1138. }
  1139. public void RenameRecipe()
  1140. {
  1141. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1142. return;
  1143. if (IsChanged)
  1144. {
  1145. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  1146. if (selection == DialogButton.Cancel)
  1147. return;
  1148. if (selection == DialogButton.Yes)
  1149. {
  1150. this.CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  1151. this.CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1152. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  1153. }
  1154. }
  1155. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description, Visibility.Hidden);
  1156. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  1157. dialog.FileName = CurrentFileNode.Name;
  1158. WindowManager wm = new WindowManager();
  1159. bool? dialogReturn = wm.ShowDialog(dialog);
  1160. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1161. return;
  1162. string recipeName = dialog.FileName.Trim();
  1163. if (string.IsNullOrEmpty(dialog.FileName))
  1164. {
  1165. DialogBox.ShowWarning("Recipe file name should not be empty");
  1166. return;
  1167. }
  1168. string prefix = CurrentChamberType + "\\" + CurrentProcessType;
  1169. string processType = string.Empty;
  1170. string newName = CurrentFileNode.FullPath.Substring(0, CurrentFileNode.FullPath.LastIndexOf("\\") + 1);
  1171. if (!string.IsNullOrEmpty(newName))
  1172. newName = newName + recipeName;
  1173. else
  1174. newName = recipeName;
  1175. if (newName == CurrentFileNode.FullPath)
  1176. return;
  1177. if (IsExist(newName, true))
  1178. {
  1179. DialogBox.ShowWarning($"Can not rename to {newName}, Recipe with the same name already exist.");
  1180. return;
  1181. }
  1182. if (newName.Length > 200)
  1183. {
  1184. DialogBox.ShowWarning($"Can not create folder {newName}, Folder name too long, should be less 200.");
  1185. return;
  1186. }
  1187. prefix = GetPrefix(prefix, CurrentFileNode);
  1188. if (_recipeProvider.RenameRecipe(prefix, CurrentFileNode.Name, recipeName))
  1189. {
  1190. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Rename Recipe from [{CurrentFileNode.FullPath}] to [{recipeName}] {DateTime.Now}";
  1191. }
  1192. CurrentRecipe.Name = dialog.FileName;
  1193. CurrentRecipe.Description = dialog.Comment;
  1194. this.CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName;
  1195. this.CurrentRecipe.PrefixPath = prefix;
  1196. this.CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1197. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  1198. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, newName, false);
  1199. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1200. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1201. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{newName}");
  1202. item.FileListByProcessType.ForEachDo(a =>
  1203. {
  1204. a.IsSelected = false;
  1205. if (a.FullPath == prefix)
  1206. {
  1207. a.IsSelected = true;
  1208. RecipeFileList = a.Files.ToList();
  1209. return;
  1210. }
  1211. });
  1212. }
  1213. public void DeleteRecipe()
  1214. {
  1215. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1216. return;
  1217. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  1218. $"Are you sure you want to delete \r\n {CurrentFileNode.FullPath}?");
  1219. if (selection == DialogButton.No)
  1220. return;
  1221. //string nextFocus = CurrentFileNode.Parent.FullPath;
  1222. //bool isFolder = true;
  1223. //if (CurrentFileNode.Parent.Files.Count > 1)
  1224. //{
  1225. // for (int i = 0; i < CurrentFileNode.Parent.Files.Count; i++)
  1226. // {
  1227. // if (CurrentFileNode.Parent.Files[i] == CurrentFileNode)
  1228. // {
  1229. // if (i == 0)
  1230. // {
  1231. // nextFocus = CurrentFileNode.Parent.Files[i + 1].FullPath;
  1232. // isFolder = !CurrentFileNode.Parent.Files[i + 1].IsFile;
  1233. // }
  1234. // else
  1235. // {
  1236. // nextFocus = CurrentFileNode.Parent.Files[i - 1].FullPath;
  1237. // isFolder = !CurrentFileNode.Parent.Files[i - 1].IsFile;
  1238. // }
  1239. // }
  1240. // }
  1241. //}
  1242. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  1243. if (_recipeProvider.DeleteRecipe(prefixPath, CurrentFileNode.Name))
  1244. {
  1245. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Delet Recipe from [{CurrentFileNode.FullPath}] {DateTime.Now}";
  1246. }
  1247. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, "", false);
  1248. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1249. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1250. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{""}");
  1251. item.FileListByProcessType.ForEachDo(a =>
  1252. {
  1253. a.IsSelected = false;
  1254. if (a.FullPath == prefixPath)
  1255. {
  1256. a.IsSelected = true;
  1257. CurrentFileNode = a;
  1258. RecipeFileList = a.Files.ToList();
  1259. return;
  1260. }
  1261. });
  1262. }
  1263. public void ReloadRecipe()
  1264. {
  1265. if (this.editMode == EditMode.Normal || this.editMode == EditMode.Edit)
  1266. {
  1267. this.LoadData(CurrentRecipe.PrefixPath, CurrentRecipe.Name);
  1268. this.UpdateView();
  1269. }
  1270. }
  1271. public void EditRecipe()
  1272. {
  1273. CGlobal.RecipeProcessEditViewEnable = true;
  1274. MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = true;
  1275. if (PopupPage())
  1276. {
  1277. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Edit {DateTime.Now}";
  1278. this.editMode = EditMode.Normal;
  1279. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  1280. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1281. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1282. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{CurrentFileNode.FullPath}");
  1283. TreeSelectChanged(CurrentFileNode);
  1284. item.FileListByProcessType.ForEachDo(a =>
  1285. {
  1286. a.IsSelected = false;
  1287. if (a.FullPath == prefixPath)
  1288. {
  1289. a.IsSelected = true;
  1290. RecipeFileList = a.Files.ToList();
  1291. return;
  1292. }
  1293. });
  1294. }
  1295. }
  1296. public void ViewRecipe()
  1297. {
  1298. CGlobal.RecipeProcessEditViewEnable = false;
  1299. MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = false;
  1300. if (PopupPage())
  1301. {
  1302. this.editMode = EditMode.Normal;
  1303. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, CurrentFileNode.FullPath, false);
  1304. this.UpdateView();
  1305. }
  1306. }
  1307. private string GetTimeFormat(string value)
  1308. {
  1309. try
  1310. {
  1311. if (value != null && value.Length > 1 && value.Split(':').Length > 2)
  1312. {
  1313. var timeH = value.Split(':')[0];
  1314. var timeM = value.Split(':')[1];
  1315. var timeS = value.Split(':')[2];
  1316. if (timeS.Contains('.'))
  1317. {
  1318. var timesArray = timeS.Split('.');
  1319. return $"{timeH}:{timeM.PadLeft(2, '0')}:{timesArray[0].PadLeft(2, '0')}.{timesArray[1].Substring(0, 1)}";
  1320. }
  1321. else
  1322. {
  1323. return $"{timeH}:{timeM.PadLeft(2, '0')}:{timeS.PadLeft(2, '0')}.0";
  1324. }
  1325. }
  1326. else
  1327. {
  1328. return value;
  1329. }
  1330. }
  1331. catch
  1332. {
  1333. return value;
  1334. }
  1335. }
  1336. public void ExportRecipe()
  1337. {
  1338. }
  1339. public void HistoryRecipe()
  1340. {
  1341. }
  1342. #endregion
  1343. #region Steps
  1344. public void SaveRecipe()
  1345. {
  1346. if (this.IsChanged)
  1347. {
  1348. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  1349. }
  1350. }
  1351. public void SavePermission()
  1352. {
  1353. CurrentRecipe.Clear();
  1354. var recipeContent = _recipeProvider.LoadRecipe(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath);
  1355. if (string.IsNullOrEmpty(recipeContent))
  1356. {
  1357. MessageBox.Show($"{CurrentRecipe.PrefixPath}\\{CurrentRecipe.Name} is empty, please confirm the file is valid.");
  1358. return;
  1359. }
  1360. CurrentRecipe.InitData(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath, recipeContent, "PM1");
  1361. CurrentRecipe.RecipeLevel = CurrentFileNode.Level;
  1362. RecipePermissionSelectViewModel dialog = new RecipePermissionSelectViewModel("Save recipe and permission", CurrentFileNode.Permission, CurrentRecipe.Description);
  1363. WindowManager wm = new WindowManager();
  1364. bool? dialogReturn = wm.ShowDialog(dialog);
  1365. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1366. return;
  1367. CurrentRecipe.RecipePermission = dialog.RecipePermission;
  1368. CurrentRecipe.Description = dialog.RecipeComment;
  1369. CurrentRecipe.RecipeLevel = CurrentFileNode.Level;
  1370. _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString());
  1371. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, CurrentFileNode.FullPath, false);
  1372. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1373. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1374. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{CurrentFileNode.FullPath}");
  1375. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  1376. item.FileListByProcessType.ForEachDo(a =>
  1377. {
  1378. a.IsSelected = false;
  1379. if (a.FullPath == prefixPath)
  1380. {
  1381. a.IsSelected = true;
  1382. RecipeFileList = a.Files.ToList();
  1383. return;
  1384. }
  1385. });
  1386. }
  1387. public bool Save(RecipeDataBase recipe, bool createNew)
  1388. {
  1389. bool result = false;
  1390. if (string.IsNullOrEmpty(recipe.Name))
  1391. {
  1392. MessageBox.Show("Recipe name can't be empty");
  1393. return false;
  1394. }
  1395. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1396. recipe.ReviseTime = DateTime.Now;
  1397. result = this._recipeProvider.SaveRecipe(recipe.PrefixPath, recipe.Name, recipe.GetXmlString());
  1398. if (result)
  1399. {
  1400. this.editMode = EditMode.Normal;
  1401. string fileName = CurrentFileNode != null ? CurrentFileNode.FullPath : recipe.Name;
  1402. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, fileName, false);
  1403. this.UpdateView();
  1404. }
  1405. else
  1406. {
  1407. MessageBox.Show("Save failed!");
  1408. }
  1409. return result;
  1410. }
  1411. private TreeViewItem GetParentObjectEx<TreeViewItem>(DependencyObject obj) where TreeViewItem : FrameworkElement
  1412. {
  1413. DependencyObject parent = VisualTreeHelper.GetParent(obj);
  1414. while (parent != null)
  1415. {
  1416. if (parent is TreeViewItem)
  1417. {
  1418. return (TreeViewItem)parent;
  1419. }
  1420. parent = VisualTreeHelper.GetParent(parent);
  1421. }
  1422. return null;
  1423. }
  1424. public void TreeRightMouseDown(MouseButtonEventArgs e)
  1425. {
  1426. var item = GetParentObjectEx<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
  1427. if (item != null)
  1428. {
  1429. item.Focus();
  1430. }
  1431. }
  1432. #endregion
  1433. private void ClearData()
  1434. {
  1435. this.editMode = EditMode.None;
  1436. this.CurrentRecipe.Clear();
  1437. this.CurrentRecipe.Name = string.Empty;
  1438. this.CurrentRecipe.Description = string.Empty;
  1439. }
  1440. private void LoadData(string prefixPath, string recipeName)
  1441. {
  1442. CurrentRecipe.Clear();
  1443. var recipeContent = _recipeProvider.LoadRecipe(prefixPath, recipeName);
  1444. if (string.IsNullOrEmpty(recipeContent))
  1445. {
  1446. MessageBox.Show($"{prefixPath}\\{recipeName} is empty, please confirm the file is valid.");
  1447. return;
  1448. }
  1449. // CurrentRecipe.RecipeChamberType = "OriginChamber";
  1450. CurrentRecipe.RecipeVersion = _columnBuilder.RecipeVersion;
  1451. CurrentRecipe.InitData(prefixPath, recipeName, recipeContent, SelectedChamber);
  1452. this.editMode = EditMode.Normal;
  1453. }
  1454. private void UpdateView()
  1455. {
  1456. bool isFileSelected = CurrentFileNode != null && CurrentFileNode.IsFile;
  1457. this.NotifyOfPropertyChange("CurrentRecipe");
  1458. }
  1459. private string oldPrefix { get; set; }
  1460. private string oldName { get; set; }
  1461. private string oldStepName { get; set; }
  1462. private bool PopupPage()
  1463. {
  1464. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1465. return false;
  1466. var windowManager = IoC.Get<IWindowManager>();
  1467. if (string.IsNullOrEmpty(CurrentFileNode.PrefixPath))
  1468. {
  1469. DialogBox.ShowWarning("Please select a file first");
  1470. return false;
  1471. }
  1472. RecipeJobEditViewModel recipeJobEditViewModel = new RecipeJobEditViewModel(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath, CurrentFileNode.Permission);
  1473. recipeJobEditViewModel.SelectRecipeType = SelectLayoutRecipeType;
  1474. bool? bret = (windowManager as WindowManager)?.ShowDialogWithTitle(recipeJobEditViewModel, null, "Job Recipe Edit");
  1475. return bret == true;
  1476. }
  1477. }
  1478. }