RecipeViewModel.cs 82 KB

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