refactor: 将Framework库和RT、UI放在同一个解决方案中。

This commit is contained in:
SL
2026-06-01 17:48:28 +08:00
parent 1948f4290d
commit b73d39a6b1
4331 changed files with 506148 additions and 49363 deletions
@@ -0,0 +1,184 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Xml;
using DocumentFormat.OpenXml.Spreadsheet;
using MECF.Framework.Common.RecipeCenter;
using MECF.Framework.UI.Client.RecipeEditorLib.DGExtension.CustomColumn;
namespace MECF.Framework.UI.Client.CenterViews.Editors.Sequence
{
public class SequenceColumnBuilder
{
public ObservableCollection<EditorDataGridTemplateColumnBase> Build()
{
var temp = RecipeClient.Instance.Service.GetSequenceFormatXml();
var doc = new XmlDocument();
doc.LoadXml(temp);
var columns = new ObservableCollection<EditorDataGridTemplateColumnBase>();
EditorDataGridTemplateColumnBase col;
//step number
col = new StepColumn()
{
DisplayName = "Step",
ControlName = "Step",
StringCellTemplate = "TemplateStep",
StringHeaderTemplate = "SequenceColumnHeaderTemplate"
};
columns.Add(col);
var nodes = doc.SelectNodes("TableSequenceFormat/Catalog/Item");
foreach (XmlNode node in nodes)
{
switch (node.Attributes["InputType"].Value)
{
case "TextInput":
col = new TextBoxColumn()
{
ControlName = node.Attributes["Name"].Value,
DisplayName = node.Attributes["DisplayName"].Value,
StringCellTemplate = "TemplateText",
StringHeaderTemplate = "SequenceColumnHeaderTemplate"
};
columns.Add(col);
break;
case "ReadOnly":
col = new TextBoxColumn()
{
ControlName = node.Attributes["Name"].Value,
DisplayName = node.Attributes["DisplayName"].Value,
StringCellTemplate = "TemplateText",
StringHeaderTemplate = "SequenceColumnHeaderTemplate"
};
columns.Add(col);
break;
case "NumInput":
col = new NumColumn()
{
ControlName = node.Attributes["Name"].Value,
DisplayName = node.Attributes["DisplayName"].Value,
//Minimun = int.Parse(node.Attributes["Min"].Value),
//Maximun = int.Parse(node.Attributes["Max"].Value),
StringCellTemplate = "TemplateSignInteger",
StringHeaderTemplate = "SequenceColumnHeaderTemplate"
};
columns.Add(col);
break;
case "RecipeSelection":
col = new RecipeSelectColumn()
{
IsReadOnly = true,
ControlName = node.Attributes["Name"].Value,
DisplayName = node.Attributes["DisplayName"].Value,
RecipeProcessType = node.Attributes["Parameter"].Value,
StringCellTemplate = "TemplateRecipeSelection",
StringHeaderTemplate = "SequenceColumnHeaderTemplate",
};
columns.Add(col);
break;
case "EditableSelection":
case "ReadOnlySelection":
if (node.Attributes["Name"].Value == "Position")
{
col = new PositionColumn()
{
ControlName = node.Attributes["Name"].Value,
DisplayName = node.Attributes["DisplayName"].Value,
StringCellTemplate = "TemplateCombox",
StringHeaderTemplate = "SequenceColumnHeaderTemplate"
};
var items = node.SelectNodes("Selection");
if (items == null)
break;
foreach (XmlElement item in items)
{
var controlName = item.Attributes["Name"].Value;
var displayName = item.Attributes["DisplayName"].Value;
var param = string.Empty;
if (item.HasAttribute("Parameter"))
param = item.Attributes["Parameter"].Value;
var opt = new ComboxColumn.Option(controlName, displayName, param);
((PositionColumn)col).Options.Add(opt);
}
}
else
{
col = new ComboxColumn()
{
ControlName = node.Attributes["Name"].Value,
DisplayName = node.Attributes["DisplayName"].Value,
StringCellTemplate = "TemplateCombox",
StringHeaderTemplate = "SequenceColumnHeaderTemplate"
};
var items = node.SelectNodes("Selection");
if (items == null)
break;
foreach (XmlElement item in items)
{
var controlName = item.Attributes["Name"].Value;
var displayName = item.Attributes["DisplayName"].Value;
var param = string.Empty;
if (item.HasAttribute("Parameter"))
param = item.Attributes["Parameter"].Value;
var opt = new ComboxColumn.Option(controlName, displayName, param);
((ComboxColumn)col).Options.Add(opt);
}
}
columns.Add(col);
break;
case "MultiSelection":
col = new MultipleSelectColumn()
{
ControlName = node.Attributes["Name"].Value,
DisplayName = node.Attributes["DisplayName"].Value,
StringCellTemplate = "TemplateMultiSelection",
StringHeaderTemplate = "SequenceColumnHeaderTemplate"
};
var multiSelItems = node.SelectNodes("Selection");
if (multiSelItems == null)
break;
foreach (XmlNode item in multiSelItems)
{
var opt = new MultipleSelectColumn.Option();
opt.IsChecked = false;
opt.ControlName = item.Attributes["Name"].Value;
opt.DisplayName = item.Attributes["DisplayName"].Value;
if (item.Attributes["Parameter"] != null)
opt.RelatedParameters = item.Attributes["Parameter"].Value;
((MultipleSelectColumn)col).Options.Add(opt);
}
columns.Add(col);
break;
}
}
return columns;
}
public static void ApplyTemplate(UserControl uc, ObservableCollection<EditorDataGridTemplateColumnBase> columns)
{
columns.ToList().ForEach(col =>
{
col.CellTemplate = (DataTemplate)uc.FindResource(col.StringCellTemplate);
col.HeaderTemplate = (DataTemplate)uc.FindResource(col.StringHeaderTemplate);
});
}
}
}
@@ -0,0 +1,316 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Xml;
using Caliburn.Micro.Core;
using MECF.Framework.UI.Client.RecipeEditorLib.DGExtension.CustomColumn;
using MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel;
using MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel.Params;
namespace MECF.Framework.UI.Client.CenterViews.Editors.Sequence
{
public class SequenceData : PropertyChangedBase
{
public SequenceData()
{
Steps = new RecipeStepCollection();
}
public RecipeStepCollection Steps { get; set; }
public RecipeStep CreateStep(ObservableCollection<EditorDataGridTemplateColumnBase> columns, XmlNode step = null)
{
PositionParam posParam = null;
var posValue = string.Empty;
var Params = new RecipeStep(null);
foreach (var col in columns)
{
Param param = null;
var value = string.Empty;
if (!(col is ExpanderColumn) && step != null && !(col is StepColumn))
{
if (step.Attributes[col.ControlName] != null)
value = step.Attributes[col.ControlName].Value;
}
if (col is StepColumn)
{
param = new StepParam()
{
ControlName = col.ControlName
};
}
else if (col is TextBoxColumn)
{
param = new StringParam()
{
ControlName = col.ControlName,
Value = value,
IsEnabled = !col.IsReadOnly
};
}
else if (col is NumColumn)
{
if (!string.IsNullOrEmpty(value))
param = new IntParam() { ControlName = col.ControlName, Value = int.Parse(value), IsEnabled = !col.IsReadOnly };
else
param = new IntParam() { ControlName = col.ControlName, Value = 0, IsEnabled = !col.IsReadOnly };
}
else if (col is ComboxColumn)
{
var options = ((ComboxColumn)col).Options;
param = new ComboxParam(options, col.ControlName, value, col.Default);
}
else if (col is PositionColumn)
{
posParam = new PositionParam()
{
ControlName = col.ControlName,
Options = ((PositionColumn)col).Options,
IsEnabled = !col.IsReadOnly
};
param = posParam;
posValue = value;
}
else if (col is ExpanderColumn)
{
param = new ExpanderParam() { };
}
else if (col is RecipeSelectColumn)
{
var path = ((RecipeSelectColumn) col).RecipeProcessType;
if (!string.IsNullOrEmpty(path) && value.StartsWith(path))
{
value = value.Substring(path.Length + 1);
}
param = new PathFileParam(col.ControlName, !col.IsReadOnly, ((RecipeSelectColumn)col).RecipeProcessType)
{
Value = value,
};
}
else if (col is MultipleSelectColumn)
{
param = new MultipleSelectParam((MultipleSelectColumn)col) { ControlName = col.ControlName, IsEnabled = !col.IsReadOnly };
var opts = value.Split(',');
((MultipleSelectParam)param).Options.Apply(opt => {
for(var index = 0; index < opts.Length; index++)
{
if (opt.ControlName == opts[index])
{
opt.IsChecked = true;
break;
}
}
});
}
param.Save();
param.Parent = Params;
param.ColumnOwner = col;
Params.Add(param);
}
posParam.Value = posValue;
return Params;
}
public RecipeStep CloneStep(ObservableCollection<EditorDataGridTemplateColumnBase> columns, RecipeStep sourceStep)
{
var targetParams = this.CreateStep(columns);
PositionParam posParam = null;
var posValue = string.Empty;
for (var index = 0; index < sourceStep.Count; index++)
{
if (sourceStep[index] is PositionParam)
{
posParam = (PositionParam)targetParams[index];
posValue = ((PositionParam)sourceStep[index]).Value;
}
else if (sourceStep[index] is StringParam)
{
((StringParam)targetParams[index]).Value = ((StringParam)sourceStep[index]).Value;
}
else if (sourceStep[index] is PathFileParam)
{
((PathFileParam)targetParams[index]).Value = ((PathFileParam)sourceStep[index]).Value;
((PathFileParam)targetParams[index]).PrefixPath = ((PathFileParam)sourceStep[index]).PrefixPath;
}
else if (sourceStep[index] is IntParam)
{
((IntParam)targetParams[index]).Value = ((IntParam)sourceStep[index]).Value;
}
else if (sourceStep[index] is ComboxParam)
{
((ComboxParam)targetParams[index]).Value = ((ComboxParam)sourceStep[index]).Value;
}
else if (sourceStep[index] is BoolParam)
{
((BoolParam)targetParams[index]).Value = ((BoolParam)sourceStep[index]).Value;
}
else if (sourceStep[index] is IntParam)
{
((IntParam)targetParams[index]).Value = ((IntParam)sourceStep[index]).Value;
}
else if (sourceStep[index] is DoubleParam)
{
((DoubleParam)targetParams[index]).Value = ((DoubleParam)sourceStep[index]).Value;
}
targetParams[index].Parent = targetParams;
}
posParam.Value = posValue;
return targetParams;
}
public void LoadSteps(ObservableCollection<EditorDataGridTemplateColumnBase> _columns, XmlNodeList _steps)
{
foreach (XmlNode _step in _steps)
{
this.Steps.Add(this.CreateStep(_columns, _step));
}
}
public void Load(ObservableCollection<EditorDataGridTemplateColumnBase> _columns, XmlDocument doc)
{
var node = doc.SelectSingleNode("Aitex/TableSequenceData");
if (node.Attributes["CreatedBy"] != null)
this.Creator = node.Attributes["CreatedBy"].Value;
if (node.Attributes["CreationTime"] != null)
this.CreateTime = DateTime.Parse(node.Attributes["CreationTime"].Value);
if (node.Attributes["LastRevisedBy"] != null)
this.Revisor = node.Attributes["LastRevisedBy"].Value;
if (node.Attributes["LastRevisionTime"] != null)
this.ReviseTime = DateTime.Parse(node.Attributes["LastRevisionTime"].Value);
if (node.Attributes["Description"] != null)
this.Description = node.Attributes["Description"].Value;
foreach (XmlNode _step in doc.SelectNodes("Aitex/TableSequenceData/Step"))
{
Steps.Add(this.CreateStep(_columns, _step));
}
}
public string ToXml()
{
var builder = new StringBuilder();
builder.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
builder.Append(string.Format("<Aitex><TableSequenceData CreatedBy=\"{0}\" CreationTime=\"{1}\" LastRevisedBy=\"{2}\" LastRevisionTime=\"{3}\" Description=\"{4}\" >", this.Creator, this.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), this.Revisor, this.ReviseTime.ToString("yyyy-MM-dd HH:mm:ss"), this.Description));
foreach (var parameters in Steps)
{
builder.Append("<Step ");
foreach (var parameter in parameters)
{
if (parameter.Visible == System.Windows.Visibility.Visible)
{
if (parameter is IntParam)
builder.Append(parameter.ControlName + "=\"" + ((IntParam)parameter).Value + "\" ");
else if (parameter is DoubleParam)
builder.Append(parameter.ControlName + "=\"" + ((DoubleParam)parameter).Value + "\" ");
else if (parameter is StringParam)
builder.Append(parameter.ControlName + "=\"" + ((StringParam)parameter).Value + "\" ");
else if (parameter is PathFileParam)
builder.Append(parameter.ControlName + "=\"" + ((PathFileParam)parameter).Value + "\" ");
else if (parameter is ComboxParam)
builder.Append(parameter.ControlName + "=\"" + ((ComboxParam)parameter).Value + "\" ");
else if (parameter is PositionParam)
builder.Append(parameter.ControlName + "=\"" + ((PositionParam)parameter).Value + "\" ");
else if (parameter is BoolParam)
builder.Append(parameter.ControlName + "=\"" + ((BoolParam)parameter).Value + "\" ");
else if (parameter is MultipleSelectParam)
{
var selected = new List<string>();
((MultipleSelectParam)parameter).Options.Apply(
opt =>
{
if (opt.IsChecked)
selected.Add(opt.ControlName);
}
);
builder.Append(parameter.ControlName + "=\"" + string.Join(",", selected) + "\" ");
}
}
}
builder.Append("/>");
}
builder.Append("</TableSequenceData></Aitex>");
return builder.ToString();
}
private string name;
public string Name
{
get { return this.name; }
set
{
this.name = value;
this.NotifyOfPropertyChange("Name");
}
}
private string creator;
public string Creator
{
get { return this.creator; }
set
{
this.creator = value;
this.NotifyOfPropertyChange("Creator");
}
}
private DateTime createTime;
public DateTime CreateTime
{
get { return this.createTime; }
set
{
this.createTime = value;
this.NotifyOfPropertyChange("CreateTime");
}
}
private string description;
public string Description
{
get { return this.description; }
set
{
this.description = value;
this.NotifyOfPropertyChange("Description");
}
}
private string devisor;
public string Revisor
{
get { return this.devisor; }
set
{
this.devisor = value;
this.NotifyOfPropertyChange("Revisor");
}
}
private DateTime deviseTime;
public DateTime ReviseTime
{
get { return this.deviseTime; }
set
{
this.deviseTime = value;
this.NotifyOfPropertyChange("ReviseTime");
}
}
}
}
@@ -0,0 +1,87 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml;
using MECF.Framework.Common.Equipment;
using MECF.Framework.Common.RecipeCenter;
using MECF.Framework.UI.Client.RecipeEditorLib.DGExtension.CustomColumn;
using OpenSEMI.ClientBase.ServiceProvider;
namespace MECF.Framework.UI.Client.CenterViews.Editors.Sequence
{
public class SequenceDataProvider : IProvider
{
private static SequenceDataProvider _Instance = null;
public static SequenceDataProvider Instance
{
get
{
if (_Instance == null)
_Instance = new SequenceDataProvider();
return _Instance;
}
}
public void Create()
{
}
public bool CreateSequenceFolder(string foldername)
{
return RecipeClient.Instance.Service.CreateSequenceFolder(foldername);
}
public bool DeleteSequenceFolder(string foldername)
{
return RecipeClient.Instance.Service.DeleteSequenceFolder(foldername);
}
public bool Save(SequenceData seq)
{
return RecipeClient.Instance.Service.SaveSequence(seq.Name, seq.ToXml());
}
public List<string> GetSequences()
{
return RecipeClient.Instance.Service.GetSequenceNameList();
}
public List<string> GetRecipes(ModuleName modulename)
{
return RecipeClient.Instance.Service.GetRecipes(modulename, true).ToList();
}
public SequenceData GetSequenceByName(ObservableCollection<EditorDataGridTemplateColumnBase> _columns, string name)
{
string content = RecipeClient.Instance.Service.GetSequence(name);
SequenceData seq = new SequenceData();
XmlDocument doc = new XmlDocument();
doc.LoadXml(content);
seq.Name = name;
seq.Load(_columns, doc);
return seq;
}
public bool Rename(string beforename, string currentname)
{
return RecipeClient.Instance.Service.RenameSequence(beforename, currentname);
}
public bool Delete(string name)
{
return RecipeClient.Instance.Service.DeleteSequence(name);
}
public bool SaveAs(string name, SequenceData seq)
{
return RecipeClient.Instance.Service.SaveAsSequence(name, seq.ToXml());
}
public string GetSequenceFromXml()
{
string template = RecipeClient.Instance.Service.GetSequenceFormatXml();
return template;
}
}
}
@@ -0,0 +1,802 @@
<UserControl
x:Class="MECF.Framework.UI.Client.CenterViews.Editors.Sequence.SequenceView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:OpenSEMI.Ctrlib.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dgExtension="clr-namespace:MECF.Framework.UI.Client.RecipeEditorLib.DGExtension"
xmlns:editors="clr-namespace:MECF.Framework.UI.Client.CenterViews.Editors"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:micro="clr-namespace:Caliburn.Micro"
xmlns:sequence="clr-namespace:MECF.Framework.UI.Client.CenterViews.Editors.Sequence"
d:Background="LightSteelBlue"
d:DataContext="{d:DesignInstance Type=sequence:SequenceViewModel,
IsDesignTimeCreatable=False}"
d:DesignHeight="450"
d:DesignWidth="1900"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="Sicentury.Localization"
lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
mc:Ignorable="d">
<UserControl.Resources>
<DataTemplate x:Key="SequenceColumnHeaderTemplate">
<Grid Width="250" Margin="0,5">
<Grid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Grid.LayoutTransform>
<TextBlock
Margin="5,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="16"
Text="{Binding DisplayName}" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="TemplateTextBlock">
<Grid>
<Grid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Grid.LayoutTransform>
<Border
Width="150"
Height="30"
Padding="5,1"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<TextBlock
Width="Auto"
FontSize="14"
Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding Visible}" />
</Border>
</Grid>
</DataTemplate>
<DataTemplate x:Key="TemplateStep">
<Grid>
<Grid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Grid.LayoutTransform>
<Border
Width="150"
Height="30"
Padding="5,1"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,1,1,1">
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Horizontal">
<controls:CheckBoxExt
Margin="0,4"
CheckBoxSaved="{Binding IsSaved, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsChecked="{Binding IsChecked}" />
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
Text="{Binding Value}"
Visibility="{Binding Visible}" />
</StackPanel>
</Border>
</Grid>
</DataTemplate>
<DataTemplate x:Key="TemplateText">
<Grid>
<Grid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Grid.LayoutTransform>
<Border
Width="150"
Height="30"
Padding="5,1"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<controls:TextBoxEx
Width="Auto"
FontSize="14"
IsEnabled="{Binding IsEnabled}"
Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextSaved="{Binding IsSaved, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding Visible}" />
</Border>
</Grid>
</DataTemplate>
<DataTemplate x:Key="TemplateSignInteger">
<Grid>
<Grid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Grid.LayoutTransform>
<Border
Width="150"
Padding="5,1"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<controls:TextBoxEx
Width="Auto"
EditBoxMode="SignInteger"
FontSize="14"
IsEnabled="{Binding IsEnabled}"
Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextSaved="{Binding IsSaved, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding Visible}" />
</Border>
</Grid>
</DataTemplate>
<DataTemplate x:Key="TemplateRecipeSelection">
<Grid>
<Grid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Grid.LayoutTransform>
<Border
Width="150"
Height="30"
Padding="5,1"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<controls:TextBoxEx
Width="Auto"
IsReadOnly="True"
Text="{Binding FileName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextSaved="True"
ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"
Visibility="{Binding Visible}" />
<Button
Grid.Column="1"
Width="25"
Height="23"
Margin="3,0,0,0"
Content="..."
Focusable="False"
FontSize="10"
Visibility="{Binding Visible}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="SelectRecipe">
<micro:Parameter Value="{Binding}" />
</micro:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
</Border>
</Grid>
</DataTemplate>
<DataTemplate x:Key="TemplateCombox">
<Grid>
<Grid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Grid.LayoutTransform>
<Border
Width="150"
Padding="5,1"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<controls:ComboBoxExt
ComboBoxSaved="{Binding IsSaved, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="DisplayName"
IsEnabled="{Binding IsEnabled}"
ItemsSource="{Binding Options}"
SelectedValue="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedValuePath="ControlName"
Style="{StaticResource ResourceKey={x:Type ComboBox}}"
Visibility="{Binding Visible}" />
</Border>
</Grid>
</DataTemplate>
<DataTemplate x:Key="TemplateMultiSelection">
<Grid>
<Grid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Grid.LayoutTransform>
<Border
MinHeight="30"
Padding="5,1"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<ListBox ItemsSource="{Binding Options}" Visibility="{Binding Visible}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5,5" Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsChecked, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Text="{Binding DisplayName}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel
Width="139"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Border>
</Grid>
</DataTemplate>
<DataTemplate x:Key="ParamExpander">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding DisplayName}" />
<Expander
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Left"
VerticalContentAlignment="Stretch"
IsExpanded="{Binding IsExpanded}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Expanded">
<micro:ActionMessage MethodName="ParamsExpanded">
<micro:Parameter Value="{Binding}" />
</micro:ActionMessage>
</i:EventTrigger>
<i:EventTrigger EventName="Collapsed">
<micro:ActionMessage MethodName="ParamsCollapsed">
<micro:Parameter Value="{Binding}" />
</micro:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
</Expander>
<Grid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Grid.LayoutTransform>
</Grid>
</DataTemplate>
<DataTemplate x:Key="TemplateExpander">
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="14">
<TextBlock.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</TextBlock.LayoutTransform>
</TextBlock>
</DataTemplate>
<HierarchicalDataTemplate x:Key="FolderTemplate" ItemsSource="{Binding Files}">
<StackPanel Orientation="Horizontal" Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=DataContext}">
<Image
x:Name="ExpandImage"
Width="14"
Height="12"
Margin="2,0,0,0"
VerticalAlignment="Center"
Source="/MECF.Framework.UI.Client;component/Resources/Images/Folder_Close.png" />
<TextBlock
Margin="5,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{Binding Name}" />
<StackPanel.ContextMenu>
<ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
<MenuItem Command="{Binding NewSequenceCommand}" Header="Create Sequence" />
<Separator />
<MenuItem Command="{Binding NewFolderCommand}" Header="Create Folder" />
<MenuItem Command="{Binding DeleteFolderCommand}" Header="Delete Folder" />
</ContextMenu>
</StackPanel.ContextMenu>
</StackPanel>
<HierarchicalDataTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="ExpandImage" Property="Image.Source" Value="/MECF.Framework.UI.Client;component/Resources/Images/Folder_Unable.png" />
</Trigger>
<!--<DataTrigger Binding="{Binding HasItems}" Value="True">
<Setter Property="Image.Source" TargetName="ExpandImage" Value="Folder_Open.png"/>
</DataTrigger>-->
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="FileTemplate" ItemsSource="{Binding Files}">
<StackPanel Orientation="Horizontal" Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=DataContext}">
<Path
Width="13"
Height="16"
HorizontalAlignment="Left"
Data="M0.5,5.125 L5.125,5.125 5.125,0.5 M5.1,0.5 L15.5,0.5 15.5,19.5 0.5,19.5 C0.5,14.7 0.5,10 0.5,5.1 2,3.6 3.6,2 5.1,0.5 z M8.1,8.5 L8.2,8.5 z M8.1,11.5 L8.2,11.5 z M8.1,14.5 L8.2,14.5 z"
Fill="#FFF3F3F3"
Stretch="Fill"
Stroke="#FF454545" />
<TextBlock
Margin="5,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{Binding Name}" />
<StackPanel.ContextMenu>
<ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
<MenuItem Command="{Binding SaveAsCommand}" Header="Save As..." />
<MenuItem Command="{Binding RenameCommand}" Header="Rename Sequence" />
<MenuItem Command="{Binding DeleteSequenceCommand}" Header="Delete Sequence" />
</ContextMenu>
</StackPanel.ContextMenu>
</StackPanel>
</HierarchicalDataTemplate>
<editors:FolderOrFileTemplateSelector
x:Key="FolderFileTemplateSelector"
FileTemplate="{StaticResource FileTemplate}"
FolderTemplate="{StaticResource FolderTemplate}" />
</UserControl.Resources>
<Grid HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="275" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<GridSplitter
Width="5"
Margin="0,0,-5,0"
HorizontalAlignment="Right"
BorderThickness="0,8">
<GridSplitter.Background>
<SolidColorBrush />
</GridSplitter.Background>
</GridSplitter>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="740" />
</Grid.RowDefinitions>
<StackPanel IsEnabled="{Binding IsPermission}" Orientation="Horizontal">
<Button
Width="76"
Height="30"
Content="{lex:Loc ID_BTN_New_Content}"
IsEnabled="{Binding EnableNew}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="NewSequence" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button
Width="76"
Height="30"
Margin="2,0,0,0"
Content="{lex:Loc ID_BTN_Rename_Content}"
IsEnabled="{Binding EnableReName}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="RenameSequence" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button
Width="76"
Height="30"
Margin="2,0,0,0"
Content="{lex:Loc ID_BTN_Delete_Content}"
IsEnabled="{Binding EnableDelete}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="DeleteSequence" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button
Width="76"
Height="30"
Margin="2,0,0,0"
Content="{lex:Loc ID_BTN_Refresh_Content}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="RefreshSequence" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
<Border
Grid.Row="1"
Margin="0,5,0,0"
Background="{DynamicResource Tab_BG}"
BorderBrush="{DynamicResource Tab_BD}"
BorderThickness="1">
<TreeView
x:Name="PART_TREE"
Grid.Row="1"
Height="{Binding Path=ActualHeight, ElementName=PART_BORDER, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
Margin="5"
ItemTemplateSelector="{StaticResource FolderFileTemplateSelector}"
ItemsSource="{Binding Files[0].Files}"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling">
<!-- Height should add for VirtualizingPanel, otherwise the App will be slow -->
<TreeView.ItemContainerStyle>
<Style BasedOn="{StaticResource ResourceKey={x:Type TreeViewItem}}" TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True" />
</Style>
</TreeView.ItemContainerStyle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectedItemChanged">
<micro:ActionMessage MethodName="TreeSelectChanged">
<micro:Parameter Value="{Binding SelectedItem, ElementName=PART_TREE}" />
</micro:ActionMessage>
</i:EventTrigger>
<i:EventTrigger EventName="MouseRightButtonDown">
<micro:ActionMessage MethodName="TreeRightMouseDown">
<micro:Parameter Value="$eventargs" />
</micro:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding NewSequenceInParentCommand}" Header="New Sequence" />
<Separator />
<!--<MenuItem Header="New Folder" Command="{Binding NewFolderInParentCommand}">
</MenuItem>-->
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</Border>
</Grid>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid
Width="1600"
Margin="10,0,0,0"
HorizontalAlignment="Left"
IsEnabled="{Binding IsPermission}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="8*" />
<ColumnDefinition Width="8*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border
Padding="5,1"
Background="{DynamicResource Table_BG_Title}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="1">
<TextBlock
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="16"
Foreground="{DynamicResource FG_Black}"
Text="{lex:Loc ID_TXT_Name}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Column="1"
Padding="5,1"
Background="{DynamicResource Table_BG_Content}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,1,1,1">
<controls:TextBoxEx
Width="Auto"
MinWidth="100"
VerticalAlignment="Center"
AllowBackgroundChange="False"
IsEnabled="false"
Text="{Binding CurrentSequence.Name}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Column="2"
Padding="5,1"
Background="{DynamicResource Table_BG_Title}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,1,1,1">
<TextBlock
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="16"
Foreground="{DynamicResource FG_Black}"
Text="{lex:Loc ID_TXT_Create}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Column="3"
Padding="5,1"
Background="{DynamicResource Table_BG_Content}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,1,1,1">
<TextBlock
Width="Auto"
MinWidth="100"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="14"
Foreground="{DynamicResource FG_Black}"
Text="{Binding CurrentSequence.Creator}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Column="4"
Padding="5,1"
Background="{DynamicResource Table_BG_Content}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,1,1,1">
<TextBlock
Width="Auto"
MinWidth="100"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="14"
Foreground="{DynamicResource FG_Black}"
Text="{Binding CurrentSequence.CreateTime}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Row="1"
Padding="5,1"
Background="{DynamicResource Table_BG_Title}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="1,0,1,1">
<TextBlock
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="16"
Foreground="{DynamicResource FG_Black}"
Text="{lex:Loc ID_TXT_Description}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Row="1"
Grid.Column="1"
Padding="5,1"
Background="{DynamicResource Table_BG_Content}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<controls:TextBoxEx
Width="Auto"
MinWidth="100"
VerticalAlignment="Center"
Text="{Binding CurrentSequence.Description}"
TextSaved="{Binding IsSavedDesc, Mode=TwoWay}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Row="1"
Grid.Column="2"
Padding="5,1"
Background="{DynamicResource Table_BG_Title}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<TextBlock
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="16"
Foreground="{DynamicResource FG_Black}"
Text="{lex:Loc ID_TXT_Revise}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Row="1"
Grid.Column="3"
Padding="5,1"
Background="{DynamicResource Table_BG_Content}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<TextBlock
Width="120"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="14"
Foreground="{DynamicResource FG_Black}"
Text="{Binding CurrentSequence.Revisor}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Row="1"
Grid.Column="4"
Padding="5,1"
Background="{DynamicResource Table_BG_Content}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<TextBlock
MinWidth="140"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="14"
Foreground="{DynamicResource FG_Black}"
Text="{Binding CurrentSequence.ReviseTime}"
TextWrapping="Wrap" />
</Border>
</Grid>
<Grid Grid.Row="1" Margin="10,10,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid>
<StackPanel IsEnabled="{Binding IsPermission}" Orientation="Horizontal">
<Button
Width="90"
Height="30"
Content="{lex:Loc ID_BTN_Append_Content}"
IsEnabled="{Binding EnableStep}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="AddStep" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button
Width="90"
Height="30"
Margin="10,0,0,0"
Content="{lex:Loc ID_BTN_Insert_Content}"
IsEnabled="{Binding EnableStep}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="AppendStep" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button
Width="90"
Height="30"
Margin="10,0,0,0"
Content="{lex:Loc ID_BTN_Copy_Content}"
IsEnabled="{Binding EnableStep}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="CopyStep" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button
Width="90"
Height="30"
Margin="10,0,0,0"
Content="{lex:Loc ID_BTN_Paste_Content}"
IsEnabled="{Binding EnableStep}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="PasteStep" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button
Width="90"
Height="30"
Margin="10,0,0,0"
Content="{lex:Loc ID_BTN_Delete_Content}"
IsEnabled="{Binding EnableStep}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="DeleteStep" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button
Width="90"
Height="30"
Margin="200,0,0,0"
Content="{lex:Loc ID_BTN_Reload_Content}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="ReloadSequence" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button
Width="90"
Height="30"
Margin="10,0,0,0"
Content="{lex:Loc ID_BTN_Save_Content}"
IsEnabled="{Binding EnableSave}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="SaveSequence" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
</Grid>
<Grid
Grid.Row="1"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<dgExtension:XDataGrid
x:Name="dgCustom"
AlternationCount="2"
AutoGenerateColumns="False"
Background="#00FFFFFF"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
GridLinesVisibility="None"
HeadersVisibility="Column"
IsEnabled="{Binding IsPermission}"
UseHorizontalScrolling="True"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling">
<dgExtension:XDataGrid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="-90" />
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</dgExtension:XDataGrid.LayoutTransform>
</dgExtension:XDataGrid>
</ScrollViewer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="263" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Rectangle
Height="1"
VerticalAlignment="Top"
Fill="{DynamicResource Table_BD}" />
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
</UserControl>
@@ -0,0 +1,15 @@
using System.Windows.Controls;
namespace MECF.Framework.UI.Client.CenterViews.Editors.Sequence
{
/// <summary>
/// SequenceView.xaml 的交互逻辑
/// </summary>
public partial class SequenceView : UserControl
{
public SequenceView()
{
InitializeComponent();
}
}
}
@@ -0,0 +1,961 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms.VisualStyles;
using System.Windows.Input;
using System.Windows.Media;
using Caliburn.Micro;
using Caliburn.Micro.Core;
using MECF.Framework.Common.OperationCenter;
using MECF.Framework.Common.RecipeCenter;
using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
using MECF.Framework.UI.Client.ClientBase;
using MECF.Framework.UI.Client.RecipeEditorLib.DGExtension.CustomColumn;
using MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel;
using MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel.Params;
using OpenSEMI.ClientBase;
using OpenSEMI.ClientBase.Command;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace MECF.Framework.UI.Client.CenterViews.Editors.Sequence
{
public class SequenceViewModel : BaseModel
{
public ObservableCollection<FileNode> Files { get; set; }
protected override void OnInitialize()
{
base.OnInitialize();
CurrentSequence = new SequenceData();
Columns = columnBuilder.Build();
editMode = EditMode.None;
IsSavedDesc = true;
var names = provider.GetSequences();
Files = new ObservableCollection<FileNode>(RecipeSequenceTreeBuilder.GetFiles("", names));
CurrentFileNode = Files[0];
SelectDefault(CurrentFileNode);
}
protected override void OnActivate()
{
base.OnActivate();
}
protected override void OnDeactivate(bool close)
{
base.OnDeactivate(close);
if (IsChanged)
{
if (DialogBox.Confirm("This sequence is changed,do you want to save it?"))
SaveSequence();
LoadData(CurrentSequence.Name);
}
}
protected override void OnViewLoaded(object view)
{
base.OnViewLoaded(view);
SequenceColumnBuilder.ApplyTemplate((UserControl)view, Columns);
var u = (SequenceView)view;
Columns.Apply((c) =>
{
c.Header = c;
u.dgCustom.Columns.Add(c);
});
u.dgCustom.ItemsSource = CurrentSequence.Steps;
UpdateView();
}
#region Sequence selection
public void TreeSelectChanged(FileNode file)
{
if (file != null && file.IsFile)
{
if (IsChanged)
if (DialogBox.Confirm("This sequence is changed,do you want to save it?"))
Save(CurrentSequence);
LoadData(file.FullPath);
CurrentFileNode = file;
}
else
{
ClearData();
editMode = EditMode.None;
CurrentSequence.Steps.Clear();
}
UpdateView();
}
private TreeViewItem GetParentObjectEx<TreeViewItem>(DependencyObject obj) where TreeViewItem : FrameworkElement
{
var parent = VisualTreeHelper.GetParent(obj);
while (parent != null)
{
if (parent is TreeViewItem)
{
return (TreeViewItem)parent;
}
parent = VisualTreeHelper.GetParent(parent);
}
return null;
}
public void TreeRightMouseDown(MouseButtonEventArgs e)
{
var item = GetParentObjectEx<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
if (item != null)
{
item.Focus();
}
}
#endregion
private ICommand _NotImplementCommand;
public ICommand NotImplementCommand
{
get
{
if (_NotImplementCommand == null)
_NotImplementCommand = new BaseCommand(() => NotImplement());
return _NotImplementCommand;
}
}
public void NotImplement()
{
DialogBox.ShowInfo("Not Implement");
}
#region Sequence operation
private ICommand _NewFolderCommand;
public ICommand NewFolderCommand
{
get
{
if (_NewFolderCommand == null)
_NewFolderCommand = new BaseCommand(() => NewFolder());
return _NewFolderCommand;
}
}
public void NewFolder()
{
if (!CurrentFileNode.IsFile)
{
var dialog = new InputFileNameDialogViewModel("Input Folder Name");
var wm = new WindowManager();
var bret = wm.ShowDialog(dialog);
if (!(bool)bret)
return;
var fullpath = (CurrentFileNode.FullPath == "" ? dialog.DialogResult : CurrentFileNode.FullPath + "\\" + dialog.DialogResult);
if (provider.CreateSequenceFolder(fullpath))
{
var folder = new FileNode();
folder.Name = dialog.DialogResult;
folder.FullPath = fullpath;
folder.Parent = CurrentFileNode;
CurrentFileNode.Files.Add(folder);
}
else
DialogBox.ShowError("Create folder failed!");
}
}
private ICommand _NewFolderInParentCommand;
public ICommand NewFolderInParentCommand
{
get
{
if (_NewFolderInParentCommand == null)
_NewFolderInParentCommand = new BaseCommand(() => NewFolderInParent());
return _NewFolderInParentCommand;
}
}
public void NewFolderInParent()
{
var dialog = new InputFileNameDialogViewModel("Input Folder Name");
var wm = new WindowManager();
var bret = wm.ShowDialog(dialog);
if (!(bool)bret)
return;
var fullpath = dialog.DialogResult;
if (provider.CreateSequenceFolder(fullpath))
{
var folder = new FileNode();
folder.Name = dialog.DialogResult;
folder.FullPath = fullpath;
folder.Parent = Files[0];
Files[0].Files.Add(folder);
}
else
DialogBox.ShowError("Create folder failed!");
}
private ICommand _NewSequenceInParentCommand;
public ICommand NewSequenceInParentCommand
{
get
{
if (_NewSequenceInParentCommand == null)
_NewSequenceInParentCommand = new BaseCommand(() => NewSequenceInParent());
return _NewSequenceInParentCommand;
}
}
public void NewSequenceInParent()
{
var dialog = new InputFileNameDialogViewModel("Input New Sequence Name");
var wm = new WindowManager();
var bret = wm.ShowDialog(dialog);
if ((bool)bret)
{
if (IsChanged)
{
if (DialogBox.Confirm("This sequence is changed,do you want to save it?"))
{
CurrentSequence.Revisor = BaseApp.Instance.UserContext.LoginName;
CurrentSequence.ReviseTime = DateTime.Now;
Save(CurrentSequence);
}
}
else
{
var fullpath = dialog.DialogResult;
if (string.IsNullOrEmpty(fullpath))
{
DialogBox.ShowError("SequenceName cannot be null or empty!");
return;
}
if (IsExist(fullpath))
{
DialogBox.ShowError("Sequence already existed!");
}
else
{
var sequence = new SequenceData
{
Name = fullpath,
Creator = BaseApp.Instance.UserContext.LoginName,
CreateTime = DateTime.Now,
Revisor = BaseApp.Instance.UserContext.LoginName,
ReviseTime = DateTime.Now,
Description = string.Empty
};
if (Save(sequence))
{
CurrentSequence.Name = sequence.Name;
CurrentSequence.Creator = sequence.Creator;
CurrentSequence.CreateTime = sequence.CreateTime;
CurrentSequence.Revisor = sequence.Revisor;
CurrentSequence.ReviseTime = sequence.ReviseTime;
CurrentSequence.Description = sequence.Description;
CurrentSequence.Steps.Clear();
var file = new FileNode();
file.Name = dialog.DialogResult;
file.FullPath = CurrentSequence.Name;
file.IsFile = true;
file.Parent = Files[0];
Files[0].Files.Insert(findInsertPosition(Files[0].Files), file);
editMode = EditMode.Normal;
UpdateView();
}
}
}
}
}
public int findInsertPosition(ObservableCollection<FileNode> files)
{
var pos = -1;
if (files.Count == 0)
pos = 0;
else
{
var foundfolder = false;
for (var index = 0; index < files.Count; index++)
{
if (!files[index].IsFile)
{
foundfolder = true;
pos = index;
break;
}
}
if (!foundfolder)
pos = files.Count;
}
return pos;
}
private ICommand _SaveAsCommand;
public ICommand SaveAsCommand
{
get
{
if (_SaveAsCommand == null)
_SaveAsCommand = new BaseCommand(() => SaveAsSequence());
return _SaveAsCommand;
}
}
public void SaveAsSequence()
{
if (CurrentFileNode.IsFile)
{
var dialog = new InputFileNameDialogViewModel("SaveAs Sequence");
var wm = new WindowManager();
var bret = wm.ShowDialog(dialog);
if (!(bool)bret)
return;
var fullpath = (CurrentFileNode.Parent.FullPath == "" ? dialog.DialogResult : CurrentFileNode.Parent.FullPath + "\\" + dialog.DialogResult);
if (string.IsNullOrEmpty(fullpath))
{
DialogBox.ShowError("SequenceName cannot be null or empty!");
return;
}
if (IsExist(fullpath))
{
DialogBox.ShowError("Sequence already existed!");
}
else
{
if (IsChanged)
{
if (DialogBox.Confirm("This sequence is changed,do you want to save it?"))
{
Save(CurrentSequence);
}
}
CurrentSequence.Revisor = BaseApp.Instance.UserContext.LoginName;
CurrentSequence.ReviseTime = DateTime.Now;
var tempName = CurrentSequence.Name;
CurrentSequence.Name = fullpath;
if (provider.SaveAs(fullpath, CurrentSequence))
{
var node = new FileNode
{
Parent = CurrentFileNode.Parent,
Name = dialog.DialogResult,
FullPath = fullpath,
IsFile = true
};
CurrentFileNode.Parent.Files.Add(node);
}
else
{
CurrentSequence.Name = tempName;
DialogBox.ShowError("SaveAs failed!");
}
}
}
}
private ICommand _DeleteFolderCommand;
public ICommand DeleteFolderCommand
{
get
{
if (_DeleteFolderCommand == null)
_DeleteFolderCommand = new BaseCommand(() => DeleteFolder());
return _DeleteFolderCommand;
}
}
public void DeleteFolder()
{
if (!CurrentFileNode.IsFile && CurrentFileNode.FullPath != "")
{
if (DialogBox.Confirm("Do you want to delete this folder? this operation will delete all files in this folder."))
{
if (provider.DeleteSequenceFolder(CurrentFileNode.FullPath))
{
CurrentFileNode.Parent.Files.Remove(CurrentFileNode);
}
else
DialogBox.ShowInfo("Delete folder failed!");
}
}
}
private ICommand _NewSequenceCommand;
public ICommand NewSequenceCommand
{
get
{
if (_NewSequenceCommand == null)
_NewSequenceCommand = new BaseCommand(() => NewSequence());
return _NewSequenceCommand;
}
}
public void NewSequence()
{
var dialog = new InputFileNameDialogViewModel("Input New Sequence Name");
var wm = new WindowManager();
var bret = wm.ShowDialog(dialog);
if ((bool)bret)
{
if (IsChanged)
{
if (DialogBox.Confirm("This sequence is changed,do you want to save it?"))
{
CurrentSequence.Revisor = BaseApp.Instance.UserContext.LoginName;
CurrentSequence.ReviseTime = DateTime.Now;
Save(CurrentSequence);
}
}
else
{
var fullpath = dialog.DialogResult;
if (CurrentFileNode.IsFile)
fullpath = (string.IsNullOrEmpty(CurrentFileNode.Parent.FullPath) ? dialog.DialogResult : CurrentFileNode.Parent.FullPath + "\\" + dialog.DialogResult);
else
fullpath = (string.IsNullOrEmpty(CurrentFileNode.FullPath) ? dialog.DialogResult : CurrentFileNode.FullPath + "\\" + dialog.DialogResult);
if (string.IsNullOrEmpty(fullpath))
{
DialogBox.ShowError("SequenceName cannot be null or empty!");
return;
}
if (IsExist(fullpath))
{
DialogBox.ShowError("Sequence already existed!");
}
else
{
var sequence = new SequenceData
{
Name = fullpath,
Creator = BaseApp.Instance.UserContext.LoginName,
CreateTime = DateTime.Now,
Revisor = BaseApp.Instance.UserContext.LoginName,
ReviseTime = DateTime.Now,
Description = string.Empty
};
if (Save(sequence))
{
CurrentSequence.Name = sequence.Name;
CurrentSequence.Creator = sequence.Creator;
CurrentSequence.CreateTime = sequence.CreateTime;
CurrentSequence.Revisor = sequence.Revisor;
CurrentSequence.ReviseTime = sequence.ReviseTime;
CurrentSequence.Description = sequence.Description;
CurrentSequence.Steps.Clear();
var file = new FileNode();
file.Name = dialog.DialogResult;
file.FullPath = CurrentSequence.Name;
file.IsFile = true;
file.Parent = CurrentFileNode.IsFile ? CurrentFileNode.Parent : CurrentFileNode;
if (CurrentFileNode.IsFile)
CurrentFileNode.Parent.Files.Insert(findInsertPosition(CurrentFileNode.Parent.Files), file);
else
CurrentFileNode.Files.Insert(findInsertPosition(CurrentFileNode.Files), file);
editMode = EditMode.Normal;
UpdateView();
// 自动选中新增节点
Files[0].Select(file.FullPath);
InvokeClient.Instance.Service.DoOperation($"GEM_PPChange",@"Sequence\" + dialog.DialogResult + ".seq", 1);
}
}
}
}
}
private ICommand _RenameCommand;
public ICommand RenameCommand
{
get
{
if (_RenameCommand == null)
_RenameCommand = new BaseCommand(() => RenameSequence());
return _RenameCommand;
}
}
public void RenameSequence()
{
if (CurrentFileNode.IsFile)
{
var dialog = new InputFileNameDialogViewModel("Rename Sequence");
var wm = new WindowManager();
dialog.FileName = CurrentFileNode.Name;
var bret = wm.ShowDialog(dialog);
if (!(bool)bret)
return;
var fullpath = CurrentFileNode.Parent.FullPath == "" ? dialog.DialogResult : CurrentFileNode.Parent.FullPath + "\\" + dialog.DialogResult;
if (string.IsNullOrEmpty(fullpath))
{
DialogBox.ShowError("SequenceName cannot be null or empty!");
return;
}
if (IsExist(fullpath))
{
DialogBox.ShowError("Sequence already existed!");
}
else
{
if (IsChanged)
{
if (DialogBox.Confirm("This sequence is changed,do you want to save it?", "") == true)
{
Save(CurrentSequence);
}
}
CurrentSequence.Revisor = BaseApp.Instance.UserContext.LoginName;
CurrentSequence.ReviseTime = DateTime.Now;
if (provider.Rename(CurrentSequence.Name, fullpath))
{
CurrentFileNode.Name = dialog.DialogResult;
CurrentFileNode.FullPath = fullpath;
CurrentSequence.Name = fullpath;
}
else
DialogBox.ShowError("Rename failed!");
}
}
}
public void SaveSequence()
{
if (IsChanged)
{
Save(CurrentSequence);
InvokeClient.Instance.Service.DoOperation($"GEM_PPChange", @"Sequence\" + CurrentSequence.Name + ".seq", 2);
}
}
private ICommand _DeleteCommand;
public ICommand DeleteSequenceCommand
{
get
{
if (_DeleteCommand == null)
_DeleteCommand = new BaseCommand(() => DeleteSequence());
return _DeleteCommand;
}
}
public void DeleteSequence()
{
if (CurrentFileNode.IsFile)
{
if (DialogBox.Confirm("Do you want to delete this sequence?"))
{
string sequenceName = CurrentSequence.Name + ".seq";
if (provider.Delete(CurrentSequence.Name))
{
CurrentFileNode.Parent.Files.Remove(CurrentFileNode);
InvokeClient.Instance.Service.DoOperation($"GEM_PPChange", @"Sequence\" + sequenceName, 3);
}
}
}
}
private ICommand _RefreshCommand;
public ICommand RefreshSequenceCommand
{
get
{
if (_RefreshCommand == null)
_RefreshCommand = new BaseCommand(() => RefreshSequence());
return _RefreshCommand;
}
}
public void RefreshSequence()
{
var names = provider.GetSequences();
Files = new ObservableCollection<FileNode>(RecipeSequenceTreeBuilder.GetFiles("", names));
CurrentFileNode = Files[0];
SelectDefault(CurrentFileNode);
Refresh();
}
public void ReloadSequence()
{
if (editMode == EditMode.Normal || editMode == EditMode.Edit)
{
LoadData(CurrentSequence.Name);
UpdateView();
}
}
private bool Save(SequenceData seq)
{
var result = false;
if (string.IsNullOrEmpty(seq.Name))
{
DialogBox.ShowError("Sequence name can't be empty");
return false;
}
string ruleCheckMessage = null;
if (!ValidateSequenceRules(seq, ref ruleCheckMessage))
{
DialogBox.ShowError(string.Format($"{seq.Name} rules check failed, don't allow to save: {ruleCheckMessage}"));
return false;
}
seq.Revisor = BaseApp.Instance.UserContext.LoginName;
seq.ReviseTime = DateTime.Now;
result = provider.Save(seq);
if (result)
{
foreach (var parameters in seq.Steps)
{
parameters.Apply(param => param.Save());
}
editMode = EditMode.Normal;
IsSavedDesc = true;
NotifyOfPropertyChange("IsSavedDesc");
UpdateView();
}
else
DialogBox.ShowError("Save failed!");
return result;
}
private bool IsExist(string sequenceName)
{
var existed = false;
var fileNode = CurrentFileNode.IsFile ? CurrentFileNode.Parent : CurrentFileNode;
for (var index = 0; index < fileNode.Files.Count; index++)
{
if (string.Equals(fileNode.Files[index].FullPath, sequenceName, StringComparison.CurrentCultureIgnoreCase))
{
existed = true;
break;
}
}
return existed;
}
private static bool ValidateSequenceRules(SequenceData currentSequence, ref string ruleCheckMessage)
{
//foreach (var stepInfo in currentSequence.Steps)
//{
// if (string.IsNullOrEmpty((stepInfo[1] as PositionParam).Value))
// {
// ruleCheckMessage = $"Step{(stepInfo[0] as StepParam).Value}, Position Is Empty";
// return false;
// }
// //if (((stepInfo[4] as PathFileParam).Visible == Visibility.Visible && string.IsNullOrEmpty((stepInfo[4] as PathFileParam).Value)) ||
// // ((stepInfo[5] as PathFileParam).Visible == Visibility.Visible && string.IsNullOrEmpty((stepInfo[5] as PathFileParam).Value)))
// //{
// // ruleCheckMessage = $"Step{(stepInfo[0] as StepParam).Value}, Recipe Is Empty";
// // return false;
// //}
//}
return true;
}
#endregion
#region Steps operation
public void AddStep()
{
CurrentSequence.Steps.Add(CurrentSequence.CreateStep(Columns));
if (editMode != EditMode.New && editMode != EditMode.ReName)
editMode = EditMode.Edit;
UpdateView();
}
public void AppendStep()
{
var index = -1;
var found = false;
for (var i = 0; i < CurrentSequence.Steps.Count; i++)
{
if (CurrentSequence.Steps[i][0] is StepParam && ((StepParam)CurrentSequence.Steps[i][0]).IsChecked)
{
index = i;
found = true;
break;
}
}
if (found)
{
if (editMode != EditMode.New && editMode != EditMode.ReName)
editMode = EditMode.Edit;
CurrentSequence.Steps.Insert(index, CurrentSequence.CreateStep(Columns));
}
}
private RecipeStepCollection copySteps = new RecipeStepCollection();
public void CopyStep()
{
copySteps.Clear();
for (var i = 0; i < CurrentSequence.Steps.Count; i++)
{
if (CurrentSequence.Steps[i][0] is StepParam && ((StepParam)CurrentSequence.Steps[i][0]).IsChecked)
{
copySteps.Add(CurrentSequence.CloneStep(Columns, CurrentSequence.Steps[i]));
}
}
}
public void PasteStep()
{
if (copySteps.Count > 0)
{
if (editMode != EditMode.New && editMode != EditMode.ReName)
editMode = EditMode.Edit;
for (var i = 0; i < CurrentSequence.Steps.Count; i++)
{
if (CurrentSequence.Steps[i][0] is StepParam && ((StepParam)CurrentSequence.Steps[i][0]).IsChecked)
{
for (var copyindex = 0; copyindex < copySteps.Count; copyindex++)
{
CurrentSequence.Steps.Insert(i, CurrentSequence.CloneStep(Columns, copySteps[copyindex]));
i++;
}
break;
}
}
UpdateView();
}
}
public void DeleteStep()
{
if (editMode != EditMode.New && editMode != EditMode.ReName)
editMode = EditMode.Edit;
var steps = CurrentSequence.Steps.ToList();
for (var i = 0; i < steps.Count; i++)
{
if (steps[i][0] is StepParam && ((StepParam)steps[i][0]).IsChecked)
{
CurrentSequence.Steps.Remove(steps[i]);
}
}
}
public void SelectRecipe(PathFileParam param)
{
var parameters = param.Parent;
var model = (PositionParam)parameters.First(p => p.ControlName == "Position");
var dialog = new RecipeSelectDialogViewModel(false, false, RecipeType.Process, model.Value);
dialog.DisplayName = "Select Recipe";
PositionParam posParam = null;
for (var index = 0; index < parameters.Count; index++)
{
if (parameters[index] is PositionParam)
{
posParam = parameters[index] as PositionParam;
break;
}
}
var lstFiles = RecipeClient.Instance.Service.GetRecipesByPath(param.PrefixWithSysName, false).ToList();
dialog.Files = new ObservableCollection<FileNode>(RecipeSequenceTreeBuilder.GetFiles("", lstFiles));
var wm = new WindowManager();
var bret = wm.ShowDialog(dialog);
if ((bool)bret)
{
param.Value = dialog.DialogResult;
/*var path = param.Value;
var index = path.LastIndexOf("\\", StringComparison.Ordinal);
if (index > -1)
{
// Remove the prefix "Sic\Process\" and show folder name in recipe selection text box.
param.FileName = seqFullPrefix.Replace($"{seqFullPrefix}\\", "");
}
else
{
param.FileName = path;
}*/
}
}
#endregion
private void SelectDefault(FileNode node)
{
if (!node.IsFile)
{
if (node.Files.Count > 0)
{
foreach (var file in node.Files)
{
if (file.IsFile)
{
TreeSelectChanged(file);
//break;
}
}
}
}
}
private void LoadData(string newSeqName)
{
var Sequence = provider.GetSequenceByName(Columns, newSeqName);
CurrentSequence.Name = Sequence.Name;
CurrentSequence.Creator = Sequence.Creator;
CurrentSequence.CreateTime = Sequence.CreateTime;
CurrentSequence.Revisor = Sequence.Revisor;
CurrentSequence.ReviseTime = Sequence.ReviseTime;
CurrentSequence.Description = Sequence.Description;
CurrentSequence.Steps.Clear();
Sequence.Steps.ToList().ForEach(step =>
CurrentSequence.Steps.Add(step));
//int index = 1;
//foreach (RecipeStep parameters in this.CurrentSequence.Steps)
//{
// (parameters[0] as StepParam).Value = index.ToString();
// index++;
// foreach (var para in parameters)
// {
// var pathFile = para as PathFileParam;
// if (pathFile != null)
// {
// pathFile.Value = pathFile.Value.Replace($"{pathFile.PrefixPath}\\", "");
// }
// }
//}
IsSavedDesc = true;
NotifyOfPropertyChange("IsSavedDesc");
editMode = EditMode.Normal;
}
private void ClearData()
{
editMode = EditMode.None;
CurrentSequence.Steps.Clear();
CurrentSequence.Name = string.Empty;
CurrentSequence.Description = string.Empty;
IsSavedDesc = true;
NotifyOfPropertyChange("IsSavedGroup");
NotifyOfPropertyChange("IsSavedDesc");
}
public void UpdateView()
{
EnableSequenceName = false;
NotifyOfPropertyChange("EnableSequenceName");
EnableNew = true;
EnableReName = true;
EnableCopy = true;
EnableDelete = true;
EnableSave = true;
EnableStep = true;
NotifyOfPropertyChange("EnableNew");
NotifyOfPropertyChange("EnableReName");
NotifyOfPropertyChange("EnableCopy");
NotifyOfPropertyChange("EnableDelete");
NotifyOfPropertyChange("EnableSave");
NotifyOfPropertyChange("EnableStep");
if (editMode == EditMode.None)
{
EnableNew = true;
EnableReName = false;
EnableCopy = false;
EnableDelete = false;
EnableStep = false;
EnableSave = false;
NotifyOfPropertyChange("EnableNew");
NotifyOfPropertyChange("EnableReName");
NotifyOfPropertyChange("EnableCopy");
NotifyOfPropertyChange("EnableDelete");
NotifyOfPropertyChange("EnableSave");
NotifyOfPropertyChange("EnableStep");
}
}
private bool IsChanged
{
get
{
var changed = false;
if (!IsSavedDesc || editMode == EditMode.Edit)
changed = true;
else
{
foreach (var parameters in CurrentSequence.Steps)
{
if (parameters.Where(param => param.IsSaved == false && param.ControlName != "Step").Count() > 0)
{
changed = true;
break;
}
}
}
return changed;
}
}
public bool EnableNew { get; set; }
public bool EnableReName { get; set; }
public bool EnableCopy { get; set; }
public bool EnableDelete { get; set; }
public bool EnableSave { get; set; }
public bool EnableStep { get; set; }
public bool IsSavedDesc { get; set; }
public FileNode CurrentFileNode { get; private set; }
public SequenceData CurrentSequence { get; private set; }
public ObservableCollection<EditorDataGridTemplateColumnBase> Columns { get; set; }
public bool EnableSequenceName { get; set; }
private string selectedSequenceName = string.Empty;
private string SequenceNameBeforeRename = string.Empty;
private string lastSequenceName = string.Empty;
private SequenceColumnBuilder columnBuilder = new SequenceColumnBuilder();
private EditMode editMode;
private SequenceDataProvider provider = new SequenceDataProvider();
}
}