NewRecipeViewModel.cs 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.IOCore;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.UI.View.Common;
  5. using MECF.Framework.Common.CommonData;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.OperationCenter;
  9. using Microsoft.VisualBasic;
  10. using Newtonsoft.Json;
  11. using Newtonsoft.Json.Linq;
  12. using Prism.Commands;
  13. using Prism.Mvvm;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Collections.ObjectModel;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Reflection;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using System.Windows;
  23. using System.Windows.Controls;
  24. using System.Windows.Data;
  25. using System.Windows.Input;
  26. using System.Windows.Media;
  27. using System.Xml;
  28. using Venus_Core;
  29. using Venus_Core.Attributes;
  30. using Venus_MainPages.PMs;
  31. using Venus_MainPages.Unity;
  32. using Venus_MainPages.Views;
  33. using Venus_Themes.UserControls;
  34. using WPF.Themes.UserControls;
  35. using MessageBox = System.Windows.MessageBox;
  36. using RecipeStep = Venus_Core.RecipeStep;
  37. namespace Venus_MainPages.ViewModels
  38. {
  39. internal class NewRecipeViewModel : BindableBase
  40. {
  41. #region 私有字段
  42. public string ModuleName = "PMA";
  43. private string m_CurrentRecipeName;
  44. private UiRecipeManager m_uiRecipeManager = new UiRecipeManager();
  45. private NewRecipeView recipeView;
  46. private TreeView treeViewRcpList;
  47. private Recipe m_currentRecipe;
  48. private string m_recipeType;
  49. private bool firstLoad = true;
  50. private WrapPanel headWrapPanel;
  51. private int copyIndex = -1;
  52. private List<string> EPDCfgList = new List<string>();
  53. private EPDType currentEPDType = EPDType.None;
  54. private JetChamber currentChamber;
  55. private bool isInstalledEPD;
  56. private bool m_IsFrozen;
  57. private bool m_PMAIsInstalled;
  58. private bool m_PMBIsInstalled;
  59. private bool m_PMCIsInstalled;
  60. private bool m_PMDIsInstalled;
  61. private readonly List<string> moduleList = new List<string>();
  62. TreeViewFileItem selectedItem;
  63. private string typeFolder = "";
  64. private bool m_HeadExpand = true;
  65. private Grid leftGrid;
  66. private Grid rightGrid;
  67. private readonly int controlHeight = 24;
  68. private readonly string tolerancePath = "_Tolerance_EAP";
  69. private readonly string eapPath = "_EAP";
  70. #endregion
  71. #region 属性
  72. public bool HeadExpand
  73. {
  74. get { return m_HeadExpand; }
  75. set { SetProperty(ref m_HeadExpand, value); }
  76. }
  77. public string CurrentRecipeName
  78. {
  79. get { return m_CurrentRecipeName; }
  80. set { SetProperty(ref m_CurrentRecipeName, value); }
  81. }
  82. public Recipe CurrentRecipe
  83. {
  84. get { return m_currentRecipe; }
  85. set
  86. {
  87. m_currentRecipe = value;
  88. RecipeType = m_currentRecipe?.Header?.Type.ToString();
  89. }
  90. }
  91. public string RecipeType
  92. {
  93. get { return m_recipeType; }
  94. set { SetProperty(ref m_recipeType, value); }
  95. }
  96. public bool IsFrozen
  97. {
  98. get { return m_IsFrozen; }
  99. set { SetProperty(ref m_IsFrozen, value); }
  100. }
  101. public bool PMAIsInstalled
  102. {
  103. get { return m_PMAIsInstalled; }
  104. set { SetProperty(ref m_PMAIsInstalled, value); }
  105. }
  106. public bool PMBIsInstalled
  107. {
  108. get { return m_PMBIsInstalled; }
  109. set { SetProperty(ref m_PMBIsInstalled, value); }
  110. }
  111. public bool PMCIsInstalled
  112. {
  113. get { return m_PMCIsInstalled; }
  114. set { SetProperty(ref m_PMCIsInstalled, value); }
  115. }
  116. public bool PMDIsInstalled
  117. {
  118. get { return m_PMDIsInstalled; }
  119. set { SetProperty(ref m_PMDIsInstalled, value); }
  120. }
  121. #endregion
  122. #region 命令
  123. private DelegateCommand<Object> _MouseRightButtonDownCommand;
  124. public DelegateCommand<Object> MouseRightButtonDownCommand =>
  125. _MouseRightButtonDownCommand ?? (_MouseRightButtonDownCommand = new DelegateCommand<Object>(OnMouseRightButtonDown));
  126. private DelegateCommand<Object> _LoadedCommand;
  127. public DelegateCommand<Object> LoadedCommand =>
  128. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand<Object>(OnLoaded));
  129. private DelegateCommand _SaveRecipeCommand;
  130. public DelegateCommand SaveRecipeCommand =>
  131. _SaveRecipeCommand ?? (_SaveRecipeCommand = new DelegateCommand(OnSaveRecipe));
  132. private DelegateCommand<object> _SaveToRecipeCommand;
  133. public DelegateCommand<object> SaveToRecipeCommand =>
  134. _SaveToRecipeCommand ?? (_SaveToRecipeCommand = new DelegateCommand<object>(OnSaveToRecipe));
  135. private DelegateCommand _AddStepCommand;
  136. public DelegateCommand AddStepCommand =>
  137. _AddStepCommand ?? (_AddStepCommand = new DelegateCommand(OnAddStep));
  138. private DelegateCommand _DeleteStepCommand;
  139. public DelegateCommand DeleteStepCommand =>
  140. _DeleteStepCommand ?? (_DeleteStepCommand = new DelegateCommand(OnDeleteStep));
  141. private DelegateCommand _RefreshCommand;
  142. public DelegateCommand RefreshCommand =>
  143. _RefreshCommand ?? (_RefreshCommand = new DelegateCommand(OnRefresh));
  144. private DelegateCommand _ExpandCommand;
  145. public DelegateCommand ExpandCommand =>
  146. _ExpandCommand ?? (_ExpandCommand = new DelegateCommand(OnExpand));
  147. private DelegateCommand _UnloadCommand;
  148. public DelegateCommand UnloadCommand =>
  149. _UnloadCommand ?? (_UnloadCommand = new DelegateCommand(OnUnload));
  150. private DelegateCommand _ClearRecipeCommand;
  151. public DelegateCommand ClearRecipeCommand =>
  152. _ClearRecipeCommand ?? (_ClearRecipeCommand = new DelegateCommand(OnClearRecipe));
  153. private DelegateCommand<Object> _MouseLeftButtonDownCommand;
  154. public DelegateCommand<Object> MouseLeftButtonDownCommand =>
  155. _MouseLeftButtonDownCommand ?? (_MouseLeftButtonDownCommand = new DelegateCommand<Object>(OnMouseLeftButtonDown));
  156. #endregion
  157. #region 命令方法
  158. private void OnAddStep()
  159. {
  160. if (CurrentRecipe != null && IsFrozen == false)
  161. {
  162. var index = rightGrid.ColumnDefinitions.Count;
  163. RecipeStep recipeStep;
  164. if (copyIndex == -1)
  165. {
  166. recipeStep = new RecipeStep();
  167. recipeStep.StepNo = index + 1;
  168. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  169. CurrentRecipe.Steps.Add(recipeStep);
  170. }
  171. else
  172. {
  173. var t = JsonConvert.SerializeObject(CurrentRecipe);
  174. recipeStep = Recipe.Load(t).Steps[copyIndex - 1];
  175. recipeStep.StepNo = index + 1;
  176. CurrentRecipe.Steps.Add(recipeStep);
  177. }
  178. ColumnDefinition col1 = new ColumnDefinition();
  179. col1.Width = GridLength.Auto;
  180. rightGrid.ColumnDefinitions.Insert(index, col1);
  181. RecipeStepToGridColumn(recipeStep, rightGrid, index);
  182. }
  183. }
  184. private void OnDeleteStep()
  185. {
  186. if (CurrentRecipe != null && IsFrozen == false)
  187. {
  188. OnDeleteStep(CurrentRecipe.Steps.Count - 1);
  189. }
  190. }
  191. private void OnSaveRecipe()
  192. {
  193. if (WPFMessageBox.ShowQuestion($"Save recipe file?", "") == MessageBoxResult.Yes)
  194. {
  195. var inLP1UseRecipe = QueryDataClient.Instance.Service.GetData($"Scheduler.LP1.InUsingRecipe");
  196. var inLP2UseRecipe = QueryDataClient.Instance.Service.GetData($"Scheduler.LP2.InUsingRecipe");
  197. var inLP3UseRecipe = QueryDataClient.Instance.Service.GetData($"Scheduler.LP3.InUsingRecipe");
  198. if (inLP1UseRecipe != null)
  199. {
  200. if ((inLP1UseRecipe as List<string>).Contains($"{ModuleName}.{CurrentRecipe.Header.Type}.{CurrentRecipeName}"))
  201. {
  202. WPFMessageBox.ShowError($"{CurrentRecipeName} Recipe is LP1 In Use,can not edit");
  203. return;
  204. }
  205. }
  206. if (inLP2UseRecipe != null)
  207. {
  208. if ((inLP2UseRecipe as List<string>).Contains($"{ModuleName}.{CurrentRecipe.Header.Type}.{CurrentRecipeName}"))
  209. {
  210. WPFMessageBox.ShowError($"{CurrentRecipeName} Recipe is LP2 In Use,can not edit");
  211. return;
  212. }
  213. }
  214. if (inLP3UseRecipe != null)
  215. {
  216. if ((inLP3UseRecipe as List<string>).Contains($"{ModuleName}.{CurrentRecipe.Header.Type}.{CurrentRecipeName}"))
  217. {
  218. WPFMessageBox.ShowError($"{CurrentRecipeName} Recipe is LP3 In Use,can not edit");
  219. return;
  220. }
  221. }
  222. CurrentRecipe.Header.EditTime = DateTime.Now.ToString();
  223. CurrentRecipe.Header.LastModifiedBy = GlobalUser.Instance.User.Name;
  224. //SaveRecipe(CurrentRecipeName, RecipeUnity.RecipeToString(CurrentRecipe));
  225. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, CurrentRecipeName + ".rcp");
  226. FileInfo fi = new FileInfo(newrecipePath);
  227. var di = fi.Directory;
  228. if (!di.Exists)
  229. {
  230. di.Create();
  231. }
  232. //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(CurrentRecipe),Encoding.UTF8);
  233. string recipeContent = RecipeUnity.RecipeToString(CurrentRecipe);
  234. SaveRecipe(CurrentRecipe.Header.Name, CurrentRecipe.Header.Type.ToString(), recipeContent);
  235. //LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  236. SaveEAPRecipe(recipeContent, CurrentRecipeName);
  237. }
  238. }
  239. private void OnSaveToRecipe(object obj)
  240. {
  241. if (CurrentRecipe == null)
  242. {
  243. return;
  244. }
  245. string moduleName = "";
  246. switch (obj.ToString())
  247. {
  248. case "0":
  249. moduleName = "PMA";
  250. break;
  251. case "1":
  252. moduleName = "PMB";
  253. break;
  254. case "2":
  255. moduleName = "PMC";
  256. break;
  257. case "3":
  258. moduleName = "PMD";
  259. break;
  260. case "4":
  261. moduleName = "ALL";
  262. break;
  263. }
  264. if (moduleName == "")
  265. {
  266. return;
  267. }
  268. if (moduleName == "ALL")
  269. {
  270. var newName = Interaction.InputBox(" ", $"Save Recipe To All", CurrentRecipeName, -1, -1);
  271. OnSaveRecipe();
  272. foreach (var x in moduleList)
  273. {
  274. if (newName != "")
  275. {
  276. var targetChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{x}.ChamberType").ToString());
  277. if (currentChamber != targetChamber || x == ModuleName)
  278. {
  279. continue;
  280. }
  281. var newRecipe = CurrentRecipe;
  282. newRecipe.Header.Name = newName;
  283. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  284. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", x, typeFolder, newName + ".rcp");
  285. FileInfo fi = new FileInfo(newrecipePath);
  286. var di = fi.Directory;
  287. if (!di.Exists)
  288. {
  289. di.Create();
  290. }
  291. //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  292. if (m_uiRecipeManager.SaveAsRecipeWithType(x, CurrentRecipe.Header.Type.ToString(), newName, RecipeUnity.RecipeToString(newRecipe)))
  293. {
  294. UpdateRecipeFileList();
  295. }
  296. UpdateRecipeFileList();
  297. }
  298. }
  299. }
  300. else
  301. {
  302. var targetChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{moduleName}.ChamberType").ToString());
  303. if (currentChamber != targetChamber)
  304. {
  305. WPFMessageBox.ShowError($"Recipe can not from {currentChamber.ToString()} copy to {targetChamber.ToString()}");
  306. return;
  307. }
  308. var newName = Interaction.InputBox(" ", $"Save Recipe To {moduleName}", CurrentRecipeName, -1, -1);
  309. if (newName != "")
  310. {
  311. OnSaveRecipe();
  312. var newRecipe = CurrentRecipe;
  313. newRecipe.Header.Name = newName;
  314. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  315. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", moduleName, typeFolder, newName + ".rcp");
  316. FileInfo fi = new FileInfo(newrecipePath);
  317. var di = fi.Directory;
  318. if (!di.Exists)
  319. {
  320. di.Create();
  321. }
  322. //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  323. if (m_uiRecipeManager.SaveAsRecipeWithType(moduleName, CurrentRecipe.Header.Type.ToString(), newName, RecipeUnity.RecipeToString(newRecipe)))
  324. {
  325. UpdateRecipeFileList();
  326. }
  327. //if (SaveAsRecipeWithType(newName, CurrentRecipe.Header.Type.ToString(), RecipeUnity.RecipeToString(newRecipe)))
  328. //{
  329. //}
  330. }
  331. }
  332. }
  333. private async void OnLoaded(Object myrecipeView)
  334. {
  335. if (firstLoad == true)
  336. {
  337. currentChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.ChamberType").ToString());
  338. if (currentChamber != JetChamber.Kepler2200A && currentChamber != JetChamber.Kepler2200B)
  339. {
  340. isInstalledEPD = bool.Parse(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.IsEnabled").ToString());
  341. }
  342. firstLoad = false;
  343. recipeView = myrecipeView as NewRecipeView;
  344. treeViewRcpList = recipeView.treeViewRcpList;
  345. headWrapPanel = recipeView.headWrapPanel;
  346. //bodyStackPanel = recipeView.bodyStackPanel;
  347. leftGrid = recipeView.leftGrid;
  348. rightGrid = recipeView.rightGrid;
  349. UpdateRecipeFileList();
  350. treeViewRcpList.SelectedItemChanged += TreeViewRcpList_SelectedItemChanged;
  351. string allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString();
  352. if (allModules.Contains("PMA"))
  353. {
  354. PMAIsInstalled = true;
  355. moduleList.Add("PMA");
  356. }
  357. if (allModules.Contains("PMB"))
  358. {
  359. PMBIsInstalled = true;
  360. moduleList.Add("PMB");
  361. }
  362. if (allModules.Contains("PMC"))
  363. {
  364. PMCIsInstalled = true;
  365. moduleList.Add("PMC");
  366. }
  367. if (allModules.Contains("PMD"))
  368. {
  369. PMDIsInstalled = true;
  370. moduleList.Add("PMD");
  371. }
  372. }
  373. if (isInstalledEPD)
  374. {
  375. for (int i = 0; i < 5; i++)
  376. {
  377. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.EndPoint.SearchCfg");
  378. await Task.Delay(200);
  379. currentEPDType = (EPDType)System.Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.EPDType"));
  380. if (currentEPDType == EPDType.Socket)
  381. {
  382. EPDCfgList = (List<string>)QueryDataClient.Instance.Service.GetData($"{ModuleName}.EPDCfgList");
  383. }
  384. if (EPDCfgList != null)
  385. {
  386. EPDCfgList.Add("");
  387. break;
  388. }
  389. }
  390. }
  391. UpdateRecipeFileList();
  392. }
  393. private void TreeViewRcpList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  394. {
  395. //rightGrid.Visibility = Visibility.Visible;
  396. selectedItem = e.NewValue as TreeViewFileItem;
  397. if (selectedItem == null)
  398. return;
  399. try
  400. {
  401. string[] info = selectedItem.FileName.Split('\\');
  402. //string path;
  403. string xmlRecipeData = "";
  404. if (info.Length == 1)
  405. {
  406. CurrentRecipeName = info[0];
  407. typeFolder = "";
  408. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{CurrentRecipeName}.rcp");
  409. xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  410. }
  411. else if (info.Length == 2)
  412. {
  413. string type = info[0];
  414. typeFolder = type;
  415. CurrentRecipeName = info[1];
  416. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, type, $"{CurrentRecipeName}.rcp");
  417. xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  418. }
  419. else
  420. {
  421. return;
  422. }
  423. if (xmlRecipeData == "")
  424. {
  425. treeViewRcpList.Items.Remove(selectedItem);
  426. return;
  427. }
  428. CurrentRecipe = Recipe.Load(xmlRecipeData);
  429. if (CurrentRecipe.Header.ChamberType != currentChamber)
  430. {
  431. WPFMessageBox.ShowError($"Can not Open {CurrentRecipe.Header.ChamberType} Recipe in {currentChamber} Chamber,please delete it.");
  432. return;
  433. }
  434. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  435. LoadRecipe(CurrentRecipe);
  436. }
  437. catch (Exception ex)
  438. {
  439. WPFMessageBox.ShowError(ex.ToString());
  440. //MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  441. }
  442. e.Handled = true;
  443. }
  444. public bool SaveRecipe(string recipeName, string type, string recipeContent)
  445. {
  446. return m_uiRecipeManager.SaveRecipeWithType(ModuleName, type, recipeName, recipeContent);
  447. }
  448. private void OnMouseRightButtonDown(Object treeView)
  449. {
  450. //treeViewRcpList = treeView as TreeView;
  451. treeViewRcpList.ContextMenu = new ContextMenu() { Background = new SolidColorBrush(Colors.AliceBlue) };
  452. MenuItem menuItem = new MenuItem();
  453. menuItem = new MenuItem();
  454. menuItem.Tag = "\\";
  455. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateRecipe);
  456. menuItem.Header = "New Recipe";
  457. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  458. menuItem = new MenuItem();
  459. menuItem.Tag = "\\";
  460. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_DeleteRecipe);
  461. menuItem.Header = "Delete Recipe";
  462. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  463. menuItem = new MenuItem();
  464. menuItem.Tag = "\\";
  465. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_SaveAsRecipe);
  466. menuItem.Header = "Save As Recipe";
  467. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  468. menuItem = new MenuItem();
  469. menuItem.Tag = "\\";
  470. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_RenameRecipe);
  471. menuItem.Header = "Rename";
  472. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  473. treeViewRcpList.ContextMenu.Visibility = Visibility.Visible;
  474. }
  475. private void OnMouseLeftButtonDown(Object treeView)
  476. {
  477. //treeViewRcpList = treeView as TreeView;
  478. }
  479. private void menuItem_MouseClick_CreateRecipe(object sender, RoutedEventArgs e)
  480. {
  481. //MenuItem mit = sender as MenuItem;
  482. //string folderName = mit.Tag as string;
  483. PerformCreateRecipe();
  484. }
  485. private void PerformCreateRecipe()
  486. {
  487. try
  488. {
  489. bool hasHV = false;
  490. if (currentChamber == JetChamber.VenusSE || currentChamber == JetChamber.VenusDE)
  491. {
  492. hasHV = true;
  493. }
  494. RecipeNameInputDlg dlg = new RecipeNameInputDlg("Input Recipe Name", hasHV)
  495. {
  496. Owner = Application.Current.MainWindow
  497. };
  498. if (dlg.ShowDialog() == true)
  499. {
  500. var recipeName = dlg.InputText;
  501. //var recipeName = folderName + dlg.InputText;
  502. //var recipeName = folderName + "\\" + dlg.InputText;
  503. if (!RecipeNameIsOk(recipeName))
  504. {
  505. return;
  506. }
  507. RecipeType type = (RecipeType)Enum.Parse(typeof(RecipeType), dlg.SelectedType);
  508. //typeFolder=type.ToString();
  509. string newRecipe = RecipeUnity.CreateRecipe(currentChamber, type, dlg.InputText, GlobalUser.Instance.User.Name);
  510. if (SaveAsRecipeWithType(recipeName, type.ToString(), newRecipe))
  511. {
  512. UpdateRecipeFileList();
  513. }
  514. //SaveEAPRecipe(newRecipe,recipeName);
  515. }
  516. }
  517. catch (Exception ex)
  518. {
  519. LOG.WriteExeption(ex);
  520. WPFMessageBox.ShowError(ex.ToString());
  521. //MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  522. }
  523. }
  524. private void menuItem_MouseClick_DeleteRecipe(object sender, RoutedEventArgs e)
  525. {
  526. //if (CurrentRecipe == null)
  527. //{
  528. // return;
  529. //}
  530. if (WPFMessageBox.ShowQuestion($"Delete {typeFolder}Recipe {CurrentRecipeName}?", "删除后无法恢复!!!") == MessageBoxResult.Yes)
  531. {
  532. //MenuItem mit = sender as MenuItem;
  533. //string recipename = mit.Header.ToString();
  534. string path = typeFolder == "" ? CurrentRecipeName : $"{typeFolder}\\{CurrentRecipeName}";
  535. m_uiRecipeManager.DeleteRecipe(ModuleName, path);
  536. DeleteEAPRecipe();
  537. DeleteToleranceRecipe();
  538. //PerformCreateRecipe(folderName);
  539. //treeViewRcpList.Items.Remove(selectedItem);
  540. UpdateRecipeFileList();
  541. }
  542. }
  543. private void menuItem_MouseClick_SaveAsRecipe(object sender, RoutedEventArgs e)
  544. {
  545. if (CurrentRecipe == null)
  546. {
  547. return;
  548. }
  549. var newName = Interaction.InputBox(" ", "Save As Recipe", CurrentRecipeName, -1, -1);
  550. if (!RecipeNameIsOk(newName))
  551. {
  552. return;
  553. }
  554. //newName = newName.Trim();
  555. if (newName != CurrentRecipeName && newName != "")
  556. {
  557. var newRecipe = CurrentRecipe;
  558. if (WPFMessageBox.ShowQuestion($"Save recipe file {newName} ?", "") == MessageBoxResult.Yes)
  559. {
  560. //MessageBox.Show($"Save as recipe {newName} ?", "Save As Recipe", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  561. newRecipe.Header.Name = newName;
  562. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  563. //var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, newName + ".rcp");
  564. //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  565. if (SaveAsRecipeWithType(newName, CurrentRecipe.Header.Type.ToString(), RecipeUnity.RecipeToString(newRecipe)))
  566. {
  567. UpdateRecipeFileList();
  568. CurrentRecipeName = newName;
  569. //LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  570. LoadRecipe(CurrentRecipe);
  571. }
  572. }
  573. }
  574. else if (newName == CurrentRecipeName || newName == "")
  575. {
  576. WPFMessageBox.Show("Please input right recipename", MessageBoxButton.OK);
  577. }
  578. }
  579. private void menuItem_MouseClick_RenameRecipe(object sender, RoutedEventArgs e)
  580. {
  581. if (CurrentRecipe == null)
  582. {
  583. return;
  584. }
  585. var newName = Interaction.InputBox(" ", "Rename Recipe", CurrentRecipeName, -1, -1);
  586. //newName = newName.Trim();
  587. if (!RecipeNameIsOk(newName))
  588. {
  589. return;
  590. }
  591. if (newName != CurrentRecipeName && newName != "")
  592. {
  593. var newRecipe = CurrentRecipe;
  594. if (WPFMessageBox.ShowQuestion($"Save recipe file {newName} ?", "") == MessageBoxResult.Yes)
  595. {
  596. newRecipe.Header.Name = newName;
  597. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  598. var oldrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, CurrentRecipeName + ".rcp");
  599. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, newName + ".rcp");
  600. File.Delete(oldrecipePath);
  601. File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  602. UpdateRecipeFileList();
  603. }
  604. }
  605. else if (newName == CurrentRecipeName || newName == "")
  606. {
  607. WPFMessageBox.Show("Please input right recipename", MessageBoxButton.OK);
  608. }
  609. }
  610. public bool SaveAsRecipeWithType(string recipeName, string type, string recipeContent)
  611. {
  612. return m_uiRecipeManager.SaveAsRecipeWithType(ModuleName, type, recipeName, recipeContent);
  613. }
  614. public string GetXmlRecipeList()
  615. {
  616. return m_uiRecipeManager.GetXmlRecipeList(ModuleName, true) ?? "";
  617. }
  618. void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
  619. {
  620. foreach (XmlElement ele in curElementNode.ChildNodes)
  621. {
  622. if (ele.Name == "File")
  623. {
  624. string fileName = ele.Attributes["Name"].Value;
  625. fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
  626. TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
  627. item.Tag = ele.Attributes["Name"].Value;
  628. if (!item.Tag.ToString().Contains("\\"))
  629. {
  630. continue;
  631. }
  632. itemsControl.Items.Add(item);
  633. }
  634. else if (ele.Name == "Folder")
  635. {
  636. string folderName = ele.Attributes["Name"].Value;
  637. folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
  638. if (folderName == Venus_Core.RecipeType.Process.ToString() || folderName == Venus_Core.RecipeType.Clean.ToString() || folderName == Venus_Core.RecipeType.Chuck.ToString() || folderName == Venus_Core.RecipeType.DeChuck.ToString())
  639. {
  640. TreeViewFolderItem item = new TreeViewFolderItem(folderName);
  641. item.Tag = ele.Attributes["Name"].Value;
  642. CreateTreeViewItems(ele, item);
  643. item.IsExpanded = false;
  644. itemsControl.Items.Add(item);
  645. }
  646. }
  647. }
  648. }
  649. private IEnumerable<string> GetFilesNames(string path)
  650. {
  651. if (Directory.Exists(path))
  652. {
  653. return Directory.GetFiles(path, "*.rcp")?
  654. .Select(Path.GetFileNameWithoutExtension);
  655. }
  656. else
  657. {
  658. return new List<string>();
  659. }
  660. }
  661. private void LoadHeadWrapPanel(WrapPanel HeadWrapPanel, Recipe recipe)
  662. {
  663. HeadWrapPanel.Children.Clear();
  664. Type type = recipe.Header.GetType();
  665. foreach (var propertyInfo in type.GetProperties())
  666. {
  667. TextBlock textBlock = new TextBlock();
  668. textBlock.FontSize = 16;
  669. textBlock.Margin = new Thickness(0, 20, 0, 0);
  670. textBlock.Width = 200;
  671. switch (propertyInfo.Name)
  672. {
  673. case "ChuckRecipe":
  674. if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE)
  675. {
  676. continue;
  677. }
  678. textBlock.Text = "Chuck:";
  679. break;
  680. case "DechuckRecipe":
  681. if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE)
  682. {
  683. continue;
  684. }
  685. textBlock.Text = "DeChuck:";
  686. break;
  687. case "WallTemperature":
  688. if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE)
  689. {
  690. continue;
  691. }
  692. break;
  693. case "BiasRFHoldTime":
  694. if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE && currentChamber != JetChamber.Kepler2300)
  695. {
  696. continue;
  697. }
  698. break;
  699. default:
  700. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  701. string name;
  702. if (NameAttrs.Length > 0)
  703. {
  704. name = (NameAttrs[0] as CustomName).Name;
  705. }
  706. else
  707. {
  708. name = propertyInfo.Name;
  709. }
  710. textBlock.Text = name + ":";
  711. break;
  712. }
  713. textBlock.Margin = new Thickness(15, 0, 0, 0);
  714. textBlock.VerticalAlignment = VerticalAlignment.Center;
  715. HeadWrapPanel.Children.Add(textBlock);
  716. Binding binding = new Binding()
  717. {
  718. Source = recipe.Header, // 数据源
  719. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  720. Mode = BindingMode.TwoWay, // 绑定模式
  721. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, //触发器
  722. };
  723. var propertyTypeName = propertyInfo.PropertyType.Name;
  724. var propertyInfoName = propertyInfo.Name;
  725. Control control = new Control();
  726. switch (propertyInfoName)
  727. {
  728. //case "ChamberType":
  729. // control = new ComboBox();
  730. // control.IsEnabled = false;
  731. // //control.Height = 23;
  732. // control.SetBinding(ComboBox.SelectedItemProperty, binding);
  733. // control.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  734. // ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  735. // break;
  736. //case "Type":
  737. // ComboBox cb = new ComboBox();
  738. // cb.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  739. // cb.IsEnabled = false;
  740. // cb.SelectionChanged += ChangeUI;
  741. // control = cb;
  742. // //control.Height = 23;
  743. // ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  744. // control.SetBinding(ComboBox.SelectedItemProperty, binding);
  745. // break;
  746. case "ChuckRecipe":
  747. StringBuilder stringBuilder = new StringBuilder();
  748. control = new ComboBox()
  749. {
  750. ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck"))
  751. };
  752. //control.Height = 23;
  753. control.MinWidth = 100;
  754. control.MaxWidth = 300;
  755. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  756. control.PreviewMouseLeftButtonDown += ChuckControl_PreviewMouseLeftButtonDown;
  757. break;
  758. case "DechuckRecipe":
  759. //if (currentChamber != JetChamber.Venus)
  760. //{
  761. // continue;
  762. //}
  763. //string[] dechucklist = new string[] { "" };
  764. //ArrayList dearrayList = new ArrayList(dechucklist.ToList());
  765. //IEnumerable<string> delist = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName)).ToList().Where(item => item.ToLower().Contains("dechuck"));
  766. //foreach (var i in delist)
  767. //{
  768. // dearrayList.Add(i);
  769. //}
  770. //dechucklist = (string[])dearrayList.ToArray(typeof(string));
  771. //StringBuilder destringBuilder = new StringBuilder();
  772. //for (int i = 0; i < dechucklist.Length; i++)
  773. //{
  774. // destringBuilder.Append(dechucklist[i] + "\t");
  775. //}
  776. control = new ComboBox()
  777. {
  778. ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck"))
  779. };
  780. //control.Height = 23;
  781. control.MinWidth = 100;
  782. control.MaxWidth = 300;
  783. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  784. control.PreviewMouseLeftButtonDown += DechuckControl_PreviewMouseLeftButtonDown;
  785. break;
  786. case "IsShowTolerance":
  787. control = new CheckBox();
  788. control.SetBinding(CheckBox.IsCheckedProperty, binding);
  789. control.Style = null;
  790. control.VerticalAlignment = VerticalAlignment.Center;
  791. (control as CheckBox).Checked += RecipeViewModel_Checked;
  792. (control as CheckBox).Unchecked += RecipeViewModel_Checked;
  793. break;
  794. default:
  795. control = new TextBox();
  796. control.Margin = new Thickness(1, 0, 0, 0);
  797. control.BorderThickness = new Thickness(0, 0, 0, 1);
  798. control.BorderBrush = Brushes.White;
  799. control.FontSize = 15;
  800. control.Foreground = Brushes.Green;
  801. control.Background = Brushes.Transparent;
  802. control.VerticalAlignment = VerticalAlignment.Center;
  803. control.MinWidth = 15;
  804. control.SetBinding(TextBox.TextProperty, binding);
  805. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  806. if (objAttrs.Length > 0)
  807. {
  808. (control as TextBox).IsReadOnly = true;
  809. }
  810. break;
  811. }
  812. control.Margin = new Thickness(20, 3, 0, 7);
  813. control.Width = 250;
  814. HeadWrapPanel.Children.Add(control);
  815. }
  816. }
  817. private void RecipeViewModel_Checked(object sender, RoutedEventArgs e)
  818. {
  819. LoadRecipe(CurrentRecipe, false);
  820. }
  821. private void ChuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  822. {
  823. var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck")).ToList();
  824. items.Add("");
  825. (sender as ComboBox).ItemsSource = items;
  826. }
  827. private void DechuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  828. {
  829. var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck")).ToList();
  830. items.Add("");
  831. (sender as ComboBox).ItemsSource = items;
  832. }
  833. private void ChangeUI(object sender, SelectionChangedEventArgs e)
  834. {
  835. var t = sender as ComboBox;
  836. if (t.SelectedValue.ToString() != "Process")
  837. {
  838. headWrapPanel.Children[8].Visibility = Visibility.Collapsed;
  839. headWrapPanel.Children[9].Visibility = Visibility.Collapsed;
  840. headWrapPanel.Children[10].Visibility = Visibility.Collapsed;
  841. headWrapPanel.Children[11].Visibility = Visibility.Collapsed;
  842. }
  843. else
  844. {
  845. headWrapPanel.Children[8].Visibility = Visibility.Visible;
  846. headWrapPanel.Children[9].Visibility = Visibility.Visible;
  847. headWrapPanel.Children[10].Visibility = Visibility.Visible;
  848. headWrapPanel.Children[11].Visibility = Visibility.Visible;
  849. }
  850. }
  851. private void MenuItemLeftInsert_Click(object sender, RoutedEventArgs e)
  852. {
  853. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  854. int insertIndex = Convert.ToInt32(t.Text) - 1;
  855. RecipeStep recipeStep;
  856. if (copyIndex == -1)
  857. {
  858. recipeStep = new RecipeStep();
  859. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  860. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  861. }
  862. else
  863. {
  864. var t1 = JsonConvert.SerializeObject(CurrentRecipe);
  865. recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
  866. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  867. }
  868. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  869. {
  870. CurrentRecipe.Steps[i].StepNo = i + 1;
  871. }
  872. ColumnDefinition col1 = new ColumnDefinition();
  873. col1.Width = GridLength.Auto;
  874. rightGrid.ColumnDefinitions.Add(col1);
  875. for (int i = 0; i < rightGrid.Children.Count; i++)
  876. {
  877. if (Grid.GetColumn(rightGrid.Children[i]) >= insertIndex)
  878. {
  879. Grid.SetColumn(rightGrid.Children[i], Grid.GetColumn(rightGrid.Children[i]) + 1);
  880. }
  881. }
  882. RecipeStepToGridColumn(recipeStep, rightGrid, insertIndex);
  883. }
  884. private void MenuItemRightInsert_Click(object sender, RoutedEventArgs e)
  885. {
  886. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  887. int insertIndex = Convert.ToInt32(t.Text);
  888. RecipeStep recipeStep;
  889. if (copyIndex == -1)
  890. {
  891. recipeStep = new RecipeStep();
  892. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  893. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  894. }
  895. else
  896. {
  897. var t1 = JsonConvert.SerializeObject(CurrentRecipe);
  898. recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
  899. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  900. }
  901. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  902. {
  903. CurrentRecipe.Steps[i].StepNo = i + 1;
  904. }
  905. ColumnDefinition col1 = new ColumnDefinition();
  906. col1.Width = GridLength.Auto;
  907. rightGrid.ColumnDefinitions.Add(col1);
  908. for (int i = 0; i < rightGrid.Children.Count; i++)
  909. {
  910. if (Grid.GetColumn(rightGrid.Children[i]) >= insertIndex)
  911. {
  912. Grid.SetColumn(rightGrid.Children[i], Grid.GetColumn(rightGrid.Children[i]) + 1);
  913. }
  914. }
  915. RecipeStepToGridColumn(recipeStep, rightGrid, insertIndex);
  916. }
  917. private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
  918. {
  919. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  920. int deleteIndex = Convert.ToInt32(t.Text) - 1;
  921. CurrentRecipe.Steps.RemoveAt(deleteIndex);
  922. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  923. {
  924. CurrentRecipe.Steps[i].StepNo = i + 1;
  925. }
  926. RemoveColumnFromGrid(rightGrid, deleteIndex);
  927. rightGrid.ColumnDefinitions.RemoveAt(deleteIndex);
  928. for (int i = 0; i < rightGrid.Children.Count; i++)
  929. {
  930. if (Grid.GetColumn(rightGrid.Children[i]) >= deleteIndex)
  931. {
  932. Grid.SetColumn(rightGrid.Children[i], Grid.GetColumn(rightGrid.Children[i]) - 1);
  933. }
  934. }
  935. }
  936. private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
  937. {
  938. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  939. copyIndex = Convert.ToInt32(t.Text);
  940. }
  941. #endregion
  942. #region 私有方法
  943. private void RecipeStepToGridColumn(RecipeStep recipeStep, Grid grid, int columnIndex)
  944. {
  945. Type recipeType = recipeStep.GetType();
  946. int rowIndex = 0;
  947. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  948. {
  949. string propertyInfoName = propertyInfo.Name;
  950. string propertyTypeName = propertyInfo.PropertyType.Name;
  951. if (propertyInfoName != "LstUnit")
  952. {
  953. if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime" || propertyInfoName == "OverEtchPercent") && isInstalledEPD == false)
  954. {
  955. continue;
  956. }
  957. if (columnIndex == 0)
  958. {
  959. RowDefinition row1 = new RowDefinition();
  960. row1.Height = new GridLength(controlHeight);
  961. grid.RowDefinitions.Add(row1);
  962. }
  963. Binding binding = new Binding()
  964. {
  965. Source = recipeStep, // 数据源
  966. Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
  967. Mode = BindingMode.TwoWay, // 绑定模式
  968. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  969. };
  970. switch (propertyTypeName)
  971. {
  972. case "Int32":
  973. case "String":
  974. case "Single":
  975. case "Double":
  976. if (propertyInfoName == "EPDConfig")
  977. {
  978. if (currentEPDType == EPDType.Socket)
  979. {
  980. ComboBox EPDcomboBox = new ComboBox();
  981. EPDcomboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  982. EPDcomboBox.Background = new SolidColorBrush(Colors.Black);
  983. EPDcomboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  984. EPDcomboBox.ItemsSource = EPDCfgList;
  985. grid.Children.Add(EPDcomboBox);
  986. Grid.SetRow(EPDcomboBox, rowIndex);
  987. Grid.SetColumn(EPDcomboBox, columnIndex);
  988. }
  989. else if (currentEPDType == EPDType.WCF)
  990. {
  991. Button EPDButton = new Button();
  992. EPDButton.Content = "EndPoint";
  993. EPDButton.Cursor = Cursors.Hand;
  994. EPDButton.Tag = $"{CurrentRecipeName}.{(columnIndex).ToString()}";
  995. EPDButton.Style = null;
  996. EPDButton.Click += EPDButton_Click;
  997. grid.Children.Add(EPDButton);
  998. Grid.SetRow(EPDButton, rowIndex);
  999. Grid.SetColumn(EPDButton, columnIndex);
  1000. }
  1001. break;
  1002. }
  1003. TextBox textBox = new TextBox();
  1004. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  1005. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  1006. textBox.SetBinding(TextBox.TextProperty, binding);
  1007. grid.Children.Add(textBox);
  1008. Grid.SetRow(textBox, rowIndex);
  1009. Grid.SetColumn(textBox, columnIndex);
  1010. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  1011. if (objAttrs.Length > 0)
  1012. {
  1013. textBox.IsReadOnly = true;
  1014. ContextMenu contextmenu = new ContextMenu();
  1015. textBox.ContextMenu = contextmenu;
  1016. MenuItem menuItemDelete = new MenuItem();
  1017. menuItemDelete.Header = "Delete";
  1018. menuItemDelete.Click += MenuItemDelete_Click;
  1019. MenuItem menuItemLeftInsert = new MenuItem();
  1020. menuItemLeftInsert.Header = "Left Insert";
  1021. menuItemLeftInsert.Click += MenuItemLeftInsert_Click;
  1022. MenuItem menuItemRightInsert = new MenuItem();
  1023. menuItemRightInsert.Header = "Right Insert";
  1024. menuItemRightInsert.Click += MenuItemRightInsert_Click;
  1025. MenuItem menuItemCopy = new MenuItem();
  1026. menuItemCopy.Tag = textBox.Text;
  1027. menuItemCopy.Header = "Copy";
  1028. menuItemCopy.Click += MenuItemCopy_Click;
  1029. contextmenu.Items.Add(menuItemCopy);
  1030. contextmenu.Items.Add(menuItemDelete);
  1031. contextmenu.Items.Add(menuItemLeftInsert);
  1032. contextmenu.Items.Add(menuItemRightInsert);
  1033. }
  1034. break;
  1035. case "Boolean":
  1036. CheckBox checkBox = new CheckBox();
  1037. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  1038. grid.Children.Add(checkBox);
  1039. Grid.SetRow(checkBox, rowIndex);
  1040. Grid.SetColumn(checkBox, columnIndex);
  1041. break;
  1042. default:
  1043. ComboBox comboBox = new ComboBox();
  1044. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  1045. comboBox.Background = new SolidColorBrush(Colors.Black);
  1046. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  1047. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  1048. grid.Children.Add(comboBox);
  1049. Grid.SetRow(comboBox, rowIndex);
  1050. Grid.SetColumn(comboBox, columnIndex);
  1051. break;
  1052. }
  1053. rowIndex++;
  1054. }
  1055. }
  1056. int unitIndex = 0;
  1057. foreach (var x in recipeStep.LstUnit.ToList())
  1058. {
  1059. Type unitType = x.GetType();
  1060. Binding checkbinding = null;
  1061. foreach (PropertyInfo propertyInfo in unitType.GetProperties())
  1062. {
  1063. object[] IgnoreAttrs = propertyInfo.GetCustomAttributes(typeof(IsCanConfigIgnore), true);
  1064. bool IsEnableRecipeExtension = Convert.ToBoolean(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.IsEnableRecipeExtension"));
  1065. if (IgnoreAttrs.Length > 0 && IsEnableRecipeExtension == false)
  1066. {
  1067. break;
  1068. }
  1069. object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
  1070. if (toleranceAttrs.Length > 0 && CurrentRecipe.Header.IsShowTolerance == false)
  1071. {
  1072. continue;
  1073. }
  1074. if (propertyInfo.Name == "UnitName")
  1075. {
  1076. continue;
  1077. }
  1078. if (columnIndex == 0)
  1079. {
  1080. RowDefinition row1 = new RowDefinition();
  1081. row1.Height = new GridLength(controlHeight);
  1082. grid.RowDefinitions.Add(row1);
  1083. }
  1084. Binding binding = new Binding()
  1085. {
  1086. Source = recipeStep.LstUnit[unitIndex], // 数据源
  1087. //Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
  1088. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  1089. Mode = BindingMode.TwoWay, // 绑定模式
  1090. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  1091. };
  1092. var item = propertyInfo.PropertyType.Name;
  1093. switch (item)
  1094. {
  1095. case "Int32":
  1096. case "String":
  1097. case "Single":
  1098. case "Double":
  1099. TextBox textBox = new TextBox();
  1100. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  1101. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  1102. if (checkbinding == null)
  1103. {
  1104. textBox.IsEnabled = true;
  1105. }
  1106. else
  1107. {
  1108. textBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  1109. }
  1110. textBox.SetBinding(TextBox.TextProperty, binding);
  1111. grid.Children.Add(textBox);
  1112. Grid.SetRow(textBox, rowIndex);
  1113. Grid.SetColumn(textBox, columnIndex);
  1114. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  1115. if (objAttrs.Length > 0)
  1116. {
  1117. textBox.IsReadOnly = true;
  1118. }
  1119. break;
  1120. case "Boolean":
  1121. CheckBox checkBox = new CheckBox();
  1122. if (checkbinding == null)
  1123. {
  1124. checkbinding = new Binding
  1125. {
  1126. Source = checkBox, // 数据源
  1127. Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
  1128. Mode = BindingMode.TwoWay, // 绑定模式
  1129. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  1130. };
  1131. }
  1132. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  1133. grid.Children.Add(checkBox);
  1134. Grid.SetRow(checkBox, rowIndex);
  1135. Grid.SetColumn(checkBox, columnIndex);
  1136. break;
  1137. default:
  1138. //if (checkbinding != null)
  1139. //{
  1140. // break;
  1141. //}
  1142. ComboBox comboBox = new ComboBox();
  1143. comboBox.BorderBrush = Brushes.Gray;
  1144. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  1145. if (checkbinding == null)
  1146. {
  1147. comboBox.IsEnabled = true;
  1148. }
  1149. else
  1150. {
  1151. comboBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  1152. }
  1153. comboBox.Background = Brushes.White;
  1154. string path = propertyInfo.Name;
  1155. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  1156. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  1157. grid.Children.Add(comboBox);
  1158. Grid.SetRow(comboBox, rowIndex);
  1159. Grid.SetColumn(comboBox, columnIndex);
  1160. break;
  1161. }
  1162. rowIndex++;
  1163. }
  1164. unitIndex++;
  1165. }
  1166. }
  1167. private void RecipeStepToGridColumnOnlyTitle(RecipeStep recipeStep, Grid grid)
  1168. {
  1169. Type recipeType = recipeStep.GetType();
  1170. int i = 0;
  1171. ColumnDefinition col1 = new ColumnDefinition();
  1172. grid.ColumnDefinitions.Add(col1);
  1173. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  1174. {
  1175. string propertyInfoName = propertyInfo.Name;
  1176. string propertyTypeName = propertyInfo.PropertyType.Name;
  1177. if (propertyInfoName != "LstUnit")
  1178. {
  1179. if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime" || propertyInfoName == "OverEtchPercent") && isInstalledEPD == false)
  1180. {
  1181. continue;
  1182. }
  1183. RowDefinition row1 = new RowDefinition();
  1184. row1.Height = new GridLength(controlHeight);
  1185. grid.RowDefinitions.Add(row1);
  1186. Border border = new Border();
  1187. TextBlock textBlock = new TextBlock();
  1188. textBlock.Padding = new Thickness(5, 3, 0, 0);
  1189. border.Child = textBlock;
  1190. border.BorderBrush = Brushes.Silver;
  1191. border.BorderThickness = new Thickness(1);
  1192. //textBlock.IsReadOnly = true;
  1193. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  1194. string name;
  1195. if (NameAttrs.Length > 0)
  1196. {
  1197. name = (NameAttrs[0] as CustomName).Name;
  1198. }
  1199. else
  1200. {
  1201. name = propertyInfo.Name;
  1202. }
  1203. textBlock.Text = name;
  1204. //textBlock.FontSize = 15;
  1205. grid.Children.Add(border);
  1206. border.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FAFAFA"));
  1207. Grid.SetRow(border, i);
  1208. Grid.SetColumn(border, 0);
  1209. i++;
  1210. }
  1211. }
  1212. foreach (var x in recipeStep.LstUnit.ToList())
  1213. {
  1214. Type unitType = x.GetType();
  1215. bool isUnitFirstRow = true;
  1216. foreach (PropertyInfo propertyInfo in unitType.GetProperties())
  1217. {
  1218. object[] IgnoreAttrs = propertyInfo.GetCustomAttributes(typeof(IsCanConfigIgnore), true);
  1219. bool IsEnableRecipeExtension = Convert.ToBoolean(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.IsEnableRecipeExtension"));
  1220. if (IgnoreAttrs.Length > 0 && IsEnableRecipeExtension == false)
  1221. {
  1222. break;
  1223. }
  1224. object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
  1225. if (toleranceAttrs.Length > 0 && CurrentRecipe.Header.IsShowTolerance == false)
  1226. {
  1227. continue;
  1228. }
  1229. if (propertyInfo.Name == "UnitName")
  1230. {
  1231. continue;
  1232. }
  1233. //if (propertyInfo.Name.Contains("Gas"))
  1234. //{
  1235. // if (!(bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas1.Enable"))
  1236. // {
  1237. // continue;
  1238. // }
  1239. //}
  1240. RowDefinition row1 = new RowDefinition();
  1241. row1.Height = new GridLength(controlHeight);
  1242. grid.RowDefinitions.Add(row1);
  1243. Border border = new Border();
  1244. TextBlock textBlock = new TextBlock();
  1245. //textBlock.Padding = new Thickness(0, 3, 0, 0);
  1246. border.Child = textBlock;
  1247. border.BorderBrush = Brushes.Silver;
  1248. border.BorderThickness = new Thickness(1);
  1249. if (isUnitFirstRow)
  1250. {
  1251. textBlock.FontWeight = FontWeights.Bold;
  1252. textBlock.FontSize = 15;
  1253. isUnitFirstRow = false;
  1254. textBlock.Padding = new Thickness(5, 2, 5, 0);
  1255. }
  1256. else
  1257. {
  1258. textBlock.Padding = new Thickness(5, 3, 5, 0);
  1259. }
  1260. switch (propertyInfo.Name)
  1261. {
  1262. case "Gas1":
  1263. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  1264. textBlock.Text = $"{propertyInfo.Name}({data1.DisplayName},{data1.Scale})";
  1265. break;
  1266. case "Gas2":
  1267. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  1268. textBlock.Text = $"{propertyInfo.Name}({data2.DisplayName},{data2.Scale})";
  1269. break;
  1270. case "Gas3":
  1271. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  1272. textBlock.Text = $"{propertyInfo.Name}({data3.DisplayName},{data3.Scale})";
  1273. break;
  1274. case "Gas4":
  1275. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  1276. textBlock.Text = $"{propertyInfo.Name}({data4.DisplayName},{data4.Scale})";
  1277. break;
  1278. case "Gas5":
  1279. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  1280. textBlock.Text = $"{propertyInfo.Name}({data5.DisplayName},{data5.Scale})";
  1281. break;
  1282. case "Gas6":
  1283. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  1284. textBlock.Text = $"{propertyInfo.Name}({data6.DisplayName},{data6.Scale})";
  1285. break;
  1286. case "Gas7":
  1287. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  1288. textBlock.Text = $"{propertyInfo.Name}({data7.DisplayName},{data7.Scale})";
  1289. break;
  1290. case "Gas8":
  1291. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  1292. textBlock.Text = $"{propertyInfo.Name}({data8.DisplayName},{data8.Scale})";
  1293. break;
  1294. case "Gas9":
  1295. var data9 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas9");
  1296. textBlock.Text = $"{propertyInfo.Name}({data9.DisplayName},{data9.Scale})";
  1297. break;
  1298. case "Gas10":
  1299. var data10 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas10");
  1300. textBlock.Text = $"{propertyInfo.Name}({data10.DisplayName},{data10.Scale})";
  1301. break;
  1302. case "Gas11":
  1303. var data11 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas11");
  1304. textBlock.Text = $"{propertyInfo.Name}({data11.DisplayName},{data11.Scale})";
  1305. break;
  1306. case "Gas12":
  1307. var data12 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas12");
  1308. textBlock.Text = $"{propertyInfo.Name}({data12.DisplayName},{data12.Scale})";
  1309. break;
  1310. default:
  1311. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  1312. string name;
  1313. if (NameAttrs.Length > 0)
  1314. {
  1315. name = (NameAttrs[0] as CustomName).Name;
  1316. }
  1317. else
  1318. {
  1319. name = propertyInfo.Name;
  1320. }
  1321. textBlock.Text = name;
  1322. break;
  1323. }
  1324. grid.Children.Add(border);
  1325. border.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FAFAFA"));
  1326. Grid.SetRow(border, i);
  1327. Grid.SetColumn(border, 0);
  1328. i++;
  1329. }
  1330. }
  1331. }
  1332. private void EPDButton_Click(object sender, RoutedEventArgs e)
  1333. {
  1334. Button button = sender as Button;
  1335. string para = button.Tag.ToString();
  1336. int stepno = Convert.ToInt32(para.Split('.')[1]) - 1;
  1337. var endpointconfigitem = new MECF.Framework.Common.CommonData.EndPointConfigItem();
  1338. if (CurrentRecipe.Steps[stepno].EPDConfig != null && CurrentRecipe.Steps[stepno].EPDConfig.Length > 20)
  1339. {
  1340. endpointconfigitem.SetValue(CurrentRecipe.Steps[stepno].EPDConfig);
  1341. }
  1342. (new EndPointDlg(para, endpointconfigitem, CurrentRecipe)).ShowDialog();
  1343. }
  1344. private void UpdateRecipeFileList()
  1345. {
  1346. XmlDocument doc = new XmlDocument();
  1347. doc.LoadXml(GetXmlRecipeList());
  1348. treeViewRcpList.Items.Clear();
  1349. CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
  1350. ExpandAllItems(this.treeViewRcpList);
  1351. }
  1352. private void LoadRecipe(Recipe recipe, bool isSaveRecipe = true)
  1353. {
  1354. copyIndex = -1;
  1355. OnClearRecipe();
  1356. CurrentRecipe = recipe;
  1357. RecipeStepToGridColumnOnlyTitle(recipe.Steps[0], leftGrid);
  1358. for (int i = 0; i < recipe.Steps.Count; i++)
  1359. {
  1360. ColumnDefinition col1 = new ColumnDefinition();
  1361. col1.Width = GridLength.Auto;
  1362. rightGrid.ColumnDefinitions.Insert(i, col1);
  1363. RecipeStepToGridColumn(recipe.Steps[i], rightGrid, i);
  1364. }
  1365. string recipeContent = RecipeUnity.RecipeToString(CurrentRecipe);
  1366. if (isSaveRecipe)
  1367. {
  1368. SaveEAPRecipe(recipeContent, CurrentRecipeName);
  1369. }
  1370. }
  1371. private void OnDeleteStep(int index)
  1372. {
  1373. if (CurrentRecipe != null && CurrentRecipe.Steps.Count > 1)
  1374. {
  1375. RemoveColumnFromGrid(rightGrid, index);
  1376. rightGrid.ColumnDefinitions.RemoveAt(index);
  1377. CurrentRecipe.Steps.RemoveAt(index);
  1378. }
  1379. }
  1380. /// <summary>
  1381. /// 删除Grid某列数据
  1382. /// </summary>
  1383. /// <param name="grid"></param>
  1384. /// <param name="column"></param>
  1385. public void RemoveColumnFromGrid(Grid grid, int column)
  1386. {
  1387. List<UIElement> listControl = new List<UIElement>();
  1388. for (int i = 0; i < grid.Children.Count; i++)
  1389. {
  1390. var child = grid.Children[i];
  1391. if (Grid.GetColumn(child) == column)
  1392. {
  1393. listControl.Add(child);
  1394. }
  1395. }
  1396. listControl.ForEach(x =>
  1397. {
  1398. grid.Children.Remove(x);
  1399. });
  1400. }
  1401. private void OnRefresh()
  1402. {
  1403. if (CurrentRecipeName != "")
  1404. {
  1405. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, $"{CurrentRecipeName}.rcp");
  1406. string xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  1407. CurrentRecipe = Recipe.Load(xmlRecipeData);
  1408. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  1409. LoadRecipe(CurrentRecipe);
  1410. }
  1411. }
  1412. private void OnExpand()
  1413. {
  1414. HeadExpand = !HeadExpand;
  1415. if (HeadExpand)
  1416. {
  1417. recipeView.expandGrid.Width = 300;
  1418. }
  1419. else
  1420. {
  1421. recipeView.expandGrid.Width = 30;
  1422. }
  1423. }
  1424. private void OnUnload()
  1425. {
  1426. //if (CurrentRecipeName == null || CurrentRecipeName == "")
  1427. //{
  1428. // return;
  1429. //}
  1430. //if (WPFMessageBox.ShowQuestion($"Is Save Recipe {CurrentRecipeName}", "", false) == MessageBoxResult.Yes)
  1431. //{
  1432. // OnSaveRecipe();
  1433. //}
  1434. }
  1435. private void OnClearRecipe()
  1436. {
  1437. for (int i = 0; i < rightGrid.ColumnDefinitions.Count; i++)
  1438. {
  1439. rightGrid.ColumnDefinitions[i].Width = new GridLength(75);
  1440. }
  1441. leftGrid.Children.Clear();
  1442. rightGrid.Children.Clear();
  1443. leftGrid.ColumnDefinitions.Clear();
  1444. rightGrid.ColumnDefinitions.Clear();
  1445. rightGrid.RowDefinitions.Clear();
  1446. leftGrid.RowDefinitions.Clear();
  1447. GC.Collect(); // This should pick up the control removed at a previous MouseDown
  1448. GC.WaitForPendingFinalizers(); // Doesn't help either
  1449. //rightGrid.Visibility = Visibility.Visible;
  1450. }
  1451. private void ExpandAllItems(ItemsControl control)
  1452. {
  1453. if (control == null)
  1454. {
  1455. return;
  1456. }
  1457. foreach (Object item in control.Items)
  1458. {
  1459. System.Windows.Controls.TreeViewItem treeItem = control.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
  1460. if (treeItem == null || !treeItem.HasItems)
  1461. {
  1462. continue;
  1463. }
  1464. treeItem.IsExpanded = true;
  1465. ExpandAllItems(treeItem as ItemsControl);
  1466. }
  1467. }
  1468. private bool RecipeNameIsOk(string recipeName)
  1469. {
  1470. if (recipeName.Contains(' '))
  1471. {
  1472. WPFMessageBox.ShowError("Recipe Name 包含空格,不符合规格");
  1473. return false;
  1474. }
  1475. if (recipeName.Length > 25)
  1476. {
  1477. WPFMessageBox.ShowError("Recipe Name 大于25个字符,不符合规格");
  1478. return false;
  1479. }
  1480. return true;
  1481. }
  1482. private void SaveEAPRecipe(string recipeContent, string recipeName)
  1483. {
  1484. if (currentChamber == JetChamber.Kepler2200A || currentChamber == JetChamber.Kepler2200B)
  1485. {
  1486. var newrecipePath2 = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{typeFolder}{eapPath}", recipeName + ".rcp");
  1487. var currentRecipe = Recipe.Load(recipeContent);
  1488. FileInfo fi2 = new FileInfo(newrecipePath2);
  1489. var di2 = fi2.Directory;
  1490. if (!di2.Exists)
  1491. {
  1492. di2.Create();
  1493. }
  1494. var newContent = Recipe.ShowEAPRecipe(recipeContent, currentRecipe.Steps);
  1495. File.WriteAllText(newrecipePath2, newContent, Encoding.UTF8);
  1496. var newrecipePath3 = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{typeFolder}{tolerancePath}", recipeName + ".rcp");
  1497. FileInfo fi3 = new FileInfo(newrecipePath3);
  1498. var di3 = fi3.Directory;
  1499. if (!di3.Exists)
  1500. {
  1501. di3.Create();
  1502. }
  1503. var newContent3 = Recipe.ShowToleranceRecipe(recipeContent, currentRecipe.Steps);
  1504. File.WriteAllText(newrecipePath3, newContent3, Encoding.UTF8);
  1505. }
  1506. }
  1507. private bool DeleteEAPRecipe()
  1508. {
  1509. var path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{typeFolder}{eapPath}", CurrentRecipeName + ".rcp");
  1510. if (File.Exists(path))
  1511. {
  1512. File.Delete(path);
  1513. }
  1514. var path2 = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{typeFolder}{tolerancePath}", CurrentRecipeName + ".rcp");
  1515. if (File.Exists(path))
  1516. {
  1517. File.Delete(path2);
  1518. }
  1519. return true;
  1520. }
  1521. private bool DeleteToleranceRecipe()
  1522. {
  1523. return true;
  1524. }
  1525. #endregion
  1526. }
  1527. }