RecipeViewModel.cs 95 KB

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