RecipeViewModel.cs 76 KB

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