RecipeViewModel.cs 69 KB

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