|
@@ -28,7 +28,7 @@ namespace Aitex.UI.RecipeEditor
|
|
|
List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>();//step模块颜色
|
|
|
public WrapPanel HeadWrapPanel { get; set; } //head容器
|
|
|
|
|
|
-
|
|
|
+ Grid currentGrid;
|
|
|
|
|
|
|
|
|
public RecipeEditorControlViewModel()
|
|
@@ -48,11 +48,12 @@ namespace Aitex.UI.RecipeEditor
|
|
|
recipeStep.LstUnit.Add(new GasControlUnit());
|
|
|
recipeStep.LstUnit.Add(new ESCHVUnit());
|
|
|
recipeStep.LstUnit.Add(new ProcessKitUnit());
|
|
|
- recipeStep.StepNo = GridStackPanel.Children.Count+1;
|
|
|
+ recipeStep.StepNo = currentGrid.ColumnDefinitions.Count;
|
|
|
|
|
|
CurrentRecipe.Steps.Add(recipeStep);
|
|
|
- var item = RecipeStepToGrid(recipeStep);
|
|
|
- GridStackPanel.Children.Add(item.Item1);
|
|
|
+ //var item = RecipeStepToGrid(recipeStep);
|
|
|
+ //GridStackPanel.Children.Add(item.Item1);
|
|
|
+ RecipeStepToGridColumn(recipeStep, currentGrid);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -61,7 +62,7 @@ namespace Aitex.UI.RecipeEditor
|
|
|
if (CurrentRecipe != null&& CurrentRecipe.Steps.Count>0)
|
|
|
{
|
|
|
CurrentRecipe.Steps.RemoveAt(CurrentRecipe.Steps.Count - 1);
|
|
|
- GridStackPanel.Children.RemoveAt(GridStackPanel.Children.Count - 1);
|
|
|
+ currentGrid.ColumnDefinitions.RemoveAt(currentGrid.ColumnDefinitions.Count-1);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -81,13 +82,20 @@ namespace Aitex.UI.RecipeEditor
|
|
|
GC.WaitForPendingFinalizers(); // Doesn't help either
|
|
|
|
|
|
CurrentRecipe = recipe;
|
|
|
+ Grid grid = new Grid();
|
|
|
+
|
|
|
+ GridOptions.SetShowBorder(grid, true);
|
|
|
+ GridOptions.SetLineBrush(grid, Brushes.White);
|
|
|
+ GridOptions.SetLineThickness(grid, 1);
|
|
|
+
|
|
|
recipe.Steps.ToList().ForEach(x =>
|
|
|
{
|
|
|
- var tupleValue = RecipeStepToGrid(x);
|
|
|
- GridStackPanel.Children.Add(tupleValue.Item1);
|
|
|
+ RecipeStepToGridColumn(x,grid);
|
|
|
});
|
|
|
+ GridStackPanel.Children.Add(grid);
|
|
|
|
|
|
LoadHeadWrapPanel(recipe);
|
|
|
+ currentGrid = grid;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 选中recipe,头部界面显示
|
|
@@ -160,6 +168,188 @@ namespace Aitex.UI.RecipeEditor
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void RecipeStepToGridColumn(RecipeStep recipeStep, Grid grid)
|
|
|
+ {
|
|
|
+ Type recipeType = recipeStep.GetType();
|
|
|
+ int i = 0;
|
|
|
+
|
|
|
+ if (grid.ColumnDefinitions.Count == 0)
|
|
|
+ {
|
|
|
+ ColumnDefinition col1 = new ColumnDefinition();//Key
|
|
|
+ grid.ColumnDefinitions.Add(col1);
|
|
|
+ }
|
|
|
+ ColumnDefinition col2 = new ColumnDefinition();//Value
|
|
|
+ grid.ColumnDefinitions.Add(col2);
|
|
|
+
|
|
|
+ foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
|
|
|
+ {
|
|
|
+ string propertyInfoName = propertyInfo.Name;
|
|
|
+ string propertyTypeName = propertyInfo.PropertyType.Name;
|
|
|
+ if (propertyInfoName != "LstUnit")
|
|
|
+ {
|
|
|
+ RowDefinition row1 = new RowDefinition();
|
|
|
+ grid.RowDefinitions.Add(row1);
|
|
|
+
|
|
|
+ Binding binding = new Binding()
|
|
|
+ {
|
|
|
+ Source = recipeStep, // 数据源
|
|
|
+ Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
|
|
|
+ Mode = BindingMode.TwoWay, // 绑定模式
|
|
|
+ UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
|
|
|
+ };
|
|
|
+ switch (propertyTypeName)
|
|
|
+ {
|
|
|
+ case "Int32":
|
|
|
+ case "String":
|
|
|
+ TextBox textBox = new TextBox();
|
|
|
+ textBox.SetBinding(TextBox.TextProperty, binding);
|
|
|
+ grid.Children.Add(textBox);
|
|
|
+ Grid.SetRow(textBox, i);
|
|
|
+ Grid.SetColumn(textBox, grid.ColumnDefinitions.Count - 1);
|
|
|
+ object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
|
|
|
+ if (objAttrs.Length > 0)
|
|
|
+ {
|
|
|
+ textBox.IsReadOnly = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "Boolean":
|
|
|
+ CheckBox checkBox = new CheckBox();
|
|
|
+ checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
|
|
|
+ grid.Children.Add(checkBox);
|
|
|
+ Grid.SetRow(checkBox, i);
|
|
|
+ Grid.SetColumn(checkBox, grid.ColumnDefinitions.Count - 1);
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ ComboBox comboBox = new ComboBox();
|
|
|
+ comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
|
|
|
+ ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
|
|
|
+ grid.Children.Add(comboBox);
|
|
|
+ Grid.SetRow(comboBox, i);
|
|
|
+ Grid.SetColumn(comboBox, grid.ColumnDefinitions.Count - 1);
|
|
|
+ if (propertyInfo.Name == "PressureUnitMode")
|
|
|
+ {
|
|
|
+ comboBox.SelectionChanged += ComboBox_SelectionChanged;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (grid.ColumnDefinitions.Count == 2)
|
|
|
+ {
|
|
|
+ TextBlock textBlock = new TextBlock();
|
|
|
+ textBlock.Text = propertyInfoName;
|
|
|
+ grid.Children.Add(textBlock);
|
|
|
+
|
|
|
+ Grid.SetRow(textBlock, i);
|
|
|
+ Grid.SetColumn(textBlock, 0);
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //ContextMenu contextmenu = new ContextMenu();
|
|
|
+ //contextmenu.Tag = grid;
|
|
|
+ //grid.ContextMenu = contextmenu;
|
|
|
+ //MenuItem menuItemDelete = new MenuItem();
|
|
|
+ //menuItemDelete.Header = "删除";
|
|
|
+ //menuItemDelete.Click += MenuItemDelete_Click;
|
|
|
+
|
|
|
+ //MenuItem menuItemInsert = new MenuItem();
|
|
|
+ //menuItemInsert.Header = "左插入";
|
|
|
+ //menuItemInsert.Click += MenuItemInsert_Click;
|
|
|
+
|
|
|
+ //contextmenu.Items.Add(menuItemDelete);
|
|
|
+ //contextmenu.Items.Add(menuItemInsert);
|
|
|
+
|
|
|
+ List<int> ints = new List<int>();
|
|
|
+
|
|
|
+ ints.Add(recipeType.GetProperties().Length);
|
|
|
+ int k = 0;
|
|
|
+ recipeStep.LstUnit.ToList().ForEach(x =>
|
|
|
+ {
|
|
|
+ Type unitType = x.GetType();
|
|
|
+ foreach (PropertyInfo propertyInfo in unitType.GetProperties())
|
|
|
+ {
|
|
|
+ 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 //触发器
|
|
|
+ };
|
|
|
+ RowDefinition row1 = new RowDefinition();
|
|
|
+ grid.RowDefinitions.Add(row1);
|
|
|
+ var item = propertyInfo.PropertyType.Name;
|
|
|
+ if (propertyInfo.Name == "UnitName")
|
|
|
+ {
|
|
|
+ TextBlock textBlock1 = new TextBlock();
|
|
|
+
|
|
|
+ //textBlock1.SetBinding(TextBlock.TextProperty, binding);
|
|
|
+ textBlock1.Text = propertyInfo.GetValue(x).ToString();
|
|
|
+ textBlock1.Foreground = Brushes.Red;
|
|
|
+ //textBlock1.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
+ grid.Children.Add(textBlock1);
|
|
|
+ Grid.SetRow(textBlock1, i);
|
|
|
+ Grid.SetColumn(textBlock1, grid.ColumnDefinitions.Count - 1);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ switch (item)
|
|
|
+ {
|
|
|
+ case "Int32":
|
|
|
+ case "String":
|
|
|
+ TextBox textBox = new TextBox();
|
|
|
+ textBox.BorderBrush = Brushes.Transparent;
|
|
|
+ textBox.SetBinding(TextBox.TextProperty, binding);
|
|
|
+ grid.Children.Add(textBox);
|
|
|
+ Grid.SetRow(textBox, i);
|
|
|
+ Grid.SetColumn(textBox, grid.ColumnDefinitions.Count - 1);
|
|
|
+ object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
|
|
|
+ if (objAttrs.Length > 0)
|
|
|
+ {
|
|
|
+ textBox.IsReadOnly = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "Boolean":
|
|
|
+ CheckBox checkBox = new CheckBox();
|
|
|
+ checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
|
|
|
+ grid.Children.Add(checkBox);
|
|
|
+ Grid.SetRow(checkBox, i);
|
|
|
+ Grid.SetColumn(checkBox, grid.ColumnDefinitions.Count - 1);
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ ComboBox comboBox = new ComboBox();
|
|
|
+ comboBox.BorderBrush = Brushes.Transparent;
|
|
|
+ //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, grid.ColumnDefinitions.Count - 1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (grid.ColumnDefinitions.Count == 2)
|
|
|
+ {
|
|
|
+ TextBlock textBlock = new TextBlock();
|
|
|
+ textBlock.Text = propertyInfo.Name;
|
|
|
+ grid.Children.Add(textBlock);
|
|
|
+ Grid.SetRow(textBlock, i);
|
|
|
+ Grid.SetColumn(textBlock, 0);
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ ints.Add(unitType.GetProperties().Length);
|
|
|
+ k++;
|
|
|
+ });
|
|
|
+ //return new ValueTuple<Grid, List<int>>(grid, ints);
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// step转换为Grid
|
|
|
/// </summary>
|