RecipeViewModel.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  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. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  614. string name;
  615. if (NameAttrs.Length > 0)
  616. {
  617. name = (NameAttrs[0] as CustomName).Name;
  618. }
  619. else
  620. {
  621. name = propertyInfo.Name;
  622. }
  623. textBlock.Text = name + ":";
  624. break;
  625. }
  626. textBlock.Margin = new Thickness(15, 0, 0, 0);
  627. textBlock.VerticalAlignment = VerticalAlignment.Center;
  628. HeadWrapPanel.Children.Add(textBlock);
  629. Binding binding = new Binding()
  630. {
  631. Source = recipe.Header, // 数据源
  632. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  633. Mode = BindingMode.TwoWay, // 绑定模式
  634. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, //触发器
  635. };
  636. var propertyTypeName = propertyInfo.PropertyType.Name;
  637. var propertyInfoName = propertyInfo.Name;
  638. Control control = new Control();
  639. switch (propertyInfoName)
  640. {
  641. case "ChamberType":
  642. control = new ComboBox();
  643. control.IsEnabled = false;
  644. control.Height = 23;
  645. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  646. ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  647. break;
  648. case "Type":
  649. ComboBox cb = new ComboBox();
  650. cb.IsEnabled = false;
  651. cb.SelectionChanged += ChangeUI;
  652. control = cb;
  653. control.Height = 23;
  654. ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  655. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  656. break;
  657. case "ChuckRecipe":
  658. //if (currentChamber != JetChamber.Venus)
  659. //{
  660. // continue;
  661. //}
  662. //string[] chucklist = new string[] { "" };
  663. //ArrayList arrayList = new ArrayList(chucklist.ToList());
  664. //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));
  665. //foreach (var i in chlist)
  666. //{
  667. // arrayList.Add(i);
  668. //}
  669. //chucklist = (string[])arrayList.ToArray(typeof(string));
  670. StringBuilder stringBuilder = new StringBuilder();
  671. //输出
  672. //for (int i = 0; i < chucklist.Length; i++)
  673. //{
  674. // stringBuilder.Append(chucklist[i] + "\t");
  675. //}
  676. control = new ComboBox()
  677. {
  678. ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck"))
  679. };
  680. control.Height = 23;
  681. control.MinWidth = 100;
  682. control.MaxWidth = 300;
  683. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  684. control.PreviewMouseLeftButtonDown += ChuckControl_PreviewMouseLeftButtonDown;
  685. break;
  686. case "DechuckRecipe":
  687. //if (currentChamber != JetChamber.Venus)
  688. //{
  689. // continue;
  690. //}
  691. //string[] dechucklist = new string[] { "" };
  692. //ArrayList dearrayList = new ArrayList(dechucklist.ToList());
  693. //IEnumerable<string> delist = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName)).ToList().Where(item => item.ToLower().Contains("dechuck"));
  694. //foreach (var i in delist)
  695. //{
  696. // dearrayList.Add(i);
  697. //}
  698. //dechucklist = (string[])dearrayList.ToArray(typeof(string));
  699. //StringBuilder destringBuilder = new StringBuilder();
  700. //for (int i = 0; i < dechucklist.Length; i++)
  701. //{
  702. // destringBuilder.Append(dechucklist[i] + "\t");
  703. //}
  704. control = new ComboBox()
  705. {
  706. ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck"))
  707. };
  708. control.Height = 23;
  709. control.MinWidth = 100;
  710. control.MaxWidth = 300;
  711. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  712. control.PreviewMouseLeftButtonDown += DechuckControl_PreviewMouseLeftButtonDown;
  713. break;
  714. case "IsShowTolerance":
  715. control = new CheckBox();
  716. control.SetBinding(CheckBox.IsCheckedProperty, binding);
  717. control.Style = null;
  718. control.VerticalAlignment = VerticalAlignment.Center;
  719. (control as CheckBox).Checked += RecipeViewModel_Checked;
  720. (control as CheckBox).Unchecked += RecipeViewModel_Checked;
  721. break;
  722. default:
  723. control = new TextBox();
  724. control.Margin = new Thickness(1, 0, 0, 0);
  725. control.BorderThickness = new Thickness(0, 0, 0, 1);
  726. control.BorderBrush = Brushes.White;
  727. control.FontSize = 15;
  728. control.Foreground = Brushes.Green;
  729. control.Background = Brushes.Transparent;
  730. control.VerticalAlignment = VerticalAlignment.Center;
  731. control.MinWidth = 15;
  732. control.SetBinding(TextBox.TextProperty, binding);
  733. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  734. if (objAttrs.Length > 0)
  735. {
  736. (control as TextBox).IsReadOnly = true;
  737. }
  738. break;
  739. }
  740. //switch (propertyTypeName)
  741. //{
  742. // case "Int32":
  743. // case "String":
  744. // control = new TextBox();
  745. // control.Margin = new Thickness(1, 0, 0, 0);
  746. // control.BorderThickness = new Thickness(0, 0, 0, 1);
  747. // //control.BorderBrush = Brushes.Black;
  748. // control.FontSize = 15;
  749. // control.Foreground = Brushes.Green;
  750. // control.Background = Brushes.Transparent;
  751. // control.VerticalAlignment = VerticalAlignment.Center;
  752. // control.MinWidth = 15;
  753. // control.SetBinding(TextBox.TextProperty, binding);
  754. // object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  755. // if (objAttrs.Length > 0)
  756. // {
  757. // (control as TextBox).IsReadOnly = true;
  758. // }
  759. // break;
  760. // case "Boolean":
  761. // control = new CheckBox();
  762. // control.SetBinding(CheckBox.IsCheckedProperty, binding);
  763. // break;
  764. // default:
  765. // control = new ComboBox();
  766. // control.Height = 23;
  767. // control.SetBinding(ComboBox.SelectedItemProperty, binding);
  768. // ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  769. // break;
  770. //}
  771. control.Margin = new Thickness(20, 3, 0, 7);
  772. control.Width = 250;
  773. HeadWrapPanel.Children.Add(control);
  774. }
  775. }
  776. private void RecipeViewModel_Checked(object sender, RoutedEventArgs e)
  777. {
  778. bool? isTolerance = (sender as CheckBox).IsChecked;
  779. LoadRecipe(CurrentRecipe);
  780. }
  781. private void Control_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  782. {
  783. }
  784. private void ChuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  785. {
  786. var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck")).ToList();
  787. items.Add("");
  788. (sender as ComboBox).ItemsSource = items;
  789. }
  790. private void DechuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  791. {
  792. var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck")).ToList();
  793. items.Add("");
  794. (sender as ComboBox).ItemsSource = items;
  795. }
  796. private void ChangeUI(object sender, SelectionChangedEventArgs e)
  797. {
  798. var t = sender as ComboBox;
  799. if (t.SelectedValue.ToString() != "Process")
  800. {
  801. headWrapPanel.Children[8].Visibility = Visibility.Collapsed;
  802. headWrapPanel.Children[9].Visibility = Visibility.Collapsed;
  803. headWrapPanel.Children[10].Visibility = Visibility.Collapsed;
  804. headWrapPanel.Children[11].Visibility = Visibility.Collapsed;
  805. }
  806. else
  807. {
  808. headWrapPanel.Children[8].Visibility = Visibility.Visible;
  809. headWrapPanel.Children[9].Visibility = Visibility.Visible;
  810. headWrapPanel.Children[10].Visibility = Visibility.Visible;
  811. headWrapPanel.Children[11].Visibility = Visibility.Visible;
  812. }
  813. }
  814. private void MenuItemLeftInsert_Click(object sender, RoutedEventArgs e)
  815. {
  816. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  817. int insertIndex = Convert.ToInt32(t.Text);
  818. if (copyIndex == -1)
  819. {
  820. var recipeStep = new RecipeStep();
  821. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  822. CurrentRecipe.Steps.Insert(insertIndex - 1, recipeStep);
  823. }
  824. else
  825. {
  826. var t1 = JsonConvert.SerializeObject(CurrentRecipe);
  827. var recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
  828. CurrentRecipe.Steps.Insert(insertIndex - 1, recipeStep);
  829. }
  830. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  831. {
  832. CurrentRecipe.Steps[i].StepNo = i + 1;
  833. }
  834. LoadRecipe(CurrentRecipe);
  835. }
  836. private void MenuItemRightInsert_Click(object sender, RoutedEventArgs e)
  837. {
  838. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  839. int insertIndex = Convert.ToInt32(t.Text);
  840. if (copyIndex == -1)
  841. {
  842. var recipeStep = new RecipeStep();
  843. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  844. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  845. }
  846. else
  847. {
  848. var t1 = JsonConvert.SerializeObject(CurrentRecipe);
  849. var recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
  850. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  851. }
  852. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  853. {
  854. CurrentRecipe.Steps[i].StepNo = i + 1;
  855. }
  856. LoadRecipe(CurrentRecipe);
  857. }
  858. private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
  859. {
  860. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  861. int deleteIndex = Convert.ToInt32(t.Text);
  862. //OnDeleteStep(deleteIndex - 1);
  863. CurrentRecipe.Steps.RemoveAt(deleteIndex - 1);
  864. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  865. {
  866. CurrentRecipe.Steps[i].StepNo = i + 1;
  867. }
  868. LoadRecipe(CurrentRecipe);
  869. }
  870. private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
  871. {
  872. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  873. copyIndex = Convert.ToInt32(t.Text);
  874. }
  875. #endregion
  876. #region 私有方法
  877. private void RecipeStepToGridColumn(RecipeStep recipeStep, Grid grid, int index, bool isInsert)
  878. {
  879. int location = 1;
  880. if (isInsert == true)
  881. {
  882. location -= 1;
  883. }
  884. Type recipeType = recipeStep.GetType();
  885. int cycleCount = 1;
  886. if (index == 0)
  887. {
  888. cycleCount = 2;
  889. }
  890. for (int j = 0; j < cycleCount; j++)
  891. {
  892. int i = 0;
  893. ColumnDefinition col1 = new ColumnDefinition();
  894. //col1.MinWidth = 50;
  895. grid.ColumnDefinitions.Insert(index, col1);
  896. //Binding stepcheckbinding = null;
  897. //grid.MinWidth = 200;
  898. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  899. {
  900. string propertyInfoName = propertyInfo.Name;
  901. string propertyTypeName = propertyInfo.PropertyType.Name;
  902. if (propertyInfoName != "LstUnit")
  903. {
  904. if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime" || propertyInfoName == "OverEtchPercent") && isInstalledEPD == false)
  905. {
  906. continue;
  907. }
  908. if (index == 0 && grid.ColumnDefinitions.Count == 1)
  909. {
  910. RowDefinition row1 = new RowDefinition();
  911. grid.RowDefinitions.Add(row1);
  912. }
  913. if (grid.ColumnDefinitions.Count == 1 && j == 0)
  914. {
  915. TextBox textBlock = new TextBox();
  916. textBlock.IsReadOnly = true;
  917. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  918. string name;
  919. if (NameAttrs.Length > 0)
  920. {
  921. name = (NameAttrs[0] as CustomName).Name;
  922. }
  923. else
  924. {
  925. name = propertyInfo.Name;
  926. }
  927. textBlock.Text = name;
  928. grid.Children.Add(textBlock);
  929. textBlock.Background = new SolidColorBrush(Colors.BurlyWood);
  930. Grid.SetRow(textBlock, i);
  931. Grid.SetColumn(textBlock, 0);
  932. }
  933. else
  934. {
  935. Binding binding = new Binding()
  936. {
  937. Source = recipeStep, // 数据源
  938. Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
  939. Mode = BindingMode.TwoWay, // 绑定模式
  940. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  941. };
  942. switch (propertyTypeName)
  943. {
  944. case "Int32":
  945. case "String":
  946. case "Single":
  947. case "Double":
  948. if (propertyInfoName == "EPDConfig")
  949. {
  950. if (currentEPDType == EPDType.Socket)
  951. {
  952. ComboBox EPDcomboBox = new ComboBox();
  953. EPDcomboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  954. EPDcomboBox.Background = new SolidColorBrush(Colors.Black);
  955. EPDcomboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  956. EPDcomboBox.ItemsSource = EPDCfgList;
  957. grid.Children.Add(EPDcomboBox);
  958. Grid.SetRow(EPDcomboBox, i);
  959. Grid.SetColumn(EPDcomboBox, index + location);
  960. //EPDcomboBox.DropDownOpened += EPDcomboBox_DropDownOpened;
  961. }
  962. else if (currentEPDType == EPDType.WCF)
  963. {
  964. Button EPDButton = new Button();
  965. EPDButton.Content = "EndPoint";
  966. EPDButton.Cursor = Cursors.Hand;
  967. EPDButton.Tag = $"{CurrentRecipeName}.{(index + location).ToString()}";
  968. EPDButton.Style = null;
  969. EPDButton.Click += EPDButton_Click;
  970. grid.Children.Add(EPDButton);
  971. Grid.SetRow(EPDButton, i);
  972. Grid.SetColumn(EPDButton, index + location);
  973. }
  974. break;
  975. }
  976. TextBox textBox = new TextBox();
  977. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  978. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  979. textBox.SetBinding(TextBox.TextProperty, binding);
  980. grid.Children.Add(textBox);
  981. Grid.SetRow(textBox, i);
  982. Grid.SetColumn(textBox, index + location);
  983. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  984. if (objAttrs.Length > 0)
  985. {
  986. textBox.IsReadOnly = true;
  987. ContextMenu contextmenu = new ContextMenu();
  988. textBox.ContextMenu = contextmenu;
  989. MenuItem menuItemDelete = new MenuItem();
  990. menuItemDelete.Header = "Delete";
  991. menuItemDelete.Click += MenuItemDelete_Click;
  992. MenuItem menuItemLeftInsert = new MenuItem();
  993. menuItemLeftInsert.Header = "Left Insert";
  994. menuItemLeftInsert.Click += MenuItemLeftInsert_Click;
  995. MenuItem menuItemRightInsert = new MenuItem();
  996. menuItemRightInsert.Header = "Right Insert";
  997. menuItemRightInsert.Click += MenuItemRightInsert_Click;
  998. MenuItem menuItemCopy = new MenuItem();
  999. menuItemCopy.Tag = textBox.Text;
  1000. menuItemCopy.Header = "Copy";
  1001. menuItemCopy.Click += MenuItemCopy_Click;
  1002. contextmenu.Items.Add(menuItemCopy);
  1003. contextmenu.Items.Add(menuItemDelete);
  1004. contextmenu.Items.Add(menuItemLeftInsert);
  1005. contextmenu.Items.Add(menuItemRightInsert);
  1006. }
  1007. break;
  1008. case "Boolean":
  1009. CheckBox checkBox = new CheckBox();
  1010. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  1011. grid.Children.Add(checkBox);
  1012. Grid.SetRow(checkBox, i);
  1013. Grid.SetColumn(checkBox, index + location);
  1014. break;
  1015. default:
  1016. ComboBox comboBox = new ComboBox();
  1017. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  1018. //comboBox.BorderThickness = new Thickness(1, 0, 1, 0);
  1019. comboBox.Background = new SolidColorBrush(Colors.Black);
  1020. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  1021. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  1022. grid.Children.Add(comboBox);
  1023. Grid.SetRow(comboBox, i);
  1024. Grid.SetColumn(comboBox, index + location);
  1025. break;
  1026. }
  1027. }
  1028. i++;
  1029. }
  1030. }
  1031. int k = 0;
  1032. foreach (var x in recipeStep.LstUnit.ToList())
  1033. {
  1034. Type unitType = x.GetType();
  1035. //bool isIgnore = false;
  1036. Binding checkbinding = null;
  1037. foreach (PropertyInfo propertyInfo in unitType.GetProperties())
  1038. {
  1039. object[] IgnoreAttrs = propertyInfo.GetCustomAttributes(typeof(IsCanConfigIgnore), true);
  1040. bool IsEnableRecipeExtension = Convert.ToBoolean(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.IsEnableRecipeExtension"));
  1041. if (IgnoreAttrs.Length > 0 && IsEnableRecipeExtension == false)
  1042. {
  1043. break;
  1044. }
  1045. object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
  1046. if (toleranceAttrs.Length > 0 && CurrentRecipe.Header.IsShowTolerance==false)
  1047. {
  1048. continue;
  1049. }
  1050. if (index == 0 && grid.ColumnDefinitions.Count == 1)
  1051. {
  1052. RowDefinition row1 = new RowDefinition();
  1053. grid.RowDefinitions.Add(row1);
  1054. }
  1055. if (grid.ColumnDefinitions.Count == 1 && j == 0)
  1056. {
  1057. TextBox textBlock = new TextBox();
  1058. textBlock.IsReadOnly = true;
  1059. switch (propertyInfo.Name)
  1060. {
  1061. case "Gas1":
  1062. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  1063. textBlock.Text = $"{propertyInfo.Name}({data1.DisplayName},{data1.Scale})";
  1064. break;
  1065. case "Gas2":
  1066. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  1067. textBlock.Text = $"{propertyInfo.Name}({data2.DisplayName},{data2.Scale})";
  1068. break;
  1069. case "Gas3":
  1070. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  1071. textBlock.Text = $"{propertyInfo.Name}({data3.DisplayName},{data3.Scale})";
  1072. break;
  1073. case "Gas4":
  1074. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  1075. textBlock.Text = $"{propertyInfo.Name}({data4.DisplayName},{data4.Scale})";
  1076. break;
  1077. case "Gas5":
  1078. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  1079. textBlock.Text = $"{propertyInfo.Name}({data5.DisplayName},{data5.Scale})";
  1080. break;
  1081. case "Gas6":
  1082. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  1083. textBlock.Text = $"{propertyInfo.Name}({data6.DisplayName},{data6.Scale})";
  1084. break;
  1085. case "Gas7":
  1086. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  1087. textBlock.Text = $"{propertyInfo.Name}({data7.DisplayName},{data7.Scale})";
  1088. break;
  1089. case "Gas8":
  1090. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  1091. textBlock.Text = $"{propertyInfo.Name}({data8.DisplayName},{data8.Scale})";
  1092. break;
  1093. case "Gas9":
  1094. var data9 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas9");
  1095. textBlock.Text = $"{propertyInfo.Name}({data9.DisplayName},{data9.Scale})";
  1096. break;
  1097. case "Gas10":
  1098. var data10 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas10");
  1099. textBlock.Text = $"{propertyInfo.Name}({data10.DisplayName},{data10.Scale})";
  1100. break;
  1101. case "Gas11":
  1102. var data11 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas11");
  1103. textBlock.Text = $"{propertyInfo.Name}({data11.DisplayName},{data11.Scale})";
  1104. break;
  1105. case "Gas12":
  1106. var data12 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas12");
  1107. textBlock.Text = $"{propertyInfo.Name}({data12.DisplayName},{data12.Scale})";
  1108. break;
  1109. //case "HeaterPressure":
  1110. // textBlock.Text = "Pressure(Pa)";
  1111. // break;
  1112. //case "HeaterTemp":
  1113. // textBlock.Text = "Heater Temp(℃)";
  1114. // break;
  1115. //case "HeaterRatio":
  1116. // textBlock.Text = "Heater Ratio";
  1117. // break;
  1118. default:
  1119. object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
  1120. string name;
  1121. if (NameAttrs.Length > 0)
  1122. {
  1123. name = (NameAttrs[0] as CustomName).Name;
  1124. }
  1125. else
  1126. {
  1127. name = propertyInfo.Name;
  1128. }
  1129. textBlock.Text = name;
  1130. break;
  1131. }
  1132. textBlock.Background = solidColorBrushes[k % solidColorBrushes.Count];
  1133. grid.Children.Add(textBlock);
  1134. Grid.SetRow(textBlock, i);
  1135. Grid.SetColumn(textBlock, 0);
  1136. }
  1137. else
  1138. {
  1139. Binding binding = new Binding()
  1140. {
  1141. Source = recipeStep.LstUnit[k], // 数据源
  1142. //Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
  1143. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  1144. Mode = BindingMode.TwoWay, // 绑定模式
  1145. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  1146. };
  1147. var item = propertyInfo.PropertyType.Name;
  1148. if (propertyInfo.Name == "UnitName")
  1149. {
  1150. TextBox textBlock1 = new TextBox();
  1151. textBlock1.HorizontalContentAlignment = HorizontalAlignment.Center;
  1152. textBlock1.VerticalContentAlignment = VerticalAlignment.Center;
  1153. textBlock1.Text = propertyInfo.GetValue(x).ToString();
  1154. textBlock1.IsReadOnly = true;
  1155. grid.Children.Add(textBlock1);
  1156. Grid.SetRow(textBlock1, i);
  1157. Grid.SetColumn(textBlock1, index + location);
  1158. }
  1159. else
  1160. {
  1161. switch (item)
  1162. {
  1163. case "Int32":
  1164. case "String":
  1165. case "Single":
  1166. case "Double":
  1167. //if (checkbinding != null)
  1168. //{
  1169. // break;
  1170. //}
  1171. TextBox textBox = new TextBox();
  1172. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  1173. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  1174. if (checkbinding == null)
  1175. {
  1176. textBox.IsEnabled = true;
  1177. }
  1178. else
  1179. {
  1180. textBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  1181. }
  1182. switch (propertyInfo.Name)
  1183. {
  1184. case "Gas1":
  1185. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  1186. TextBoxMaxValue.SetMaxValue(textBox, (int)data1.Scale);
  1187. break;
  1188. case "Gas2":
  1189. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  1190. TextBoxMaxValue.SetMaxValue(textBox, (int)data2.Scale);
  1191. break;
  1192. case "Gas3":
  1193. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  1194. TextBoxMaxValue.SetMaxValue(textBox, (int)data3.Scale);
  1195. break;
  1196. case "Gas4":
  1197. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  1198. TextBoxMaxValue.SetMaxValue(textBox, (int)data4.Scale);
  1199. break;
  1200. case "Gas5":
  1201. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  1202. TextBoxMaxValue.SetMaxValue(textBox, (int)data5.Scale);
  1203. break;
  1204. case "Gas6":
  1205. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  1206. TextBoxMaxValue.SetMaxValue(textBox, (int)data6.Scale);
  1207. break;
  1208. case "Gas7":
  1209. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  1210. TextBoxMaxValue.SetMaxValue(textBox, (int)data7.Scale);
  1211. break;
  1212. case "Gas8":
  1213. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  1214. TextBoxMaxValue.SetMaxValue(textBox, (int)data8.Scale);
  1215. break;
  1216. }
  1217. textBox.SetBinding(TextBox.TextProperty, binding);
  1218. grid.Children.Add(textBox);
  1219. Grid.SetRow(textBox, i);
  1220. Grid.SetColumn(textBox, index + location);
  1221. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  1222. if (objAttrs.Length > 0)
  1223. {
  1224. textBox.IsReadOnly = true;
  1225. }
  1226. break;
  1227. case "Boolean":
  1228. CheckBox checkBox = new CheckBox();
  1229. if (checkbinding == null)
  1230. {
  1231. checkbinding = new Binding
  1232. {
  1233. Source = checkBox, // 数据源
  1234. Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
  1235. Mode = BindingMode.TwoWay, // 绑定模式
  1236. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  1237. };
  1238. }
  1239. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  1240. grid.Children.Add(checkBox);
  1241. Grid.SetRow(checkBox, i);
  1242. Grid.SetColumn(checkBox, index + location);
  1243. break;
  1244. default:
  1245. //if (checkbinding != null)
  1246. //{
  1247. // break;
  1248. //}
  1249. ComboBox comboBox = new ComboBox();
  1250. comboBox.BorderBrush = Brushes.Gray;
  1251. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  1252. //comboBox.BorderThickness =new Thickness(1,0,1,0);
  1253. if (checkbinding == null)
  1254. {
  1255. comboBox.IsEnabled = true;
  1256. }
  1257. else
  1258. {
  1259. comboBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  1260. }
  1261. comboBox.Background = Brushes.White;
  1262. string path = propertyInfo.Name;
  1263. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  1264. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  1265. grid.Children.Add(comboBox);
  1266. Grid.SetRow(comboBox, i);
  1267. Grid.SetColumn(comboBox, index + location);
  1268. break;
  1269. }
  1270. }
  1271. }
  1272. i++;
  1273. }
  1274. k++;
  1275. }
  1276. }
  1277. }
  1278. private void EPDButton_Click(object sender, RoutedEventArgs e)
  1279. {
  1280. Button button = sender as Button;
  1281. string para = button.Tag.ToString();
  1282. int stepno = Convert.ToInt32(para.Split('.')[1]) - 1;
  1283. var endpointconfigitem = new MECF.Framework.Common.CommonData.EndPointConfigItem();
  1284. if (CurrentRecipe.Steps[stepno].EPDConfig != null && CurrentRecipe.Steps[stepno].EPDConfig.Length > 20)
  1285. {
  1286. endpointconfigitem.SetValue(CurrentRecipe.Steps[stepno].EPDConfig);
  1287. }
  1288. (new EndPointDlg(para, endpointconfigitem, CurrentRecipe)).ShowDialog();
  1289. }
  1290. private void UpdateRecipeFileList()
  1291. {
  1292. XmlDocument doc = new XmlDocument();
  1293. doc.LoadXml(GetXmlRecipeList());
  1294. treeViewRcpList.Items.Clear();
  1295. CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
  1296. ExpandAllItems(this.treeViewRcpList);
  1297. }
  1298. private void LoadRecipe(Recipe recipe)
  1299. {
  1300. copyIndex = -1;
  1301. bodyStackPanel.Children.Clear();
  1302. //CurrentRecipe = null;
  1303. GC.Collect(); // This should pick up the control removed at a previous MouseDown
  1304. GC.WaitForPendingFinalizers(); // Doesn't help either
  1305. GC.Collect();
  1306. GC.WaitForPendingFinalizers(); // Doesn't help either
  1307. CurrentRecipe = recipe;
  1308. if (CurrentRecipe.Header.Type == Venus_Core.RecipeType.Process && CurrentRecipe.Header.ChuckRecipe != "" && CurrentRecipe.Header.ChuckRecipe != null)
  1309. {
  1310. Grid chuckGrid = new Grid();
  1311. chuckGrid.IsEnabled = false;
  1312. chuckGrid.Margin = new Thickness(15);
  1313. string chuckRecipeData = m_uiRecipeManager.LoadRecipe(ModuleName, $"Chuck\\{CurrentRecipe.Header.ChuckRecipe}");
  1314. if (chuckRecipeData == "")
  1315. {
  1316. return;
  1317. }
  1318. var chuckRecipe = Recipe.Load(chuckRecipeData);
  1319. for (int i = 0; i < chuckRecipe.Steps.Count; i++)
  1320. {
  1321. RecipeStepToGridColumn(chuckRecipe.Steps[i], chuckGrid, i, false);
  1322. }
  1323. bodyStackPanel.Children.Add(chuckGrid);
  1324. }
  1325. Grid proressGrid = new Grid();
  1326. proressGrid.Margin = new Thickness(15);
  1327. //index = 0;
  1328. for (int i = 0; i < recipe.Steps.Count; i++)
  1329. {
  1330. RecipeStepToGridColumn(recipe.Steps[i], proressGrid, i, false);
  1331. }
  1332. bodyStackPanel.Children.Add(proressGrid);
  1333. currentRecipeGrid = proressGrid;
  1334. if (CurrentRecipe.Header.Type == Venus_Core.RecipeType.Process && CurrentRecipe.Header.DechuckRecipe != "" && CurrentRecipe.Header.DechuckRecipe != null)
  1335. {
  1336. Grid deChuckGrid = new Grid();
  1337. deChuckGrid.IsEnabled = false;
  1338. deChuckGrid.Margin = new Thickness(15);
  1339. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, "DeChuck", $"{CurrentRecipe.Header.DechuckRecipe}.rcp");
  1340. string DechuckRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  1341. //index = 0;
  1342. var dechuckRecipe = Recipe.Load(DechuckRecipeData);
  1343. for (int i = 0; i < dechuckRecipe.Steps.Count; i++)
  1344. {
  1345. RecipeStepToGridColumn(dechuckRecipe.Steps[i], deChuckGrid, i, false);
  1346. }
  1347. bodyStackPanel.Children.Add(deChuckGrid);
  1348. }
  1349. }
  1350. private void OnDeleteStep(int index)
  1351. {
  1352. if (CurrentRecipe != null && CurrentRecipe.Steps.Count > 1)
  1353. {
  1354. currentRecipeGrid.Children.RemoveRange(currentRecipeGrid.RowDefinitions.Count * (index + 1), currentRecipeGrid.RowDefinitions.Count);
  1355. currentRecipeGrid.ColumnDefinitions.RemoveAt(index);
  1356. for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
  1357. {
  1358. CurrentRecipe.Steps[i - 1].StepNo = i;
  1359. }
  1360. CurrentRecipe.Steps.RemoveAt(index);
  1361. }
  1362. }
  1363. private void OnRefresh()
  1364. {
  1365. if (CurrentRecipeName != "")
  1366. {
  1367. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, $"{CurrentRecipeName}.rcp");
  1368. string xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  1369. CurrentRecipe = Recipe.Load(xmlRecipeData);
  1370. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  1371. LoadRecipe(CurrentRecipe);
  1372. }
  1373. }
  1374. private void OnTolerance()
  1375. {
  1376. }
  1377. private void OnExpand()
  1378. {
  1379. HeadExpand = !HeadExpand;
  1380. if (HeadExpand)
  1381. {
  1382. recipeView.expandGrid.Width = 300;
  1383. }
  1384. else
  1385. {
  1386. recipeView.expandGrid.Width = 30;
  1387. }
  1388. }
  1389. private void OnUnload()
  1390. {
  1391. //if (CurrentRecipeName == null || CurrentRecipeName == "")
  1392. //{
  1393. // return;
  1394. //}
  1395. //if (WPFMessageBox.ShowQuestion($"Is Save Recipe {CurrentRecipeName}", "", false) == MessageBoxResult.Yes)
  1396. //{
  1397. // OnSaveRecipe();
  1398. //}
  1399. }
  1400. private void ExpandAllItems(ItemsControl control)
  1401. {
  1402. if (control == null)
  1403. {
  1404. return;
  1405. }
  1406. foreach (Object item in control.Items)
  1407. {
  1408. System.Windows.Controls.TreeViewItem treeItem = control.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
  1409. if (treeItem == null || !treeItem.HasItems)
  1410. {
  1411. continue;
  1412. }
  1413. treeItem.IsExpanded = true;
  1414. ExpandAllItems(treeItem as ItemsControl);
  1415. }
  1416. }
  1417. #endregion
  1418. }
  1419. }