RecipeViewModel.cs 68 KB

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