RecipeViewModel.cs 94 KB

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