RecipeViewModel.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.UI.View.Common;
  4. //using MECF.Framework.Common.CommonData;
  5. using MECF.Framework.Common.DataCenter;
  6. using MECF.Framework.Common.OperationCenter;
  7. using Microsoft.VisualBasic;
  8. using Newtonsoft.Json;
  9. using Prism.Commands;
  10. using Prism.Mvvm;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Threading;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Input;
  21. using System.Windows.Media;
  22. using System.Windows.Threading;
  23. using System.Xml;
  24. using Venus_Core;
  25. using Venus_Core.Attributes;
  26. using Venus_MainPages.PMs;
  27. using Venus_MainPages.Unity;
  28. using Venus_MainPages.Views;
  29. using Venus_Themes.CustomControls;
  30. using Venus_Themes.UserControls;
  31. using WPF.Themes.UserControls;
  32. namespace Venus_MainPages.ViewModels
  33. {
  34. public enum EPDType
  35. {
  36. Socket,
  37. WCF,
  38. None
  39. }
  40. internal class RecipeViewModel : BindableBase
  41. {
  42. #region 私有字段
  43. public string ModuleName = "PMA";
  44. private string m_CurrentRecipeName;
  45. private UiRecipeManager m_uiRecipeManager = new UiRecipeManager();
  46. private RecipeView recipeView;
  47. private TreeView treeViewRcpList;
  48. private Recipe m_currentRecipe;
  49. private string m_recipeType;
  50. private bool firstLoad=true;
  51. private WrapPanel headWrapPanel;
  52. private StackPanel bodyStackPanel;
  53. private List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>()
  54. {
  55. new SolidColorBrush(Colors.Coral),
  56. new SolidColorBrush(Colors.Cyan),
  57. new SolidColorBrush(Colors.Honeydew)
  58. };
  59. private Grid currentRecipeGrid;
  60. private int copyIndex = -1;
  61. private List<string> EPDCfgList=new List<string> ();
  62. private EPDType currentEPDType=EPDType.None;
  63. private JetChamber currentChamber;
  64. private bool isInstalledEPD;
  65. #endregion
  66. #region 属性
  67. public string CurrentRecipeName
  68. {
  69. get { return m_CurrentRecipeName; }
  70. set { SetProperty(ref m_CurrentRecipeName, value); }
  71. }
  72. public Recipe CurrentRecipe
  73. {
  74. get { return m_currentRecipe; }
  75. set
  76. {
  77. m_currentRecipe = value;
  78. RecipeType = m_currentRecipe.Header.Type.ToString();
  79. }
  80. }
  81. public string RecipeType
  82. {
  83. get { return m_recipeType; }
  84. set { SetProperty(ref m_recipeType, value); }
  85. }
  86. #endregion
  87. #region 命令
  88. private DelegateCommand<Object> _MouseRightButtonDownCommand;
  89. public DelegateCommand<Object> MouseRightButtonDownCommand =>
  90. _MouseRightButtonDownCommand ?? (_MouseRightButtonDownCommand = new DelegateCommand<Object>(OnMouseRightButtonDown));
  91. private DelegateCommand<Object> _LoadedCommand;
  92. public DelegateCommand<Object> LoadedCommand =>
  93. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand<Object>(OnLoaded));
  94. private DelegateCommand _SaveRecipeCommand;
  95. public DelegateCommand SaveRecipeCommand =>
  96. _SaveRecipeCommand ?? (_SaveRecipeCommand = new DelegateCommand(OnSaveRecipe));
  97. private DelegateCommand _AddStepCommand;
  98. public DelegateCommand AddStepCommand =>
  99. _AddStepCommand ?? (_AddStepCommand = new DelegateCommand(OnAddStep));
  100. private DelegateCommand _DeleteStepCommand;
  101. public DelegateCommand DeleteStepCommand =>
  102. _DeleteStepCommand ?? (_DeleteStepCommand = new DelegateCommand(OnDeleteStep));
  103. #endregion
  104. #region 构造函数
  105. public RecipeViewModel()
  106. {
  107. }
  108. #endregion
  109. #region 命令方法
  110. private void OnAddStep()
  111. {
  112. if (CurrentRecipe != null)
  113. {
  114. var index = currentRecipeGrid.ColumnDefinitions.Count;
  115. RecipeStep recipeStep;
  116. if (copyIndex == -1)
  117. {
  118. recipeStep = new RecipeStep();
  119. switch (currentChamber)
  120. {
  121. case JetChamber.Venus:
  122. case JetChamber.Kepler2300:
  123. recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
  124. recipeStep.LstUnit.Add(new TCPUnit());
  125. recipeStep.LstUnit.Add(new BiasUnit());
  126. recipeStep.LstUnit.Add(new GasControlUnit());
  127. recipeStep.LstUnit.Add(new ESCHVUnit());
  128. recipeStep.LstUnit.Add(new ProcessKitUnit());
  129. break;
  130. case JetChamber.Kepler2200A:
  131. recipeStep.LstUnit.Add(new Kepler2200GasControlUnit());
  132. recipeStep.LstUnit.Add(new HeaterUnit());
  133. recipeStep.LstUnit.Add(new Kepler2200RFUnit());
  134. break;
  135. }
  136. CurrentRecipe.Steps.Insert(index - 1, recipeStep);
  137. }
  138. else
  139. {
  140. var t = JsonConvert.SerializeObject(CurrentRecipe);
  141. recipeStep = Recipe.Load(t).Steps[copyIndex - 1];
  142. CurrentRecipe.Steps.Insert(index - 1, recipeStep);
  143. }
  144. RecipeStepToGridColumn(recipeStep, currentRecipeGrid, index, true);
  145. for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
  146. {
  147. CurrentRecipe.Steps[i - 1].StepNo = i;
  148. }
  149. }
  150. }
  151. private void OnDeleteStep()
  152. {
  153. if (CurrentRecipe != null)
  154. {
  155. OnDeleteStep(CurrentRecipe.Steps.Count - 1);
  156. }
  157. }
  158. private void OnSaveRecipe()
  159. {
  160. SaveRecipe(CurrentRecipeName, RecipeUnity.RecipeToString(CurrentRecipe));
  161. }
  162. private void OnLoaded(Object myrecipeView)
  163. {
  164. if (firstLoad == true)
  165. {
  166. currentChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.ChamberType").ToString());
  167. isInstalledEPD = bool.Parse(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.IsEnabled").ToString()) ;
  168. firstLoad = false;
  169. recipeView = myrecipeView as RecipeView;
  170. treeViewRcpList = recipeView.treeViewRcpList;
  171. headWrapPanel = recipeView.headWrapPanel;
  172. bodyStackPanel = recipeView.bodyStackPanel;
  173. UpdateRecipeFileList();
  174. treeViewRcpList.SelectedItemChanged += TreeViewRcpList_SelectedItemChanged;
  175. DispatcherTimer timer = new DispatcherTimer();
  176. timer.Interval = TimeSpan.FromSeconds(1);
  177. timer.Tick += Timer_Tick; ;
  178. timer.Start();
  179. for (int i = 0; i < 5; i++)
  180. {
  181. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.EndPoint.SearchCfg");
  182. Thread.Sleep(200);
  183. currentEPDType = (EPDType)System.Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.EPDType"));
  184. if (currentEPDType == EPDType.Socket)
  185. {
  186. EPDCfgList = (List<string>)QueryDataClient.Instance.Service.GetData($"{ModuleName}.EPDCfgList");
  187. }
  188. if (EPDCfgList != null)
  189. {
  190. break;
  191. }
  192. }
  193. }
  194. }
  195. private void Timer_Tick(object sender, EventArgs e)
  196. {
  197. }
  198. TreeViewFileItem selectedItem;
  199. private void TreeViewRcpList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  200. {
  201. selectedItem = e.NewValue as TreeViewFileItem;
  202. if (selectedItem == null)
  203. return;
  204. try
  205. {
  206. CurrentRecipeName = selectedItem.FileName;
  207. string xmlRecipeData = m_uiRecipeManager.LoadRecipe(ModuleName, selectedItem.FileName);
  208. if (xmlRecipeData == "")
  209. {
  210. treeViewRcpList.Items.Remove(selectedItem);
  211. return;
  212. }
  213. CurrentRecipe = Recipe.Load(xmlRecipeData);
  214. LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
  215. LoadRecipe(CurrentRecipe);
  216. }
  217. catch (Exception ex)
  218. {
  219. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  220. }
  221. e.Handled = true;
  222. }
  223. public bool SaveRecipe(string recipeName, string recipeContent)
  224. {
  225. return m_uiRecipeManager.SaveRecipe(ModuleName, recipeName, recipeContent);
  226. }
  227. private void OnMouseRightButtonDown(Object treeView)
  228. {
  229. //treeViewRcpList = treeView as TreeView;
  230. treeViewRcpList.ContextMenu = new ContextMenu() { Background = new SolidColorBrush(Colors.AliceBlue)};
  231. MenuItem menuItem = new MenuItem();
  232. menuItem = new MenuItem();
  233. menuItem.Tag = "\\";
  234. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateRecipe);
  235. menuItem.Header = "New Recipe";
  236. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  237. menuItem = new MenuItem();
  238. menuItem.Tag = "\\";
  239. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_DeleteRecipe);
  240. menuItem.Header = "Delete Recipe";
  241. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  242. menuItem = new MenuItem();
  243. menuItem.Tag = "\\";
  244. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_SaveAsRecipe);
  245. menuItem.Header = "Save As Recipe";
  246. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  247. menuItem = new MenuItem();
  248. menuItem.Tag = "\\";
  249. menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_RenameRecipe);
  250. menuItem.Header = "Rename";
  251. treeViewRcpList.ContextMenu.Items.Add(menuItem);
  252. treeViewRcpList.ContextMenu.Visibility = Visibility.Visible;
  253. }
  254. private void menuItem_MouseClick_CreateRecipe(object sender, RoutedEventArgs e)
  255. {
  256. MenuItem mit = sender as MenuItem;
  257. string folderName = mit.Tag as string;
  258. PerformCreateRecipe(folderName);
  259. }
  260. private void PerformCreateRecipe(string folderName)
  261. {
  262. try
  263. {
  264. RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
  265. {
  266. Owner = Application.Current.MainWindow
  267. };
  268. if (dlg.ShowDialog() == true)
  269. {
  270. var recipeName = folderName + "\\" + dlg.InputText;
  271. RecipeType type = (RecipeType)Enum.Parse(typeof(RecipeType), dlg.SelectedType);
  272. string newRecipe =RecipeUnity.CreateRecipe(currentChamber,type, dlg.InputText);
  273. //string recipeContent = m_uiRecipeManager.GetRecipeTemplate(ModuleName);
  274. //m_uiRecipeManager.SaveAsRecipe(ModuleName, recipeName, m_uiRecipeManager.LoadRecipe("system",folderName));
  275. if (SaveAsRecipe(recipeName, newRecipe))
  276. {
  277. //UpdateRecipeFileList();
  278. //SelectRecipe(recipeName);
  279. treeViewRcpList.Items.Add(new TreeViewFileItem(dlg.InputText));
  280. }
  281. else
  282. {
  283. WPFMessageBox.ShowError("Error");
  284. }
  285. }
  286. }
  287. catch (Exception ex)
  288. {
  289. LOG.WriteExeption(ex);
  290. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
  291. }
  292. }
  293. private void menuItem_MouseClick_DeleteRecipe(object sender, RoutedEventArgs e)
  294. {
  295. if (CurrentRecipe == null)
  296. {
  297. return;
  298. }
  299. if (WPFMessageBox.ShowQuestion($"Delete {CurrentRecipeName}?","删除后无法恢复!!!") == MessageBoxResult.Yes)
  300. {
  301. MenuItem mit = sender as MenuItem;
  302. //string recipename = mit.Header.ToString();
  303. m_uiRecipeManager.DeleteRecipe(ModuleName, CurrentRecipeName);
  304. //PerformCreateRecipe(folderName);
  305. treeViewRcpList.Items.Remove(selectedItem);
  306. }
  307. }
  308. private void menuItem_MouseClick_SaveAsRecipe(object sender, RoutedEventArgs e)
  309. {
  310. if (CurrentRecipe == null)
  311. {
  312. return;
  313. }
  314. var newName = Interaction.InputBox(" ", "Save As Recipe", CurrentRecipeName, -1, -1);
  315. if (newName != CurrentRecipeName && newName != "")
  316. {
  317. var newRecipe = CurrentRecipe;
  318. newRecipe.Header.Name = newName;
  319. newRecipe.Header.CreateTime = DateTime.Now.ToString();
  320. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, newName + ".rcp");
  321. File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
  322. UpdateRecipeFileList();
  323. }
  324. }
  325. private void menuItem_MouseClick_RenameRecipe(object sender, RoutedEventArgs e)
  326. {
  327. if (CurrentRecipe == null)
  328. {
  329. return;
  330. }
  331. var newName= Interaction.InputBox(" ", "Rename Recipe", CurrentRecipeName, -1, -1);
  332. if (newName != CurrentRecipeName && newName!="")
  333. {
  334. var oldrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, CurrentRecipeName + ".rcp");
  335. var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, newName + ".rcp");
  336. CurrentRecipe.Header.Name = newName;
  337. SaveRecipe(CurrentRecipeName, RecipeUnity.RecipeToString(CurrentRecipe));
  338. File.Move(oldrecipePath, newrecipePath);
  339. UpdateRecipeFileList();
  340. }
  341. }
  342. public bool SaveAsRecipe(string recipeName, string recipeContent)
  343. {
  344. return m_uiRecipeManager.SaveAsRecipe(ModuleName, recipeName, recipeContent);
  345. }
  346. public string GetXmlRecipeList()
  347. {
  348. return m_uiRecipeManager.GetXmlRecipeList(ModuleName, true) ?? "";
  349. }
  350. void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
  351. {
  352. foreach (XmlElement ele in curElementNode.ChildNodes)
  353. {
  354. if (ele.Name == "File")
  355. {
  356. string fileName = ele.Attributes["Name"].Value;
  357. fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
  358. TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
  359. item.Tag = ele.Attributes["Name"].Value;
  360. //item.ToolTip = fileName;
  361. itemsControl.Items.Add(item);
  362. }
  363. else if (ele.Name == "Folder")
  364. {
  365. string folderName = ele.Attributes["Name"].Value;
  366. folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
  367. TreeViewFolderItem item = new TreeViewFolderItem(folderName);
  368. item.Tag = ele.Attributes["Name"].Value;
  369. CreateTreeViewItems(ele, item);
  370. item.IsExpanded = false;
  371. itemsControl.Items.Add(item);
  372. }
  373. }
  374. }
  375. private void LoadHeadWrapPanel(WrapPanel HeadWrapPanel, Recipe recipe)
  376. {
  377. HeadWrapPanel.Children.Clear();
  378. Type type = recipe.Header.GetType();
  379. foreach (var propertyInfo in type.GetProperties())
  380. {
  381. TextBlock textBlock = new TextBlock();
  382. textBlock.FontSize = 15;
  383. //textBlock.Width = 100;
  384. textBlock.Text = propertyInfo.Name + ":";
  385. textBlock.Margin = new Thickness(15, 0, 0, 0);
  386. textBlock.VerticalAlignment = VerticalAlignment.Center;
  387. HeadWrapPanel.Children.Add(textBlock);
  388. Binding binding = new Binding()
  389. {
  390. Source = recipe.Header, // 数据源
  391. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  392. Mode = BindingMode.TwoWay, // 绑定模式
  393. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  394. };
  395. var propertyTypeName = propertyInfo.PropertyType.Name;
  396. var propertyInfoName = propertyInfo.Name;
  397. Control control = new Control();
  398. switch (propertyTypeName)
  399. {
  400. case "Int32":
  401. case "String":
  402. control = new TextBox();
  403. control.Margin = new Thickness(1, 0, 0, 0);
  404. control.BorderThickness = new Thickness(0, 0, 0, 1);
  405. //control.BorderBrush = Brushes.Black;
  406. control.FontSize = 15;
  407. control.Foreground = Brushes.Green;
  408. control.Background = Brushes.Transparent;
  409. control.VerticalAlignment = VerticalAlignment.Center;
  410. control.MinWidth = 15;
  411. control.SetBinding(TextBox.TextProperty, binding);
  412. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  413. if (objAttrs.Length > 0)
  414. {
  415. (control as TextBox).IsReadOnly = true;
  416. }
  417. break;
  418. case "Boolean":
  419. control = new CheckBox();
  420. control.SetBinding(CheckBox.IsCheckedProperty, binding);
  421. break;
  422. default:
  423. control = new ComboBox();
  424. control.Height = 23;
  425. control.SetBinding(ComboBox.SelectedItemProperty, binding);
  426. ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
  427. break;
  428. }
  429. HeadWrapPanel.Children.Add(control);
  430. }
  431. }
  432. private void MenuItemLeftInsert_Click(object sender, RoutedEventArgs e)
  433. {
  434. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  435. int insertIndex = Convert.ToInt32(t.Text);
  436. OnAddStep(insertIndex);
  437. }
  438. private void MenuItemRightInsert_Click(object sender, RoutedEventArgs e)
  439. {
  440. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  441. int insertIndex = Convert.ToInt32(t.Text);
  442. OnAddStep(insertIndex + 1);
  443. }
  444. private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
  445. {
  446. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  447. int deleteIndex = Convert.ToInt32(t.Text);
  448. OnDeleteStep(deleteIndex - 1);
  449. }
  450. private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
  451. {
  452. var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
  453. copyIndex = Convert.ToInt32(t.Text);
  454. }
  455. #endregion
  456. #region 私有方法
  457. private void RecipeStepToGridColumn(RecipeStep recipeStep, Grid grid, int index, bool isInsert)
  458. {
  459. int location = 1;
  460. if (isInsert == true)
  461. {
  462. location -= 1;
  463. }
  464. Type recipeType = recipeStep.GetType();
  465. int cycleCount = 1;
  466. if (index == 0)
  467. {
  468. cycleCount = 2;
  469. }
  470. for (int j = 0; j < cycleCount; j++)
  471. {
  472. int i = 0;
  473. ColumnDefinition col1 = new ColumnDefinition();
  474. //col1.MinWidth = 50;
  475. grid.ColumnDefinitions.Insert(index, col1);
  476. Binding stepcheckbinding = null;
  477. //grid.MinWidth = 200;
  478. foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
  479. {
  480. string propertyInfoName = propertyInfo.Name;
  481. string propertyTypeName = propertyInfo.PropertyType.Name;
  482. if (propertyInfoName != "LstUnit")
  483. {
  484. if (index == 0 && grid.ColumnDefinitions.Count == 1)
  485. {
  486. RowDefinition row1 = new RowDefinition();
  487. grid.RowDefinitions.Add(row1);
  488. if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime") && isInstalledEPD == false)
  489. {
  490. row1.Height = new GridLength(0);
  491. }
  492. }
  493. if (grid.ColumnDefinitions.Count == 1 && j == 0)
  494. {
  495. TextBox textBlock = new TextBox();
  496. textBlock.IsReadOnly = true;
  497. textBlock.Text = propertyInfoName;
  498. grid.Children.Add(textBlock);
  499. textBlock.Background = new SolidColorBrush(Colors.BurlyWood);
  500. Grid.SetRow(textBlock, i);
  501. Grid.SetColumn(textBlock, 0);
  502. }
  503. else
  504. {
  505. Binding binding = new Binding()
  506. {
  507. Source = recipeStep, // 数据源
  508. Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
  509. Mode = BindingMode.TwoWay, // 绑定模式
  510. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  511. };
  512. switch (propertyTypeName)
  513. {
  514. case "Int32":
  515. case "String":
  516. if (propertyInfoName == "EPDConfig")
  517. {
  518. if (currentEPDType == EPDType.Socket)
  519. {
  520. ComboBox EPDcomboBox = new ComboBox();
  521. EPDcomboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  522. EPDcomboBox.Background = new SolidColorBrush(Colors.Black);
  523. EPDcomboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  524. EPDcomboBox.ItemsSource = EPDCfgList;
  525. grid.Children.Add(EPDcomboBox);
  526. Grid.SetRow(EPDcomboBox, i);
  527. Grid.SetColumn(EPDcomboBox, index + location);
  528. EPDcomboBox.DropDownOpened += EPDcomboBox_DropDownOpened;
  529. }
  530. else if (currentEPDType == EPDType.WCF)
  531. {
  532. Button EPDButton = new Button();
  533. EPDButton.Content = "EndPoint";
  534. EPDButton.Cursor = Cursors.Hand;
  535. EPDButton.Tag = $"{CurrentRecipeName}.{(index + location).ToString()}";
  536. EPDButton.Style = null;
  537. EPDButton.Click += EPDButton_Click;
  538. grid.Children.Add(EPDButton);
  539. Grid.SetRow(EPDButton, i);
  540. Grid.SetColumn(EPDButton, index + location);
  541. }
  542. break;
  543. }
  544. TextBox textBox = new TextBox();
  545. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  546. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  547. if (stepcheckbinding == null)
  548. {
  549. textBox.IsEnabled = true;
  550. }
  551. else
  552. {
  553. textBox.SetBinding(TextBox.IsEnabledProperty, stepcheckbinding);
  554. }
  555. textBox.SetBinding(TextBox.TextProperty, binding);
  556. grid.Children.Add(textBox);
  557. Grid.SetRow(textBox, i);
  558. Grid.SetColumn(textBox, index + location);
  559. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  560. if (objAttrs.Length > 0)
  561. {
  562. textBox.IsReadOnly = true;
  563. ContextMenu contextmenu = new ContextMenu();
  564. textBox.ContextMenu = contextmenu;
  565. MenuItem menuItemDelete = new MenuItem();
  566. menuItemDelete.Header = "删除";
  567. menuItemDelete.Click += MenuItemDelete_Click;
  568. MenuItem menuItemLeftInsert = new MenuItem();
  569. menuItemLeftInsert.Header = "左插入";
  570. menuItemLeftInsert.Click += MenuItemLeftInsert_Click;
  571. MenuItem menuItemRightInsert = new MenuItem();
  572. menuItemRightInsert.Header = "右插入";
  573. menuItemRightInsert.Click += MenuItemRightInsert_Click;
  574. MenuItem menuItemCopy = new MenuItem();
  575. menuItemCopy.Tag = textBox.Text;
  576. menuItemCopy.Header = "复制";
  577. menuItemCopy.Click += MenuItemCopy_Click;
  578. contextmenu.Items.Add(menuItemCopy);
  579. contextmenu.Items.Add(menuItemDelete);
  580. contextmenu.Items.Add(menuItemLeftInsert);
  581. contextmenu.Items.Add(menuItemRightInsert);
  582. }
  583. break;
  584. case "Boolean":
  585. CheckBox checkBox = new CheckBox();
  586. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  587. grid.Children.Add(checkBox);
  588. Grid.SetRow(checkBox, i);
  589. Grid.SetColumn(checkBox, index + location);
  590. //if (stepcheckbinding == null)
  591. //{
  592. // stepcheckbinding = new Binding
  593. // {
  594. // Source = checkBox, // 数据源
  595. // Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
  596. // Mode = BindingMode.TwoWay, // 绑定模式
  597. // UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  598. // };
  599. //}
  600. //else
  601. //{
  602. //}
  603. if (stepcheckbinding == null)
  604. {
  605. checkBox.IsEnabled = true;
  606. }
  607. else
  608. {
  609. checkBox.SetBinding(TextBox.IsEnabledProperty, stepcheckbinding);
  610. }
  611. break;
  612. default:
  613. ComboBox comboBox = new ComboBox();
  614. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  615. comboBox.Background = new SolidColorBrush(Colors.Black);
  616. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  617. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  618. grid.Children.Add(comboBox);
  619. Grid.SetRow(comboBox, i);
  620. Grid.SetColumn(comboBox, index + location);
  621. if (stepcheckbinding == null)
  622. {
  623. comboBox.IsEnabled = true;
  624. }
  625. else
  626. {
  627. comboBox.SetBinding(TextBox.IsEnabledProperty, stepcheckbinding);
  628. }
  629. break;
  630. }
  631. }
  632. i++;
  633. }
  634. }
  635. int k = 0;
  636. recipeStep.LstUnit.ToList().ForEach(x =>
  637. {
  638. Type unitType = x.GetType();
  639. Binding checkbinding = null;
  640. foreach (PropertyInfo propertyInfo in unitType.GetProperties())
  641. {
  642. if (index == 0 && grid.ColumnDefinitions.Count == 1)
  643. {
  644. RowDefinition row1 = new RowDefinition();
  645. grid.RowDefinitions.Add(row1);
  646. }
  647. if (grid.ColumnDefinitions.Count == 1 && j == 0)
  648. {
  649. TextBox textBlock = new TextBox();
  650. textBlock.IsReadOnly = true;
  651. switch (propertyInfo.Name)
  652. {
  653. case "Gas1":
  654. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  655. textBlock.Text = $"{propertyInfo.Name}({data1.DisplayName},{data1.Scale})";
  656. break;
  657. case "Gas2":
  658. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  659. textBlock.Text = $"{propertyInfo.Name}({data2.DisplayName},{data2.Scale})";
  660. break;
  661. case "Gas3":
  662. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  663. textBlock.Text = $"{propertyInfo.Name}({data3.DisplayName},{data3.Scale})";
  664. break;
  665. case "Gas4":
  666. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  667. textBlock.Text = $"{propertyInfo.Name}({data4.DisplayName},{data4.Scale})";
  668. break;
  669. case "Gas5":
  670. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  671. textBlock.Text = $"{propertyInfo.Name}({data5.DisplayName},{data5.Scale})";
  672. break;
  673. case "Gas6":
  674. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  675. textBlock.Text = $"{propertyInfo.Name}({data6.DisplayName},{data6.Scale})";
  676. break;
  677. case "Gas7":
  678. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  679. textBlock.Text = $"{propertyInfo.Name}({data7.DisplayName},{data7.Scale})";
  680. break;
  681. case "Gas8":
  682. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  683. textBlock.Text = $"{propertyInfo.Name}({data8.DisplayName},{data8.Scale})";
  684. break;
  685. case "HeaterPressure":
  686. textBlock.Text = "Pressure(Pa)";
  687. break;
  688. case "HeaterTemp":
  689. textBlock.Text = "Heater Temp(℃)";
  690. break;
  691. case "HeaterRatio":
  692. textBlock.Text = "Heater Ratio";
  693. break;
  694. default:
  695. textBlock.Text = propertyInfo.Name;
  696. break;
  697. }
  698. textBlock.Background = solidColorBrushes[k % 3];
  699. grid.Children.Add(textBlock);
  700. Grid.SetRow(textBlock, i);
  701. Grid.SetColumn(textBlock, 0);
  702. }
  703. else
  704. {
  705. Binding binding = new Binding()
  706. {
  707. Source = recipeStep.LstUnit[k], // 数据源
  708. //Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
  709. Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
  710. Mode = BindingMode.TwoWay, // 绑定模式
  711. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  712. };
  713. var item = propertyInfo.PropertyType.Name;
  714. if (propertyInfo.Name == "UnitName")
  715. {
  716. TextBox textBlock1 = new TextBox();
  717. textBlock1.HorizontalContentAlignment = HorizontalAlignment.Center;
  718. textBlock1.VerticalContentAlignment =VerticalAlignment.Center;
  719. textBlock1.Text = propertyInfo.GetValue(x).ToString();
  720. textBlock1.IsReadOnly = true;
  721. grid.Children.Add(textBlock1);
  722. Grid.SetRow(textBlock1, i);
  723. Grid.SetColumn(textBlock1, index + location);
  724. }
  725. else
  726. {
  727. switch (item)
  728. {
  729. case "Int32":
  730. case "String":
  731. TextBox textBox = new TextBox();
  732. textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
  733. textBox.VerticalContentAlignment = VerticalAlignment.Center;
  734. if (checkbinding == null)
  735. {
  736. textBox.IsEnabled = true;
  737. }
  738. else
  739. {
  740. textBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  741. }
  742. switch (propertyInfo.Name)
  743. {
  744. case "Gas1":
  745. var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
  746. TextBoxMaxValue.SetMaxValue(textBox, (int)data1.Scale);
  747. break;
  748. case "Gas2":
  749. var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
  750. TextBoxMaxValue.SetMaxValue(textBox, (int)data2.Scale);
  751. break;
  752. case "Gas3":
  753. var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
  754. break;
  755. case "Gas4":
  756. var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
  757. break;
  758. case "Gas5":
  759. var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
  760. break;
  761. case "Gas6":
  762. var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
  763. break;
  764. case "Gas7":
  765. var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
  766. break;
  767. case "Gas8":
  768. var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
  769. break;
  770. }
  771. textBox.SetBinding(TextBox.TextProperty, binding);
  772. grid.Children.Add(textBox);
  773. Grid.SetRow(textBox, i);
  774. Grid.SetColumn(textBox, index + location);
  775. object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
  776. if (objAttrs.Length > 0)
  777. {
  778. textBox.IsReadOnly = true;
  779. }
  780. break;
  781. case "Boolean":
  782. CheckBox checkBox = new CheckBox();
  783. if (checkbinding == null)
  784. {
  785. checkbinding = new Binding
  786. {
  787. Source = checkBox, // 数据源
  788. Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
  789. Mode = BindingMode.TwoWay, // 绑定模式
  790. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
  791. };
  792. }
  793. checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
  794. grid.Children.Add(checkBox);
  795. Grid.SetRow(checkBox, i);
  796. Grid.SetColumn(checkBox, index + location);
  797. break;
  798. default:
  799. ComboBox comboBox = new ComboBox();
  800. comboBox.BorderBrush = Brushes.Gray;
  801. comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
  802. if (checkbinding == null)
  803. {
  804. comboBox.IsEnabled = true;
  805. }
  806. else
  807. {
  808. comboBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
  809. }
  810. comboBox.Background = Brushes.White;
  811. string path = propertyInfo.Name;
  812. comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
  813. ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
  814. grid.Children.Add(comboBox);
  815. Grid.SetRow(comboBox, i);
  816. Grid.SetColumn(comboBox, index + location);
  817. break;
  818. }
  819. }
  820. }
  821. i++;
  822. }
  823. k++;
  824. });
  825. //index++;
  826. }
  827. }
  828. private void EPDcomboBox_DropDownOpened(object sender, EventArgs e)
  829. {
  830. }
  831. private void EPDButton_Click(object sender, RoutedEventArgs e)
  832. {
  833. Button button = sender as Button;
  834. string para = button.Tag.ToString();
  835. int stepno = Convert.ToInt32(para.Split('.')[1])-1;
  836. var endpointconfigitem = new MECF.Framework.Common.CommonData.EndPointConfigItem();
  837. if (CurrentRecipe.Steps[stepno].EPDConfig!=null && CurrentRecipe.Steps[stepno].EPDConfig.Length>20)
  838. {
  839. endpointconfigitem.SetValue(CurrentRecipe.Steps[stepno].EPDConfig);
  840. }
  841. (new EndPointDlg(para, endpointconfigitem,CurrentRecipe)).ShowDialog();
  842. }
  843. private void UpdateRecipeFileList()
  844. {
  845. XmlDocument doc = new XmlDocument();
  846. doc.LoadXml(GetXmlRecipeList());
  847. treeViewRcpList.Items.Clear();
  848. CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
  849. }
  850. private void LoadRecipe(Recipe recipe)
  851. {
  852. copyIndex = -1;
  853. bodyStackPanel.Children.Clear();
  854. //CurrentRecipe = null;
  855. GC.Collect(); // This should pick up the control removed at a previous MouseDown
  856. GC.WaitForPendingFinalizers(); // Doesn't help either
  857. GC.Collect();
  858. GC.WaitForPendingFinalizers(); // Doesn't help either
  859. CurrentRecipe = recipe;
  860. Grid grid = new Grid();
  861. grid.Margin = new Thickness(15);
  862. //index = 0;
  863. for (int i = 0; i < recipe.Steps.Count; i++)
  864. {
  865. RecipeStepToGridColumn(recipe.Steps[i], grid, i, false);
  866. }
  867. bodyStackPanel.Children.Add(grid);
  868. currentRecipeGrid = grid;
  869. }
  870. private void OnAddStep(int index)
  871. {
  872. if (CurrentRecipe != null)
  873. {
  874. RecipeStep recipeStep;
  875. if (copyIndex == -1)
  876. {
  877. recipeStep = new RecipeStep();
  878. //recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
  879. //recipeStep.LstUnit.Add(new TCPUnit());
  880. //recipeStep.LstUnit.Add(new BiasUnit());
  881. //recipeStep.LstUnit.Add(new GasControlUnit());
  882. //recipeStep.LstUnit.Add(new ESCHVUnit());
  883. //recipeStep.LstUnit.Add(new ProcessKitUnit());
  884. switch (currentChamber)
  885. {
  886. case JetChamber.Venus:
  887. case JetChamber.Kepler2300:
  888. recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
  889. recipeStep.LstUnit.Add(new TCPUnit());
  890. recipeStep.LstUnit.Add(new BiasUnit());
  891. recipeStep.LstUnit.Add(new GasControlUnit());
  892. recipeStep.LstUnit.Add(new ESCHVUnit());
  893. recipeStep.LstUnit.Add(new ProcessKitUnit());
  894. break;
  895. case JetChamber.Kepler2200A:
  896. recipeStep.LstUnit.Add(new Kepler2200GasControlUnit());
  897. recipeStep.LstUnit.Add(new HeaterUnit());
  898. recipeStep.LstUnit.Add(new Kepler2200RFUnit());
  899. break;
  900. }
  901. CurrentRecipe.Steps.Insert(index - 1, recipeStep);
  902. }
  903. else
  904. {
  905. var t = JsonConvert.SerializeObject(CurrentRecipe);
  906. recipeStep = Recipe.Load(t).Steps[copyIndex - 1];
  907. CurrentRecipe.Steps.Insert(index - 1, recipeStep);
  908. }
  909. RecipeStepToGridColumn(recipeStep, currentRecipeGrid, index, true);
  910. for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
  911. {
  912. CurrentRecipe.Steps[i - 1].StepNo = i;
  913. }
  914. }
  915. }
  916. private void OnDeleteStep(int index)
  917. {
  918. if (CurrentRecipe != null && CurrentRecipe.Steps.Count > 1)
  919. {
  920. CurrentRecipe.Steps.RemoveAt(index);
  921. currentRecipeGrid.Children.RemoveRange(currentRecipeGrid.RowDefinitions.Count * (index + 1), currentRecipeGrid.RowDefinitions.Count);
  922. currentRecipeGrid.ColumnDefinitions.RemoveAt(index);
  923. for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
  924. {
  925. CurrentRecipe.Steps[i - 1].StepNo = i;
  926. }
  927. }
  928. }
  929. #endregion
  930. }
  931. }