RecipeViewModel.cs 95 KB

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