RecipeViewModel.cs 95 KB

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