RecipeViewModel.cs 95 KB

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