RecipeViewModel.cs 45 KB

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