RecipeViewModel.cs 68 KB

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