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