NewRecipeViewModel.cs 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  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)
  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)
  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. }
  223. CurrentRecipe.Header.EditTime = DateTime.Now.ToString();
  224. CurrentRecipe.Header.LastModifiedBy=GlobalUser.Instance.User.Name;
  225. //SaveRecipe(CurrentRecipeName, RecipeUnity.RecipeToString(CurrentRecipe));
  226. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, CurrentRecipeName + ".rcp");
  227. FileInfo fi = new FileInfo(newrecipePath);
  228. var di = fi.Directory;
  229. if (!di.Exists)
  230. {
  231. di.Create();
  232. }
  233. //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(CurrentRecipe),Encoding.UTF8);
  234. string recipeContent = RecipeUnity.RecipeToString(CurrentRecipe);
  235. SaveRecipe(CurrentRecipe.Header.Name, CurrentRecipe.Header.Type.ToString(), recipeContent);
  236. //LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  237. SaveEAPRecipe(recipeContent);
  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. string newRecipe = RecipeUnity.CreateRecipe(currentChamber, type, dlg.InputText,GlobalUser.Instance.User.Name);
  509. if (SaveAsRecipeWithType(recipeName, type.ToString(), newRecipe))
  510. {
  511. UpdateRecipeFileList();
  512. }
  513. SaveEAPRecipe(newRecipe);
  514. }
  515. }
  516. catch (Exception ex)
  517. {
  518. LOG.WriteExeption(ex);
  519. WPFMessageBox.ShowError(ex.ToString());
  520. //MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  521. }
  522. }
  523. private void menuItem_MouseClick_DeleteRecipe(object sender, RoutedEventArgs e)
  524. {
  525. //if (CurrentRecipe == null)
  526. //{
  527. // return;
  528. //}
  529. if (WPFMessageBox.ShowQuestion($"Delete {typeFolder}Recipe {CurrentRecipeName}?", "删除后无法恢复!!!") == MessageBoxResult.Yes)
  530. {
  531. //MenuItem mit = sender as MenuItem;
  532. //string recipename = mit.Header.ToString();
  533. string path = typeFolder == "" ? CurrentRecipeName : $"{typeFolder}\\{CurrentRecipeName}";
  534. m_uiRecipeManager.DeleteRecipe(ModuleName, path);
  535. DeleteEAPRecipe();
  536. DeleteToleranceRecipe();
  537. //PerformCreateRecipe(folderName);
  538. //treeViewRcpList.Items.Remove(selectedItem);
  539. UpdateRecipeFileList();
  540. }
  541. }
  542. private void menuItem_MouseClick_SaveAsRecipe(object sender, RoutedEventArgs e)
  543. {
  544. if (CurrentRecipe == null)
  545. {
  546. return;
  547. }
  548. var newName = Interaction.InputBox(" ", "Save As Recipe", CurrentRecipeName, -1, -1);
  549. if (!RecipeNameIsOk(newName))
  550. {
  551. return;
  552. }
  553. //newName = newName.Trim();
  554. if (newName != CurrentRecipeName && newName != "")
  555. {
  556. var newRecipe = CurrentRecipe;
  557. if (WPFMessageBox.ShowQuestion($"Save recipe file {newName} ?", "") == MessageBoxResult.Yes)
  558. {
  559. //MessageBox.Show($"Save as recipe {newName} ?", "Save As Recipe", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
  560. newRecipe.Header.Name = newName;
  561. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  562. //var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, newName + ".rcp");
  563. //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  564. if (SaveAsRecipeWithType(newName, CurrentRecipe.Header.Type.ToString(), RecipeUnity.RecipeToString(newRecipe)))
  565. {
  566. UpdateRecipeFileList();
  567. CurrentRecipeName = newName;
  568. //LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  569. LoadRecipe(CurrentRecipe);
  570. }
  571. }
  572. }
  573. else if (newName == CurrentRecipeName || newName == "")
  574. {
  575. WPFMessageBox.Show("Please input right recipename", MessageBoxButton.OK);
  576. }
  577. }
  578. private void menuItem_MouseClick_RenameRecipe(object sender, RoutedEventArgs e)
  579. {
  580. if (CurrentRecipe == null)
  581. {
  582. return;
  583. }
  584. var newName = Interaction.InputBox(" ", "Rename Recipe", CurrentRecipeName, -1, -1);
  585. //newName = newName.Trim();
  586. if (!RecipeNameIsOk(newName))
  587. {
  588. return;
  589. }
  590. if (newName != CurrentRecipeName && newName != "")
  591. {
  592. var newRecipe = CurrentRecipe;
  593. if (WPFMessageBox.ShowQuestion($"Save recipe file {newName} ?", "") == MessageBoxResult.Yes)
  594. {
  595. newRecipe.Header.Name = newName;
  596. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  597. var oldrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, CurrentRecipeName + ".rcp");
  598. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, newName + ".rcp");
  599. File.Delete(oldrecipePath);
  600. File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  601. UpdateRecipeFileList();
  602. }
  603. }
  604. else if (newName == CurrentRecipeName || newName == "")
  605. {
  606. WPFMessageBox.Show("Please input right recipename", MessageBoxButton.OK);
  607. }
  608. }
  609. public bool SaveAsRecipeWithType(string recipeName, string type, string recipeContent)
  610. {
  611. return m_uiRecipeManager.SaveAsRecipeWithType(ModuleName, type, recipeName, recipeContent);
  612. }
  613. public string GetXmlRecipeList()
  614. {
  615. return m_uiRecipeManager.GetXmlRecipeList(ModuleName, true) ?? "";
  616. }
  617. void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
  618. {
  619. foreach (XmlElement ele in curElementNode.ChildNodes)
  620. {
  621. if (ele.Name == "File")
  622. {
  623. string fileName = ele.Attributes["Name"].Value;
  624. fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
  625. TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
  626. item.Tag = ele.Attributes["Name"].Value;
  627. if (!item.Tag.ToString().Contains("\\"))
  628. {
  629. continue;
  630. }
  631. itemsControl.Items.Add(item);
  632. }
  633. else if (ele.Name == "Folder")
  634. {
  635. string folderName = ele.Attributes["Name"].Value;
  636. folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
  637. 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())
  638. {
  639. TreeViewFolderItem item = new TreeViewFolderItem(folderName);
  640. item.Tag = ele.Attributes["Name"].Value;
  641. CreateTreeViewItems(ele, item);
  642. item.IsExpanded = false;
  643. itemsControl.Items.Add(item);
  644. }
  645. }
  646. }
  647. }
  648. private IEnumerable<string> GetFilesNames(string path)
  649. {
  650. if (Directory.Exists(path))
  651. {
  652. return Directory.GetFiles(path, "*.rcp")?
  653. .Select(Path.GetFileNameWithoutExtension);
  654. }
  655. else
  656. {
  657. return new List<string>();
  658. }
  659. }
  660. private void LoadHeadWrapPanel(WrapPanel HeadWrapPanel, Recipe recipe)
  661. {
  662. HeadWrapPanel.Children.Clear();
  663. Type type = recipe.Header.GetType();
  664. foreach (var propertyInfo in type.GetProperties())
  665. {
  666. TextBlock textBlock = new TextBlock();
  667. textBlock.FontSize = 16;
  668. textBlock.Margin = new Thickness(0, 20, 0, 0);
  669. textBlock.Width = 200;
  670. switch (propertyInfo.Name)
  671. {
  672. case "ChuckRecipe":
  673. if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE)
  674. {
  675. continue;
  676. }
  677. textBlock.Text = "Chuck:";
  678. break;
  679. case "DechuckRecipe":
  680. if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE)
  681. {
  682. continue;
  683. }
  684. textBlock.Text = "DeChuck:";
  685. break;
  686. case "WallTemperature":
  687. if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE)
  688. {
  689. continue;
  690. }
  691. break;
  692. case "BiasRFHoldTime":
  693. if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE && currentChamber != JetChamber.Kepler2300)
  694. {
  695. continue;
  696. }
  697. break;
  698. default:
  699. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  700. string name;
  701. if (NameAttrs.Length > 0)
  702. {
  703. name = (NameAttrs[0] as CustomName).Name;
  704. }
  705. else
  706. {
  707. name = propertyInfo.Name;
  708. }
  709. textBlock.Text = name + ":";
  710. break;
  711. }
  712. textBlock.Margin = new Thickness(15, 0, 0, 0);
  713. textBlock.VerticalAlignment = VerticalAlignment.Center;
  714. HeadWrapPanel.Children.Add(textBlock);
  715. Binding binding = new Binding()
  716. {
  717. Source = recipe.Header, // 数据源
  718. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  719. Mode = BindingMode.TwoWay, // 绑定模式
  720. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, //触发器
  721. };
  722. var propertyTypeName = propertyInfo.PropertyType.Name;
  723. var propertyInfoName = propertyInfo.Name;
  724. Control control = new Control();
  725. switch (propertyInfoName)
  726. {
  727. //case "ChamberType":
  728. // control = new ComboBox();
  729. // control.IsEnabled = false;
  730. // //control.Height = 23;
  731. // control.SetBinding(ComboBox.SelectedItemProperty, binding);
  732. // control.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  733. // ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  734. // break;
  735. //case "Type":
  736. // ComboBox cb = new ComboBox();
  737. // cb.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  738. // cb.IsEnabled = false;
  739. // cb.SelectionChanged += ChangeUI;
  740. // control = cb;
  741. // //control.Height = 23;
  742. // ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  743. // control.SetBinding(ComboBox.SelectedItemProperty, binding);
  744. // break;
  745. case "ChuckRecipe":
  746. StringBuilder stringBuilder = new StringBuilder();
  747. control = new ComboBox()
  748. {
  749. ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck"))
  750. };
  751. //control.Height = 23;
  752. control.MinWidth = 100;
  753. control.MaxWidth = 300;
  754. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  755. control.PreviewMouseLeftButtonDown += ChuckControl_PreviewMouseLeftButtonDown;
  756. break;
  757. case "DechuckRecipe":
  758. //if (currentChamber != JetChamber.Venus)
  759. //{
  760. // continue;
  761. //}
  762. //string[] dechucklist = new string[] { "" };
  763. //ArrayList dearrayList = new ArrayList(dechucklist.ToList());
  764. //IEnumerable<string> delist = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName)).ToList().Where(item => item.ToLower().Contains("dechuck"));
  765. //foreach (var i in delist)
  766. //{
  767. // dearrayList.Add(i);
  768. //}
  769. //dechucklist = (string[])dearrayList.ToArray(typeof(string));
  770. //StringBuilder destringBuilder = new StringBuilder();
  771. //for (int i = 0; i < dechucklist.Length; i++)
  772. //{
  773. // destringBuilder.Append(dechucklist[i] + "\t");
  774. //}
  775. control = new ComboBox()
  776. {
  777. ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck"))
  778. };
  779. //control.Height = 23;
  780. control.MinWidth = 100;
  781. control.MaxWidth = 300;
  782. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  783. control.PreviewMouseLeftButtonDown += DechuckControl_PreviewMouseLeftButtonDown;
  784. break;
  785. case "IsShowTolerance":
  786. control = new CheckBox();
  787. control.SetBinding(CheckBox.IsCheckedProperty, binding);
  788. control.Style = null;
  789. control.VerticalAlignment = VerticalAlignment.Center;
  790. (control as CheckBox).Checked += RecipeViewModel_Checked;
  791. (control as CheckBox).Unchecked += RecipeViewModel_Checked;
  792. break;
  793. default:
  794. control = new TextBox();
  795. control.Margin = new Thickness(1, 0, 0, 0);
  796. control.BorderThickness = new Thickness(0, 0, 0, 1);
  797. control.BorderBrush = Brushes.White;
  798. control.FontSize = 15;
  799. control.Foreground = Brushes.Green;
  800. control.Background = Brushes.Transparent;
  801. control.VerticalAlignment = VerticalAlignment.Center;
  802. control.MinWidth = 15;
  803. control.SetBinding(TextBox.TextProperty, binding);
  804. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  805. if (objAttrs.Length > 0)
  806. {
  807. (control as TextBox).IsReadOnly = true;
  808. }
  809. break;
  810. }
  811. control.Margin = new Thickness(20, 3, 0, 7);
  812. control.Width = 250;
  813. HeadWrapPanel.Children.Add(control);
  814. }
  815. }
  816. private void RecipeViewModel_Checked(object sender, RoutedEventArgs e)
  817. {
  818. LoadRecipe(CurrentRecipe);
  819. }
  820. private void ChuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  821. {
  822. var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck")).ToList();
  823. items.Add("");
  824. (sender as ComboBox).ItemsSource = items;
  825. }
  826. private void DechuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  827. {
  828. var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck")).ToList();
  829. items.Add("");
  830. (sender as ComboBox).ItemsSource = items;
  831. }
  832. private void ChangeUI(object sender, SelectionChangedEventArgs e)
  833. {
  834. var t = sender as ComboBox;
  835. if (t.SelectedValue.ToString() != "Process")
  836. {
  837. headWrapPanel.Children[8].Visibility = Visibility.Collapsed;
  838. headWrapPanel.Children[9].Visibility = Visibility.Collapsed;
  839. headWrapPanel.Children[10].Visibility = Visibility.Collapsed;
  840. headWrapPanel.Children[11].Visibility = Visibility.Collapsed;
  841. }
  842. else
  843. {
  844. headWrapPanel.Children[8].Visibility = Visibility.Visible;
  845. headWrapPanel.Children[9].Visibility = Visibility.Visible;
  846. headWrapPanel.Children[10].Visibility = Visibility.Visible;
  847. headWrapPanel.Children[11].Visibility = Visibility.Visible;
  848. }
  849. }
  850. private void MenuItemLeftInsert_Click(object sender, RoutedEventArgs e)
  851. {
  852. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  853. int insertIndex = Convert.ToInt32(t.Text)-1;
  854. RecipeStep recipeStep;
  855. if (copyIndex == -1)
  856. {
  857. recipeStep = new RecipeStep();
  858. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  859. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  860. }
  861. else
  862. {
  863. var t1 = JsonConvert.SerializeObject(CurrentRecipe);
  864. recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
  865. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  866. }
  867. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  868. {
  869. CurrentRecipe.Steps[i].StepNo = i + 1;
  870. }
  871. ColumnDefinition col1 = new ColumnDefinition();
  872. col1.Width = GridLength.Auto;
  873. rightGrid.ColumnDefinitions.Add(col1);
  874. for (int i = 0; i < rightGrid.Children.Count; i++)
  875. {
  876. if (Grid.GetColumn(rightGrid.Children[i]) >= insertIndex)
  877. {
  878. Grid.SetColumn(rightGrid.Children[i], Grid.GetColumn(rightGrid.Children[i])+1);
  879. }
  880. }
  881. RecipeStepToGridColumn(recipeStep, rightGrid, insertIndex);
  882. }
  883. private void MenuItemRightInsert_Click(object sender, RoutedEventArgs e)
  884. {
  885. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  886. int insertIndex = Convert.ToInt32(t.Text);
  887. RecipeStep recipeStep;
  888. if (copyIndex == -1)
  889. {
  890. recipeStep = new RecipeStep();
  891. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  892. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  893. }
  894. else
  895. {
  896. var t1 = JsonConvert.SerializeObject(CurrentRecipe);
  897. recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
  898. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  899. }
  900. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  901. {
  902. CurrentRecipe.Steps[i].StepNo = i + 1;
  903. }
  904. ColumnDefinition col1 = new ColumnDefinition();
  905. col1.Width = GridLength.Auto;
  906. rightGrid.ColumnDefinitions.Add(col1);
  907. for (int i = 0; i < rightGrid.Children.Count; i++)
  908. {
  909. if (Grid.GetColumn(rightGrid.Children[i]) >= insertIndex)
  910. {
  911. Grid.SetColumn(rightGrid.Children[i], Grid.GetColumn(rightGrid.Children[i]) + 1);
  912. }
  913. }
  914. RecipeStepToGridColumn(recipeStep, rightGrid, insertIndex);
  915. }
  916. private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
  917. {
  918. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  919. int deleteIndex = Convert.ToInt32(t.Text)-1;
  920. CurrentRecipe.Steps.RemoveAt(deleteIndex);
  921. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  922. {
  923. CurrentRecipe.Steps[i].StepNo = i + 1;
  924. }
  925. RemoveColumnFromGrid(rightGrid, deleteIndex);
  926. rightGrid.ColumnDefinitions.RemoveAt(deleteIndex);
  927. for (int i = 0; i < rightGrid.Children.Count; i++)
  928. {
  929. if (Grid.GetColumn(rightGrid.Children[i]) >= deleteIndex)
  930. {
  931. Grid.SetColumn(rightGrid.Children[i], Grid.GetColumn(rightGrid.Children[i]) - 1);
  932. }
  933. }
  934. }
  935. private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
  936. {
  937. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  938. copyIndex = Convert.ToInt32(t.Text);
  939. }
  940. #endregion
  941. #region 私有方法
  942. private void RecipeStepToGridColumn(RecipeStep recipeStep, Grid grid, int columnIndex)
  943. {
  944. Type recipeType = recipeStep.GetType();
  945. int rowIndex = 0;
  946. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  947. {
  948. string propertyInfoName = propertyInfo.Name;
  949. string propertyTypeName = propertyInfo.PropertyType.Name;
  950. if (propertyInfoName != "LstUnit")
  951. {
  952. if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime" || propertyInfoName == "OverEtchPercent") && isInstalledEPD == false)
  953. {
  954. continue;
  955. }
  956. if (columnIndex == 0)
  957. {
  958. RowDefinition row1 = new RowDefinition();
  959. row1.Height = new GridLength(controlHeight);
  960. grid.RowDefinitions.Add(row1);
  961. }
  962. Binding binding = new Binding()
  963. {
  964. Source = recipeStep, // 数据源
  965. Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
  966. Mode = BindingMode.TwoWay, // 绑定模式
  967. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  968. };
  969. switch (propertyTypeName)
  970. {
  971. case "Int32":
  972. case "String":
  973. case "Single":
  974. case "Double":
  975. if (propertyInfoName == "EPDConfig")
  976. {
  977. if (currentEPDType == EPDType.Socket)
  978. {
  979. ComboBox EPDcomboBox = new ComboBox();
  980. EPDcomboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  981. EPDcomboBox.Background = new SolidColorBrush(Colors.Black);
  982. EPDcomboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  983. EPDcomboBox.ItemsSource = EPDCfgList;
  984. grid.Children.Add(EPDcomboBox);
  985. Grid.SetRow(EPDcomboBox, rowIndex);
  986. Grid.SetColumn(EPDcomboBox, columnIndex);
  987. }
  988. else if (currentEPDType == EPDType.WCF)
  989. {
  990. Button EPDButton = new Button();
  991. EPDButton.Content = "EndPoint";
  992. EPDButton.Cursor = Cursors.Hand;
  993. EPDButton.Tag = $"{CurrentRecipeName}.{(columnIndex).ToString()}";
  994. EPDButton.Style = null;
  995. EPDButton.Click += EPDButton_Click;
  996. grid.Children.Add(EPDButton);
  997. Grid.SetRow(EPDButton, rowIndex);
  998. Grid.SetColumn(EPDButton, columnIndex);
  999. }
  1000. break;
  1001. }
  1002. TextBox textBox = new TextBox();
  1003. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  1004. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  1005. textBox.SetBinding(TextBox.TextProperty, binding);
  1006. grid.Children.Add(textBox);
  1007. Grid.SetRow(textBox, rowIndex);
  1008. Grid.SetColumn(textBox, columnIndex);
  1009. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  1010. if (objAttrs.Length > 0)
  1011. {
  1012. textBox.IsReadOnly = true;
  1013. ContextMenu contextmenu = new ContextMenu();
  1014. textBox.ContextMenu = contextmenu;
  1015. MenuItem menuItemDelete = new MenuItem();
  1016. menuItemDelete.Header = "Delete";
  1017. menuItemDelete.Click += MenuItemDelete_Click;
  1018. MenuItem menuItemLeftInsert = new MenuItem();
  1019. menuItemLeftInsert.Header = "Left Insert";
  1020. menuItemLeftInsert.Click += MenuItemLeftInsert_Click;
  1021. MenuItem menuItemRightInsert = new MenuItem();
  1022. menuItemRightInsert.Header = "Right Insert";
  1023. menuItemRightInsert.Click += MenuItemRightInsert_Click;
  1024. MenuItem menuItemCopy = new MenuItem();
  1025. menuItemCopy.Tag = textBox.Text;
  1026. menuItemCopy.Header = "Copy";
  1027. menuItemCopy.Click += MenuItemCopy_Click;
  1028. contextmenu.Items.Add(menuItemCopy);
  1029. contextmenu.Items.Add(menuItemDelete);
  1030. contextmenu.Items.Add(menuItemLeftInsert);
  1031. contextmenu.Items.Add(menuItemRightInsert);
  1032. }
  1033. break;
  1034. case "Boolean":
  1035. CheckBox checkBox = new CheckBox();
  1036. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  1037. grid.Children.Add(checkBox);
  1038. Grid.SetRow(checkBox, rowIndex);
  1039. Grid.SetColumn(checkBox, columnIndex);
  1040. break;
  1041. default:
  1042. ComboBox comboBox = new ComboBox();
  1043. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  1044. comboBox.Background = new SolidColorBrush(Colors.Black);
  1045. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  1046. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  1047. grid.Children.Add(comboBox);
  1048. Grid.SetRow(comboBox, rowIndex);
  1049. Grid.SetColumn(comboBox, columnIndex);
  1050. break;
  1051. }
  1052. rowIndex++;
  1053. }
  1054. }
  1055. int unitIndex = 0;
  1056. foreach (var x in recipeStep.LstUnit.ToList())
  1057. {
  1058. Type unitType = x.GetType();
  1059. Binding checkbinding = null;
  1060. foreach (PropertyInfo propertyInfo in unitType.GetProperties())
  1061. {
  1062. object[] IgnoreAttrs = propertyInfo.GetCustomAttributes(typeof(IsCanConfigIgnore), true);
  1063. bool IsEnableRecipeExtension = Convert.ToBoolean(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.IsEnableRecipeExtension"));
  1064. if (IgnoreAttrs.Length > 0 && IsEnableRecipeExtension == false)
  1065. {
  1066. break;
  1067. }
  1068. object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
  1069. if (toleranceAttrs.Length > 0 && CurrentRecipe.Header.IsShowTolerance == false)
  1070. {
  1071. continue;
  1072. }
  1073. if (propertyInfo.Name == "UnitName")
  1074. {
  1075. continue;
  1076. }
  1077. if (columnIndex == 0)
  1078. {
  1079. RowDefinition row1 = new RowDefinition();
  1080. row1.Height = new GridLength(controlHeight);
  1081. grid.RowDefinitions.Add(row1);
  1082. }
  1083. Binding binding = new Binding()
  1084. {
  1085. Source = recipeStep.LstUnit[unitIndex], // 数据源
  1086. //Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
  1087. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  1088. Mode = BindingMode.TwoWay, // 绑定模式
  1089. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  1090. };
  1091. var item = propertyInfo.PropertyType.Name;
  1092. switch (item)
  1093. {
  1094. case "Int32":
  1095. case "String":
  1096. case "Single":
  1097. case "Double":
  1098. TextBox textBox = new TextBox();
  1099. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  1100. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  1101. if (checkbinding == null)
  1102. {
  1103. textBox.IsEnabled = true;
  1104. }
  1105. else
  1106. {
  1107. textBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  1108. }
  1109. textBox.SetBinding(TextBox.TextProperty, binding);
  1110. grid.Children.Add(textBox);
  1111. Grid.SetRow(textBox, rowIndex);
  1112. Grid.SetColumn(textBox, columnIndex);
  1113. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  1114. if (objAttrs.Length > 0)
  1115. {
  1116. textBox.IsReadOnly = true;
  1117. }
  1118. break;
  1119. case "Boolean":
  1120. CheckBox checkBox = new CheckBox();
  1121. if (checkbinding == null)
  1122. {
  1123. checkbinding = new Binding
  1124. {
  1125. Source = checkBox, // 数据源
  1126. Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
  1127. Mode = BindingMode.TwoWay, // 绑定模式
  1128. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  1129. };
  1130. }
  1131. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  1132. grid.Children.Add(checkBox);
  1133. Grid.SetRow(checkBox, rowIndex);
  1134. Grid.SetColumn(checkBox, columnIndex);
  1135. break;
  1136. default:
  1137. //if (checkbinding != null)
  1138. //{
  1139. // break;
  1140. //}
  1141. ComboBox comboBox = new ComboBox();
  1142. comboBox.BorderBrush = Brushes.Gray;
  1143. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  1144. if (checkbinding == null)
  1145. {
  1146. comboBox.IsEnabled = true;
  1147. }
  1148. else
  1149. {
  1150. comboBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  1151. }
  1152. comboBox.Background = Brushes.White;
  1153. string path = propertyInfo.Name;
  1154. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  1155. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  1156. grid.Children.Add(comboBox);
  1157. Grid.SetRow(comboBox, rowIndex);
  1158. Grid.SetColumn(comboBox, columnIndex);
  1159. break;
  1160. }
  1161. rowIndex++;
  1162. }
  1163. unitIndex++;
  1164. }
  1165. }
  1166. private void RecipeStepToGridColumnOnlyTitle(RecipeStep recipeStep, Grid grid)
  1167. {
  1168. Type recipeType = recipeStep.GetType();
  1169. int i = 0;
  1170. ColumnDefinition col1 = new ColumnDefinition();
  1171. grid.ColumnDefinitions.Add(col1);
  1172. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  1173. {
  1174. string propertyInfoName = propertyInfo.Name;
  1175. string propertyTypeName = propertyInfo.PropertyType.Name;
  1176. if (propertyInfoName != "LstUnit")
  1177. {
  1178. if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime" || propertyInfoName == "OverEtchPercent") && isInstalledEPD == false)
  1179. {
  1180. continue;
  1181. }
  1182. RowDefinition row1 = new RowDefinition();
  1183. row1.Height = new GridLength(controlHeight);
  1184. grid.RowDefinitions.Add(row1);
  1185. Border border = new Border();
  1186. TextBlock textBlock = new TextBlock();
  1187. textBlock.Padding = new Thickness(5, 3, 0, 0);
  1188. border.Child = textBlock;
  1189. border.BorderBrush = Brushes.Silver;
  1190. border.BorderThickness = new Thickness(1);
  1191. //textBlock.IsReadOnly = true;
  1192. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  1193. string name;
  1194. if (NameAttrs.Length > 0)
  1195. {
  1196. name = (NameAttrs[0] as CustomName).Name;
  1197. }
  1198. else
  1199. {
  1200. name = propertyInfo.Name;
  1201. }
  1202. textBlock.Text = name;
  1203. //textBlock.FontSize = 15;
  1204. grid.Children.Add(border);
  1205. border.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FAFAFA"));
  1206. Grid.SetRow(border, i);
  1207. Grid.SetColumn(border, 0);
  1208. i++;
  1209. }
  1210. }
  1211. foreach (var x in recipeStep.LstUnit.ToList())
  1212. {
  1213. Type unitType = x.GetType();
  1214. bool isUnitFirstRow = true;
  1215. foreach (PropertyInfo propertyInfo in unitType.GetProperties())
  1216. {
  1217. object[] IgnoreAttrs = propertyInfo.GetCustomAttributes(typeof(IsCanConfigIgnore), true);
  1218. bool IsEnableRecipeExtension = Convert.ToBoolean(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.IsEnableRecipeExtension"));
  1219. if (IgnoreAttrs.Length > 0 && IsEnableRecipeExtension == false)
  1220. {
  1221. break;
  1222. }
  1223. object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
  1224. if (toleranceAttrs.Length > 0 && CurrentRecipe.Header.IsShowTolerance == false)
  1225. {
  1226. continue;
  1227. }
  1228. if (propertyInfo.Name == "UnitName")
  1229. {
  1230. continue;
  1231. }
  1232. if (propertyInfo.Name.Contains("Gas"))
  1233. {
  1234. if (!(bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas1.Enable"))
  1235. {
  1236. continue;
  1237. }
  1238. }
  1239. RowDefinition row1 = new RowDefinition();
  1240. row1.Height = new GridLength(controlHeight);
  1241. grid.RowDefinitions.Add(row1);
  1242. Border border = new Border();
  1243. TextBlock textBlock = new TextBlock();
  1244. //textBlock.Padding = new Thickness(0, 3, 0, 0);
  1245. border.Child = textBlock;
  1246. border.BorderBrush = Brushes.Silver;
  1247. border.BorderThickness = new Thickness(1);
  1248. if (isUnitFirstRow)
  1249. {
  1250. textBlock.FontWeight = FontWeights.Bold;
  1251. textBlock.FontSize = 15;
  1252. isUnitFirstRow = false;
  1253. textBlock.Padding = new Thickness(5, 2, 5, 0);
  1254. }
  1255. else
  1256. {
  1257. textBlock.Padding = new Thickness(5, 3, 5, 0);
  1258. }
  1259. switch (propertyInfo.Name)
  1260. {
  1261. case "Gas1":
  1262. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  1263. textBlock.Text = $"{propertyInfo.Name}({data1.DisplayName},{data1.Scale})";
  1264. break;
  1265. case "Gas2":
  1266. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  1267. textBlock.Text = $"{propertyInfo.Name}({data2.DisplayName},{data2.Scale})";
  1268. break;
  1269. case "Gas3":
  1270. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  1271. textBlock.Text = $"{propertyInfo.Name}({data3.DisplayName},{data3.Scale})";
  1272. break;
  1273. case "Gas4":
  1274. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  1275. textBlock.Text = $"{propertyInfo.Name}({data4.DisplayName},{data4.Scale})";
  1276. break;
  1277. case "Gas5":
  1278. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  1279. textBlock.Text = $"{propertyInfo.Name}({data5.DisplayName},{data5.Scale})";
  1280. break;
  1281. case "Gas6":
  1282. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  1283. textBlock.Text = $"{propertyInfo.Name}({data6.DisplayName},{data6.Scale})";
  1284. break;
  1285. case "Gas7":
  1286. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  1287. textBlock.Text = $"{propertyInfo.Name}({data7.DisplayName},{data7.Scale})";
  1288. break;
  1289. case "Gas8":
  1290. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  1291. textBlock.Text = $"{propertyInfo.Name}({data8.DisplayName},{data8.Scale})";
  1292. break;
  1293. case "Gas9":
  1294. var data9 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas9");
  1295. textBlock.Text = $"{propertyInfo.Name}({data9.DisplayName},{data9.Scale})";
  1296. break;
  1297. case "Gas10":
  1298. var data10 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas10");
  1299. textBlock.Text = $"{propertyInfo.Name}({data10.DisplayName},{data10.Scale})";
  1300. break;
  1301. case "Gas11":
  1302. var data11 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas11");
  1303. textBlock.Text = $"{propertyInfo.Name}({data11.DisplayName},{data11.Scale})";
  1304. break;
  1305. case "Gas12":
  1306. var data12 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas12");
  1307. textBlock.Text = $"{propertyInfo.Name}({data12.DisplayName},{data12.Scale})";
  1308. break;
  1309. default:
  1310. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  1311. string name;
  1312. if (NameAttrs.Length > 0)
  1313. {
  1314. name = (NameAttrs[0] as CustomName).Name;
  1315. }
  1316. else
  1317. {
  1318. name = propertyInfo.Name;
  1319. }
  1320. textBlock.Text = name;
  1321. break;
  1322. }
  1323. grid.Children.Add(border);
  1324. border.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FAFAFA"));
  1325. Grid.SetRow(border, i);
  1326. Grid.SetColumn(border, 0);
  1327. i++;
  1328. }
  1329. }
  1330. }
  1331. private void EPDButton_Click(object sender, RoutedEventArgs e)
  1332. {
  1333. Button button = sender as Button;
  1334. string para = button.Tag.ToString();
  1335. int stepno = Convert.ToInt32(para.Split('.')[1]) - 1;
  1336. var endpointconfigitem = new MECF.Framework.Common.CommonData.EndPointConfigItem();
  1337. if (CurrentRecipe.Steps[stepno].EPDConfig != null && CurrentRecipe.Steps[stepno].EPDConfig.Length > 20)
  1338. {
  1339. endpointconfigitem.SetValue(CurrentRecipe.Steps[stepno].EPDConfig);
  1340. }
  1341. (new EndPointDlg(para, endpointconfigitem, CurrentRecipe)).ShowDialog();
  1342. }
  1343. private void UpdateRecipeFileList()
  1344. {
  1345. XmlDocument doc = new XmlDocument();
  1346. doc.LoadXml(GetXmlRecipeList());
  1347. treeViewRcpList.Items.Clear();
  1348. CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
  1349. ExpandAllItems(this.treeViewRcpList);
  1350. }
  1351. private void LoadRecipe(Recipe recipe)
  1352. {
  1353. copyIndex = -1;
  1354. OnClearRecipe();
  1355. CurrentRecipe = recipe;
  1356. RecipeStepToGridColumnOnlyTitle(recipe.Steps[0], leftGrid);
  1357. for (int i = 0; i < recipe.Steps.Count; i++)
  1358. {
  1359. ColumnDefinition col1 = new ColumnDefinition();
  1360. col1.Width = GridLength.Auto;
  1361. rightGrid.ColumnDefinitions.Insert(i, col1);
  1362. RecipeStepToGridColumn(recipe.Steps[i], rightGrid, i);
  1363. }
  1364. string recipeContent = RecipeUnity.RecipeToString(CurrentRecipe);
  1365. SaveEAPRecipe(recipeContent);
  1366. }
  1367. private void OnDeleteStep(int index)
  1368. {
  1369. if (CurrentRecipe != null && CurrentRecipe.Steps.Count > 1)
  1370. {
  1371. RemoveColumnFromGrid(rightGrid, index);
  1372. rightGrid.ColumnDefinitions.RemoveAt(index);
  1373. CurrentRecipe.Steps.RemoveAt(index);
  1374. }
  1375. }
  1376. /// <summary>
  1377. /// 删除Grid某列数据
  1378. /// </summary>
  1379. /// <param name="grid"></param>
  1380. /// <param name="column"></param>
  1381. public void RemoveColumnFromGrid(Grid grid, int column)
  1382. {
  1383. List<UIElement> listControl=new List<UIElement>();
  1384. for (int i = 0; i < grid.Children.Count; i++)
  1385. {
  1386. var child = grid.Children[i];
  1387. if (Grid.GetColumn(child) == column)
  1388. {
  1389. listControl.Add(child);
  1390. }
  1391. }
  1392. listControl.ForEach(x =>
  1393. {
  1394. grid.Children.Remove(x);
  1395. });
  1396. }
  1397. private void OnRefresh()
  1398. {
  1399. if (CurrentRecipeName != "")
  1400. {
  1401. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, $"{CurrentRecipeName}.rcp");
  1402. string xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  1403. CurrentRecipe = Recipe.Load(xmlRecipeData);
  1404. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  1405. LoadRecipe(CurrentRecipe);
  1406. }
  1407. }
  1408. private void OnExpand()
  1409. {
  1410. HeadExpand = !HeadExpand;
  1411. if (HeadExpand)
  1412. {
  1413. recipeView.expandGrid.Width = 300;
  1414. }
  1415. else
  1416. {
  1417. recipeView.expandGrid.Width = 30;
  1418. }
  1419. }
  1420. private void OnUnload()
  1421. {
  1422. //if (CurrentRecipeName == null || CurrentRecipeName == "")
  1423. //{
  1424. // return;
  1425. //}
  1426. //if (WPFMessageBox.ShowQuestion($"Is Save Recipe {CurrentRecipeName}", "", false) == MessageBoxResult.Yes)
  1427. //{
  1428. // OnSaveRecipe();
  1429. //}
  1430. }
  1431. private void OnClearRecipe()
  1432. {
  1433. for (int i = 0; i < rightGrid.ColumnDefinitions.Count; i++)
  1434. {
  1435. rightGrid.ColumnDefinitions[i].Width = new GridLength(75);
  1436. }
  1437. leftGrid.Children.Clear();
  1438. rightGrid.Children.Clear();
  1439. leftGrid.ColumnDefinitions.Clear();
  1440. rightGrid.ColumnDefinitions.Clear();
  1441. rightGrid.RowDefinitions.Clear();
  1442. leftGrid.RowDefinitions.Clear();
  1443. GC.Collect(); // This should pick up the control removed at a previous MouseDown
  1444. GC.WaitForPendingFinalizers(); // Doesn't help either
  1445. //rightGrid.Visibility = Visibility.Visible;
  1446. }
  1447. private void ExpandAllItems(ItemsControl control)
  1448. {
  1449. if (control == null)
  1450. {
  1451. return;
  1452. }
  1453. foreach (Object item in control.Items)
  1454. {
  1455. System.Windows.Controls.TreeViewItem treeItem = control.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
  1456. if (treeItem == null || !treeItem.HasItems)
  1457. {
  1458. continue;
  1459. }
  1460. treeItem.IsExpanded = true;
  1461. ExpandAllItems(treeItem as ItemsControl);
  1462. }
  1463. }
  1464. private bool RecipeNameIsOk(string recipeName)
  1465. {
  1466. if (recipeName.Contains(' '))
  1467. {
  1468. WPFMessageBox.ShowError("Recipe Name 包含空格,不符合规格");
  1469. return false;
  1470. }
  1471. if (recipeName.Length > 25)
  1472. {
  1473. WPFMessageBox.ShowError("Recipe Name 大于25个字符,不符合规格");
  1474. return false;
  1475. }
  1476. return true;
  1477. }
  1478. private void SaveEAPRecipe(string recipeContent)
  1479. {
  1480. if (currentChamber == JetChamber.Kepler2200A || currentChamber == JetChamber.Kepler2200B)
  1481. {
  1482. var newrecipePath2 = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{typeFolder}{eapPath}", CurrentRecipeName + ".rcp");
  1483. FileInfo fi2 = new FileInfo(newrecipePath2);
  1484. var di2 = fi2.Directory;
  1485. if (!di2.Exists)
  1486. {
  1487. di2.Create();
  1488. }
  1489. var newContent = Recipe.ShowEAPRecipe(recipeContent, CurrentRecipe.Steps);
  1490. File.WriteAllText(newrecipePath2, newContent, Encoding.UTF8);
  1491. var newrecipePath3 = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{typeFolder}{tolerancePath}", CurrentRecipeName + ".rcp");
  1492. FileInfo fi3 = new FileInfo(newrecipePath3);
  1493. var di3 = fi3.Directory;
  1494. if (!di3.Exists)
  1495. {
  1496. di3.Create();
  1497. }
  1498. var newContent3 = Recipe.ShowToleranceRecipe(recipeContent, CurrentRecipe.Steps);
  1499. File.WriteAllText(newrecipePath3, newContent3, Encoding.UTF8);
  1500. }
  1501. }
  1502. private bool DeleteEAPRecipe()
  1503. {
  1504. var path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{typeFolder}{eapPath}", CurrentRecipeName + ".rcp");
  1505. if (File.Exists(path))
  1506. {
  1507. File.Delete(path);
  1508. }
  1509. var path2 = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{typeFolder}{tolerancePath}", CurrentRecipeName + ".rcp");
  1510. if (File.Exists(path))
  1511. {
  1512. File.Delete(path2);
  1513. }
  1514. return true;
  1515. }
  1516. private bool DeleteToleranceRecipe()
  1517. {
  1518. return true;
  1519. }
  1520. #endregion
  1521. }
  1522. }