RecipeViewModel.cs 74 KB

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