RecipeViewModel.cs 94 KB

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