RecipeViewModel.cs 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230
  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 ProcessTypeFileItem : NotifiableItem
  31. {
  32. public string ProcessType { get; set; }
  33. public ObservableCollection<FileNode> FileListByProcessType { get; set; }
  34. public ProcessTypeFileItem()
  35. {
  36. FileListByProcessType = new ObservableCollection<FileNode>();
  37. }
  38. }
  39. public class ChamberTypeItem : NotifiableItem
  40. {
  41. public string ChamberType { get; set; }
  42. public ObservableCollection<ProcessTypeFileItem> FileListByChamberType { get; set; }
  43. public ChamberTypeItem()
  44. {
  45. FileListByChamberType = new ObservableCollection<ProcessTypeFileItem>();
  46. }
  47. }
  48. public class RecipeViewModel : FurnaceUIViewModelBase
  49. {
  50. public bool IsPermission { get => this.Permission == 3; }//&& RtStatus != "AutoRunning";
  51. private ICommand _RenameFolderCommand;
  52. public ICommand RenameFolderCommand
  53. {
  54. get
  55. {
  56. if (this._RenameFolderCommand == null)
  57. this._RenameFolderCommand = new BaseCommand(() => this.RenameFolder());
  58. return this._RenameFolderCommand;
  59. }
  60. }
  61. private ICommand _DeleteFolderCommand;
  62. public ICommand DeleteFolderCommand
  63. {
  64. get
  65. {
  66. if (this._DeleteFolderCommand == null)
  67. this._DeleteFolderCommand = new BaseCommand(() => this.DeleteFolder());
  68. return this._DeleteFolderCommand;
  69. }
  70. }
  71. private ICommand _NewFolderCommand;
  72. public ICommand NewFolderCommand
  73. {
  74. get
  75. {
  76. if (this._NewFolderCommand == null)
  77. this._NewFolderCommand = new BaseCommand(() => this.NewFolder());
  78. return this._NewFolderCommand;
  79. }
  80. }
  81. private ICommand _NewFolderRootCommand;
  82. public ICommand NewFolderRootCommand
  83. {
  84. get
  85. {
  86. if (this._NewFolderRootCommand == null)
  87. this._NewFolderRootCommand = new BaseCommand(() => this.NewFolderRoot());
  88. return this._NewFolderRootCommand;
  89. }
  90. }
  91. private ICommand _NewRecipeCommand;
  92. public ICommand NewRecipeCommand
  93. {
  94. get
  95. {
  96. if (this._NewRecipeCommand == null)
  97. this._NewRecipeCommand = new BaseCommand(() => this.NewRecipe());
  98. return this._NewRecipeCommand;
  99. }
  100. }
  101. private ICommand _NewRecipeRootCommand;
  102. public ICommand NewRecipeRootCommand
  103. {
  104. get
  105. {
  106. if (this._NewRecipeRootCommand == null)
  107. this._NewRecipeRootCommand = new BaseCommand(() => this.NewRecipeRoot());
  108. return this._NewRecipeRootCommand;
  109. }
  110. }
  111. private ICommand _RenameRecipeCommand;
  112. public ICommand RenameRecipeCommand
  113. {
  114. get
  115. {
  116. if (this._RenameRecipeCommand == null)
  117. this._RenameRecipeCommand = new BaseCommand(() => this.RenameRecipe());
  118. return this._RenameRecipeCommand;
  119. }
  120. }
  121. private ICommand _DeleteRecipeCommand;
  122. public ICommand DeleteRecipeCommand
  123. {
  124. get
  125. {
  126. if (this._DeleteRecipeCommand == null)
  127. this._DeleteRecipeCommand = new BaseCommand(() => this.DeleteRecipe());
  128. return this._DeleteRecipeCommand;
  129. }
  130. }
  131. private ICommand _SaveAsRecipeCommand;
  132. public ICommand SaveAsRecipeCommand
  133. {
  134. get
  135. {
  136. if (this._SaveAsRecipeCommand == null)
  137. this._SaveAsRecipeCommand = new BaseCommand(() => this.SaveAsRecipe());
  138. return this._SaveAsRecipeCommand;
  139. }
  140. }
  141. private ICommand _EditRecipeCommand;
  142. public ICommand EditRecipeCommand
  143. {
  144. get
  145. {
  146. if (this._EditRecipeCommand == null)
  147. this._EditRecipeCommand = new BaseCommand(() => this.EditRecipe());
  148. return this._EditRecipeCommand;
  149. }
  150. }
  151. private ICommand _SelectRecipeTypeCommand;
  152. public ICommand SelectRecipeTypeCommand
  153. {
  154. get
  155. {
  156. if (this._SelectRecipeTypeCommand == null)
  157. this._SelectRecipeTypeCommand = new BaseCommand(() => this.SelectRecipeType());
  158. return this._SelectRecipeTypeCommand;
  159. }
  160. }
  161. private ICommand _ViewRecipeCommand;
  162. public ICommand ViewRecipeCommand
  163. {
  164. get
  165. {
  166. if (this._ViewRecipeCommand == null)
  167. this._ViewRecipeCommand = new BaseCommand(() => this.ViewRecipe());
  168. return this._ViewRecipeCommand;
  169. }
  170. }
  171. private ICommand _ChangePermission;
  172. public ICommand ChangePermission
  173. {
  174. get
  175. {
  176. if (this._ChangePermission == null)
  177. this._ChangePermission = new BaseCommand(() => this.SavePermission());
  178. return this._ChangePermission;
  179. }
  180. }
  181. private ICommand _ExportRecipeCommand;
  182. public ICommand ExportRecipeCommand
  183. {
  184. get
  185. {
  186. if (this._ExportRecipeCommand == null)
  187. this._ExportRecipeCommand = new BaseCommand(() => this.ExportRecipe());
  188. return this._ExportRecipeCommand;
  189. }
  190. }
  191. private ICommand _historyRecipeCommand;
  192. public ICommand HistoryRecipeCommand
  193. {
  194. get
  195. {
  196. if (this._historyRecipeCommand == null)
  197. this._historyRecipeCommand = new BaseCommand(() => this.HistoryRecipe());
  198. return this._historyRecipeCommand;
  199. }
  200. }
  201. private List<FileNode> _recipeFileList = new List<FileNode>();
  202. public List<FileNode> RecipeFileList
  203. {
  204. get { return _recipeFileList; }
  205. set { _recipeFileList = value; this.NotifyOfPropertyChange(nameof(RecipeFileList)); }
  206. }
  207. private List<ProcessTypeFileItem> _processTypeFileList = new List<ProcessTypeFileItem>();
  208. public List<ProcessTypeFileItem> ProcessTypeFileList
  209. {
  210. get { return _processTypeFileList; }
  211. set { _processTypeFileList = value; this.NotifyOfPropertyChange(nameof(ProcessTypeFileList)); }
  212. }
  213. public RecipeDataBase CurrentRecipe { get; private set; }
  214. public FileNode CurrentFileNode { get; set; }
  215. public bool IsCurrentNodePath { get => CurrentFileNode != null; }
  216. public bool IsCurrentNodeFile { get => CurrentFileNode != null && CurrentFileNode.IsFile; }
  217. private bool _isReadAndWritePermission = false;
  218. public bool IsReadAndWritePermission
  219. {
  220. get
  221. {
  222. // _isReadAndWritePermission = IsSelectPermission;
  223. return _isReadAndWritePermission;
  224. }
  225. set
  226. {
  227. _isReadAndWritePermission = value;
  228. NotifyOfPropertyChange(nameof(IsReadAndWritePermission));
  229. }
  230. }
  231. private bool _isFreePermission = false;
  232. public bool IsFreePermission
  233. {
  234. get
  235. {
  236. //_isFreePermission = IsSelectPermission;
  237. return _isFreePermission;
  238. }
  239. set
  240. {
  241. _isFreePermission = value;
  242. NotifyOfPropertyChange(nameof(IsFreePermission));
  243. }
  244. }
  245. private bool _isSelectPermission = false;
  246. public bool IsSelectPermission
  247. {
  248. get
  249. {
  250. _isSelectPermission = LevelDisplay != "LEVEL1" && IsCurrentNodeFile;
  251. return _isSelectPermission;
  252. }
  253. set
  254. {
  255. _isSelectPermission = value;
  256. NotifyOfPropertyChange(nameof(IsSelectPermission));
  257. }
  258. }
  259. public bool IsSingleSelectPermission
  260. {
  261. get => _isSelectPermission && !IsSingleFile;
  262. }
  263. private bool _isEnabledFolderPermission = false;
  264. public bool IsEnabledFolderPermission
  265. {
  266. get
  267. {
  268. _isEnabledFolderPermission = !IsCurrentNodeFile && !IsSingleFile;
  269. return _isEnabledFolderPermission;
  270. }
  271. set
  272. {
  273. _isEnabledFolderPermission = value;
  274. NotifyOfPropertyChange(nameof(IsEnabledFolderPermission));
  275. }
  276. }
  277. public bool IsEnabledNewRecipe
  278. {
  279. get
  280. {
  281. return !IsSingleFile;
  282. }
  283. }
  284. private bool IsChanged
  285. {
  286. get
  287. {
  288. return editMode == EditMode.Edit || (CurrentRecipe != null && CurrentRecipe.IsChanged);
  289. }
  290. }
  291. private RecipeFormatBuilder _columnBuilder = new RecipeFormatBuilder();
  292. private EditMode editMode;
  293. private RecipeProvider _recipeProvider = new RecipeProvider();
  294. public ObservableCollection<string> ChamberType { get; set; } = new ObservableCollection<string>();
  295. public int ChamberTypeIndexSelection { get; set; }
  296. private int _ProcessTypeIndexSelection;
  297. public int ProcessTypeIndexSelection
  298. {
  299. get
  300. {
  301. return _ProcessTypeIndexSelection;
  302. }
  303. set
  304. {
  305. _ProcessTypeIndexSelection = value;
  306. NotifyOfPropertyChange(nameof(ProcessTypeIndexSelection));
  307. }
  308. }
  309. public string CurrentChamberType
  310. {
  311. get
  312. {
  313. return ChamberType[ChamberTypeIndexSelection];
  314. }
  315. }
  316. public string CurrentProcessType
  317. {
  318. get
  319. {
  320. return ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  321. }
  322. }
  323. public Visibility MultiChamberVisibility
  324. {
  325. get;
  326. set;
  327. }
  328. public Visibility ToleranceVisibility
  329. {
  330. get;
  331. set;
  332. }
  333. public ObservableCollection<string> Chambers { get; set; }
  334. public string SelectedChamber { get; set; }
  335. public object View { get; set; }
  336. private string _SelectRecipeTypeName;
  337. public string SelectRecipeTypeName
  338. {
  339. get
  340. {
  341. return _SelectRecipeTypeName;
  342. }
  343. set
  344. {
  345. _SelectRecipeTypeName = value;
  346. NotifyOfPropertyChange("SelectRecipeTypeName");
  347. }
  348. }
  349. private bool IsSingleFile { get; set; } = false;
  350. protected override void OnInitialize()
  351. {
  352. base.OnInitialize();
  353. InitializeDefault();
  354. }
  355. private void InitializeDefault()
  356. {
  357. var chamberType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedChamberType");
  358. ChamberType.Clear();
  359. if (chamberType == null)
  360. {
  361. ChamberType.Add("Default");
  362. }
  363. else
  364. {
  365. (((string)(chamberType)).Split(',')).ToList().ForEach(x => ChamberType.Add(x));
  366. }
  367. ChamberTypeIndexSelection = 0;
  368. //Etch:Process,Clean,Chuck,Dechuck;CVD:Process,Clean;
  369. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{CurrentMenuID}");
  370. if (processType == null)
  371. {
  372. processType = CurrentMenuID;
  373. }
  374. if (processType == null) processType = "alarm";
  375. string[] recipeProcessType = ((string)processType).Split(',');
  376. for (int i = 0; i < recipeProcessType.Length; i++)
  377. {
  378. var type = new ProcessTypeFileItem();
  379. type.ProcessType = recipeProcessType[i];
  380. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{recipeProcessType[i]}";
  381. // var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  382. type.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefix);// RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  383. ProcessTypeFileList.Add(type);
  384. RecipeFileList = type.FileListByProcessType.FirstOrDefault()?.Files.ToList();
  385. }
  386. //if (ProcessTypeFileList[0].FileListByProcessType.Count > 0)
  387. // CurrentFileNode = ProcessTypeFileList[0].FileListByProcessType[ProcessTypeFileList[0].FileListByProcessType.Count - 1];
  388. SelectRecipeTypeName = processType + " Recipe";
  389. UpdateRecipeFormat();
  390. if (CurrentFileNode != null && CurrentFileNode.IsFile)
  391. {
  392. if (CurrentRecipe != null)
  393. {
  394. CurrentRecipe.PrefixPath = CurrentFileNode.PrefixPath;
  395. CurrentRecipe.Name = CurrentFileNode.FullPath;
  396. }
  397. //this.LoadData(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath);
  398. }
  399. GetRecipeType();
  400. }
  401. private void GetRecipeType()
  402. {
  403. var single = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.SingleRecipeFileType");
  404. if (single != null && !string.IsNullOrEmpty((string)single))
  405. {
  406. string[] singleTypes = ((string)single).ToLower().Split(';');
  407. if (singleTypes != null)
  408. {
  409. int findIndex = Array.IndexOf(singleTypes, CurrentMenuID.ToLower());
  410. if (findIndex != -1)
  411. {
  412. CreateDefaultRecipe();
  413. IsSingleFile = true;
  414. }
  415. }
  416. }
  417. }
  418. private void CreateDefaultRecipe()
  419. {
  420. var defaultFileName = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.DefaultFileName");
  421. string fileName = "default";
  422. if (defaultFileName != null && !string.IsNullOrEmpty((string)defaultFileName))
  423. {
  424. fileName = (string)defaultFileName;
  425. }
  426. string recipeName = fileName.Trim();
  427. string description = "";
  428. string prefix = CurrentChamberType + "\\" + CurrentProcessType + "\\" + fileName;
  429. if (!IsExist(recipeName.ToLower(), true))
  430. {
  431. RecipeDataBase recipe = new RecipeDataBase();
  432. recipe.Name = recipeName;
  433. recipe.PrefixPath = prefix;
  434. recipe.Creator = BaseApp.Instance.UserContext.LoginName;
  435. recipe.CreateTime = DateTime.Now;
  436. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  437. recipe.RecipeChamberType = CurrentProcessType;
  438. recipe.ReviseTime = DateTime.Now;
  439. recipe.Description = description;
  440. recipe.RecipeLevel = LevelDisplay;
  441. recipe.RecipePermission = "Free";
  442. var step = recipe.CreateStep();
  443. recipe.Steps.Add(step);
  444. if (!Save(recipe, true))
  445. return;
  446. }
  447. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  448. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  449. var tempFile = item.FileListByProcessType.FirstOrDefault(x => x.Name == fileName);
  450. if (tempFile != null)
  451. {
  452. TreeSelectChanged(tempFile);
  453. }
  454. }
  455. protected override void OnActivate()
  456. {
  457. base.OnActivate();
  458. }
  459. protected override void OnDeactivate(bool close)
  460. {
  461. base.OnDeactivate(close);
  462. if (this.IsChanged)
  463. {
  464. if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} content is changed, do you want to save it?") == DialogButton.Yes)
  465. {
  466. this.SaveRecipe();
  467. }
  468. }
  469. }
  470. public void TabSelectionChanged()
  471. {
  472. UpdateRecipeFormat();
  473. OnViewLoaded(View);
  474. }
  475. public void UpdateRecipeFormat()
  476. {
  477. this.CurrentRecipe = new RecipeDataBase();
  478. CurrentRecipe.RecipeChamberType = _columnBuilder.RecipeChamberType;
  479. CurrentRecipe.RecipeVersion = _columnBuilder.RecipeVersion;
  480. this.editMode = EditMode.None;
  481. var chamber = QueryDataClient.Instance.Service.GetConfig("System.Recipe.ChamberModules");
  482. if (chamber == null)
  483. {
  484. chamber = "PM1";
  485. }
  486. Chambers = new ObservableCollection<string>(((string)chamber).Split(','));
  487. SelectedChamber = Chambers[0];
  488. MultiChamberVisibility = Chambers.Count > 1 ? Visibility.Visible : Visibility.Collapsed;
  489. ToleranceVisibility = CurrentRecipe.ToleranceEnable ? Visibility.Visible : Visibility.Collapsed;
  490. }
  491. public void TreeSelectChanged(FileNode node)
  492. {
  493. if (IsChanged)
  494. {
  495. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No,
  496. DialogType.CONFIRM,
  497. $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  498. if (selection == DialogButton.Yes)
  499. {
  500. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  501. this.CurrentRecipe.ReviseTime = DateTime.Now;
  502. // this.Save(this.CurrentRecipe, false);
  503. }
  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. RecipeFileList = a.Files.ToList();
  514. return;
  515. }
  516. });
  517. }
  518. CurrentFileNode = node;
  519. IsFreePermission = true;
  520. IsReadAndWritePermission = true;
  521. NotifyOfPropertyChange(nameof(IsCurrentNodeFile));
  522. NotifyOfPropertyChange(nameof(IsCurrentNodePath));
  523. NotifyOfPropertyChange(nameof(IsSelectPermission));
  524. NotifyOfPropertyChange(nameof(IsSingleSelectPermission));
  525. NotifyOfPropertyChange(nameof(IsEnabledFolderPermission));
  526. if (node != null && node.IsFile)
  527. {
  528. if (CurrentRecipe != null)
  529. {
  530. CurrentRecipe.Name = node.Name;
  531. CurrentRecipe.PrefixPath = node.PrefixPath;
  532. }
  533. // this.LoadData(node.PrefixPath, node.FullPath);
  534. }
  535. else
  536. {
  537. this.ClearData();
  538. this.editMode = EditMode.None;
  539. }
  540. this.UpdateView();
  541. }
  542. #region folder
  543. public void SelectRecipeType()
  544. {
  545. var windowManager = IoC.Get<IWindowManager>();
  546. RecipeSelectRecipeTypeViewModel recipeSelectRecipeTypeViewModel = new RecipeSelectRecipeTypeViewModel();
  547. (windowManager as WindowManager)?.ShowDialogWithTitle(recipeSelectRecipeTypeViewModel, null, "Select Recipe Type");
  548. if (recipeSelectRecipeTypeViewModel.SelectRecipeType != null)
  549. {
  550. var selectRecipeType = recipeSelectRecipeTypeViewModel.SelectRecipeType;
  551. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{selectRecipeType}");
  552. if (processType == null)
  553. {
  554. processType = selectRecipeType;
  555. }
  556. ProcessTypeFileList = new List<ProcessTypeFileItem>();
  557. string[] recipeProcessType = ((string)processType).Split(',');
  558. for (int i = 0; i < recipeProcessType.Length; i++)
  559. {
  560. var type = new ProcessTypeFileItem();
  561. type.ProcessType = recipeProcessType[i];
  562. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{recipeProcessType[i]}";
  563. // var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  564. type.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefix);// RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  565. ProcessTypeFileList.Add(type);
  566. }
  567. SelectRecipeTypeName = processType + " Recipe";
  568. this.NotifyOfPropertyChange("ProcessTypeFileList");
  569. if (ProcessTypeFileList[0].FileListByProcessType.Count > 0)
  570. CurrentFileNode = ProcessTypeFileList[0].FileListByProcessType[ProcessTypeFileList[0].FileListByProcessType.Count - 1];
  571. NotifyOfPropertyChange(nameof(IsCurrentNodeFile));
  572. NotifyOfPropertyChange(nameof(IsCurrentNodePath));
  573. NotifyOfPropertyChange(nameof(IsSelectPermission));
  574. NotifyOfPropertyChange(nameof(IsReadAndWritePermission));
  575. // NotifyOfPropertyChange(nameof(IsFreePermission));
  576. ProcessTypeIndexSelection = 0;
  577. }
  578. }
  579. public void NewFolder()
  580. {
  581. if (IsChanged)
  582. {
  583. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  584. if (selection == DialogButton.Cancel)
  585. return;
  586. if (selection == DialogButton.Yes)
  587. {
  588. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  589. this.CurrentRecipe.ReviseTime = DateTime.Now;
  590. // this.Save(this.CurrentRecipe, false);
  591. }
  592. }
  593. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType, "", Visibility.Visible, Visibility.Collapsed);
  594. // dialog.FileName = "new folder";
  595. WindowManager wm = new WindowManager();
  596. bool? dialogReturn = wm.ShowDialog(dialog);
  597. if (!dialogReturn.HasValue || !dialogReturn.Value)
  598. return;
  599. if (string.IsNullOrWhiteSpace(dialog.FileName))
  600. {
  601. DialogBox.ShowWarning("Folder name should not be empty");
  602. }
  603. else
  604. {
  605. string name = dialog.FileName.Trim();
  606. FileNode selectNode = dialog.SelectNode;
  607. string prefix = ChamberType[ChamberTypeIndexSelection] + "\\" + ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  608. string newFolder = string.Empty;
  609. string folder = string.Empty;
  610. if (selectNode != null)
  611. {
  612. prefix = selectNode.PrefixPath;
  613. folder = selectNode.FullPath.Replace($"{prefix}\\", "");
  614. newFolder = $"{folder}\\{name}";
  615. }
  616. else
  617. {
  618. newFolder = name;
  619. }
  620. if (IsExist(newFolder, false))
  621. {
  622. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder with the same name already exist.");
  623. return;
  624. }
  625. if (newFolder.Length > 200)
  626. {
  627. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder name too long, should be less 200.");
  628. return;
  629. }
  630. prefix = GetPrefix(prefix, selectNode);
  631. _recipeProvider.CreateRecipeFolder(prefix, name);
  632. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  633. if (item == null)
  634. {
  635. LOG.Write("error reload recipe file list, type = " + CurrentProcessType);
  636. }
  637. //var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  638. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  639. FindSelectedFile(item.FileListByProcessType, $"{prefix}\\{newFolder}");
  640. item.InvokePropertyChanged();
  641. TreeSelectChanged(CurrentFileNode);
  642. }
  643. }
  644. private string GetPrefix(string prefix, FileNode CurrentFileNode)
  645. {
  646. string temppreFix = prefix;
  647. if (CurrentFileNode != null)
  648. {
  649. if (string.IsNullOrEmpty(CurrentFileNode.AllParentPath))
  650. {
  651. if (CurrentFileNode.IsFile)
  652. {
  653. return temppreFix;
  654. }
  655. else
  656. {
  657. temppreFix = CurrentFileNode.FullPath;
  658. }
  659. }
  660. else
  661. {
  662. if (CurrentFileNode.IsFile)
  663. {
  664. if (temppreFix.EndsWith("\\"))
  665. {
  666. temppreFix = $"{temppreFix}{CurrentFileNode.AllParentPath}";
  667. }
  668. else
  669. {
  670. temppreFix = $"{temppreFix}\\{CurrentFileNode.AllParentPath}";
  671. }
  672. }
  673. else
  674. {
  675. temppreFix = $"{temppreFix}\\{CurrentFileNode.AllParentPath}\\{CurrentFileNode.Name}";
  676. }
  677. }
  678. }
  679. return temppreFix;
  680. }
  681. public void NewFolderRoot()
  682. {
  683. if (IsChanged)
  684. {
  685. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  686. if (selection == DialogButton.Cancel)
  687. return;
  688. if (selection == DialogButton.Yes)
  689. {
  690. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  691. this.CurrentRecipe.ReviseTime = DateTime.Now;
  692. // this.Save(this.CurrentRecipe, false);
  693. }
  694. }
  695. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType);
  696. dialog.FileName = "new folder";
  697. WindowManager wm = new WindowManager();
  698. bool? dialogReturn = wm.ShowDialog(dialog);
  699. if (!dialogReturn.HasValue || !dialogReturn.Value)
  700. return;
  701. string name = dialog.FileName.Trim();
  702. if (string.IsNullOrEmpty(name))
  703. {
  704. DialogBox.ShowWarning("Folder name should not be empty");
  705. return;
  706. }
  707. if (IsExist(name, false))
  708. {
  709. DialogBox.ShowWarning($"Can not create folder {name}, Folder with the same name already exist.");
  710. return;
  711. }
  712. if (name.Length > 200)
  713. {
  714. DialogBox.ShowWarning($"Can not create folder {name}, Folder name too long, should be less 200.");
  715. return;
  716. }
  717. string prefix = ChamberType[ChamberTypeIndexSelection] + "\\" + ProcessTypeFileList[ProcessTypeIndexSelection].ProcessType;
  718. _recipeProvider.CreateRecipeFolder(prefix, name);
  719. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, name, true);
  720. }
  721. public void DeleteFolder()
  722. {
  723. if (CurrentFileNode == null || CurrentFileNode.IsFile)
  724. return;
  725. if (CurrentFileNode.Files.Count > 0)
  726. {
  727. DialogBox.ShowWarning($"Can not delete non-empty folder, Remove the files or folders under \r\n{CurrentFileNode.FullPath}.");
  728. return;
  729. }
  730. var prefix = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  731. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  732. $"Are you sure you want to delete \r\n {prefix}?");
  733. if (selection == DialogButton.No)
  734. return;
  735. //string nextFocus = CurrentFileNode.Parent.FullPath;
  736. //bool isFolder = true;
  737. //if (CurrentFileNode.Parent!=null&&CurrentFileNode.Parent.Files.Count > 1)
  738. //{
  739. // for (int i = 0; i < CurrentFileNode.Parent.Files.Count; i++)
  740. // {
  741. // if (CurrentFileNode.Parent.Files[i] == CurrentFileNode)
  742. // {
  743. // if (i == 0)
  744. // {
  745. // nextFocus = CurrentFileNode.Parent.Files[i + 1].FullPath;
  746. // isFolder = !CurrentFileNode.Parent.Files[i + 1].IsFile;
  747. // }
  748. // else
  749. // {
  750. // nextFocus = CurrentFileNode.Parent.Files[i - 1].FullPath;
  751. // isFolder = !CurrentFileNode.Parent.Files[i - 1].IsFile;
  752. // }
  753. // }
  754. // }
  755. //}
  756. prefix = prefix.Replace($"\\{CurrentFileNode.Name}", "");
  757. _recipeProvider.DeleteRecipeFolder(prefix, CurrentFileNode.Name);
  758. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, "", false, true);
  759. }
  760. public void RenameFolder()
  761. {
  762. if (CurrentFileNode == null || CurrentFileNode.IsFile)
  763. return;
  764. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Folder Name", ProcessTypeFileList[0].FileListByProcessType, "", Visibility.Hidden, Visibility.Collapsed);
  765. dialog.FileName = CurrentFileNode.Name;
  766. WindowManager wm = new WindowManager();
  767. bool? dialogReturn = wm.ShowDialog(dialog);
  768. if (!dialogReturn.HasValue || !dialogReturn.Value)
  769. return;
  770. string name = dialog.FileName.Trim();
  771. if (string.IsNullOrEmpty(name))
  772. return;
  773. string newFolder = CurrentFileNode.FullPath.Substring(0, CurrentFileNode.FullPath.LastIndexOf("\\") + 1);
  774. if (!string.IsNullOrEmpty(newFolder))
  775. newFolder = newFolder + name;
  776. else
  777. newFolder = name;
  778. if (newFolder == CurrentFileNode.FullPath)
  779. return;
  780. if (IsExist(newFolder, false))
  781. {
  782. DialogBox.ShowWarning($"Can not rename to {newFolder}, Folder with the same name already exist.");
  783. return;
  784. }
  785. if (newFolder.Length > 200)
  786. {
  787. DialogBox.ShowWarning($"Can not create folder {newFolder}, Folder name too long, should be less 200.");
  788. return;
  789. }
  790. if (_recipeProvider.RenameFolder(CurrentFileNode.PrefixPath, CurrentFileNode.Name, name))
  791. {
  792. foreach (var node in CurrentFileNode.Files)
  793. {
  794. UIGlobalVariable.Instance.ProcessModifiedRecipe[node.FullPath] = $"Folder Rename from [{CurrentFileNode.FullPath}] to [{name}] {DateTime.Now}";
  795. }
  796. }
  797. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, name, true, true);
  798. }
  799. #endregion
  800. #region recipe
  801. public void NewRecipe()
  802. {
  803. if (IsChanged)
  804. {
  805. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  806. if (selection == DialogButton.Cancel)
  807. return;
  808. if (selection == DialogButton.Yes)
  809. {
  810. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  811. this.CurrentRecipe.ReviseTime = DateTime.Now;
  812. this.Save(this.CurrentRecipe, false);
  813. }
  814. }
  815. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, "");
  816. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  817. //dialog.FileName = (string)QueryDataClient.Instance.Service.GetConfig($"System.Recipe.DefaultProcessRecipeName");
  818. WindowManager wm = new WindowManager();
  819. bool? dialogReturn = wm.ShowDialog(dialog);
  820. if (!dialogReturn.HasValue || !dialogReturn.Value)
  821. return;
  822. string recipeName = dialog.FileName.Trim();
  823. string filepath = dialog.FilePath;
  824. string description = dialog.Comment;
  825. if (string.IsNullOrEmpty(dialog.FileName))
  826. {
  827. DialogBox.ShowWarning("Recipe file name should not be empty");
  828. return;
  829. }
  830. string prefix;
  831. if (filepath.Contains("\\"))
  832. {
  833. prefix = filepath;
  834. }
  835. else
  836. {
  837. prefix = CurrentChamberType + "\\" + CurrentProcessType + "\\" + filepath;
  838. if (CurrentFileNode != null)
  839. {
  840. //获取目录
  841. prefix = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  842. }
  843. }
  844. if (RecipeFileList.Find(a => a.Name == recipeName.ToLower()) != null)
  845. {
  846. DialogBox.ShowWarning($"Can not create {recipeName}, Recipe with the same name already exist.");
  847. return;
  848. }
  849. if ((prefix + recipeName).Length > 200)
  850. {
  851. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  852. return;
  853. }
  854. RecipeDataBase recipe = new RecipeDataBase();
  855. recipe.Name = recipeName;
  856. recipe.PrefixPath = prefix;
  857. recipe.Creator = BaseApp.Instance.UserContext.LoginName;
  858. recipe.CreateTime = DateTime.Now;
  859. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  860. recipe.RecipeChamberType = CurrentProcessType;
  861. recipe.ReviseTime = DateTime.Now;
  862. recipe.Description = description;
  863. recipe.RecipeLevel = LevelDisplay;
  864. recipe.RecipePermission = "Free";
  865. if (recipe.RecipeChamberType == RecipeDataBase.ProcessType)
  866. {
  867. recipe.Steps.Add(recipe.CreateStandbyStep());
  868. recipe.Steps.Add(recipe.CreateFirstStep());
  869. recipe.Steps.Add(recipe.CreateEndStep());
  870. }
  871. else
  872. {
  873. var step = recipe.CreateStep();
  874. if (SelectRecipeTypeName.Contains("sub"))
  875. {
  876. step.TemperatureControlMode = new StringParam() { Name = "TemperatureControlMode", Value = "Furnace" };
  877. }
  878. recipe.Steps.Add(step);
  879. }
  880. if (!Save(recipe, true))
  881. return;
  882. var types = prefix.Split('\\');
  883. string newfile = string.Empty;
  884. if (types.Length > 2)
  885. {
  886. newfile = $"{string.Join("\\", types.Skip(2))}\\{recipeName}";
  887. }
  888. else
  889. {
  890. newfile = recipeName;
  891. }
  892. //ReloadRecipeFileList(types[0], types[1], newfile, false);
  893. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == types[1]);
  894. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  895. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{newfile}");
  896. item.FileListByProcessType.ForEachDo(a =>
  897. {
  898. a.IsSelected = false;
  899. if (a.FullPath == prefix)
  900. {
  901. a.IsSelected = true;
  902. CurrentFileNode = a;
  903. RecipeFileList = a.Files.ToList();
  904. return;
  905. }
  906. });
  907. }
  908. public void NewRecipeRoot()
  909. {
  910. if (IsChanged)
  911. {
  912. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  913. if (selection == DialogButton.Cancel)
  914. return;
  915. if (selection == DialogButton.Yes)
  916. {
  917. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  918. this.CurrentRecipe.ReviseTime = DateTime.Now;
  919. this.Save(this.CurrentRecipe, false);
  920. }
  921. }
  922. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description);
  923. dialog.FileName = "new recipe";
  924. WindowManager wm = new WindowManager();
  925. bool? dialogReturn = wm.ShowDialog(dialog);
  926. if (!dialogReturn.HasValue || !dialogReturn.Value)
  927. return;
  928. string recipeName = dialog.FileName.Trim();
  929. string description = dialog.Comment;
  930. if (string.IsNullOrEmpty(dialog.FileName))
  931. {
  932. DialogBox.ShowWarning("Recipe file name should not be empty");
  933. return;
  934. }
  935. if (IsExist(recipeName, true))
  936. {
  937. DialogBox.ShowWarning($"Can not create {recipeName}, Recipe with the same name already exist.");
  938. return;
  939. }
  940. if (recipeName.Length > 200)
  941. {
  942. DialogBox.ShowWarning($"Can not create folder {recipeName}, Folder name too long, should be less 200.");
  943. return;
  944. }
  945. RecipeDataBase recipe = new RecipeDataBase();
  946. recipe.Name = recipeName;
  947. recipe.PrefixPath = CurrentChamberType + "\\" + CurrentProcessType;
  948. recipe.Creator = BaseApp.Instance.UserContext.LoginName;
  949. recipe.CreateTime = DateTime.Now;
  950. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  951. recipe.ReviseTime = DateTime.Now;
  952. recipe.Description = string.Empty;
  953. recipe.Description = description;
  954. recipe.RecipeLevel = LevelDisplay;
  955. recipe.RecipePermission = "Free";
  956. if (!Save(recipe, true))
  957. return;
  958. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  959. }
  960. private void ReloadRecipeFileList(string chamberType, string processType, string selectedFile, bool selectionIsFolder, bool isRefreshFlod = false)
  961. {
  962. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == processType);
  963. if (item == null)
  964. {
  965. LOG.Write("error reload recipe file list, type = " + processType);
  966. }
  967. var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}";
  968. //var recipes = _recipeProvider.GetXmlRecipeList(prefix);
  969. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList(prefix);// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  970. FindSelectedFile(item.FileListByProcessType, $"{prefix}\\{selectedFile}");
  971. if (isRefreshFlod)
  972. item.InvokePropertyChanged();
  973. }
  974. private bool FindSelectedFile(ObservableCollection<FileNode> nodes, string selectedFile)
  975. {
  976. foreach (var recipe in nodes)
  977. {
  978. recipe.IsSelected = false;
  979. if (!recipe.IsFile)
  980. {
  981. if (recipe.FullPath == selectedFile && recipe.Files.Count == 0)
  982. {
  983. recipe.IsSelected = true;
  984. CurrentFileNode = recipe;
  985. return true;
  986. }
  987. else
  988. {
  989. if (FindSelectedFile(recipe.Files, selectedFile)) return true;
  990. }
  991. }
  992. else
  993. {
  994. string filepath = string.Empty;
  995. if (string.IsNullOrEmpty(recipe.AllParentPath))
  996. {
  997. filepath = recipe.Name;
  998. }
  999. else
  1000. {
  1001. filepath = recipe.AllParentPath + "\\" + recipe.Name;
  1002. }
  1003. if (filepath == selectedFile.Replace($"{recipe.PrefixPath}\\", ""))
  1004. {
  1005. recipe.IsSelected = true;
  1006. CurrentFileNode = recipe;
  1007. return true;
  1008. }
  1009. }
  1010. }
  1011. return false;
  1012. }
  1013. private bool IsExist(string fullPath, bool isFile)
  1014. {
  1015. for (int i = 0; i < ProcessTypeFileList.Count; i++)
  1016. {
  1017. if (ProcessTypeFileList[i].ProcessType == CurrentProcessType)
  1018. {
  1019. if (ProcessTypeFileList[i].FileListByProcessType.Count == 0)
  1020. return false;
  1021. foreach (var item in ProcessTypeFileList[i].FileListByProcessType)
  1022. {
  1023. if (FindFile(fullPath, item, isFile))
  1024. {
  1025. return true;
  1026. }
  1027. }
  1028. return false;
  1029. }
  1030. }
  1031. return true;
  1032. }
  1033. private bool FindFile(string path, FileNode root, bool isFile)
  1034. {
  1035. if (root.FullPath.ToLower() == path && !isFile)
  1036. {
  1037. return true;
  1038. }
  1039. if (root.IsFile && isFile)
  1040. {
  1041. return root.FullPath.ToLower().Equals(path);
  1042. }
  1043. else if (!root.IsFile && isFile)
  1044. {
  1045. foreach (var node in root.Files)
  1046. {
  1047. if (isFile && node.IsFile && node.FullPath.ToLower() == path)
  1048. return true;
  1049. if (!node.IsFile && FindFile(path, node, isFile))
  1050. return true;
  1051. }
  1052. }
  1053. return false;
  1054. }
  1055. public void SaveAsRecipe()
  1056. {
  1057. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1058. return;
  1059. if (IsChanged)
  1060. {
  1061. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  1062. if (selection == DialogButton.Cancel)
  1063. return;
  1064. if (selection == DialogButton.Yes)
  1065. {
  1066. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1067. this.CurrentRecipe.ReviseTime = DateTime.Now;
  1068. this.Save(this.CurrentRecipe, false);
  1069. }
  1070. }
  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.Creator = BaseApp.Instance.UserContext.LoginName;
  1109. CurrentRecipe.CreateTime = DateTime.Now;
  1110. CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1111. CurrentRecipe.ReviseTime = DateTime.Now;
  1112. CurrentRecipe.Description = CurrentRecipe.Description + ". Renamed from " + CurrentFileNode.Name;
  1113. _recipeProvider.SaveAsRecipe(prefix, recipeName, CurrentRecipe.GetXmlString());
  1114. prefix = GetPrefix(prefix, CurrentFileNode);
  1115. if (selectNode.Name == prefix)
  1116. {
  1117. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, recipeName, false);
  1118. }
  1119. else
  1120. {
  1121. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1122. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1123. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{recipeName}");
  1124. item.FileListByProcessType.ForEachDo(a =>
  1125. {
  1126. a.IsSelected = false;
  1127. if (a.FullPath == prefix)
  1128. {
  1129. a.IsSelected = true;
  1130. RecipeFileList = a.Files.ToList();
  1131. return;
  1132. }
  1133. });
  1134. }
  1135. }
  1136. public void RenameRecipe()
  1137. {
  1138. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1139. return;
  1140. if (IsChanged)
  1141. {
  1142. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No | DialogButton.Cancel, DialogType.CONFIRM, $"Recipe {CurrentRecipe.Name} is changed, do you want to save it?");
  1143. if (selection == DialogButton.Cancel)
  1144. return;
  1145. if (selection == DialogButton.Yes)
  1146. {
  1147. this.CurrentRecipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1148. this.CurrentRecipe.ReviseTime = DateTime.Now;
  1149. this.Save(this.CurrentRecipe, false);
  1150. }
  1151. }
  1152. InputFileNameDialogViewModel dialog = new InputFileNameDialogViewModel("Input New Recipe Name", ProcessTypeFileList[0].FileListByProcessType, CurrentRecipe.Description, Visibility.Hidden);
  1153. dialog.SelectIndex = ProcessTypeFileList[0].FileListByProcessType.IndexOf(ProcessTypeFileList[0].FileListByProcessType.FirstOrDefault(a => a.IsSelected));
  1154. dialog.FileName = CurrentFileNode.Name;
  1155. WindowManager wm = new WindowManager();
  1156. bool? dialogReturn = wm.ShowDialog(dialog);
  1157. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1158. return;
  1159. string recipeName = dialog.FileName.Trim();
  1160. if (string.IsNullOrEmpty(dialog.FileName))
  1161. {
  1162. DialogBox.ShowWarning("Recipe file name should not be empty");
  1163. return;
  1164. }
  1165. string prefix = CurrentChamberType + "\\" + CurrentProcessType;
  1166. string processType = string.Empty;
  1167. string newName = CurrentFileNode.FullPath.Substring(0, CurrentFileNode.FullPath.LastIndexOf("\\") + 1);
  1168. if (!string.IsNullOrEmpty(newName))
  1169. newName = newName + recipeName;
  1170. else
  1171. newName = recipeName;
  1172. if (newName == CurrentFileNode.FullPath)
  1173. return;
  1174. if (IsExist(newName, true))
  1175. {
  1176. DialogBox.ShowWarning($"Can not rename to {newName}, Recipe with the same name already exist.");
  1177. return;
  1178. }
  1179. if (newName.Length > 200)
  1180. {
  1181. DialogBox.ShowWarning($"Can not create folder {newName}, Folder name too long, should be less 200.");
  1182. return;
  1183. }
  1184. prefix = GetPrefix(prefix, CurrentFileNode);
  1185. if (_recipeProvider.RenameRecipe(prefix, CurrentFileNode.Name, recipeName))
  1186. {
  1187. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Rename Recipe from [{CurrentFileNode.FullPath}] to [{recipeName}] {DateTime.Now}";
  1188. }
  1189. CurrentRecipe.Name = dialog.FileName;
  1190. CurrentRecipe.Description = dialog.Comment;
  1191. CurrentRecipe.ReviseTime= DateTime.Now;
  1192. CurrentRecipe.PrefixPath= prefix;
  1193. this.Save(CurrentRecipe, false);
  1194. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, newName, false);
  1195. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1196. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1197. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{newName}");
  1198. item.FileListByProcessType.ForEachDo(a =>
  1199. {
  1200. a.IsSelected = false;
  1201. if (a.FullPath == prefix)
  1202. {
  1203. a.IsSelected = true;
  1204. RecipeFileList = a.Files.ToList();
  1205. return;
  1206. }
  1207. });
  1208. }
  1209. public void DeleteRecipe()
  1210. {
  1211. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1212. return;
  1213. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM,
  1214. $"Are you sure you want to delete \r\n {CurrentFileNode.FullPath}?");
  1215. if (selection == DialogButton.No)
  1216. return;
  1217. //string nextFocus = CurrentFileNode.Parent.FullPath;
  1218. //bool isFolder = true;
  1219. //if (CurrentFileNode.Parent.Files.Count > 1)
  1220. //{
  1221. // for (int i = 0; i < CurrentFileNode.Parent.Files.Count; i++)
  1222. // {
  1223. // if (CurrentFileNode.Parent.Files[i] == CurrentFileNode)
  1224. // {
  1225. // if (i == 0)
  1226. // {
  1227. // nextFocus = CurrentFileNode.Parent.Files[i + 1].FullPath;
  1228. // isFolder = !CurrentFileNode.Parent.Files[i + 1].IsFile;
  1229. // }
  1230. // else
  1231. // {
  1232. // nextFocus = CurrentFileNode.Parent.Files[i - 1].FullPath;
  1233. // isFolder = !CurrentFileNode.Parent.Files[i - 1].IsFile;
  1234. // }
  1235. // }
  1236. // }
  1237. //}
  1238. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  1239. if (_recipeProvider.DeleteRecipe(prefixPath, CurrentFileNode.Name))
  1240. {
  1241. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Delet Recipe from [{CurrentFileNode.FullPath}] {DateTime.Now}";
  1242. }
  1243. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, "", false);
  1244. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1245. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1246. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{""}");
  1247. item.FileListByProcessType.ForEachDo(a =>
  1248. {
  1249. a.IsSelected = false;
  1250. if (a.FullPath == prefixPath)
  1251. {
  1252. a.IsSelected = true;
  1253. RecipeFileList = a.Files.ToList();
  1254. return;
  1255. }
  1256. });
  1257. }
  1258. public void ReloadRecipe()
  1259. {
  1260. if (this.editMode == EditMode.Normal || this.editMode == EditMode.Edit)
  1261. {
  1262. this.LoadData(CurrentRecipe.PrefixPath, CurrentRecipe.Name);
  1263. this.UpdateView();
  1264. }
  1265. }
  1266. public void SaveToAll()
  1267. {
  1268. if (!CurrentRecipe.IsCompatibleWithCurrentFormat)
  1269. {
  1270. DialogBox.ShowWarning($"Save failed, {CurrentRecipe.Name} is not a valid recipe file");
  1271. return;
  1272. }
  1273. var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No,
  1274. DialogType.CONFIRM, $"Do you want to save to all? \r\n This will replace all the other chamber recipe content");
  1275. if (selection == DialogButton.No)
  1276. return;
  1277. CurrentRecipe.SaveTo(Chambers.ToArray());
  1278. Save(this.CurrentRecipe, false);
  1279. }
  1280. public void SaveTo()
  1281. {
  1282. if (!CurrentRecipe.IsCompatibleWithCurrentFormat)
  1283. {
  1284. DialogBox.ShowWarning($"Save failed, {CurrentRecipe.Name} is not a valid recipe file");
  1285. return;
  1286. }
  1287. SaveToDialogViewModel dialog = new SaveToDialogViewModel("Select which chamber to copy to", SelectedChamber, Chambers.ToList());
  1288. WindowManager wm = new WindowManager();
  1289. bool? dialogReturn = wm.ShowDialog(dialog);
  1290. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1291. return;
  1292. List<string> chambers = new List<string>();
  1293. foreach (var dialogChamber in dialog.Chambers)
  1294. {
  1295. if (dialogChamber.IsEnabled && dialogChamber.IsChecked)
  1296. chambers.Add(dialogChamber.Name);
  1297. }
  1298. if (chambers.Count == 0)
  1299. return;
  1300. CurrentRecipe.SaveTo(chambers.ToArray());
  1301. Save(this.CurrentRecipe, false);
  1302. }
  1303. public void EditRecipe()
  1304. {
  1305. CGlobal.RecipeProcessEditViewEnable = true;
  1306. MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = true;
  1307. if (PopupPage())
  1308. {
  1309. UIGlobalVariable.Instance.ProcessModifiedRecipe[CurrentFileNode.FullPath] = $"Edit {DateTime.Now}";
  1310. this.editMode = EditMode.Normal;
  1311. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  1312. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1313. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1314. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{CurrentFileNode.FullPath}");
  1315. item.FileListByProcessType.ForEachDo(a =>
  1316. {
  1317. a.IsSelected = false;
  1318. if (a.FullPath == prefixPath)
  1319. {
  1320. a.IsSelected = true;
  1321. CurrentFileNode = a;
  1322. RecipeFileList = a.Files.ToList();
  1323. return;
  1324. }
  1325. });
  1326. this.UpdateView();
  1327. }
  1328. }
  1329. public void ViewRecipe()
  1330. {
  1331. CGlobal.RecipeProcessEditViewEnable = false;
  1332. MECF.Framework.UI.Client.CenterViews.Editors.Recipe.CGlobal.RecipeProcessEditViewEnable = false;
  1333. if (PopupPage())
  1334. {
  1335. this.editMode = EditMode.Normal;
  1336. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, CurrentFileNode.FullPath, false);
  1337. this.UpdateView();
  1338. }
  1339. }
  1340. private string GetTimeFormat(string value)
  1341. {
  1342. try
  1343. {
  1344. if (value != null && value.Length > 1 && value.Split(':').Length > 2)
  1345. {
  1346. var timeH = value.Split(':')[0];
  1347. var timeM = value.Split(':')[1];
  1348. var timeS = value.Split(':')[2];
  1349. if (timeS.Contains('.'))
  1350. {
  1351. var timesArray = timeS.Split('.');
  1352. return $"{timeH}:{timeM.PadLeft(2, '0')}:{timesArray[0].PadLeft(2, '0')}.{timesArray[1].Substring(0, 1)}";
  1353. }
  1354. else
  1355. {
  1356. return $"{timeH}:{timeM.PadLeft(2, '0')}:{timeS.PadLeft(2, '0')}.0";
  1357. }
  1358. }
  1359. else
  1360. {
  1361. return value;
  1362. }
  1363. }
  1364. catch
  1365. {
  1366. return value;
  1367. }
  1368. }
  1369. public void ExportRecipe()
  1370. {
  1371. try
  1372. {
  1373. if (CurrentRecipe == null)
  1374. {
  1375. MessageBox.Show("No choice recipe or Step is null");
  1376. return;
  1377. }
  1378. CurrentRecipe.Clear();
  1379. // var prefixPath = GetPrefix(CurrentRecipe.PrefixPath, CurrentFileNode);
  1380. var recipeContent = _recipeProvider.LoadRecipe(CurrentRecipe.PrefixPath, CurrentFileNode.FullPath);
  1381. if (string.IsNullOrEmpty(recipeContent))
  1382. {
  1383. MessageBox.Show($"{CurrentRecipe.PrefixPath}\\{CurrentRecipe.Name} is empty, please confirm the file is valid.");
  1384. return;
  1385. }
  1386. CurrentRecipe.InitData(CurrentRecipe.PrefixPath, CurrentRecipe.Name, recipeContent, "PM1");
  1387. if (CurrentRecipe.Steps.Count == 0)
  1388. {
  1389. MessageBox.Show("Step is null");
  1390. }
  1391. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1392. dlg.DefaultExt = ".xlsx"; // Default file extension
  1393. dlg.FileName = $"{CurrentRecipe.Name}_{DateTime.Now:yyyyMMdd_HHmmss}";
  1394. dlg.Filter = "Excel数据表格文件(*.xlsx)|*.xlsx"; // Filter files by extension
  1395. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  1396. if (result == true) // Process open file dialog box results
  1397. {
  1398. System.Data.DataSet ds = new System.Data.DataSet();
  1399. if (CurrentRecipe.GetIsTableType)
  1400. {
  1401. SaveTablesStepsToTable(ds);
  1402. }
  1403. else
  1404. {
  1405. SaveStepsToTable(ds);
  1406. }
  1407. if (!ExcelHelper.ExportToExcel(dlg.FileName, ds, out string reason))
  1408. {
  1409. MessageBox.Show($"Export failed, {reason}", "Export", MessageBoxButton.OK, MessageBoxImage.Warning);
  1410. return;
  1411. }
  1412. MessageBox.Show($"Export succeed, file save as {dlg.FileName}", "Export", MessageBoxButton.OK, MessageBoxImage.Information);
  1413. }
  1414. }
  1415. catch (Exception ex)
  1416. {
  1417. LOG.Write(ex);
  1418. MessageBox.Show("导出系统日志发生错误", "导出失败", MessageBoxButton.OK, MessageBoxImage.Warning);
  1419. }
  1420. }
  1421. public void HistoryRecipe()
  1422. {
  1423. if (CurrentRecipe == null || CurrentFileNode == null)
  1424. {
  1425. return;
  1426. }
  1427. RecipeHistoryViewModel dialog = new RecipeHistoryViewModel();
  1428. WindowManager wm = new WindowManager();
  1429. dialog.FilePath = $"{CurrentFileNode.PrefixPath}\\{CurrentFileNode.FullPath}";
  1430. dialog.CurrentRecipe = CurrentRecipe;
  1431. bool? dialogReturn = wm.ShowDialogWithTitle(dialog);
  1432. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1433. return;
  1434. }
  1435. private void SaveStepsToTable(System.Data.DataSet ds)
  1436. {
  1437. ds.Tables.Add(new System.Data.DataTable("Recipe"));
  1438. Step step = CurrentRecipe.Steps[0];
  1439. ds.Tables[0].Columns.Add("StepNo");
  1440. ds.Tables[0].Columns.Add("Name");
  1441. ds.Tables[0].Columns.Add("Time");
  1442. ds.Tables[0].Columns.Add("Command");
  1443. ds.Tables[0].Columns.Add("EndBy");
  1444. ds.Tables[0].Columns.Add("ConditionCheck");
  1445. ds.Tables[0].Columns.Add("SkipWait");
  1446. ds.Tables[0].Columns.Add("AbortRecipeTableIndex");
  1447. ds.Tables[0].Columns.Add("Temperature.ControlMode");
  1448. ds.Tables[0].Columns.Add("Temperature.Correct");
  1449. ds.Tables[0].Columns.Add("Temperature.PID");
  1450. foreach (var item in step.TemperatureSets)
  1451. {
  1452. ds.Tables[0].Columns.Add($"{item.Name}.ZoneName");
  1453. ds.Tables[0].Columns.Add($"{item.Name}.Set");
  1454. ds.Tables[0].Columns.Add($"{item.Name}.SetUnit");
  1455. ds.Tables[0].Columns.Add($"{item.Name}.Ramprate");
  1456. ds.Tables[0].Columns.Add($"{item.Name}.RamprateUnit");
  1457. ds.Tables[0].Columns.Add($"{item.Name}.Check");
  1458. ds.Tables[0].Columns.Add($"{item.Name}.High");
  1459. ds.Tables[0].Columns.Add($"{item.Name}.Low");
  1460. ds.Tables[0].Columns.Add($"{item.Name}.Unit");
  1461. }
  1462. foreach (var item in step.MFCSets)
  1463. {
  1464. ds.Tables[0].Columns.Add($"{item.ControlName}.Set");
  1465. ds.Tables[0].Columns.Add($"{item.ControlName}.SetUnit");
  1466. ds.Tables[0].Columns.Add($"{item.ControlName}.Ramprate");
  1467. ds.Tables[0].Columns.Add($"{item.ControlName}.RamprateUnit");
  1468. ds.Tables[0].Columns.Add($"{item.ControlName}.Check");
  1469. ds.Tables[0].Columns.Add($"{item.ControlName}.High");
  1470. ds.Tables[0].Columns.Add($"{item.ControlName}.Low");
  1471. ds.Tables[0].Columns.Add($"{item.ControlName}.Unit");
  1472. }
  1473. ds.Tables[0].Columns.Add("Press.Command");
  1474. ds.Tables[0].Columns.Add("Press.PID");
  1475. ds.Tables[0].Columns.Add("Press.Set");
  1476. ds.Tables[0].Columns.Add("Press.SlowVacSet");
  1477. ds.Tables[0].Columns.Add("Press.ValveAngleSet");
  1478. ds.Tables[0].Columns.Add("Press.IsWait");
  1479. ds.Tables[0].Columns.Add("Press.LowWait");
  1480. ds.Tables[0].Columns.Add("Press.HighWait");
  1481. ds.Tables[0].Columns.Add("Press.WaitUnit");
  1482. ds.Tables[0].Columns.Add("Press.LowPressWait");
  1483. ds.Tables[0].Columns.Add("Press.WaitPress");
  1484. foreach (var item in step.ValveSets)
  1485. {
  1486. ds.Tables[0].Columns.Add(item.Name);
  1487. }
  1488. ds.Tables[0].Columns.Add("Loader.Command");
  1489. ds.Tables[0].Columns.Add("Loader.Speed1");
  1490. ds.Tables[0].Columns.Add("Loader.Speed2");
  1491. ds.Tables[0].Columns.Add("Loader.Speed3");
  1492. ds.Tables[0].Columns.Add("Loader.RPM");
  1493. foreach (var item in step.MFMSets.Keys)
  1494. {
  1495. ds.Tables[0].Columns.Add(item);
  1496. }
  1497. foreach (var item in step.EXOUSets.Keys)
  1498. {
  1499. ds.Tables[0].Columns.Add(item);
  1500. }
  1501. ds.Tables[0].Columns.Add("AlarmTableIndex");
  1502. ds.Tables[0].Columns.Add("FilmThickFormula");
  1503. foreach (var tempstep in CurrentRecipe.Steps)
  1504. {
  1505. var row = ds.Tables[0].NewRow();
  1506. row["StepNo"] = tempstep.StepNo;
  1507. row["Name"] = tempstep.Name;
  1508. row["EndBy"] = tempstep.EndBy;
  1509. row["Time"] = GetTimeFormat(tempstep.Time);
  1510. row["SkipWait"] = tempstep.SkipWait;
  1511. row["ConditionCheck"] = tempstep.IsnoneConditionCheck;
  1512. row["Command"] = tempstep.Command;
  1513. row["AbortRecipeTableIndex"] = tempstep.AbortRecipeTableIndex;
  1514. foreach (var item in tempstep.ValveSets)
  1515. {
  1516. row[item.Name] = item.Value ? "Open" : "Close";
  1517. }
  1518. foreach (var item in tempstep.MFCSets)
  1519. {
  1520. row[$"{item.ControlName}.Set"] = item.SetValue.Value;
  1521. row[$"{item.ControlName}.SetUnit"] = item.SetUnit.Value;
  1522. row[$"{item.ControlName}.Ramprate"] = item.Rampng.Value;
  1523. row[$"{item.ControlName}.RamprateUnit"] = item.RampngUnit.Value;
  1524. row[$"{item.ControlName}.Check"] = item.IsCheck.Value.ToString();
  1525. row[$"{item.ControlName}.High"] = item.MaxValue.Value;
  1526. row[$"{item.ControlName}.Low"] = item.MinValue.Value;
  1527. row[$"{item.ControlName}.Unit"] = item.Unit;
  1528. }
  1529. foreach (var item in tempstep.MFMSets.Keys)
  1530. {
  1531. row[item] = tempstep.MFMSets[item];
  1532. }
  1533. foreach (var item in tempstep.EXOUSets.Keys)
  1534. {
  1535. row[item] = tempstep.EXOUSets[item];
  1536. }
  1537. foreach (var item in tempstep.TemperatureSets)
  1538. {
  1539. row[$"{item.Name}.ZoneName"] = item.Name;
  1540. row[$"{item.Name}.Set"] = item.SetValue.Value;
  1541. row[$"{item.Name}.SetUnit"] = item.SetUnit.Value;
  1542. row[$"{item.Name}.Ramprate"] = item.RampngValue.Value;
  1543. row[$"{item.Name}.RamprateUnit"] = item.RampngUnit.Value;
  1544. row[$"{item.Name}.Check"] = item.IsCheck.Value.ToString();
  1545. row[$"{item.Name}.High"] = item.HighValue.Value;
  1546. row[$"{item.Name}.Low"] = item.LowValue.Value;
  1547. row[$"{item.Name}.Unit"] = item.Unit;
  1548. }
  1549. row["Temperature.ControlMode"] = tempstep.TemperatureControlMode.Value;
  1550. row["Temperature.Correct"] = tempstep.TemperatureCorrect.Value;
  1551. row["Temperature.PID"] = tempstep.TemperaturePID.Value;
  1552. row["Loader.Command"] = tempstep.LoaderCommand.Value;
  1553. row["Loader.Speed1"] = tempstep.LoaderSpeed1.Value;
  1554. row["Loader.Speed2"] = tempstep.LoaderSpeed2.Value;
  1555. row["Loader.Speed3"] = tempstep.LoaderSpeed3.Value;
  1556. row["Loader.RPM"] = tempstep.LoaderRPM.Value;
  1557. row["Press.Command"] = tempstep.PressCommand.Value;
  1558. row["Press.PID"] = RecipeDataBase.GetPressPidValue(tempstep);
  1559. row["Press.Set"] = RecipeDataBase.GetPressSetValue(tempstep);// tempstep.PressSet.Value;
  1560. row["Press.SlowVacSet"] = RecipeDataBase.GetPressSlowVacSet(tempstep);// tempstep.PressSlowVacSet.Value;
  1561. row["Press.ValveAngleSet"] = RecipeDataBase.GetValveAngleSet(tempstep); //tempstep.PressValveAngleSet.Value;
  1562. row["Press.IsWait"] = tempstep.PressIsWait.Value;
  1563. row["Press.LowWait"] = tempstep.PressLowWait.Value;
  1564. row["Press.HighWait"] = tempstep.PressHighWait.Value;
  1565. row["Press.WaitUnit"] = tempstep.PressWaitUnit.Value;
  1566. row["Press.LowPressWait"] = tempstep.PressLowPressWait.Value;
  1567. row["Press.WaitPress"] = RecipeDataBase.GetWaitPress(tempstep);//tempstep.WaitPress.Value;
  1568. row["AlarmTableIndex"] = tempstep.AlarmConditionTable.Value;
  1569. row["FilmThickFormula"] = tempstep.FilmThickFormula;
  1570. ds.Tables[0].Rows.Add(row);
  1571. }
  1572. }
  1573. private void SaveTablesStepsToTable(System.Data.DataSet ds)
  1574. {
  1575. foreach (var table in CurrentRecipe.Tables)
  1576. {
  1577. if (table.TableData.Steps == null || table.TableData.Steps.Count == 0)
  1578. {
  1579. continue;
  1580. }
  1581. string tableStr = $"table{table.Index}";
  1582. ds.Tables.Add(new System.Data.DataTable(tableStr));
  1583. Step step = table.TableData.Steps[0];
  1584. ds.Tables[tableStr].Columns.Add("StepNo");
  1585. ds.Tables[tableStr].Columns.Add("Name");
  1586. ds.Tables[tableStr].Columns.Add("Time");
  1587. ds.Tables[tableStr].Columns.Add("Command");
  1588. ds.Tables[tableStr].Columns.Add("EndBy");
  1589. ds.Tables[tableStr].Columns.Add("ConditionCheck");
  1590. ds.Tables[tableStr].Columns.Add("SkipWait");
  1591. ds.Tables[tableStr].Columns.Add("AbortRecipeTableIndex");
  1592. ds.Tables[tableStr].Columns.Add("Temperature.ControlMode");
  1593. ds.Tables[tableStr].Columns.Add("Temperature.Correct");
  1594. ds.Tables[tableStr].Columns.Add("Temperature.PID");
  1595. foreach (var item in step.TemperatureSets)
  1596. {
  1597. ds.Tables[tableStr].Columns.Add($"{item.Name}.ZoneName");
  1598. ds.Tables[tableStr].Columns.Add($"{item.Name}.Set");
  1599. ds.Tables[tableStr].Columns.Add($"{item.Name}.SetUnit");
  1600. ds.Tables[tableStr].Columns.Add($"{item.Name}.Ramprate");
  1601. ds.Tables[tableStr].Columns.Add($"{item.Name}.RamprateUnit");
  1602. ds.Tables[tableStr].Columns.Add($"{item.Name}.Check");
  1603. ds.Tables[tableStr].Columns.Add($"{item.Name}.High");
  1604. ds.Tables[tableStr].Columns.Add($"{item.Name}.Low");
  1605. ds.Tables[tableStr].Columns.Add($"{item.Name}.Unit");
  1606. }
  1607. foreach (var item in step.MFCSets)
  1608. {
  1609. ds.Tables[tableStr].Columns.Add($"{item.ControlName}.Set");
  1610. ds.Tables[tableStr].Columns.Add($"{item.ControlName}.SetUnit");
  1611. ds.Tables[tableStr].Columns.Add($"{item.ControlName}.Ramprate");
  1612. ds.Tables[tableStr].Columns.Add($"{item.ControlName}.RamprateUnit");
  1613. ds.Tables[tableStr].Columns.Add($"{item.ControlName}.Check");
  1614. ds.Tables[tableStr].Columns.Add($"{item.ControlName}.High");
  1615. ds.Tables[tableStr].Columns.Add($"{item.ControlName}.Low");
  1616. ds.Tables[tableStr].Columns.Add($"{item.ControlName}.Unit");
  1617. }
  1618. ds.Tables[tableStr].Columns.Add("Press.Command");
  1619. ds.Tables[tableStr].Columns.Add("Press.PID");
  1620. ds.Tables[tableStr].Columns.Add("Press.Set");
  1621. ds.Tables[tableStr].Columns.Add("Press.SlowVacSet");
  1622. ds.Tables[tableStr].Columns.Add("Press.ValveAngleSet");
  1623. ds.Tables[tableStr].Columns.Add("Press.IsWait");
  1624. ds.Tables[tableStr].Columns.Add("Press.LowWait");
  1625. ds.Tables[tableStr].Columns.Add("Press.HighWait");
  1626. ds.Tables[tableStr].Columns.Add("Press.WaitUnit");
  1627. ds.Tables[tableStr].Columns.Add("Press.LowPressWait");
  1628. ds.Tables[tableStr].Columns.Add("Press.WaitPress");
  1629. foreach (var item in step.ValveSets)
  1630. {
  1631. ds.Tables[tableStr].Columns.Add(item.Name);
  1632. }
  1633. ds.Tables[tableStr].Columns.Add("Loader.Command");
  1634. ds.Tables[tableStr].Columns.Add("Loader.Speed1");
  1635. ds.Tables[tableStr].Columns.Add("Loader.Speed2");
  1636. ds.Tables[tableStr].Columns.Add("Loader.Speed3");
  1637. ds.Tables[tableStr].Columns.Add("Loader.RPM");
  1638. foreach (var item in step.MFMSets.Keys)
  1639. {
  1640. ds.Tables[tableStr].Columns.Add(item);
  1641. }
  1642. foreach (var item in step.EXOUSets.Keys)
  1643. {
  1644. ds.Tables[tableStr].Columns.Add(item);
  1645. }
  1646. ds.Tables[tableStr].Columns.Add("AlarmTableIndex");
  1647. ds.Tables[tableStr].Columns.Add("FilmThickFormula");
  1648. foreach (var tempstep in table.TableData.Steps)
  1649. {
  1650. var row = ds.Tables[tableStr].NewRow();
  1651. row["StepNo"] = tempstep.StepNo;
  1652. row["Name"] = tempstep.Name;
  1653. row["EndBy"] = tempstep.EndBy;
  1654. row["Time"] = GetTimeFormat(tempstep.Time);
  1655. row["SkipWait"] = tempstep.SkipWait;
  1656. row["ConditionCheck"] = tempstep.IsnoneConditionCheck;
  1657. row["Command"] = tempstep.Command;
  1658. row["AbortRecipeTableIndex"] = tempstep.AbortRecipeTableIndex;
  1659. foreach (var item in tempstep.ValveSets)
  1660. {
  1661. row[item.Name] = item.Value ? "Open" : "Close";
  1662. }
  1663. foreach (var item in tempstep.MFCSets)
  1664. {
  1665. row[$"{item.ControlName}.Set"] = item.SetValue.Value;
  1666. row[$"{item.ControlName}.SetUnit"] = item.SetUnit.Value;
  1667. row[$"{item.ControlName}.Ramprate"] = item.Rampng.Value;
  1668. row[$"{item.ControlName}.RamprateUnit"] = item.RampngUnit.Value;
  1669. row[$"{item.ControlName}.Check"] = item.IsCheck.Value.ToString();
  1670. row[$"{item.ControlName}.High"] = item.MaxValue.Value;
  1671. row[$"{item.ControlName}.Low"] = item.MinValue.Value;
  1672. row[$"{item.ControlName}.Unit"] = item.Unit;
  1673. }
  1674. foreach (var item in tempstep.MFMSets.Keys)
  1675. {
  1676. row[item] = tempstep.MFMSets[item].Value;
  1677. }
  1678. foreach (var item in tempstep.EXOUSets.Keys)
  1679. {
  1680. row[item] = tempstep.EXOUSets[item];
  1681. }
  1682. foreach (var item in tempstep.TemperatureSets)
  1683. {
  1684. row[$"{item.Name}.ZoneName"] = item.Name;
  1685. row[$"{item.Name}.Set"] = item.SetValue.Value;
  1686. row[$"{item.Name}.SetUnit"] = item.SetUnit.Value;
  1687. row[$"{item.Name}.Ramprate"] = item.RampngValue.Value;
  1688. row[$"{item.Name}.RamprateUnit"] = item.RampngUnit.Value;
  1689. row[$"{item.Name}.Check"] = item.IsCheck.Value.ToString();
  1690. row[$"{item.Name}.High"] = item.HighValue.Value;
  1691. row[$"{item.Name}.Low"] = item.LowValue.Value;
  1692. row[$"{item.Name}.Unit"] = item.Unit;
  1693. }
  1694. row["Temperature.ControlMode"] = tempstep.TemperatureControlMode.Value;
  1695. row["Temperature.Correct"] = tempstep.TemperatureCorrect.Value;
  1696. row["Temperature.PID"] = tempstep.TemperaturePID.Value;
  1697. row["Loader.Command"] = tempstep.LoaderCommand.Value;
  1698. row["Loader.Speed1"] = tempstep.LoaderSpeed1.Value;
  1699. row["Loader.Speed2"] = tempstep.LoaderSpeed2.Value;
  1700. row["Loader.Speed3"] = tempstep.LoaderSpeed3.Value;
  1701. row["Loader.RPM"] = tempstep.LoaderRPM.Value;
  1702. row["Press.Command"] = tempstep.PressCommand.Value;
  1703. row["Press.PID"] = tempstep.PressPID.Value.Replace(",", ":");
  1704. row["Press.Set"] = RecipeDataBase.GetPressSetValue(tempstep);// tempstep.PressSet.Value;
  1705. row["Press.SlowVacSet"] = RecipeDataBase.GetPressSlowVacSet(tempstep);// tempstep.PressSlowVacSet.Value;
  1706. row["Press.ValveAngleSet"] = RecipeDataBase.GetValveAngleSet(tempstep);//tempstep.PressValveAngleSet.Value;
  1707. row["Press.IsWait"] = tempstep.PressIsWait.Value;
  1708. row["Press.LowWait"] = tempstep.PressLowWait.Value;
  1709. row["Press.HighWait"] = tempstep.PressHighWait.Value;
  1710. row["Press.WaitUnit"] = tempstep.PressWaitUnit.Value;
  1711. row["Press.LowPressWait"] = tempstep.PressLowPressWait.Value;
  1712. row["Press.WaitPress"] = RecipeDataBase.GetWaitPress(tempstep);//tempstep.WaitPress.Value;
  1713. row["AlarmTableIndex"] = tempstep.AlarmConditionTable.Value;
  1714. row["FilmThickFormula"] = tempstep.FilmThickFormula;
  1715. ds.Tables[tableStr].Rows.Add(row);
  1716. }
  1717. }
  1718. }
  1719. #endregion
  1720. #region Steps
  1721. public void SaveRecipe()
  1722. {
  1723. if (this.IsChanged)
  1724. {
  1725. this.Save(this.CurrentRecipe, false);
  1726. }
  1727. }
  1728. public void PopSetting(string controlName, Param paramData)
  1729. {
  1730. int stepNum = Convert.ToInt32(((StepParam)paramData.Parent[1]).Value);
  1731. PublicPopSettingDialogViewModel dialog = new PublicPopSettingDialogViewModel();
  1732. dialog.DisplayName = paramData.DisplayName;
  1733. ObservableCollection<Param> Parameters = new ObservableCollection<Param>();
  1734. Parameters = this.CurrentRecipe.PopSettingSteps[controlName][stepNum - 1];
  1735. ObservableCollection<Param> ControlParameters = new ObservableCollection<Param>();
  1736. ObservableCollection<BandParam> BrandParameters = new ObservableCollection<BandParam>();
  1737. foreach (var item in Parameters)
  1738. {
  1739. if (item.Name.Contains("Band"))
  1740. {
  1741. string name = item.Name.Replace("Wavelength", "").Replace("Bandwidth", "");
  1742. string displayName = item.DisplayName.Replace("Wavelength", "").Replace("Bandwidth", "");
  1743. if (BrandParameters.Where(x => x.Name == name).Count() == 0)
  1744. {
  1745. BrandParameters.Add(new BandParam()
  1746. {
  1747. Name = name,
  1748. DisplayName = displayName
  1749. });
  1750. }
  1751. if (item.Name.Contains("Wavelength"))
  1752. {
  1753. BrandParameters.First(x => x.Name == name).WavelengthDoubleParam = item;
  1754. }
  1755. else if (item.Name.Contains("Bandwidth"))
  1756. {
  1757. BrandParameters.First(x => x.Name == name).BandwidthDoubleParam = item;
  1758. }
  1759. }
  1760. else
  1761. ControlParameters.Add(item);
  1762. }
  1763. dialog.Parameters = Parameters;
  1764. dialog.ControlParameters = ControlParameters;
  1765. dialog.BandParameters = BrandParameters;
  1766. WindowManager wm = new WindowManager();
  1767. bool? bret = wm.ShowDialog(dialog);
  1768. if ((bool)bret)
  1769. {
  1770. this.CurrentRecipe.PopSettingSteps[controlName][stepNum - 1] = dialog.Parameters;
  1771. }
  1772. }
  1773. public void SavePermission()
  1774. {
  1775. CurrentRecipe.Clear();
  1776. var prefixPath = GetPrefix(CurrentFileNode.PrefixPath, CurrentFileNode);
  1777. var recipeContent = _recipeProvider.LoadRecipe(prefixPath, CurrentRecipe.Name);
  1778. if (string.IsNullOrEmpty(recipeContent))
  1779. {
  1780. MessageBox.Show($"{CurrentRecipe.PrefixPath}\\{CurrentRecipe.Name} is empty, please confirm the file is valid.");
  1781. return;
  1782. }
  1783. CurrentRecipe.InitData(prefixPath, CurrentRecipe.Name, recipeContent, "PM1");
  1784. CurrentRecipe.RecipeLevel = CurrentFileNode.Level;
  1785. RecipePermissionSelectViewModel dialog = new RecipePermissionSelectViewModel("Save recipe and permission", CurrentFileNode.Permission, CurrentRecipe.Description);
  1786. WindowManager wm = new WindowManager();
  1787. bool? dialogReturn = wm.ShowDialog(dialog);
  1788. if (!dialogReturn.HasValue || !dialogReturn.Value)
  1789. return;
  1790. this.LoadData(CurrentRecipe.PrefixPath, CurrentRecipe.Name);
  1791. CurrentRecipe.RecipePermission = dialog.RecipePermission;
  1792. CurrentRecipe.Description = dialog.RecipeComment;
  1793. CurrentRecipe.RecipeLevel = CurrentFileNode.Level;
  1794. this.Save(CurrentRecipe, false);
  1795. //ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, CurrentFileNode.FullPath, false);
  1796. ProcessTypeFileItem item = ProcessTypeFileList.FirstOrDefault(x => x.ProcessType == CurrentProcessType);
  1797. item.FileListByProcessType = RecipeSequenceTreeBuilder.GetFileNodeParameterList($"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}");// RecipeSequenceTreeBuilder.BuildFileNode(prefix, selectedFile, selectionIsFolder, recipes)[0].Files;
  1798. FindSelectedFile(item.FileListByProcessType, $"{$"{ChamberType[ChamberTypeIndexSelection]}\\{item.ProcessType}"}\\{CurrentFileNode.FullPath}");
  1799. item.FileListByProcessType.ForEachDo(a =>
  1800. {
  1801. a.IsSelected = false;
  1802. if (a.FullPath == CurrentRecipe.PrefixPath)
  1803. {
  1804. a.IsSelected = true;
  1805. RecipeFileList = a.Files.ToList();
  1806. return;
  1807. }
  1808. });
  1809. }
  1810. public bool Save(RecipeDataBase recipe, bool createNew)
  1811. {
  1812. bool result = false;
  1813. if (string.IsNullOrEmpty(recipe.Name))
  1814. {
  1815. MessageBox.Show("Recipe name can't be empty");
  1816. return false;
  1817. }
  1818. recipe.Revisor = BaseApp.Instance.UserContext.LoginName;
  1819. recipe.ReviseTime = DateTime.Now;
  1820. result = this._recipeProvider.SaveRecipe(recipe.PrefixPath, recipe.Name, recipe.GetXmlString());
  1821. if (result)
  1822. {
  1823. this.editMode = EditMode.Normal;
  1824. string fileName = CurrentFileNode != null ? CurrentFileNode.FullPath : recipe.Name;
  1825. ReloadRecipeFileList(CurrentChamberType, CurrentProcessType, fileName, false);
  1826. this.UpdateView();
  1827. }
  1828. else
  1829. {
  1830. MessageBox.Show("Save failed!");
  1831. }
  1832. return result;
  1833. }
  1834. private TreeViewItem GetParentObjectEx<TreeViewItem>(DependencyObject obj) where TreeViewItem : FrameworkElement
  1835. {
  1836. DependencyObject parent = VisualTreeHelper.GetParent(obj);
  1837. while (parent != null)
  1838. {
  1839. if (parent is TreeViewItem)
  1840. {
  1841. return (TreeViewItem)parent;
  1842. }
  1843. parent = VisualTreeHelper.GetParent(parent);
  1844. }
  1845. return null;
  1846. }
  1847. public void TreeRightMouseDown(MouseButtonEventArgs e)
  1848. {
  1849. var item = GetParentObjectEx<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
  1850. if (item != null)
  1851. {
  1852. item.Focus();
  1853. }
  1854. }
  1855. #endregion
  1856. private void ClearData()
  1857. {
  1858. this.editMode = EditMode.None;
  1859. this.CurrentRecipe.Clear();
  1860. this.CurrentRecipe.Name = string.Empty;
  1861. this.CurrentRecipe.Description = string.Empty;
  1862. }
  1863. private void LoadData(string prefixPath, string recipeName)
  1864. {
  1865. CurrentRecipe.Clear();
  1866. var recipeContent = _recipeProvider.LoadRecipe(prefixPath, recipeName);
  1867. if (string.IsNullOrEmpty(recipeContent))
  1868. {
  1869. MessageBox.Show($"{prefixPath}\\{recipeName} is empty, please confirm the file is valid.");
  1870. return;
  1871. }
  1872. // CurrentRecipe.RecipeChamberType = "OriginChamber";
  1873. CurrentRecipe.RecipeVersion = _columnBuilder.RecipeVersion;
  1874. CurrentRecipe.InitData(prefixPath, recipeName, recipeContent, SelectedChamber);
  1875. this.editMode = EditMode.Normal;
  1876. }
  1877. private void UpdateView()
  1878. {
  1879. bool isFileSelected = CurrentFileNode != null && CurrentFileNode.IsFile;
  1880. this.NotifyOfPropertyChange("CurrentRecipe");
  1881. }
  1882. private string oldPrefix { get; set; }
  1883. private string oldName { get; set; }
  1884. private string oldStepName { get; set; }
  1885. private bool PopupPage()
  1886. {
  1887. if (CurrentFileNode == null || !CurrentFileNode.IsFile)
  1888. return false;
  1889. var windowManager = IoC.Get<IWindowManager>();
  1890. RecipeProcessEditViewModel recipeEditViewModel = new RecipeProcessEditViewModel(CurrentFileNode.PrefixPath, CurrentFileNode.FullPath, CurrentFileNode.Permission);
  1891. recipeEditViewModel.SetParent(Window.GetWindow((UIElement)GetView()));
  1892. recipeEditViewModel.RecipeType = CurrentProcessType;
  1893. this.CurrentRecipe = recipeEditViewModel.CurrentRecipe;
  1894. if (!string.IsNullOrEmpty(oldPrefix) && !string.IsNullOrEmpty(oldName) && !string.IsNullOrEmpty(oldStepName)
  1895. && (CurrentRecipe.PrefixPath == oldPrefix && CurrentFileNode.FullPath == oldName))
  1896. {
  1897. recipeEditViewModel.SelectedStepName = oldStepName;
  1898. }
  1899. bool? bret = (windowManager as WindowManager)?.ShowDialogWithTitle(recipeEditViewModel, null, $"Recipe Edit");
  1900. if (recipeEditViewModel.CurrentRecipe != null && recipeEditViewModel.selectStep != null)
  1901. {
  1902. oldPrefix = recipeEditViewModel.CurrentRecipe.PrefixPath;
  1903. oldName = recipeEditViewModel.CurrentRecipe.Name;
  1904. oldStepName = recipeEditViewModel.SelectedRecipeStep.Name;
  1905. }
  1906. return bret == true;
  1907. }
  1908. }
  1909. public class BringSelectedItemIntoViewBehavior
  1910. {
  1911. public static readonly DependencyProperty IsBringSelectedIntoViewProperty = DependencyProperty.RegisterAttached(
  1912. "IsBringSelectedIntoView", typeof(bool), typeof(BringSelectedItemIntoViewBehavior), new PropertyMetadata(default(bool), PropertyChangedCallback));
  1913. public static void SetIsBringSelectedIntoView(DependencyObject element, bool value)
  1914. {
  1915. element.SetValue(IsBringSelectedIntoViewProperty, value);
  1916. }
  1917. public static bool GetIsBringSelectedIntoView(DependencyObject element)
  1918. {
  1919. return (bool)element.GetValue(IsBringSelectedIntoViewProperty);
  1920. }
  1921. private static void PropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
  1922. {
  1923. var treeViewItem = dependencyObject as TreeViewItem;
  1924. if (treeViewItem == null)
  1925. {
  1926. return;
  1927. }
  1928. if (!((bool)dependencyPropertyChangedEventArgs.OldValue) &&
  1929. ((bool)dependencyPropertyChangedEventArgs.NewValue))
  1930. {
  1931. treeViewItem.Unloaded += TreeViewItemOnUnloaded;
  1932. treeViewItem.Selected += TreeViewItemOnSelected;
  1933. }
  1934. }
  1935. private static void TreeViewItemOnUnloaded(object sender, RoutedEventArgs routedEventArgs)
  1936. {
  1937. var treeViewItem = sender as TreeViewItem;
  1938. if (treeViewItem == null)
  1939. {
  1940. return;
  1941. }
  1942. treeViewItem.Unloaded -= TreeViewItemOnUnloaded;
  1943. treeViewItem.Selected -= TreeViewItemOnSelected;
  1944. }
  1945. private static void TreeViewItemOnSelected(object sender, RoutedEventArgs routedEventArgs)
  1946. {
  1947. var treeViewItem = sender as TreeViewItem;
  1948. treeViewItem?.BringIntoView();
  1949. }
  1950. }
  1951. }