RecipeViewModel.cs 96 KB

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