RecipeViewModel.cs 74 KB

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