RecipeViewModel.cs 74 KB

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