NewRecipeViewModel.cs 70 KB

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