NewRecipeViewModel.cs 70 KB

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