RecipeJobViewModel.cs 66 KB

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