RecipeViewModel.cs 67 KB

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