RecipeViewModel.cs 66 KB

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