RecipeViewModel.cs 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  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.Venus)
  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. }
  493. }
  494. private void menuItem_MouseClick_RenameRecipe(object sender, RoutedEventArgs e)
  495. {
  496. if (CurrentRecipe == null)
  497. {
  498. return;
  499. }
  500. var newName = Interaction.InputBox(" ", "Rename Recipe", CurrentRecipeName, -1, -1);
  501. if (newName != CurrentRecipeName && newName != "")
  502. {
  503. var newRecipe = CurrentRecipe;
  504. newRecipe.Header.Name = newName;
  505. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  506. var oldrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, CurrentRecipeName + ".rcp");
  507. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, newName + ".rcp");
  508. File.Delete(oldrecipePath);
  509. File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  510. UpdateRecipeFileList();
  511. }
  512. }
  513. public bool SaveAsRecipe(string recipeName, string recipeContent)
  514. {
  515. return m_uiRecipeManager.SaveAsRecipe(ModuleName, recipeName, recipeContent);
  516. }
  517. public bool SaveAsRecipe2(string recipeName, string type, string recipeContent)
  518. {
  519. return m_uiRecipeManager.SaveAsRecipe2(ModuleName, type, recipeName, recipeContent);
  520. }
  521. public string GetXmlRecipeList()
  522. {
  523. return m_uiRecipeManager.GetXmlRecipeList(ModuleName, true) ?? "";
  524. }
  525. void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
  526. {
  527. foreach (XmlElement ele in curElementNode.ChildNodes)
  528. {
  529. if (ele.Name == "File")
  530. {
  531. string fileName = ele.Attributes["Name"].Value;
  532. fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
  533. TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
  534. item.Tag = ele.Attributes["Name"].Value;
  535. if (!item.Tag.ToString().Contains("\\"))
  536. {
  537. continue;
  538. }
  539. itemsControl.Items.Add(item);
  540. }
  541. else if (ele.Name == "Folder")
  542. {
  543. string folderName = ele.Attributes["Name"].Value;
  544. folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
  545. 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())
  546. {
  547. TreeViewFolderItem item = new TreeViewFolderItem(folderName);
  548. item.Tag = ele.Attributes["Name"].Value;
  549. CreateTreeViewItems(ele, item);
  550. item.IsExpanded = false;
  551. itemsControl.Items.Add(item);
  552. }
  553. }
  554. }
  555. }
  556. private IEnumerable<string> GetFilesNames(string path)
  557. {
  558. if (Directory.Exists(path))
  559. {
  560. return Directory.GetFiles(path, "*.rcp")?
  561. .Select(Path.GetFileNameWithoutExtension);
  562. }
  563. else
  564. {
  565. return new List<string>();
  566. }
  567. }
  568. private void LoadHeadWrapPanel(WrapPanel HeadWrapPanel, Recipe recipe)
  569. {
  570. HeadWrapPanel.Children.Clear();
  571. Type type = recipe.Header.GetType();
  572. foreach (var propertyInfo in type.GetProperties())
  573. {
  574. TextBlock textBlock = new TextBlock();
  575. textBlock.FontSize = 16;
  576. textBlock.Margin=new Thickness(0,20,0,0);
  577. textBlock.Width = 200;
  578. switch (propertyInfo.Name)
  579. {
  580. case "ChuckRecipe":
  581. if (currentChamber != JetChamber.Venus)
  582. {
  583. continue;
  584. }
  585. textBlock.Text = "Chuck:";
  586. break;
  587. case "DechuckRecipe":
  588. if (currentChamber != JetChamber.Venus)
  589. {
  590. continue;
  591. }
  592. textBlock.Text = "DeChuck:";
  593. break;
  594. default:
  595. textBlock.Text = propertyInfo.Name + ":";
  596. break;
  597. }
  598. textBlock.Margin = new Thickness(15, 0, 0, 0);
  599. textBlock.VerticalAlignment = VerticalAlignment.Center;
  600. HeadWrapPanel.Children.Add(textBlock);
  601. Binding binding = new Binding()
  602. {
  603. Source = recipe.Header, // 数据源
  604. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  605. Mode = BindingMode.TwoWay, // 绑定模式
  606. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, //触发器
  607. };
  608. var propertyTypeName = propertyInfo.PropertyType.Name;
  609. var propertyInfoName = propertyInfo.Name;
  610. Control control = new Control();
  611. switch (propertyInfoName)
  612. {
  613. case "ChamberType":
  614. control = new ComboBox();
  615. control.IsEnabled = false;
  616. control.Height = 23;
  617. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  618. ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  619. break;
  620. case "Type":
  621. ComboBox cb = new ComboBox();
  622. cb.IsEnabled = false;
  623. cb.SelectionChanged += ChangeUI;
  624. control = cb;
  625. control.Height = 23;
  626. ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  627. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  628. break;
  629. case "ChuckRecipe":
  630. if (currentChamber != JetChamber.Venus)
  631. {
  632. continue;
  633. }
  634. //string[] chucklist = new string[] { "" };
  635. //ArrayList arrayList = new ArrayList(chucklist.ToList());
  636. //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));
  637. //foreach (var i in chlist)
  638. //{
  639. // arrayList.Add(i);
  640. //}
  641. //chucklist = (string[])arrayList.ToArray(typeof(string));
  642. StringBuilder stringBuilder = new StringBuilder();
  643. //输出
  644. //for (int i = 0; i < chucklist.Length; i++)
  645. //{
  646. // stringBuilder.Append(chucklist[i] + "\t");
  647. //}
  648. control = new ComboBox()
  649. {
  650. ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck"))
  651. };
  652. control.Height = 23;
  653. control.MinWidth = 100;
  654. control.MaxWidth = 300;
  655. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  656. control.PreviewMouseLeftButtonDown += ChuckControl_PreviewMouseLeftButtonDown;
  657. break;
  658. case "DechuckRecipe":
  659. if (currentChamber != JetChamber.Venus)
  660. {
  661. continue;
  662. }
  663. //string[] dechucklist = new string[] { "" };
  664. //ArrayList dearrayList = new ArrayList(dechucklist.ToList());
  665. //IEnumerable<string> delist = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName)).ToList().Where(item => item.ToLower().Contains("dechuck"));
  666. //foreach (var i in delist)
  667. //{
  668. // dearrayList.Add(i);
  669. //}
  670. //dechucklist = (string[])dearrayList.ToArray(typeof(string));
  671. //StringBuilder destringBuilder = new StringBuilder();
  672. //for (int i = 0; i < dechucklist.Length; i++)
  673. //{
  674. // destringBuilder.Append(dechucklist[i] + "\t");
  675. //}
  676. control = new ComboBox()
  677. {
  678. ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck"))
  679. };
  680. control.Height = 23;
  681. control.MinWidth = 100;
  682. control.MaxWidth = 300;
  683. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  684. control.PreviewMouseLeftButtonDown += DechuckControl_PreviewMouseLeftButtonDown;
  685. break;
  686. case "IsShowTolerance":
  687. control = new CheckBox();
  688. control.SetBinding(CheckBox.IsCheckedProperty, binding);
  689. control.Style = null;
  690. control.VerticalAlignment = VerticalAlignment.Center;
  691. (control as CheckBox).Checked += RecipeViewModel_Checked;
  692. (control as CheckBox).Unchecked += RecipeViewModel_Checked;
  693. break;
  694. default:
  695. control = new TextBox();
  696. control.Margin = new Thickness(1, 0, 0, 0);
  697. control.BorderThickness = new Thickness(0, 0, 0, 1);
  698. control.BorderBrush = Brushes.White;
  699. control.FontSize = 15;
  700. control.Foreground = Brushes.Green;
  701. control.Background = Brushes.Transparent;
  702. control.VerticalAlignment = VerticalAlignment.Center;
  703. control.MinWidth = 15;
  704. control.SetBinding(TextBox.TextProperty, binding);
  705. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  706. if (objAttrs.Length > 0)
  707. {
  708. (control as TextBox).IsReadOnly = true;
  709. }
  710. break;
  711. }
  712. //switch (propertyTypeName)
  713. //{
  714. // case "Int32":
  715. // case "String":
  716. // control = new TextBox();
  717. // control.Margin = new Thickness(1, 0, 0, 0);
  718. // control.BorderThickness = new Thickness(0, 0, 0, 1);
  719. // //control.BorderBrush = Brushes.Black;
  720. // control.FontSize = 15;
  721. // control.Foreground = Brushes.Green;
  722. // control.Background = Brushes.Transparent;
  723. // control.VerticalAlignment = VerticalAlignment.Center;
  724. // control.MinWidth = 15;
  725. // control.SetBinding(TextBox.TextProperty, binding);
  726. // object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  727. // if (objAttrs.Length > 0)
  728. // {
  729. // (control as TextBox).IsReadOnly = true;
  730. // }
  731. // break;
  732. // case "Boolean":
  733. // control = new CheckBox();
  734. // control.SetBinding(CheckBox.IsCheckedProperty, binding);
  735. // break;
  736. // default:
  737. // control = new ComboBox();
  738. // control.Height = 23;
  739. // control.SetBinding(ComboBox.SelectedItemProperty, binding);
  740. // ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  741. // break;
  742. //}
  743. control.Margin = new Thickness(20, 3, 0, 7);
  744. control.Width = 250;
  745. HeadWrapPanel.Children.Add(control);
  746. }
  747. }
  748. private void RecipeViewModel_Checked(object sender, RoutedEventArgs e)
  749. {
  750. bool? isTolerance = (sender as CheckBox).IsChecked;
  751. LoadRecipe(CurrentRecipe);
  752. }
  753. private void Control_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  754. {
  755. }
  756. private void ChuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  757. {
  758. var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck")).ToList();
  759. items.Add("");
  760. (sender as ComboBox).ItemsSource = items;
  761. }
  762. private void DechuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  763. {
  764. var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck")).ToList();
  765. items.Add("");
  766. (sender as ComboBox).ItemsSource = items;
  767. }
  768. private void ChangeUI(object sender, SelectionChangedEventArgs e)
  769. {
  770. var t = sender as ComboBox;
  771. if (t.SelectedValue.ToString() != "Process")
  772. {
  773. headWrapPanel.Children[8].Visibility = Visibility.Collapsed;
  774. headWrapPanel.Children[9].Visibility = Visibility.Collapsed;
  775. headWrapPanel.Children[10].Visibility = Visibility.Collapsed;
  776. headWrapPanel.Children[11].Visibility = Visibility.Collapsed;
  777. }
  778. else
  779. {
  780. headWrapPanel.Children[8].Visibility = Visibility.Visible;
  781. headWrapPanel.Children[9].Visibility = Visibility.Visible;
  782. headWrapPanel.Children[10].Visibility = Visibility.Visible;
  783. headWrapPanel.Children[11].Visibility = Visibility.Visible;
  784. }
  785. }
  786. private void MenuItemLeftInsert_Click(object sender, RoutedEventArgs e)
  787. {
  788. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  789. int insertIndex = Convert.ToInt32(t.Text);
  790. if (copyIndex == -1)
  791. {
  792. var recipeStep = new RecipeStep();
  793. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  794. CurrentRecipe.Steps.Insert(insertIndex - 1, recipeStep);
  795. }
  796. else
  797. {
  798. var t1 = JsonConvert.SerializeObject(CurrentRecipe);
  799. var recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
  800. CurrentRecipe.Steps.Insert(insertIndex - 1, recipeStep);
  801. }
  802. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  803. {
  804. CurrentRecipe.Steps[i].StepNo = i + 1;
  805. }
  806. LoadRecipe(CurrentRecipe);
  807. }
  808. private void MenuItemRightInsert_Click(object sender, RoutedEventArgs e)
  809. {
  810. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  811. int insertIndex = Convert.ToInt32(t.Text);
  812. if (copyIndex == -1)
  813. {
  814. var recipeStep = new RecipeStep();
  815. recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
  816. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  817. }
  818. else
  819. {
  820. var t1 = JsonConvert.SerializeObject(CurrentRecipe);
  821. var recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
  822. CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
  823. }
  824. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  825. {
  826. CurrentRecipe.Steps[i].StepNo = i + 1;
  827. }
  828. LoadRecipe(CurrentRecipe);
  829. }
  830. private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
  831. {
  832. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  833. int deleteIndex = Convert.ToInt32(t.Text);
  834. //OnDeleteStep(deleteIndex - 1);
  835. CurrentRecipe.Steps.RemoveAt(deleteIndex - 1);
  836. for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
  837. {
  838. CurrentRecipe.Steps[i].StepNo = i + 1;
  839. }
  840. LoadRecipe(CurrentRecipe);
  841. }
  842. private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
  843. {
  844. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  845. copyIndex = Convert.ToInt32(t.Text);
  846. }
  847. #endregion
  848. #region 私有方法
  849. private void RecipeStepToGridColumn(RecipeStep recipeStep, Grid grid, int index, bool isInsert)
  850. {
  851. int location = 1;
  852. if (isInsert == true)
  853. {
  854. location -= 1;
  855. }
  856. Type recipeType = recipeStep.GetType();
  857. int cycleCount = 1;
  858. if (index == 0)
  859. {
  860. cycleCount = 2;
  861. }
  862. for (int j = 0; j < cycleCount; j++)
  863. {
  864. int i = 0;
  865. ColumnDefinition col1 = new ColumnDefinition();
  866. //col1.MinWidth = 50;
  867. grid.ColumnDefinitions.Insert(index, col1);
  868. //Binding stepcheckbinding = null;
  869. //grid.MinWidth = 200;
  870. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  871. {
  872. string propertyInfoName = propertyInfo.Name;
  873. string propertyTypeName = propertyInfo.PropertyType.Name;
  874. if (propertyInfoName != "LstUnit")
  875. {
  876. if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime" || propertyInfoName == "OverEtchPercent") && isInstalledEPD == false)
  877. {
  878. continue;
  879. }
  880. if (index == 0 && grid.ColumnDefinitions.Count == 1)
  881. {
  882. RowDefinition row1 = new RowDefinition();
  883. grid.RowDefinitions.Add(row1);
  884. }
  885. if (grid.ColumnDefinitions.Count == 1 && j == 0)
  886. {
  887. TextBox textBlock = new TextBox();
  888. textBlock.IsReadOnly = true;
  889. textBlock.Text = propertyInfoName;
  890. grid.Children.Add(textBlock);
  891. textBlock.Background = new SolidColorBrush(Colors.BurlyWood);
  892. Grid.SetRow(textBlock, i);
  893. Grid.SetColumn(textBlock, 0);
  894. }
  895. else
  896. {
  897. Binding binding = new Binding()
  898. {
  899. Source = recipeStep, // 数据源
  900. Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
  901. Mode = BindingMode.TwoWay, // 绑定模式
  902. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  903. };
  904. switch (propertyTypeName)
  905. {
  906. case "Int32":
  907. case "String":
  908. case "Single":
  909. case "Double":
  910. if (propertyInfoName == "EPDConfig")
  911. {
  912. if (currentEPDType == EPDType.Socket)
  913. {
  914. ComboBox EPDcomboBox = new ComboBox();
  915. EPDcomboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  916. EPDcomboBox.Background = new SolidColorBrush(Colors.Black);
  917. EPDcomboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  918. EPDcomboBox.ItemsSource = EPDCfgList;
  919. grid.Children.Add(EPDcomboBox);
  920. Grid.SetRow(EPDcomboBox, i);
  921. Grid.SetColumn(EPDcomboBox, index + location);
  922. //EPDcomboBox.DropDownOpened += EPDcomboBox_DropDownOpened;
  923. }
  924. else if (currentEPDType == EPDType.WCF)
  925. {
  926. Button EPDButton = new Button();
  927. EPDButton.Content = "EndPoint";
  928. EPDButton.Cursor = Cursors.Hand;
  929. EPDButton.Tag = $"{CurrentRecipeName}.{(index + location).ToString()}";
  930. EPDButton.Style = null;
  931. EPDButton.Click += EPDButton_Click;
  932. grid.Children.Add(EPDButton);
  933. Grid.SetRow(EPDButton, i);
  934. Grid.SetColumn(EPDButton, index + location);
  935. }
  936. break;
  937. }
  938. TextBox textBox = new TextBox();
  939. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  940. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  941. textBox.SetBinding(TextBox.TextProperty, binding);
  942. grid.Children.Add(textBox);
  943. Grid.SetRow(textBox, i);
  944. Grid.SetColumn(textBox, index + location);
  945. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  946. if (objAttrs.Length > 0)
  947. {
  948. textBox.IsReadOnly = true;
  949. ContextMenu contextmenu = new ContextMenu();
  950. textBox.ContextMenu = contextmenu;
  951. MenuItem menuItemDelete = new MenuItem();
  952. menuItemDelete.Header = "Delete";
  953. menuItemDelete.Click += MenuItemDelete_Click;
  954. MenuItem menuItemLeftInsert = new MenuItem();
  955. menuItemLeftInsert.Header = "Left Insert";
  956. menuItemLeftInsert.Click += MenuItemLeftInsert_Click;
  957. MenuItem menuItemRightInsert = new MenuItem();
  958. menuItemRightInsert.Header = "Right Insert";
  959. menuItemRightInsert.Click += MenuItemRightInsert_Click;
  960. MenuItem menuItemCopy = new MenuItem();
  961. menuItemCopy.Tag = textBox.Text;
  962. menuItemCopy.Header = "Copy";
  963. menuItemCopy.Click += MenuItemCopy_Click;
  964. contextmenu.Items.Add(menuItemCopy);
  965. contextmenu.Items.Add(menuItemDelete);
  966. contextmenu.Items.Add(menuItemLeftInsert);
  967. contextmenu.Items.Add(menuItemRightInsert);
  968. }
  969. break;
  970. case "Boolean":
  971. CheckBox checkBox = new CheckBox();
  972. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  973. grid.Children.Add(checkBox);
  974. Grid.SetRow(checkBox, i);
  975. Grid.SetColumn(checkBox, index + location);
  976. break;
  977. default:
  978. ComboBox comboBox = new ComboBox();
  979. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  980. //comboBox.BorderThickness = new Thickness(1, 0, 1, 0);
  981. comboBox.Background = new SolidColorBrush(Colors.Black);
  982. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  983. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  984. grid.Children.Add(comboBox);
  985. Grid.SetRow(comboBox, i);
  986. Grid.SetColumn(comboBox, index + location);
  987. break;
  988. }
  989. }
  990. i++;
  991. }
  992. }
  993. int k = 0;
  994. foreach (var x in recipeStep.LstUnit.ToList())
  995. {
  996. Type unitType = x.GetType();
  997. //bool isIgnore = false;
  998. Binding checkbinding = null;
  999. foreach (PropertyInfo propertyInfo in unitType.GetProperties())
  1000. {
  1001. object[] IgnoreAttrs = propertyInfo.GetCustomAttributes(typeof(IsCanConfigIgnore), true);
  1002. bool IsEnableRecipeExtension = Convert.ToBoolean(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.IsEnableRecipeExtension"));
  1003. if (IgnoreAttrs.Length > 0 && IsEnableRecipeExtension == false)
  1004. {
  1005. break;
  1006. }
  1007. object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
  1008. if (toleranceAttrs.Length > 0 && CurrentRecipe.Header.IsShowTolerance==false)
  1009. {
  1010. continue;
  1011. }
  1012. if (index == 0 && grid.ColumnDefinitions.Count == 1)
  1013. {
  1014. RowDefinition row1 = new RowDefinition();
  1015. grid.RowDefinitions.Add(row1);
  1016. }
  1017. if (grid.ColumnDefinitions.Count == 1 && j == 0)
  1018. {
  1019. TextBox textBlock = new TextBox();
  1020. textBlock.IsReadOnly = true;
  1021. switch (propertyInfo.Name)
  1022. {
  1023. case "Gas1":
  1024. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  1025. textBlock.Text = $"{propertyInfo.Name}({data1.DisplayName},{data1.Scale})";
  1026. break;
  1027. case "Gas2":
  1028. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  1029. textBlock.Text = $"{propertyInfo.Name}({data2.DisplayName},{data2.Scale})";
  1030. break;
  1031. case "Gas3":
  1032. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  1033. textBlock.Text = $"{propertyInfo.Name}({data3.DisplayName},{data3.Scale})";
  1034. break;
  1035. case "Gas4":
  1036. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  1037. textBlock.Text = $"{propertyInfo.Name}({data4.DisplayName},{data4.Scale})";
  1038. break;
  1039. case "Gas5":
  1040. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  1041. textBlock.Text = $"{propertyInfo.Name}({data5.DisplayName},{data5.Scale})";
  1042. break;
  1043. case "Gas6":
  1044. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  1045. textBlock.Text = $"{propertyInfo.Name}({data6.DisplayName},{data6.Scale})";
  1046. break;
  1047. case "Gas7":
  1048. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  1049. textBlock.Text = $"{propertyInfo.Name}({data7.DisplayName},{data7.Scale})";
  1050. break;
  1051. case "Gas8":
  1052. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  1053. textBlock.Text = $"{propertyInfo.Name}({data8.DisplayName},{data8.Scale})";
  1054. break;
  1055. case "HeaterPressure":
  1056. textBlock.Text = "Pressure(Pa)";
  1057. break;
  1058. case "HeaterTemp":
  1059. textBlock.Text = "Heater Temp(℃)";
  1060. break;
  1061. case "HeaterRatio":
  1062. textBlock.Text = "Heater Ratio";
  1063. break;
  1064. default:
  1065. textBlock.Text = propertyInfo.Name;
  1066. break;
  1067. }
  1068. textBlock.Background = solidColorBrushes[k % solidColorBrushes.Count];
  1069. grid.Children.Add(textBlock);
  1070. Grid.SetRow(textBlock, i);
  1071. Grid.SetColumn(textBlock, 0);
  1072. }
  1073. else
  1074. {
  1075. Binding binding = new Binding()
  1076. {
  1077. Source = recipeStep.LstUnit[k], // 数据源
  1078. //Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
  1079. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  1080. Mode = BindingMode.TwoWay, // 绑定模式
  1081. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  1082. };
  1083. var item = propertyInfo.PropertyType.Name;
  1084. if (propertyInfo.Name == "UnitName")
  1085. {
  1086. TextBox textBlock1 = new TextBox();
  1087. textBlock1.HorizontalContentAlignment = HorizontalAlignment.Center;
  1088. textBlock1.VerticalContentAlignment = VerticalAlignment.Center;
  1089. textBlock1.Text = propertyInfo.GetValue(x).ToString();
  1090. textBlock1.IsReadOnly = true;
  1091. grid.Children.Add(textBlock1);
  1092. Grid.SetRow(textBlock1, i);
  1093. Grid.SetColumn(textBlock1, index + location);
  1094. }
  1095. else
  1096. {
  1097. switch (item)
  1098. {
  1099. case "Int32":
  1100. case "String":
  1101. case "Single":
  1102. case "Double":
  1103. //if (checkbinding != null)
  1104. //{
  1105. // break;
  1106. //}
  1107. TextBox textBox = new TextBox();
  1108. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  1109. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  1110. if (checkbinding == null)
  1111. {
  1112. textBox.IsEnabled = true;
  1113. }
  1114. else
  1115. {
  1116. textBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  1117. }
  1118. switch (propertyInfo.Name)
  1119. {
  1120. case "Gas1":
  1121. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  1122. TextBoxMaxValue.SetMaxValue(textBox, (int)data1.Scale);
  1123. break;
  1124. case "Gas2":
  1125. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  1126. TextBoxMaxValue.SetMaxValue(textBox, (int)data2.Scale);
  1127. break;
  1128. case "Gas3":
  1129. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  1130. TextBoxMaxValue.SetMaxValue(textBox, (int)data3.Scale);
  1131. break;
  1132. case "Gas4":
  1133. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  1134. TextBoxMaxValue.SetMaxValue(textBox, (int)data4.Scale);
  1135. break;
  1136. case "Gas5":
  1137. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  1138. TextBoxMaxValue.SetMaxValue(textBox, (int)data5.Scale);
  1139. break;
  1140. case "Gas6":
  1141. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  1142. TextBoxMaxValue.SetMaxValue(textBox, (int)data6.Scale);
  1143. break;
  1144. case "Gas7":
  1145. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  1146. TextBoxMaxValue.SetMaxValue(textBox, (int)data7.Scale);
  1147. break;
  1148. case "Gas8":
  1149. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  1150. TextBoxMaxValue.SetMaxValue(textBox, (int)data8.Scale);
  1151. break;
  1152. }
  1153. textBox.SetBinding(TextBox.TextProperty, binding);
  1154. grid.Children.Add(textBox);
  1155. Grid.SetRow(textBox, i);
  1156. Grid.SetColumn(textBox, index + location);
  1157. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  1158. if (objAttrs.Length > 0)
  1159. {
  1160. textBox.IsReadOnly = true;
  1161. }
  1162. break;
  1163. case "Boolean":
  1164. CheckBox checkBox = new CheckBox();
  1165. if (checkbinding == null)
  1166. {
  1167. checkbinding = new Binding
  1168. {
  1169. Source = checkBox, // 数据源
  1170. Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
  1171. Mode = BindingMode.TwoWay, // 绑定模式
  1172. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  1173. };
  1174. }
  1175. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  1176. grid.Children.Add(checkBox);
  1177. Grid.SetRow(checkBox, i);
  1178. Grid.SetColumn(checkBox, index + location);
  1179. break;
  1180. default:
  1181. //if (checkbinding != null)
  1182. //{
  1183. // break;
  1184. //}
  1185. ComboBox comboBox = new ComboBox();
  1186. comboBox.BorderBrush = Brushes.Gray;
  1187. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  1188. //comboBox.BorderThickness =new Thickness(1,0,1,0);
  1189. if (checkbinding == null)
  1190. {
  1191. comboBox.IsEnabled = true;
  1192. }
  1193. else
  1194. {
  1195. comboBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  1196. }
  1197. comboBox.Background = Brushes.White;
  1198. string path = propertyInfo.Name;
  1199. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  1200. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  1201. grid.Children.Add(comboBox);
  1202. Grid.SetRow(comboBox, i);
  1203. Grid.SetColumn(comboBox, index + location);
  1204. break;
  1205. }
  1206. }
  1207. }
  1208. i++;
  1209. }
  1210. k++;
  1211. }
  1212. }
  1213. }
  1214. private void EPDButton_Click(object sender, RoutedEventArgs e)
  1215. {
  1216. Button button = sender as Button;
  1217. string para = button.Tag.ToString();
  1218. int stepno = Convert.ToInt32(para.Split('.')[1]) - 1;
  1219. var endpointconfigitem = new MECF.Framework.Common.CommonData.EndPointConfigItem();
  1220. if (CurrentRecipe.Steps[stepno].EPDConfig != null && CurrentRecipe.Steps[stepno].EPDConfig.Length > 20)
  1221. {
  1222. endpointconfigitem.SetValue(CurrentRecipe.Steps[stepno].EPDConfig);
  1223. }
  1224. (new EndPointDlg(para, endpointconfigitem, CurrentRecipe)).ShowDialog();
  1225. }
  1226. private void UpdateRecipeFileList()
  1227. {
  1228. XmlDocument doc = new XmlDocument();
  1229. doc.LoadXml(GetXmlRecipeList());
  1230. treeViewRcpList.Items.Clear();
  1231. CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
  1232. ExpandAllItems(this.treeViewRcpList);
  1233. }
  1234. private void LoadRecipe(Recipe recipe)
  1235. {
  1236. copyIndex = -1;
  1237. bodyStackPanel.Children.Clear();
  1238. //CurrentRecipe = null;
  1239. GC.Collect(); // This should pick up the control removed at a previous MouseDown
  1240. GC.WaitForPendingFinalizers(); // Doesn't help either
  1241. GC.Collect();
  1242. GC.WaitForPendingFinalizers(); // Doesn't help either
  1243. CurrentRecipe = recipe;
  1244. if (CurrentRecipe.Header.Type == Venus_Core.RecipeType.Process && CurrentRecipe.Header.ChuckRecipe != "" && CurrentRecipe.Header.ChuckRecipe != null)
  1245. {
  1246. Grid chuckGrid = new Grid();
  1247. chuckGrid.IsEnabled = false;
  1248. chuckGrid.Margin = new Thickness(15);
  1249. string chuckRecipeData = m_uiRecipeManager.LoadRecipe(ModuleName, $"Chuck\\{CurrentRecipe.Header.ChuckRecipe}");
  1250. if (chuckRecipeData == "")
  1251. {
  1252. return;
  1253. }
  1254. var chuckRecipe = Recipe.Load(chuckRecipeData);
  1255. for (int i = 0; i < chuckRecipe.Steps.Count; i++)
  1256. {
  1257. RecipeStepToGridColumn(chuckRecipe.Steps[i], chuckGrid, i, false);
  1258. }
  1259. bodyStackPanel.Children.Add(chuckGrid);
  1260. }
  1261. Grid proressGrid = new Grid();
  1262. proressGrid.Margin = new Thickness(15);
  1263. //index = 0;
  1264. for (int i = 0; i < recipe.Steps.Count; i++)
  1265. {
  1266. RecipeStepToGridColumn(recipe.Steps[i], proressGrid, i, false);
  1267. }
  1268. bodyStackPanel.Children.Add(proressGrid);
  1269. currentRecipeGrid = proressGrid;
  1270. if (CurrentRecipe.Header.Type == Venus_Core.RecipeType.Process && CurrentRecipe.Header.DechuckRecipe != "" && CurrentRecipe.Header.DechuckRecipe != null)
  1271. {
  1272. Grid deChuckGrid = new Grid();
  1273. deChuckGrid.IsEnabled = false;
  1274. deChuckGrid.Margin = new Thickness(15);
  1275. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, "DeChuck", $"{CurrentRecipe.Header.DechuckRecipe}.rcp");
  1276. string DechuckRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  1277. //index = 0;
  1278. var dechuckRecipe = Recipe.Load(DechuckRecipeData);
  1279. for (int i = 0; i < dechuckRecipe.Steps.Count; i++)
  1280. {
  1281. RecipeStepToGridColumn(dechuckRecipe.Steps[i], deChuckGrid, i, false);
  1282. }
  1283. bodyStackPanel.Children.Add(deChuckGrid);
  1284. }
  1285. }
  1286. private void OnDeleteStep(int index)
  1287. {
  1288. if (CurrentRecipe != null && CurrentRecipe.Steps.Count > 1)
  1289. {
  1290. currentRecipeGrid.Children.RemoveRange(currentRecipeGrid.RowDefinitions.Count * (index + 1), currentRecipeGrid.RowDefinitions.Count);
  1291. currentRecipeGrid.ColumnDefinitions.RemoveAt(index);
  1292. for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
  1293. {
  1294. CurrentRecipe.Steps[i - 1].StepNo = i;
  1295. }
  1296. CurrentRecipe.Steps.RemoveAt(index);
  1297. }
  1298. }
  1299. private void OnRefresh()
  1300. {
  1301. if (CurrentRecipeName != "")
  1302. {
  1303. string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, $"{CurrentRecipeName}.rcp");
  1304. string xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
  1305. CurrentRecipe = Recipe.Load(xmlRecipeData);
  1306. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  1307. LoadRecipe(CurrentRecipe);
  1308. }
  1309. }
  1310. private void OnTolerance()
  1311. {
  1312. }
  1313. private void OnExpand()
  1314. {
  1315. HeadExpand = !HeadExpand;
  1316. if (HeadExpand)
  1317. {
  1318. recipeView.expandGrid.Width = 300;
  1319. }
  1320. else
  1321. {
  1322. recipeView.expandGrid.Width = 30;
  1323. }
  1324. }
  1325. private void ExpandAllItems(ItemsControl control)
  1326. {
  1327. if (control == null)
  1328. {
  1329. return;
  1330. }
  1331. foreach (Object item in control.Items)
  1332. {
  1333. System.Windows.Controls.TreeViewItem treeItem = control.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
  1334. if (treeItem == null || !treeItem.HasItems)
  1335. {
  1336. continue;
  1337. }
  1338. treeItem.IsExpanded = true;
  1339. ExpandAllItems(treeItem as ItemsControl);
  1340. }
  1341. }
  1342. #endregion
  1343. }
  1344. }