RecipeViewModel.cs 74 KB

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