123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Xml;
- using Aitex.UI.RecipeEditor.Core;
- using Aitex.UI.RecipeEditor.View;
- using ExcelLibrary.SpreadSheet;
- using Microsoft.Win32;
- using Venus_Core;
- using Xceed.Wpf.DataGrid;
- namespace Aitex.UI.RecipeEditor
- {
- public class RecipeEditorControlViewModel : INotifyPropertyChanged
- {
- private ObservableCollection<RecipeModel> m_RecipeModelObservableCollection = new ObservableCollection<RecipeModel>();
- public ObservableCollection<RecipeModel> RecipeModelObservableCollection
- {
- get { return m_RecipeModelObservableCollection; }
- set { m_RecipeModelObservableCollection = value; InvokePropertyChanged("RecipeModelObservableCollection"); }
- }
- private Recipe m_currentRecipe;
- public Recipe CurrentRecipe
- {
- get { return m_currentRecipe; }
- set { m_currentRecipe = value; InvokePropertyChanged("CurrentRecipe"); }
- }
- private Visibility m_DataGridVisibility=Visibility.Collapsed;
- public Visibility DataGridVisibility
- {
- get { return m_DataGridVisibility; }
- set { m_DataGridVisibility = value; InvokePropertyChanged("DataGridVisibility"); }
- }
- public StackPanel DataGridStackPanel { get; set; }
- public ICommand AddStepCommand { get; set; }
- public ICommand DeleteStepCommand { get; set; }
-
- public List<Tuple<string, string, ObservableCollection<RecipeRow>, Guid>> UndoList { get; set; }
- public List<Tuple<string, string, ObservableCollection<RecipeRow>, Guid>> RedoList { get; set; }
- public bool IsUndoEnabled { get { return UndoList != null && UndoList.Count > 0; } }
- public bool IsRedoEnabled { get { return RedoList != null && RedoList.Count > 0; } }
- public ObservableCollection<RecipeRow> RecipeRows { get; set; }
- private ObservableCollection<RecipeRow> _previousRecipeRows { get; set; }
- private string _valueBeforeEditing { get; set; }
- private string _currentRecipeVariationName = string.Empty;
- private SmartCellData _currentEditingCellData { get; set; }
- public List<Tuple<int/*row no*/, int/*col no*/, string/*var name*/, string/*reason*/>> Errors { get; set; }
- public List<Tuple<string, string>> CreateRecipeList { get; set; }
- public List<Tuple<string, string>> OpenRecipeList { get; set; }
- public DataGrid DataGridControl { get; set; }
- public int CurrentRunningStepNo { get; set; }
- public Visibility SingleAppElementVisibility { get; set; }
- public Visibility RecipeInfoTextVisibility { get; set; }
- public ICommand ShowDetailedErrInfoCommand { get; set; }
- public ICommand EditRecipeInfoCommand { get; set; }
- //public ICommand CellContentChangedCommand { get; set; }
- public ICommand RightClickCommand { get; set; }
- public ICommand OpenLocalRecipeCommand { get; set; }
- public ICommand ExpandGroupCommand { get; set; }
- public ICommand CollapseGroupCommand { get; set; }
- public ICommand SaveRecipeCommand { get; set; }
- public ICommand RecipeHelpDocCommand { get; set; }
- public ICommand RecipeExport2ExcelCommand { get; set; }
- public ICommand ToggleHideSameCommand { get; set; }
- public ICommand UndoCommand { get; set; }
- public ICommand RedoCommand { get; set; }
- public ICommand SmartCellEditorLoadedCommand { get; set; }
- public ICommand SmartCellEditorUnloadedCommand { get; set; }
- public RecipeHead RecipeHead { get; set; }
- public bool IsBusy { get; set; }
- public bool IsHideSameContent { get; set; }
- public string RecipeInfo { get; set; }
- public HashSet<string> MaskedTechNames { get; set; }
- public HashSet<string> MaskedCatalogNames { get; set; }
- public event EventHandler OnSaveRecipeFile;
- public event EventHandler OnLocalRecipeOpened;
- //public event EventHandler OnLoadRecipeContent;
- public bool IsRecipeModified { get; set; }
- //public string UserName { set; get; }
- //private List<Tuple<string, string, string>> SourceDilteInjectRestrictions { get; set; }
- //private Dictionary<string, string> _preDefinedRecipeVars { get; set; }
- //private List<Tuple<string/*varName*/, string/*check condition*/, string/*message*/>> _validationRules { get; set; }
- //private List<string> _checkVariables { get; set; }
- //private Dictionary<string, int> RowVarNameDic { get; set; }
- //private Dictionary<int, List<SmartCellData>> _copiedColumnDatas = new Dictionary<int, List<SmartCellData>>();
- //private Dictionary<string/*CatalogName*/, Dictionary<string/*GroupName*/, List<RecipeVariableDefine/*StepList*/>>> _recipeReadingFormat;
- //private Dictionary<string/*ModuleName*/, List<string>/*each item's control name*/> _recipeSavingFormat;
- //private string _currentRecipeFormatContent;
- List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>();
- public bool IsBarcodeEnabled
- {
- get; set;
- }
- public Visibility IsBarcodeVisibility
- {
- get
- {
- return IsBarcodeEnabled ? Visibility.Visible : Visibility.Hidden;
- }
- }
- private string _defaultEndPointValue { get; set; }
- /// <summary>
- /// class construction
- /// </summary>
- public RecipeEditorControlViewModel()
- {
- //UndoList = new List<Tuple<string, string, ObservableCollection<RecipeRow>, Guid>>();
- //RedoList = new List<Tuple<string, string, ObservableCollection<RecipeRow>, Guid>>();
- //if(SingleAppElementVisibility
- CreateRecipeList = new List<Tuple<string, string>>();
- OpenRecipeList = new List<Tuple<string, string>>();
- //foreach (var item in GetDefinedRecipeVariations())
- //{
- // CreateRecipeList.Add(new Tuple<string, string>("配置:" + item, item));
- // OpenRecipeList.Add(new Tuple<string, string>("转换为配置:" + item, item));
- //}
- RecipeInfoTextVisibility = Visibility.Collapsed;
- SingleAppElementVisibility = Visibility.Collapsed;
- //RightClickCommand = new DelegatedCommand((o) => true, (o) => RightClickAction());
- SaveRecipeCommand = new DelegatedCommand((o) => true, (o) => SaveRecipeFile());
- OpenLocalRecipeCommand = new DelegatedCommand((o) => true, (o) => OpenLocalRecipe());
- //ShowDetailedErrInfoCommand = new DelegatedCommand((o) => true, (o) => ShowDetailedErrInformation());
- //EditRecipeInfoCommand = new DelegatedCommand((o) => true, (o) => EditRecipeInformation());
- AddStepCommand = new DelegatedCommand((o) => true, (o) => OnAddStep());
- DeleteStepCommand = new DelegatedCommand((o) => true, (o) => OnDeleteStep());
- solidColorBrushes.Add(new SolidColorBrush(Colors.Aqua));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Aquamarine));
- solidColorBrushes.Add(new SolidColorBrush(Colors.LawnGreen));
- solidColorBrushes.Add(new SolidColorBrush(Colors.LightYellow));
- solidColorBrushes.Add(new SolidColorBrush(Colors.DarkOrange));
- solidColorBrushes.Add(new SolidColorBrush(Colors.MistyRose));
- solidColorBrushes.Add(new SolidColorBrush(Colors.BurlyWood));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Gainsboro));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Beige));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Yellow));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Magenta));
- }
- private void OnAddStep()
- {
- if (CurrentRecipe != null)
- {
- RecipeStep recipeStep = new RecipeStep();
- recipeStep.LstUnit.Add(new PressureUnitByValveMode());
- 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());
- CurrentRecipe.Steps.Add(recipeStep);
- var item = RecipeStepToGrid(recipeStep);
- DataGridStackPanel.Children.Add(item.Item1);
- }
- }
- private void OnDeleteStep()
- {
- if (CurrentRecipe != null)
- {
- CurrentRecipe.Steps.RemoveAt(CurrentRecipe.Steps.Count - 1);
- DataGridStackPanel.Children.RemoveAt(DataGridStackPanel.Children.Count - 1);
- }
- }
- /// <summary>
- /// Open local recipe operation
- /// </summary>
- /// <param name="recipeDefineFilePath"></param>
- public void OpenLocalRecipe(string recipeVariationName = "")
- {
- var dlg = new OpenFileDialog();
- dlg.DefaultExt = ".rcp";
- dlg.Filter = "Recipe File (.rcp)|*.rcp|All (*.*)|*.*";
- if (dlg.ShowDialog() == true)
- {
- try
- {
- XmlDocument rcpDoc = new XmlDocument();
- rcpDoc.Load(dlg.FileName);
- string recipeVariation = recipeVariationName;
- if (string.IsNullOrEmpty(recipeVariation))
- {
- var root = rcpDoc.SelectSingleNode("/TableRecipeData") as XmlElement;
- recipeVariation = root.Attributes["RecipeVersion"].Value;
- }
- var startupPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
- string dir = System.IO.Path.GetDirectoryName(startupPath);
- List<Aitex.Controls.RecipeCompare.Item> map = CustomXmlSerializer.Deserialize<List<Aitex.Controls.RecipeCompare.Item>>(new System.IO.FileInfo(System.IO.Path.Combine(dir, "map.xml")));
- Func<Aitex.Controls.RecipeCompare.Item, bool> predicate = item => item.Name.Equals(recipeVariation);
- System.IO.FileInfo fi = new System.IO.FileInfo(string.Format("{0}\\config\\{1}.xml", dir, map.Any(predicate) ? map.Single(predicate).No : recipeVariation));
- if (fi.Exists)
- {
- XmlDocument doc = new XmlDocument();
- doc.Load(fi.FullName);
- string formatXml = doc.SelectSingleNode("/Aitex/TableRecipeFormat").OuterXml;
- string recipeXml = rcpDoc.SelectSingleNode("/TableRecipeData").OuterXml;
- //LoadRecipe(formatXml, recipeXml);
- if (OnLocalRecipeOpened != null)
- OnLocalRecipeOpened.Invoke(new Tuple<string, string>(recipeVariation, dlg.FileName), null);
- }
- else
- {
- MessageBox.Show(string.Format("工艺程序版本{0}的描述文件不存在,无法正确识别该版本的工艺程序文件。", recipeVariation), "工艺程序打开失败",
- MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.Message);
- MessageBox.Show(string.Format("open recipe {0} failed,please confirm the recipe file is exist and valid。\r\n{1}", dlg.FileName, ex.Message), "Open recipe failed",
- MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- }
- /// <summary>
- /// Save recipe file
- /// </summary>
- private void SaveRecipeFile()
- {
- try
- {
- if (Errors != null && Errors.Count > 0)
- {
- var ret = MessageBox.Show(string.Format("Recipe have {0} error,continue save?", Errors.Count), "Save", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
- if (ret != MessageBoxResult.Yes)
- return;
- }
- if (OnSaveRecipeFile != null)
- {
- IsRecipeModified = false;
-
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.Message);
- MessageBox.Show("save recipe failed!\r\n\r\n" + ex.Message, "Save", MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- }
- /// <summary>
- /// Parse recipe content with recipe format
- /// </summary>
- /// <param name="recipeFormat"></param>
- /// <param name="recipeContent"></param>
- /// <param name="selectedStepNo"></param>
- public void LoadRecipe(Recipe recipe)
- {
- DataGridStackPanel.Children.Clear();
- CurrentRecipe =recipe;
- recipe.Steps.ToList().ForEach(x =>
- {
- var tupleValue = RecipeStepToGrid(x);
- DataGridStackPanel.Children.Add(tupleValue.Item1);
- });
- }
-
- private Tuple<DataGrid,List<int>> RecipeStepToDataGrid(RecipeStep recipeStep)
- {
- DataGrid dataGrid = new DataGrid();
- List<int> ints = new List<int>();
- DataTable dataTable = new DataTable();
- dataTable.Columns.Add("Key");
- dataTable.Columns.Add("Value");
- dataGrid.CanUserAddRows = false;
- dataGrid.AutoGenerateColumns = true;
- dataGrid.CellEditEnding += DataGrid_CellEditEnding;
- //dataGrid.Margin = new Thickness(10, 0, 0, 0);
- //dataGrid.IsReadOnly = true;
- dataGrid.SelectedCellsChanged += DataGrid_SelectedCellsChanged;
- dataGrid.SelectionUnit = DataGridSelectionUnit.Cell;
- //dataGrid.EnableRowVirtualization = false;
- //dataGrid.IsReadOnly = true;
- dataGrid.SetValue(System.Windows.Controls.VirtualizingStackPanel.IsVirtualizingProperty, false);
- Type recipeType = recipeStep.GetType();
- foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
- {
- if (propertyInfo.Name != "LstUnit")
- {
- dataTable.Rows.Add(propertyInfo.Name, propertyInfo.GetValue(recipeStep));
- }
- }
- ints.Add(dataTable.Rows.Count);
-
- recipeStep.LstUnit.ToList().ForEach(k =>
- {
- //List<dynamic> dynamics = new List<dynamic>();
- Type type = k.GetType();
- ints.Add(type.GetProperties().Length);
- foreach (PropertyInfo propertyInfo in type.GetProperties())
- {
- var name = propertyInfo.Name;
- var value = propertyInfo.GetValue(k);
- //dynamicModel.PropertyName = name;
- //dynamicModel.Property = value;
- dataTable.Rows.Add(name, value);
- }
- });
- dataGrid.ItemsSource = dataTable.DefaultView;
- //});
- return new Tuple<DataGrid, List<int>>(dataGrid, ints);
- }
- private Tuple<Grid, List<int>> RecipeStepToGrid(RecipeStep recipeStep)
- {
- Grid grid = new Grid();
- List<int> ints = new List<int>();
- ColumnDefinition col1 = new ColumnDefinition();
- ColumnDefinition col2 = new ColumnDefinition();
- grid.ColumnDefinitions.Add(col1);
- grid.ColumnDefinitions.Add(col2);
- GridOptions.SetShowBorder(grid, true);
- GridOptions.SetLineBrush(grid, Brushes.White);
- GridOptions.SetLineThickness(grid, 1);
- grid.Margin = new Thickness(15, 0, 0, 0);
- Type recipeType2 = recipeStep.GetType();
- int i = 0;
- foreach (PropertyInfo propertyInfo in recipeType2.GetProperties())
- {
- if (propertyInfo.Name != "LstUnit")
- {
- RowDefinition row1 = new RowDefinition();
- grid.RowDefinitions.Add(row1);
- var item = propertyInfo.PropertyType.ToString();
- switch (item)
- {
- case "System.Int32":
- TextBox textBox = new TextBox();
- Binding binding = new Binding()
- {
- Source = recipeStep, // 数据源
- Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- textBox.SetBinding(TextBox.TextProperty, binding);
- grid.Children.Add(textBox);
- Grid.SetRow(textBox, i);
- Grid.SetColumn(textBox, 1);
- break;
- case "System.Boolean":
- CheckBox checkBox = new CheckBox();
- Binding binding2 = new Binding()
- {
- Source = recipeStep, // 数据源
- Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- checkBox.SetBinding(CheckBox.IsCheckedProperty, binding2);
- grid.Children.Add(checkBox);
- Grid.SetRow(checkBox, i);
- Grid.SetColumn(checkBox, 1);
- break;
- default:
- ComboBox comboBox = new ComboBox();
- Binding binding3 = new Binding()
- {
- Source = recipeStep, // 数据源
- Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- comboBox.SetBinding(ComboBox.SelectedItemProperty, binding3);
- ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
- grid.Children.Add(comboBox);
- Grid.SetRow(comboBox, i);
- Grid.SetColumn(comboBox, 1);
- break;
- }
-
- TextBlock textBlock = new TextBlock();
- textBlock.Text = propertyInfo.Name;
- grid.Children.Add(textBlock);
-
- Grid.SetRow(textBlock, i);
- Grid.SetColumn(textBlock, 0);
- i++;
- }
-
- }
- ints.Add(recipeType2.GetProperties().Length);
- int k = 0;
- recipeStep.LstUnit.ToList().ForEach(x =>
- {
- Type type = x.GetType();
- foreach (PropertyInfo propertyInfo in type.GetProperties())
- {
-
-
- RowDefinition row1 = new RowDefinition();
- grid.RowDefinitions.Add(row1);
- var item = propertyInfo.PropertyType.ToString();
- if (propertyInfo.Name == "UnitName")
- {
- TextBlock textBlock1= new TextBlock();
- Binding binding = new Binding()
- {
- Source = recipeStep, // 数据源
- Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- textBlock1.SetBinding(TextBlock.TextProperty, binding);
- grid.Children.Add(textBlock1);
- Grid.SetRow(textBlock1, i);
- Grid.SetColumn(textBlock1, 1);
- }
- else
- {
- switch (item)
- {
- case "System.Int32":
- TextBox textBox = new TextBox();
- Binding binding = new Binding()
- {
- Source = recipeStep, // 数据源
- Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- textBox.SetBinding(TextBox.TextProperty, binding);
- grid.Children.Add(textBox);
- Grid.SetRow(textBox, i);
- Grid.SetColumn(textBox, 1);
- break;
- case "System.Boolean":
- CheckBox checkBox = new CheckBox();
- Binding binding2 = new Binding()
- {
- Source = recipeStep, // 数据源
- Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- checkBox.SetBinding(CheckBox.IsCheckedProperty, binding2);
- grid.Children.Add(checkBox);
- Grid.SetRow(checkBox, i);
- Grid.SetColumn(checkBox, 1);
- break;
- default:
- ComboBox comboBox = new ComboBox();
- string path= propertyInfo.Name;
- Binding binding3 = new Binding()
- {
- Source = recipeStep.LstUnit[k], // 数据源
- Path = new PropertyPath(path), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- comboBox.SetBinding(ComboBox.SelectedItemProperty, binding3);
- ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
- grid.Children.Add(comboBox);
- Grid.SetRow(comboBox, i);
- Grid.SetColumn(comboBox, 1);
- break;
- }
- }
-
- //TextBox textBox = new TextBox();
- ////textBox.Text = propertyInfo.GetValue(x).ToString();
- //Binding binding = new Binding()
- //{
- // Source = recipeStep, // 数据源
- // Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
- // Mode = BindingMode.TwoWay, // 绑定模式
- // UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- //};
- //textBox.SetBinding(TextBox.TextProperty, binding);
- //grid.Children.Add(textBox);
- TextBlock textBlock = new TextBlock();
- textBlock.Text = propertyInfo.Name;
- grid.Children.Add(textBlock);
- Grid.SetRow(textBlock, i);
- Grid.SetColumn(textBlock, 0);
- i++;
- }
- ints.Add(type.GetProperties().Length);
- k++;
- });
- return new Tuple<Grid, List<int>>(grid, ints);
- }
- private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
- {
- //string prop1 = (e.Row.Item as DataRowView).Row[1].ToString();
- string prop1=(e.Row.Item as DataRowView).Row[0].ToString();
- string newValue = (e.EditingElement as TextBox).Text;
- }
- private void DataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
- {
- foreach (DataGridCellInfo cell in e.AddedCells)
- {
- if (cell.Column.Header.ToString() == "Key")
- {
- (sender as DataGrid).SelectedCells.Remove(cell);
- }
- }
- }
- //private void DataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
- //{
- // var dg = sender as DataGrid;
- // foreach (DataGridCellInfo info in dg.SelectedCells)
- // {
- // FrameworkElement element = info.Column.GetCellContent(info.Item);
- // //((TextBlock)info.Column.GetCellContent(info.Item)).Text = "123";
- // }
- //}
- private void ChangeDataGridRowColor(DataGrid dataGrid,List<int> ints)
- {
- int count = 0;
- for (int i = 0; i < ints.Count; i++)
- {
- for (int j = 0; j < ints[i]; j++)
- {
- dataGrid.UpdateLayout();
- int index = count + j;
- DataGridRow row = dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.Items[index]) as DataGridRow;
- row.Background = solidColorBrushes[i];
- }
- count += ints[i];
- }
- }
- private void ChangeGridRowColor(Grid grid, List<int> ints)
- {
- int count = 0;
- for (int i = 0; i < ints.Count; i++)
- {
- for (int j = 0; j < ints[i]; j++)
- {
- //dataGrid.UpdateLayout();
- int index = count + j;
- //DataGridRow row = dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.Items[index]) as DataGridRow;
- //grid.RowDefinitions[index]
- }
- count += ints[i];
- }
- }
- /// <summary>
- /// calc recipe total time
- /// </summary>
- private void CalcRecipeTime()
- {
- int timeStepRowId = -1;
- int loopStepRowId = -1;
- for (int i = 0; i < RecipeRows.Count; i++)
- {
- if (RecipeRows[i].TechnicalName == "Time")
- timeStepRowId = i;
- if (RecipeRows[i].TechnicalName == "Loop")
- loopStepRowId = i;
- if (loopStepRowId != -1 && timeStepRowId != -1)
- break;
- }
- TimeSpan tspan = new TimeSpan();
- for (int stepNo = 0; stepNo < RecipeRows[timeStepRowId].RecipeItems.Count; stepNo++)
- {
- string loopStr = RecipeRows[loopStepRowId].RecipeItems[stepNo].Value;
- bool isLoopStart = Regex.IsMatch(loopStr, @"^Loop\x20\d+$");
- if (isLoopStart)
- {
- int loopNum = int.Parse(loopStr.ToLower().Replace("loop", "").Replace(" ", ""));
- TimeSpan ts = new TimeSpan();
- for (int innerStepNo = stepNo; innerStepNo < RecipeRows[timeStepRowId].RecipeItems.Count; innerStepNo++)
- {
- loopStr = RecipeRows[loopStepRowId].RecipeItems[innerStepNo].Value;
- stepNo = innerStepNo;
- string timeDuration = RecipeRows[timeStepRowId].RecipeItems[innerStepNo].Value;
- string[] timeArr = timeDuration.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
- if (timeArr.Length == 3)
- {
- int h, mi, s;
- if (int.TryParse(timeArr[0], out h) && int.TryParse(timeArr[1], out mi) && int.TryParse(timeArr[2], out s))
- {
- var tt = new TimeSpan(h, mi, s);
- ts += tt;
- }
- }
- bool isLoopEnd = Regex.IsMatch(loopStr, @"^Loop End$");
- if (isLoopEnd)
- {
- tspan += new TimeSpan(ts.Ticks * loopNum);
- break;
- }
- }
- }
- else
- {
- string timeDuration = RecipeRows[timeStepRowId].RecipeItems[stepNo].Value;
- string[] timeArr = timeDuration.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
- if (timeArr.Length == 3)
- {
- int h, mi, s;
- if (int.TryParse(timeArr[0], out h) && int.TryParse(timeArr[1], out mi) && int.TryParse(timeArr[2], out s))
- {
- var ts = new TimeSpan(h, mi, s);
- tspan += ts;
- }
- }
- }
- }
- RecipeInfo = string.Format("共{0}步,总时间{1}:{2}:{3}", RecipeRows[0].RecipeItems.Count, (int)tspan.TotalHours, tspan.Minutes.ToString("00"), tspan.Seconds.ToString("00"));
- InvokePropertyChanged("RecipeInfo");
- }
- #region INotifyPropertyChanged
- public event PropertyChangedEventHandler PropertyChanged;
- public void InvokePropertyChanged(string propertyName)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- #endregion INotifyPropertyChanged
- }
- public class RecipeRow
- {
- private ObservableCollection<SmartCellData> _recipeItems = new ObservableCollection<SmartCellData>();
- public RecipeRow(params SmartCellData[] vars)
- {
- foreach (var var in vars)
- _recipeItems.Add(var);
- }
- public string CatalogName { get; set; }
- public string FriendlyName { get; set; }
- public string TechnicalName { get; set; }
- public ObservableCollection<SmartCellData> RecipeItems
- {
- get { return _recipeItems; }
- set { _recipeItems = value; }
- }
- }
- /// <summary>
- /// Recipe head
- /// </summary>
- public class RecipeHead
- {
- public string RecipeVariation { get; set; }
- public string CreationTime { get; set; }
- public string LastRevisionTime { get; set; }
- public string CreatedBy { get; set; }
- public string LastModifiedBy { get; set; }
- public string PressureMode { get; set; }
- public string Description { get; set; }
- public string BasePressure
- {
- get; set;
- }
- public string PumpDownLimit
- {
- get; set;
- }
- public string PurgeActive
- {
- get; set;
- }
- public string NotToPurgeOrVent
- {
- get; set;
- }
- public string Barcode
- {
- get; set;
- }
- public string SubstrateTemp
- {
- get; set;
- }
- public string PumpingPinState
- {
- get; set;
- }
- public string VentingPinState
- {
- get; set;
- }
- public string PinDownPressure
- {
- get; set;
- }
- }
- public class EndPointConfigItem : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public void InvokePropertyChanged(string propertyName)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- public string ExposureTime { get; set; }
- public string WaveLengthA { get; set; }
- public string BinningA { get; set; }
- public string WaveLengthB { get; set; }
- public string BinningB { get; set; }
- public string WaveLengthC { get; set; }
- public string BinningC { get; set; }
- public string WaveLengthD { get; set; }
- public string BinningD { get; set; }
- public string Fd { get; set; }
- public string PrefilterTime { get; set; }
- public string PostfilterTime { get; set; }
- public string AlgorithmType { get; set; }
- public string Criteria { get; set; }
- public string DelayTime { get; set; }
- public string ValidationTime { get; set; }
- public string ValidationValue { get; set; }
- public string TimeWindow { get; set; }
- public string MinimalTime { get; set; }
- public string PostponeTime { get; set; }
- public bool Control { get; set; }
- public bool Normalization { get; set; }
- public bool EnablePostponePercent { get; set; }
- public bool EnableCriterialPercent { get; set; }
- public bool EnableEventTrigger { get; set; }
- public bool IsFaultIfNoTrigger { get; set; }
- public string ToValue()
- {
- return
- $@"ExposureTime={ExposureTime};WaveLengthA={WaveLengthA};BinningA={BinningA};WaveLengthB={WaveLengthB};" +
- $@"BinningB={BinningB};WaveLengthC={WaveLengthC};BinningC={BinningC};WaveLengthD={WaveLengthD};BinningD={BinningD};Fd={Fd};" +
- $@"PrefilterTime={PrefilterTime};PostfilterTime={PostfilterTime};AlgorithmType={AlgorithmType};Criteria={Criteria};DelayTime={DelayTime};ValidationTime={ValidationTime};" +
- $@"ValidationValue={ValidationValue};TimeWindow={TimeWindow};MinimalTime={MinimalTime};PostponeTime={PostponeTime};Control={Control};Normalization={Normalization};" +
- $@"EnablePostponePercent={EnablePostponePercent};EnableCriterialPercent={EnableCriterialPercent};EnableEventTrigger={EnableEventTrigger};IsFaultIfNoTrigger={IsFaultIfNoTrigger};"
- ;
- }
- public void SetValue(string config)
- {
- if (string.IsNullOrEmpty(config))
- return;
- string[] items = config.Split(';');
- foreach (var item in items)
- {
- if (string.IsNullOrEmpty(item))
- continue;
- string[] pairs = item.Split('=');
- if (pairs.Length != 2)
- continue;
- Parallel.ForEach(this.GetType().GetProperties(),
- property =>
- {
- PropertyInfo pi = (PropertyInfo) property;
- if (pi.Name == pairs[0])
- {
- try
- {
- var convertedValue = Convert.ChangeType(pairs[1], pi.PropertyType);
- var originValue = Convert.ChangeType(pi.GetValue(this, null), pi.PropertyType);
- if (originValue != convertedValue)
- {
- pi.SetValue(this, convertedValue, null);
- }
- }
- catch (Exception)
- {
- }
- }
- });
- }
- }
- }
- }
|