RecipeViewModel.cs 95 KB

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