123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068 |
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.Log;
- using Aitex.Core.UI.View.Common;
- //using MECF.Framework.Common.CommonData;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using Microsoft.VisualBasic;
- using Newtonsoft.Json;
- using Prism.Commands;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Threading;
- using System.Xml;
- using Venus_Core;
- using Venus_Core.Attributes;
- using Venus_MainPages.PMs;
- using Venus_MainPages.Unity;
- using Venus_MainPages.Views;
- using Venus_Themes.CustomControls;
- using Venus_Themes.UserControls;
- using WPF.Themes.UserControls;
- namespace Venus_MainPages.ViewModels
- {
- public enum EPDType
- {
- Socket,
- WCF,
- None
- }
- internal class RecipeViewModel : BindableBase
- {
- #region 私有字段
- public string ModuleName = "PMA";
- private string m_CurrentRecipeName;
- private UiRecipeManager m_uiRecipeManager = new UiRecipeManager();
- private RecipeView recipeView;
- private TreeView treeViewRcpList;
- private Recipe m_currentRecipe;
- private string m_recipeType;
- private bool firstLoad=true;
- private WrapPanel headWrapPanel;
- private StackPanel bodyStackPanel;
- private List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>()
- {
- new SolidColorBrush(Colors.Coral),
- new SolidColorBrush(Colors.Cyan),
- new SolidColorBrush(Colors.Honeydew)
- };
- private Grid currentRecipeGrid;
- private int copyIndex = -1;
- private List<string> EPDCfgList=new List<string> ();
- private EPDType currentEPDType=EPDType.None;
- private JetChamber currentChamber;
- private bool isInstalledEPD;
- #endregion
- #region 属性
- public string CurrentRecipeName
- {
- get { return m_CurrentRecipeName; }
- set { SetProperty(ref m_CurrentRecipeName, value); }
- }
- public Recipe CurrentRecipe
- {
- get { return m_currentRecipe; }
- set
- {
- m_currentRecipe = value;
- RecipeType = m_currentRecipe.Header.Type.ToString();
- }
- }
- public string RecipeType
- {
- get { return m_recipeType; }
- set { SetProperty(ref m_recipeType, value); }
- }
- #endregion
- #region 命令
-
- private DelegateCommand<Object> _MouseRightButtonDownCommand;
- public DelegateCommand<Object> MouseRightButtonDownCommand =>
- _MouseRightButtonDownCommand ?? (_MouseRightButtonDownCommand = new DelegateCommand<Object>(OnMouseRightButtonDown));
- private DelegateCommand<Object> _LoadedCommand;
- public DelegateCommand<Object> LoadedCommand =>
- _LoadedCommand ?? (_LoadedCommand = new DelegateCommand<Object>(OnLoaded));
- private DelegateCommand _SaveRecipeCommand;
- public DelegateCommand SaveRecipeCommand =>
- _SaveRecipeCommand ?? (_SaveRecipeCommand = new DelegateCommand(OnSaveRecipe));
- private DelegateCommand _AddStepCommand;
- public DelegateCommand AddStepCommand =>
- _AddStepCommand ?? (_AddStepCommand = new DelegateCommand(OnAddStep));
- private DelegateCommand _DeleteStepCommand;
- public DelegateCommand DeleteStepCommand =>
- _DeleteStepCommand ?? (_DeleteStepCommand = new DelegateCommand(OnDeleteStep));
- #endregion
- #region 构造函数
- public RecipeViewModel()
- {
-
- }
- #endregion
- #region 命令方法
-
-
- private void OnAddStep()
- {
- if (CurrentRecipe != null)
- {
- var index = currentRecipeGrid.ColumnDefinitions.Count;
- RecipeStep recipeStep;
- if (copyIndex == -1)
- {
- recipeStep = new RecipeStep();
- switch (currentChamber)
- {
- case JetChamber.Venus:
- case JetChamber.Kepler2300:
- recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
- recipeStep.LstUnit.Add(new TCPUnit());
- recipeStep.LstUnit.Add(new BiasUnit());
- recipeStep.LstUnit.Add(new GasControlUnit());
- recipeStep.LstUnit.Add(new ESCHVUnit());
- recipeStep.LstUnit.Add(new ProcessKitUnit());
- break;
- case JetChamber.Kepler2200A:
- recipeStep.LstUnit.Add(new Kepler2200GasControlUnit());
- recipeStep.LstUnit.Add(new HeaterUnit());
- recipeStep.LstUnit.Add(new Kepler2200RFUnit());
-
- break;
- }
- CurrentRecipe.Steps.Insert(index - 1, recipeStep);
- }
- else
- {
- var t = JsonConvert.SerializeObject(CurrentRecipe);
- recipeStep = Recipe.Load(t).Steps[copyIndex - 1];
- CurrentRecipe.Steps.Insert(index - 1, recipeStep);
- }
- RecipeStepToGridColumn(recipeStep, currentRecipeGrid, index, true);
- for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
- {
- CurrentRecipe.Steps[i - 1].StepNo = i;
- }
- }
- }
- private void OnDeleteStep()
- {
- if (CurrentRecipe != null)
- {
- OnDeleteStep(CurrentRecipe.Steps.Count - 1);
- }
- }
- private void OnSaveRecipe()
- {
- SaveRecipe(CurrentRecipeName, RecipeUnity.RecipeToString(CurrentRecipe));
- }
- private void OnLoaded(Object myrecipeView)
- {
- if (firstLoad == true)
- {
- currentChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.ChamberType").ToString());
- isInstalledEPD = bool.Parse(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.IsEnabled").ToString()) ;
- firstLoad = false;
- recipeView = myrecipeView as RecipeView;
- treeViewRcpList = recipeView.treeViewRcpList;
- headWrapPanel = recipeView.headWrapPanel;
- bodyStackPanel = recipeView.bodyStackPanel;
- UpdateRecipeFileList();
- treeViewRcpList.SelectedItemChanged += TreeViewRcpList_SelectedItemChanged;
- DispatcherTimer timer = new DispatcherTimer();
- timer.Interval = TimeSpan.FromSeconds(1);
- timer.Tick += Timer_Tick; ;
- timer.Start();
- for (int i = 0; i < 5; i++)
- {
- InvokeClient.Instance.Service.DoOperation($"{ModuleName}.EndPoint.SearchCfg");
- Thread.Sleep(200);
- currentEPDType = (EPDType)System.Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.EPDType"));
- if (currentEPDType == EPDType.Socket)
- {
- EPDCfgList = (List<string>)QueryDataClient.Instance.Service.GetData($"{ModuleName}.EPDCfgList");
- }
- if (EPDCfgList != null)
- {
- break;
- }
- }
-
- }
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
-
- }
- TreeViewFileItem selectedItem;
- private void TreeViewRcpList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
- {
- selectedItem = e.NewValue as TreeViewFileItem;
- if (selectedItem == null)
- return;
- try
- {
- CurrentRecipeName = selectedItem.FileName;
- string xmlRecipeData = m_uiRecipeManager.LoadRecipe(ModuleName, selectedItem.FileName);
- if (xmlRecipeData == "")
- {
- treeViewRcpList.Items.Remove(selectedItem);
- return;
- }
- CurrentRecipe = Recipe.Load(xmlRecipeData);
- LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
- LoadRecipe(CurrentRecipe);
- }
- catch (Exception ex)
- {
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- e.Handled = true;
- }
- public bool SaveRecipe(string recipeName, string recipeContent)
- {
- return m_uiRecipeManager.SaveRecipe(ModuleName, recipeName, recipeContent);
- }
- private void OnMouseRightButtonDown(Object treeView)
- {
- //treeViewRcpList = treeView as TreeView;
- treeViewRcpList.ContextMenu = new ContextMenu() { Background = new SolidColorBrush(Colors.AliceBlue)};
- MenuItem menuItem = new MenuItem();
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateRecipe);
- menuItem.Header = "New Recipe";
- treeViewRcpList.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_DeleteRecipe);
- menuItem.Header = "Delete Recipe";
- treeViewRcpList.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_SaveAsRecipe);
- menuItem.Header = "Save As Recipe";
- treeViewRcpList.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_RenameRecipe);
- menuItem.Header = "Rename";
- treeViewRcpList.ContextMenu.Items.Add(menuItem);
- treeViewRcpList.ContextMenu.Visibility = Visibility.Visible;
- }
- private void menuItem_MouseClick_CreateRecipe(object sender, RoutedEventArgs e)
- {
- MenuItem mit = sender as MenuItem;
- string folderName = mit.Tag as string;
- PerformCreateRecipe(folderName);
- }
- private void PerformCreateRecipe(string folderName)
- {
- try
- {
- RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString())
- {
- Owner = Application.Current.MainWindow
- };
- if (dlg.ShowDialog() == true)
- {
- var recipeName = folderName + "\\" + dlg.InputText;
- RecipeType type = (RecipeType)Enum.Parse(typeof(RecipeType), dlg.SelectedType);
- string newRecipe =RecipeUnity.CreateRecipe(currentChamber,type, dlg.InputText);
- //string recipeContent = m_uiRecipeManager.GetRecipeTemplate(ModuleName);
- //m_uiRecipeManager.SaveAsRecipe(ModuleName, recipeName, m_uiRecipeManager.LoadRecipe("system",folderName));
- if (SaveAsRecipe(recipeName, newRecipe))
- {
- //UpdateRecipeFileList();
- //SelectRecipe(recipeName);
- treeViewRcpList.Items.Add(new TreeViewFileItem(dlg.InputText));
- }
- else
- {
- WPFMessageBox.ShowError("Error");
- }
- }
- }
- catch (Exception ex)
- {
- LOG.WriteExeption(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- private void menuItem_MouseClick_DeleteRecipe(object sender, RoutedEventArgs e)
- {
- if (CurrentRecipe == null)
- {
- return;
- }
- if (WPFMessageBox.ShowQuestion($"Delete {CurrentRecipeName}?","删除后无法恢复!!!") == MessageBoxResult.Yes)
- {
- MenuItem mit = sender as MenuItem;
- //string recipename = mit.Header.ToString();
- m_uiRecipeManager.DeleteRecipe(ModuleName, CurrentRecipeName);
- //PerformCreateRecipe(folderName);
- treeViewRcpList.Items.Remove(selectedItem);
- }
-
- }
- private void menuItem_MouseClick_SaveAsRecipe(object sender, RoutedEventArgs e)
- {
- if (CurrentRecipe == null)
- {
- return;
- }
- var newName = Interaction.InputBox(" ", "Save As Recipe", CurrentRecipeName, -1, -1);
- if (newName != CurrentRecipeName && newName != "")
- {
- var newRecipe = CurrentRecipe;
- newRecipe.Header.Name = newName;
- newRecipe.Header.CreateTime = DateTime.Now.ToString();
- var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, newName + ".rcp");
- File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
- UpdateRecipeFileList();
- }
- }
- private void menuItem_MouseClick_RenameRecipe(object sender, RoutedEventArgs e)
- {
- if (CurrentRecipe == null)
- {
- return;
- }
- var newName= Interaction.InputBox(" ", "Rename Recipe", CurrentRecipeName, -1, -1);
- if (newName != CurrentRecipeName && newName!="")
- {
- var oldrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, CurrentRecipeName + ".rcp");
- var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, newName + ".rcp");
- CurrentRecipe.Header.Name = newName;
- SaveRecipe(CurrentRecipeName, RecipeUnity.RecipeToString(CurrentRecipe));
- File.Move(oldrecipePath, newrecipePath);
- UpdateRecipeFileList();
- }
-
- }
- public bool SaveAsRecipe(string recipeName, string recipeContent)
- {
- return m_uiRecipeManager.SaveAsRecipe(ModuleName, recipeName, recipeContent);
- }
- public string GetXmlRecipeList()
- {
- return m_uiRecipeManager.GetXmlRecipeList(ModuleName, true) ?? "";
- }
- void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
- {
- foreach (XmlElement ele in curElementNode.ChildNodes)
- {
- if (ele.Name == "File")
- {
- string fileName = ele.Attributes["Name"].Value;
- fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
- TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
- item.Tag = ele.Attributes["Name"].Value;
- //item.ToolTip = fileName;
- itemsControl.Items.Add(item);
- }
- else if (ele.Name == "Folder")
- {
- string folderName = ele.Attributes["Name"].Value;
- folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
- TreeViewFolderItem item = new TreeViewFolderItem(folderName);
- item.Tag = ele.Attributes["Name"].Value;
- CreateTreeViewItems(ele, item);
- item.IsExpanded = false;
- itemsControl.Items.Add(item);
- }
- }
- }
- private void LoadHeadWrapPanel(WrapPanel HeadWrapPanel, Recipe recipe)
- {
- HeadWrapPanel.Children.Clear();
- Type type = recipe.Header.GetType();
- foreach (var propertyInfo in type.GetProperties())
- {
- TextBlock textBlock = new TextBlock();
- textBlock.FontSize = 15;
- //textBlock.Width = 100;
- textBlock.Text = propertyInfo.Name + ":";
- textBlock.Margin = new Thickness(15, 0, 0, 0);
- textBlock.VerticalAlignment = VerticalAlignment.Center;
- HeadWrapPanel.Children.Add(textBlock);
- Binding binding = new Binding()
- {
- Source = recipe.Header, // 数据源
- Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- var propertyTypeName = propertyInfo.PropertyType.Name;
- var propertyInfoName = propertyInfo.Name;
- Control control = new Control();
- switch (propertyTypeName)
- {
- case "Int32":
- case "String":
- control = new TextBox();
- control.Margin = new Thickness(1, 0, 0, 0);
- control.BorderThickness = new Thickness(0, 0, 0, 1);
- //control.BorderBrush = Brushes.Black;
- control.FontSize = 15;
- control.Foreground = Brushes.Green;
- control.Background = Brushes.Transparent;
- control.VerticalAlignment = VerticalAlignment.Center;
- control.MinWidth = 15;
- control.SetBinding(TextBox.TextProperty, binding);
- object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
- if (objAttrs.Length > 0)
- {
- (control as TextBox).IsReadOnly = true;
- }
- break;
- case "Boolean":
- control = new CheckBox();
- control.SetBinding(CheckBox.IsCheckedProperty, binding);
- break;
- default:
- control = new ComboBox();
- control.Height = 23;
- control.SetBinding(ComboBox.SelectedItemProperty, binding);
- ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
- break;
- }
- HeadWrapPanel.Children.Add(control);
- }
- }
- private void MenuItemLeftInsert_Click(object sender, RoutedEventArgs e)
- {
- var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
- int insertIndex = Convert.ToInt32(t.Text);
- OnAddStep(insertIndex);
- }
- private void MenuItemRightInsert_Click(object sender, RoutedEventArgs e)
- {
- var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
- int insertIndex = Convert.ToInt32(t.Text);
- OnAddStep(insertIndex + 1);
- }
- private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
- {
- var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
- int deleteIndex = Convert.ToInt32(t.Text);
- OnDeleteStep(deleteIndex - 1);
- }
- private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
- {
- var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
- copyIndex = Convert.ToInt32(t.Text);
- }
- #endregion
- #region 私有方法
- private void RecipeStepToGridColumn(RecipeStep recipeStep, Grid grid, int index, bool isInsert)
- {
- int location = 1;
- if (isInsert == true)
- {
- location -= 1;
- }
- Type recipeType = recipeStep.GetType();
- int cycleCount = 1;
- if (index == 0)
- {
- cycleCount = 2;
- }
- for (int j = 0; j < cycleCount; j++)
- {
- int i = 0;
- ColumnDefinition col1 = new ColumnDefinition();
- //col1.MinWidth = 50;
- grid.ColumnDefinitions.Insert(index, col1);
- Binding stepcheckbinding = null;
- //grid.MinWidth = 200;
- foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
- {
- string propertyInfoName = propertyInfo.Name;
- string propertyTypeName = propertyInfo.PropertyType.Name;
- if (propertyInfoName != "LstUnit")
- {
- if (index == 0 && grid.ColumnDefinitions.Count == 1)
- {
-
- RowDefinition row1 = new RowDefinition();
- grid.RowDefinitions.Add(row1);
- if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime") && isInstalledEPD == false)
- {
- row1.Height = new GridLength(0);
- }
- }
- if (grid.ColumnDefinitions.Count == 1 && j == 0)
- {
- TextBox textBlock = new TextBox();
- textBlock.IsReadOnly = true;
- textBlock.Text = propertyInfoName;
- grid.Children.Add(textBlock);
- textBlock.Background = new SolidColorBrush(Colors.BurlyWood);
- Grid.SetRow(textBlock, i);
- Grid.SetColumn(textBlock, 0);
- }
- else
- {
- Binding binding = new Binding()
- {
- Source = recipeStep, // 数据源
- Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- switch (propertyTypeName)
- {
-
- case "Int32":
- case "String":
- if (propertyInfoName == "EPDConfig")
- {
- if (currentEPDType == EPDType.Socket)
- {
- ComboBox EPDcomboBox = new ComboBox();
- EPDcomboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
- EPDcomboBox.Background = new SolidColorBrush(Colors.Black);
- EPDcomboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
- EPDcomboBox.ItemsSource = EPDCfgList;
- grid.Children.Add(EPDcomboBox);
- Grid.SetRow(EPDcomboBox, i);
- Grid.SetColumn(EPDcomboBox, index + location);
- EPDcomboBox.DropDownOpened += EPDcomboBox_DropDownOpened;
- }
- else if (currentEPDType == EPDType.WCF)
- {
- Button EPDButton = new Button();
- EPDButton.Content = "EndPoint";
- EPDButton.Cursor = Cursors.Hand;
- EPDButton.Tag = $"{CurrentRecipeName}.{(index + location).ToString()}";
- EPDButton.Style = null;
- EPDButton.Click += EPDButton_Click;
- grid.Children.Add(EPDButton);
- Grid.SetRow(EPDButton, i);
- Grid.SetColumn(EPDButton, index + location);
- }
-
- break;
- }
- TextBox textBox = new TextBox();
- textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
- textBox.VerticalContentAlignment = VerticalAlignment.Center;
- if (stepcheckbinding == null)
- {
- textBox.IsEnabled = true;
- }
- else
- {
- textBox.SetBinding(TextBox.IsEnabledProperty, stepcheckbinding);
- }
- textBox.SetBinding(TextBox.TextProperty, binding);
- grid.Children.Add(textBox);
- Grid.SetRow(textBox, i);
- Grid.SetColumn(textBox, index + location);
- object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
- if (objAttrs.Length > 0)
- {
- textBox.IsReadOnly = true;
- ContextMenu contextmenu = new ContextMenu();
- textBox.ContextMenu = contextmenu;
- MenuItem menuItemDelete = new MenuItem();
- menuItemDelete.Header = "删除";
- menuItemDelete.Click += MenuItemDelete_Click;
- MenuItem menuItemLeftInsert = new MenuItem();
- menuItemLeftInsert.Header = "左插入";
- menuItemLeftInsert.Click += MenuItemLeftInsert_Click;
- MenuItem menuItemRightInsert = new MenuItem();
- menuItemRightInsert.Header = "右插入";
- menuItemRightInsert.Click += MenuItemRightInsert_Click;
- MenuItem menuItemCopy = new MenuItem();
- menuItemCopy.Tag = textBox.Text;
- menuItemCopy.Header = "复制";
- menuItemCopy.Click += MenuItemCopy_Click;
- contextmenu.Items.Add(menuItemCopy);
- contextmenu.Items.Add(menuItemDelete);
- contextmenu.Items.Add(menuItemLeftInsert);
- contextmenu.Items.Add(menuItemRightInsert);
- }
- break;
- case "Boolean":
- CheckBox checkBox = new CheckBox();
- checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
- grid.Children.Add(checkBox);
- Grid.SetRow(checkBox, i);
- Grid.SetColumn(checkBox, index + location);
- //if (stepcheckbinding == null)
- //{
- // stepcheckbinding = new Binding
- // {
- // Source = checkBox, // 数据源
- // Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
- // Mode = BindingMode.TwoWay, // 绑定模式
- // UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- // };
- //}
- //else
- //{
- //}
- if (stepcheckbinding == null)
- {
- checkBox.IsEnabled = true;
- }
- else
- {
- checkBox.SetBinding(TextBox.IsEnabledProperty, stepcheckbinding);
- }
- break;
- default:
- ComboBox comboBox = new ComboBox();
- comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
- comboBox.Background = new SolidColorBrush(Colors.Black);
- comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
- ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
- grid.Children.Add(comboBox);
- Grid.SetRow(comboBox, i);
- Grid.SetColumn(comboBox, index + location);
- if (stepcheckbinding == null)
- {
- comboBox.IsEnabled = true;
- }
- else
- {
- comboBox.SetBinding(TextBox.IsEnabledProperty, stepcheckbinding);
- }
- break;
- }
- }
- i++;
- }
- }
- int k = 0;
- recipeStep.LstUnit.ToList().ForEach(x =>
- {
- Type unitType = x.GetType();
- Binding checkbinding = null;
- foreach (PropertyInfo propertyInfo in unitType.GetProperties())
- {
- if (index == 0 && grid.ColumnDefinitions.Count == 1)
- {
- RowDefinition row1 = new RowDefinition();
- grid.RowDefinitions.Add(row1);
- }
- if (grid.ColumnDefinitions.Count == 1 && j == 0)
- {
- TextBox textBlock = new TextBox();
- textBlock.IsReadOnly = true;
- switch (propertyInfo.Name)
- {
- case "Gas1":
- var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
- textBlock.Text = $"{propertyInfo.Name}({data1.DisplayName},{data1.Scale})";
- break;
- case "Gas2":
- var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
- textBlock.Text = $"{propertyInfo.Name}({data2.DisplayName},{data2.Scale})";
- break;
- case "Gas3":
- var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
- textBlock.Text = $"{propertyInfo.Name}({data3.DisplayName},{data3.Scale})";
- break;
- case "Gas4":
- var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
- textBlock.Text = $"{propertyInfo.Name}({data4.DisplayName},{data4.Scale})";
- break;
- case "Gas5":
- var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
- textBlock.Text = $"{propertyInfo.Name}({data5.DisplayName},{data5.Scale})";
- break;
- case "Gas6":
- var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
- textBlock.Text = $"{propertyInfo.Name}({data6.DisplayName},{data6.Scale})";
- break;
- case "Gas7":
- var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
- textBlock.Text = $"{propertyInfo.Name}({data7.DisplayName},{data7.Scale})";
- break;
- case "Gas8":
- var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
- textBlock.Text = $"{propertyInfo.Name}({data8.DisplayName},{data8.Scale})";
- break;
- case "HeaterPressure":
- textBlock.Text = "Pressure(Pa)";
- break;
- case "HeaterTemp":
- textBlock.Text = "Heater Temp(℃)";
- break;
- case "HeaterRatio":
- textBlock.Text = "Heater Ratio";
- break;
- default:
- textBlock.Text = propertyInfo.Name;
- break;
- }
- textBlock.Background = solidColorBrushes[k % 3];
- grid.Children.Add(textBlock);
- Grid.SetRow(textBlock, i);
- Grid.SetColumn(textBlock, 0);
- }
- else
- {
- Binding binding = new Binding()
- {
- Source = recipeStep.LstUnit[k], // 数据源
- //Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
- Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- var item = propertyInfo.PropertyType.Name;
- if (propertyInfo.Name == "UnitName")
- {
- TextBox textBlock1 = new TextBox();
- textBlock1.HorizontalContentAlignment = HorizontalAlignment.Center;
- textBlock1.VerticalContentAlignment =VerticalAlignment.Center;
- textBlock1.Text = propertyInfo.GetValue(x).ToString();
- textBlock1.IsReadOnly = true;
- grid.Children.Add(textBlock1);
- Grid.SetRow(textBlock1, i);
- Grid.SetColumn(textBlock1, index + location);
- }
- else
- {
- switch (item)
- {
- case "Int32":
- case "String":
- TextBox textBox = new TextBox();
- textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
- textBox.VerticalContentAlignment = VerticalAlignment.Center;
- if (checkbinding == null)
- {
- textBox.IsEnabled = true;
- }
- else
- {
- textBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
- }
- switch (propertyInfo.Name)
- {
- case "Gas1":
- var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
- TextBoxMaxValue.SetMaxValue(textBox, (int)data1.Scale);
- break;
- case "Gas2":
- var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
- TextBoxMaxValue.SetMaxValue(textBox, (int)data2.Scale);
- break;
- case "Gas3":
- var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
-
- break;
- case "Gas4":
- var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
-
- break;
- case "Gas5":
- var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
-
- break;
- case "Gas6":
- var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
-
- break;
- case "Gas7":
- var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
-
- break;
- case "Gas8":
- var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
-
- break;
-
- }
- textBox.SetBinding(TextBox.TextProperty, binding);
- grid.Children.Add(textBox);
- Grid.SetRow(textBox, i);
- Grid.SetColumn(textBox, index + location);
- object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
- if (objAttrs.Length > 0)
- {
- textBox.IsReadOnly = true;
- }
- break;
- case "Boolean":
- CheckBox checkBox = new CheckBox();
- if (checkbinding == null)
- {
- checkbinding = new Binding
- {
- Source = checkBox, // 数据源
- Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- }
- checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
- grid.Children.Add(checkBox);
- Grid.SetRow(checkBox, i);
- Grid.SetColumn(checkBox, index + location);
- break;
- default:
- ComboBox comboBox = new ComboBox();
- comboBox.BorderBrush = Brushes.Gray;
- comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
- if (checkbinding == null)
- {
- comboBox.IsEnabled = true;
- }
- else
- {
- comboBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
- }
-
- comboBox.Background = Brushes.White;
- string path = propertyInfo.Name;
- comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
- ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
- grid.Children.Add(comboBox);
- Grid.SetRow(comboBox, i);
- Grid.SetColumn(comboBox, index + location);
- break;
- }
- }
- }
- i++;
- }
- k++;
- });
- //index++;
- }
- }
- private void EPDcomboBox_DropDownOpened(object sender, EventArgs e)
- {
-
- }
- private void EPDButton_Click(object sender, RoutedEventArgs e)
- {
- Button button = sender as Button;
- string para = button.Tag.ToString();
- int stepno = Convert.ToInt32(para.Split('.')[1])-1;
- var endpointconfigitem = new MECF.Framework.Common.CommonData.EndPointConfigItem();
- if (CurrentRecipe.Steps[stepno].EPDConfig!=null && CurrentRecipe.Steps[stepno].EPDConfig.Length>20)
- {
- endpointconfigitem.SetValue(CurrentRecipe.Steps[stepno].EPDConfig);
- }
- (new EndPointDlg(para, endpointconfigitem,CurrentRecipe)).ShowDialog();
- }
- private void UpdateRecipeFileList()
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(GetXmlRecipeList());
- treeViewRcpList.Items.Clear();
- CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
- }
- private void LoadRecipe(Recipe recipe)
- {
- copyIndex = -1;
- bodyStackPanel.Children.Clear();
- //CurrentRecipe = null;
- GC.Collect(); // This should pick up the control removed at a previous MouseDown
- GC.WaitForPendingFinalizers(); // Doesn't help either
- GC.Collect();
- GC.WaitForPendingFinalizers(); // Doesn't help either
- CurrentRecipe = recipe;
- Grid grid = new Grid();
- grid.Margin = new Thickness(15);
- //index = 0;
- for (int i = 0; i < recipe.Steps.Count; i++)
- {
- RecipeStepToGridColumn(recipe.Steps[i], grid, i, false);
- }
- bodyStackPanel.Children.Add(grid);
- currentRecipeGrid = grid;
- }
- private void OnAddStep(int index)
- {
- if (CurrentRecipe != null)
- {
- RecipeStep recipeStep;
- if (copyIndex == -1)
- {
- recipeStep = new RecipeStep();
- //recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
- //recipeStep.LstUnit.Add(new TCPUnit());
- //recipeStep.LstUnit.Add(new BiasUnit());
- //recipeStep.LstUnit.Add(new GasControlUnit());
- //recipeStep.LstUnit.Add(new ESCHVUnit());
- //recipeStep.LstUnit.Add(new ProcessKitUnit());
- switch (currentChamber)
- {
- case JetChamber.Venus:
- case JetChamber.Kepler2300:
- recipeStep.LstUnit.Add(new PressureByPressureModeUnit());
- recipeStep.LstUnit.Add(new TCPUnit());
- recipeStep.LstUnit.Add(new BiasUnit());
- recipeStep.LstUnit.Add(new GasControlUnit());
- recipeStep.LstUnit.Add(new ESCHVUnit());
- recipeStep.LstUnit.Add(new ProcessKitUnit());
- break;
- case JetChamber.Kepler2200A:
- recipeStep.LstUnit.Add(new Kepler2200GasControlUnit());
- recipeStep.LstUnit.Add(new HeaterUnit());
- recipeStep.LstUnit.Add(new Kepler2200RFUnit());
- break;
- }
- CurrentRecipe.Steps.Insert(index - 1, recipeStep);
- }
- else
- {
- var t = JsonConvert.SerializeObject(CurrentRecipe);
- recipeStep = Recipe.Load(t).Steps[copyIndex - 1];
- CurrentRecipe.Steps.Insert(index - 1, recipeStep);
- }
- RecipeStepToGridColumn(recipeStep, currentRecipeGrid, index, true);
- for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
- {
- CurrentRecipe.Steps[i - 1].StepNo = i;
- }
- }
- }
- private void OnDeleteStep(int index)
- {
- if (CurrentRecipe != null && CurrentRecipe.Steps.Count > 1)
- {
- CurrentRecipe.Steps.RemoveAt(index);
- currentRecipeGrid.Children.RemoveRange(currentRecipeGrid.RowDefinitions.Count * (index + 1), currentRecipeGrid.RowDefinitions.Count);
- currentRecipeGrid.ColumnDefinitions.RemoveAt(index);
- for (int i = 1; i <= CurrentRecipe.Steps.Count; i++)
- {
- CurrentRecipe.Steps[i - 1].StepNo = i;
- }
- }
- }
- #endregion
- }
- }
|