RecipeViewModel.cs 95 KB

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