RecipeViewModel.cs 94 KB

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