RecipeViewModel.cs 85 KB

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