RecipeViewModel.cs 73 KB

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