RecipeViewModel.cs 66 KB

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