RecipeViewModel.cs 94 KB

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