RecipeViewModel.cs 45 KB

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