RecipeViewModel.cs 68 KB

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