添加项目文件。

This commit is contained in:
czj
2026-06-05 10:57:09 +08:00
parent f29671b374
commit d960cb5912
166 changed files with 15996 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
using TestingModule.ViewModels;
using System.Reflection;
using TestingModule.Views;
using TestingModule.Views.Dialogs;
namespace TestingModule
{
public class TestingModule : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
IRegionManager regionManager = containerProvider.Resolve<IRegionManager>();
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<CommandTree>("CommandTree");
containerRegistry.RegisterForNavigation<LogArea>("LogArea");
containerRegistry.RegisterForNavigation<SingleStepEdit>("SingleStepEdit");
containerRegistry.RegisterForNavigation<StepsManager>("StepsManager");
containerRegistry.RegisterForNavigation<ParametersManager>("ParametersManager");
containerRegistry.RegisterDialog<ParameterSetting>("ParameterSetting");
}
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Service\Service.csproj" />
<ProjectReference Include="..\UIShare\UIShare.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="gong-wpf-dragdrop" Version="4.0.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,590 @@
using UIShare.UIViewModel;
using UIShare.GlobalVariable;
using Common.Attributes;
using Logger;
using Microsoft.IdentityModel.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Xml;
using Model;
using static UIShare.UIViewModel.ParameterModel;
using UIShare.ViewModelBase;
using NLog;
namespace TestingModule.ViewModels
{
public class CommandTreeViewModel:NavigateViewModelBase
{
#region
private string _SearchText;
public string SearchText
{
get => _SearchText;
set => SetProperty(ref _SearchText, value);
}
private ObservableCollection<InstructionNode> _instructionTree = new();
public ObservableCollection<InstructionNode> InstructionTree
{
get => _instructionTree;
set => SetProperty(ref _instructionTree, value);
}
public ProgramModel Program
{
get => _ScopedContext.Program;
set
{
if (_ScopedContext.Program != value)
{
_ScopedContext.Program = value;
RaisePropertyChanged();
}
}
}
public ObservableCollection<Assembly> Assemblies
{
get => _ScopedContext.Assemblies;
set
{
if (_ScopedContext.Assemblies != value)
{
_ScopedContext.Assemblies = value;
RaisePropertyChanged();
}
}
}
private ObservableCollection<SubProgramItem> _subPrograms = new();
public ObservableCollection<SubProgramItem> SubPrograms
{
get => _subPrograms;
set => SetProperty(ref _subPrograms, value);
}
private Dictionary<object, InstructionNode> _treeNodeMap = new();
public Dictionary<object, InstructionNode> TreeNodeMap
{
get => _treeNodeMap;
set => SetProperty(ref _treeNodeMap, value);
}
private Dictionary<string, XmlDocument> _xmlDocumentCache = new();
public Dictionary<string, XmlDocument> XmlDocumentCache
{
get => _xmlDocumentCache;
set => SetProperty(ref _xmlDocumentCache, value);
}
#endregion
public ICommand LoadedCommand { get; set; }
public ICommand SearchEnterCommand { get; set; }
public ICommand TreeDoubleClickCommand { get; set; }
public ICommand ReloadCommand { get; set; }
private ScopedContext _ScopedContext { get; set; }
private readonly SystemConfig _systemConfig;
private readonly GlobalInfo _globalInfo;
public CommandTreeViewModel(IContainerProvider containerProvider, ScopedContext scopedContext, SystemConfig systemConfig, GlobalInfo globalInfo) : base(containerProvider)
{
_ScopedContext = scopedContext;
_systemConfig = systemConfig;
_globalInfo = globalInfo;
LoadedCommand = new DelegateCommand(Loaded);
SearchEnterCommand = new DelegateCommand(Search);
TreeDoubleClickCommand = new DelegateCommand<object>(TreeDoubleClick);
ReloadCommand = new DelegateCommand(Reload);
}
#region
private void Reload()
{
LoadAllAssemblies();
LoadSubPrograms();
LoadInstructionsToTreeView();
}
private void TreeDoubleClick(object obj)
{
if (!_globalInfo.IsAdmin) return;
if(obj is InstructionNode Node)
{
if(Node.Children.Count == 0)
{
int index = _ScopedContext.SelectedStep?.Index >= 0 ? _ScopedContext.SelectedStep.Index : -1;
if (Node.Tag is MethodInfo method)
{
AddMethodToProgram(method, index);
}
else if(Node.Tag is string tag)
{
switch (tag)
{
case "循环开始":
AddLoopStartStep(index);
break;
case "循环结束":
AddLoopEndStep(index);
break;
}
}
else if(Node.Tag is SubProgramItem subProgram)
{
AddSubProgramToProgram(subProgram, index);
}
}
}
}
private void Search()
{
}
private void Loaded()
{
LoadAllAssemblies();
LoadSubPrograms();
LoadInstructionsToTreeView();
}
#endregion
#region
/// <summary>
/// 加载指定目录下的所有DLL
/// </summary>
private void LoadAllAssemblies()
{
Assemblies.Clear();
foreach (var dllPath in Directory.GetFiles(_systemConfig.DLLFilePath, "*.dll"))
{
try
{
var assembly = Assembly.LoadFile(dllPath);
Assemblies.Add(assembly);
// 加载对应的XML注释文件 (项目没有用到)
//string xmlPath = Path.ChangeExtension(dllPath, ".xml");
//if (File.Exists(xmlPath))
//{
// try
// {
// XmlDocument xmlDoc = new XmlDocument();
// xmlDoc.Load(xmlPath);
// _xmlDocumentCache[assembly.FullName!] = xmlDoc;
// }
// catch (Exception xmlEx)
// {
// LoggerHelper.WarnWithNotify($"加载XML注释失败: {Path.GetFileName(xmlPath)} - {xmlEx.Message}");
// }
//}
}
catch (Exception ex)
{
LoggerHelper.WarnWithNotify($"无法加载程序集 {Path.GetFileName(dllPath)}: {ex.Message}");
}
}
}
// 子程序加载方法
private void LoadSubPrograms()
{
SubPrograms.Clear();
if (!Directory.Exists(_systemConfig.SubProgramFilePath))
{
Directory.CreateDirectory(_systemConfig.SubProgramFilePath);
return;
}
foreach (var filePath in Directory.GetFiles(_systemConfig.SubProgramFilePath, "*.adp"))
{
try
{
SubPrograms.Add(new SubProgramItem
{
Name = Path.GetFileNameWithoutExtension(filePath),
FilePath = filePath
});
}
catch (Exception ex)
{
LoggerHelper.WarnWithNotify($"加载子程序错误: {filePath} - {ex.Message}");
}
}
}
/// <summary>
/// 加载指令集到TreeView
/// </summary>
private void LoadInstructionsToTreeView()
{
InstructionTree.Clear();
var controlRootNode = new InstructionNode
{
Name = "系统指令",
Tag = "ControlRoot"
};
InstructionTree.Add(controlRootNode);
// 循环开始
controlRootNode.Children.Add(new InstructionNode
{
Name = "循环开始",
Tag = "循环开始"
});
// 循环结束
controlRootNode.Children.Add(new InstructionNode
{
Name = "循环结束",
Tag = "循环结束"
});
// ----------------------
// 子程序 根节点
// ----------------------
var subProgramRoot = new InstructionNode
{
Name = "子程序",
Tag = "SubProgramRoot"
};
InstructionTree.Add(subProgramRoot);
foreach (var subProgram in SubPrograms)
{
subProgramRoot.Children.Add(new InstructionNode
{
Name = subProgram.Name,
Tag = subProgram,
});
}
// ----------------------
// 动态 DLL 指令
// ----------------------
foreach (var assembly in Assemblies)
{
List<Type> validTypes = new List<Type>();
try
{
var types = assembly.GetTypes().Where(t =>
t.IsPublic &&
!t.IsNested &&
(t.IsClass || t.IsValueType) &&
(!t.IsAbstract || t.IsSealed) &&
t.GetCustomAttribute<ADPCommandAttribute>() != null);
foreach (var type in types)
{
if (type.GetCustomAttribute<BrowsableAttribute>()?.Browsable == false)
continue;
var allMethods = new HashSet<MethodInfo>();
GetPublicMethods(type, allMethods);
if (allMethods.Count > 0)
validTypes.Add(type);
}
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"加载类型错误: {assembly.FullName} - {ex.Message}");
}
if (validTypes.Count > 0)
{
var assemblyNode = new InstructionNode
{
Name = assembly.GetName().Name,
Tag = assembly
};
InstructionTree.Add(assemblyNode);
TreeNodeMap[assembly] = assemblyNode;
foreach (var type in validTypes)
{
//拦截没有在设备列表中的设备类型
//if (SystemConfig.Instance.DeviceList.Where(x=>x.Remark==type.Name).ToList().Count==0 && type.FullName.Contains("DeviceCommand.Device"))
//{
// continue;
//}
var typeNode = new InstructionNode
{
Name = type.Name,
Tag = type,
};
assemblyNode.Children.Add(typeNode);
TreeNodeMap[type] = typeNode;
var allMethods = new HashSet<MethodInfo>();
GetPublicMethods(type, allMethods);
foreach (var method in allMethods)
{
if (method.IsSpecialName) continue;
if (method.DeclaringType == typeof(object)) continue;
string[] ignoreMethods = { "GetType", "ToString", "Equals", "GetHashCode" };
if (ignoreMethods.Contains(method.Name)) continue;
if (method.GetCustomAttribute<BrowsableAttribute>()?.Browsable == false)
continue;
if (type.IsAbstract && type.IsSealed && !method.IsStatic) continue;
var parameters = method.GetParameters();
var paramText = string.Join(", ", parameters.Select(p => $"{p.ParameterType.Name} {p.Name}"));
var methodNode = new InstructionNode
{
Name = $"{method.Name}({paramText})",
Tag = method,
};
typeNode.Children.Add(methodNode);
TreeNodeMap[method] = methodNode;
}
}
}
}
}
#endregion
#region
/// <summary>
/// 递归获取类型的所有公共方法(包括继承的方法),但跳过被重写的方法
/// </summary>
/// <param name="type">要处理的目标类型</param>
/// <param name="methods">存储方法的集合</param>
private void GetPublicMethods(Type type, HashSet<MethodInfo> methods)
{
// 获取当前类型的所有公共方法(包括继承的)
var allMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)
.Where(m => !m.IsSpecialName &&
m.DeclaringType != typeof(object))
.ToList();
// 按方法签名分组
var groupedMethods = allMethods
.GroupBy(m => new { m.Name, Parameters = string.Join(",", m.GetParameters().Select(p => p.ParameterType.FullName)) });
foreach (var group in groupedMethods)
{
// 从组中选择声明类型最接近当前类型(即继承层次最深)的方法
MethodInfo? selectedMethod = null;
int minDepth = int.MaxValue;
foreach (var method in group)
{
// 计算声明类型的深度
int depth = 0;
Type? current = type;
Type declaringType = method.DeclaringType!;
while (current != null && current != declaringType)
{
depth++;
current = current.BaseType;
}
// 如果找到声明类型且在继承链上
if (current == declaringType)
{
if (selectedMethod == null || depth < minDepth)
{
selectedMethod = method;
minDepth = depth;
}
}
}
if (selectedMethod != null)
{
methods.Add(selectedMethod);
}
}
}
#endregion
#region
private void AddMethodToProgram(MethodInfo method, int insertIndex = -1)
{
try
{
var newStep = new StepModel
{
Name = method.Name,
StepType = "方法",
Method = new MethodModel
{
FullName = method.DeclaringType?.FullName,
Name = method.Name
}
};
// 添加输入参数
foreach (var param in method.GetParameters())
{
newStep.Method.Parameters.Add(new ParameterModel
{
Name = param.Name!,
Type = param.ParameterType,
Category = ParameterCategory.Input
});
}
// 添加输出参数(返回值)
Type returnType = method.ReturnType;
if (returnType == typeof(Task))
{
// 不添加输出参数(无返回值)
}
else if (returnType.IsGenericType &&
returnType.GetGenericTypeDefinition() == typeof(Task<>))
{
// 提取实际返回类型(如 Task<bool> -> bool
Type actualType = returnType.GetGenericArguments()[0];
newStep.Method.Parameters.Add(new ParameterModel
{
Name = "Result",
Type = actualType, // 使用实际类型
Category = ParameterCategory.Output
});
}
else if (returnType != typeof(void))
{
// 同步方法正常添加
newStep.Method.Parameters.Add(new ParameterModel
{
Name = "Result",
Type = returnType,
Category = ParameterCategory.Output
});
}
// 添加到程序
if(_ScopedContext.SelectedStepList == "主程序")
{
if(insertIndex >= 0 && insertIndex <= Program.StepCollection.Count) Program.StepCollection.Insert(insertIndex, newStep);
else Program.StepCollection.Add(newStep); }
else
{
if (insertIndex >= 0 && insertIndex <= Program.ErrorStepCollection.Count) Program.ErrorStepCollection.Insert(insertIndex, newStep);
else Program.ErrorStepCollection.Add(newStep);
}
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"添加方法失败: {method.Name} - {ex.Message}");
}
}
private void AddSubProgramToProgram(SubProgramItem subProgram, int insertIndex = -1)
{
try
{
var newStep = new StepModel
{
Name = subProgram.Name,
StepType = "子程序"
};
var jsonstr = File.ReadAllText($"{subProgram.FilePath}");
var tmp = JsonConvert.DeserializeObject<ProgramModel>(jsonstr);
if (tmp != null)
{
newStep.SubProgram = tmp;
}
// 添加到程序
if (_ScopedContext.SelectedStepList == "主程序")
{
if (insertIndex >= 0 && insertIndex <= Program.StepCollection.Count) Program.StepCollection.Insert(insertIndex, newStep);
else Program.StepCollection.Add(newStep);
}
else
{
if (insertIndex >= 0 && insertIndex <= Program.ErrorStepCollection.Count) Program.ErrorStepCollection.Insert(insertIndex, newStep);
else Program.ErrorStepCollection.Add(newStep);
}
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"添加子程序失败: {subProgram.Name} - {ex.Message}");
}
}
private void AddLoopStartStep(int insertIndex = -1)
{
var newStep = new StepModel
{
Name = "循环开始",
StepType = "循环开始",
LoopCount = 1,
Method = new() { Parameters = [new() { Name = "循环次数", Type = typeof(int), Category = ParameterCategory.Input }] }
};
// 添加到程序
if (_ScopedContext.SelectedStepList == "主程序")
{
if (insertIndex >= 0) Program.StepCollection.Insert(insertIndex, newStep);
else Program.StepCollection.Add(newStep);
}
else
{
if (insertIndex >= 0) Program.ErrorStepCollection.Insert(insertIndex, newStep);
else Program.ErrorStepCollection.Add(newStep);
}
}
private void AddLoopEndStep(int insertIndex = -1)
{
// 查找最近的未匹配循环开始
StepModel? lastUnmatchedLoopStart = null;
for (int i = Program.StepCollection.Count - 1; i >= 0; i--)
{
if (Program.StepCollection[i].StepType == "循环开始")
{
bool isMatched = Program.StepCollection.Any(s => s.StepType == "循环结束" && s.LoopStartStepId == Program.StepCollection[i].ID);
if (!isMatched)
{
lastUnmatchedLoopStart = Program.StepCollection[i];
break;
}
}
}
var newStep = new StepModel
{
Name = "循环结束",
StepType = "循环结束",
LoopStartStepId = lastUnmatchedLoopStart?.ID
};
// 添加到程序
if (_ScopedContext.SelectedStepList == "主程序")
{
if (insertIndex >= 0) Program.StepCollection.Insert(insertIndex, newStep);
else Program.StepCollection.Add(newStep);
}
else
{
if (insertIndex >= 0) Program.ErrorStepCollection.Insert(insertIndex, newStep);
else Program.ErrorStepCollection.Add(newStep);
}
}
#endregion
}
}

View File

@@ -0,0 +1,135 @@
using UIShare.UIViewModel;
using UIShare.PubEvent;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using UIShare.GlobalVariable;
using static UIShare.UIViewModel.ParameterModel;
using UIShare.ViewModelBase;
using Prism.Ioc;
using Prism.Navigation.Regions;
namespace TestingModule.ViewModels.Dialogs
{
public class ParameterSettingViewModel : DialogViewModelBase
{
#region
private string _title = "参数设置界面";
public string Title
{
get => _title;
set => SetProperty(ref _title, value);
}
private Array _EnumValues;
public Array EnumValues
{
get => _EnumValues;
set => SetProperty(ref _EnumValues, value);
}
private ObservableCollection<Type> _types =
[
typeof(string), typeof(bool),
typeof(short), typeof(int), typeof(long), typeof(float), typeof(double),
typeof(byte[]), typeof(short[]), typeof(ushort[]), typeof(int[]), typeof(long[]), typeof(float[]), typeof(double[]),
typeof(object)
];
public ObservableCollection<Type> Types
{
get => _types;
set => SetProperty(ref _types, value);
}
private ObservableCollection<string> _categories = new ObservableCollection<string>(
Enum.GetNames(typeof(ParameterCategory))
);
public ObservableCollection<string> Categories
{
get => _categories;
set => SetProperty(ref _categories, value);
}
private string _Mode;
public string Mode
{
get => _Mode;
set => SetProperty(ref _Mode, value);
}
private ProgramModel _program;
public ProgramModel Program
{
get => _program;
set => SetProperty(ref _program, value);
}
private ParameterModel _Parameter;
public ParameterModel Parameter
{
get => _Parameter;
set => SetProperty(ref _Parameter, value);
}
#endregion
public DialogCloseListener RequestClose{get;set;}
private ScopedContext _ScopedContext;
public ICommand CancelCommand { get; set; }
public ICommand SaveCommand { get; set; }
public ParameterSettingViewModel(IContainerProvider containerProvider) : base(containerProvider)
{
CancelCommand = new DelegateCommand(Cancel);
SaveCommand = new DelegateCommand(Save);
}
private void Save()
{
if (Mode == "ADD")
{
Program.Parameters.Add(Parameter);
_ScopedContext.SelectedParameter = Parameter;
}
else
{
var index = Program.Parameters
.Select((x, i) => new { x, i })
.FirstOrDefault(p => p.x.ID == _ScopedContext.SelectedParameter.ID)?.i;
if (index.HasValue)
{
Program.Parameters[index.Value] = Parameter;
}
}
RequestClose.Invoke(ButtonResult.OK);
}
private void Cancel()
{
RequestClose.Invoke(ButtonResult.No);
}
#region Prism Dialog
public override void OnDialogClosed()
{
_eventAggregator.GetEvent<OverlayEvent>().Publish(false);
}
public override void OnDialogOpened(IDialogParameters parameters)
{
if (parameters.ContainsKey("ScopedContext"))
_ScopedContext = parameters.GetValue<ScopedContext>("ScopedContext");
_eventAggregator.GetEvent<OverlayEvent>().Publish(true);
Program =_ScopedContext.Program;
Mode = parameters.GetValue<string>("Mode");
if (Mode == "ADD")
{
Parameter = new();
}
else
{
Parameter = new ParameterModel(_ScopedContext.SelectedParameter);
}
}
#endregion
}
}

View File

@@ -0,0 +1,58 @@
using UIShare.GlobalVariable;
using Logger;
using Prism.Mvvm;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using UIShare.ViewModelBase;
namespace TestingModule.ViewModels
{
public class LogAreaViewModel : NavigateViewModelBase
{
// 日志集合
private ObservableCollection<LogItem> _logs = new();
public ObservableCollection<LogItem> Logs
{
get => _logs;
set => SetProperty(ref _logs, value);
}
public ICommand ClearLogCommand { get; set; }
public LogAreaViewModel(IContainerProvider containerProvider) : base(containerProvider)
{
ClearLogCommand = new DelegateCommand(ClearLog);
LoggerHelper.Progress = new System.Progress<(string message, string color, int depth)>(
log =>
{
var brush = (Brush)new BrushConverter().ConvertFromString(log.color);
Logs.Add(new LogItem(log.message, brush, log.depth));
});
}
private void ClearLog()
{
Logs.Clear();
}
}
// 日志条目类
public class LogItem
{
public string Message { get; set; }
public Brush Color { get; set; } = Brushes.Black;
public int Depth { get; set; }
public LogItem(string message, Brush color, int depth = 0)
{
Message = new string(' ', depth * 20) + message;
Color = color;
Depth = depth;
}
}
}

View File

@@ -0,0 +1,165 @@
using UIShare.UIViewModel;
using UIShare.GlobalVariable;
using UIShare.PubEvent;
using Logger;
using MaterialDesignThemes.Wpf;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Xml;
using UIShare.ViewModelBase;
using Prism.Events;
namespace TestingModule.ViewModels
{
public class ParametersManagerViewModel:NavigateViewModelBase
{
#region
//private ObservableCollection<DeviceConfigModel> _DeviceList;
//public ObservableCollection<DeviceConfigModel> DeviceList
//{
// get { return _DeviceList; }
// set { SetProperty(ref _DeviceList,value); }
//}
private ObservableCollection<DeviceInfoModel> _DeviceInfoModel;
public ObservableCollection<DeviceInfoModel> DeviceInfoModel
{
get { return _DeviceInfoModel; }
set { SetProperty(ref _DeviceInfoModel, value); }
}
public ProgramModel Program
{
get => _ScopedContext.Program;
set
{
if (_ScopedContext.Program != value)
{
_ScopedContext.Program = value;
RaisePropertyChanged();
}
}
}
private ParameterModel _SelectedParameter;
public ParameterModel SelectedParameter
{
get => _SelectedParameter;
set
{
if (SetProperty(ref _SelectedParameter, value))
{
_ScopedContext.SelectedParameter = value;
}
}
}
private DeviceInfoModel _SelectedDevice;
public DeviceInfoModel SelectedDevice
{
get { return _SelectedDevice; }
set { SetProperty(ref _SelectedDevice, value); }
}
#endregion
private ScopedContext _ScopedContext { get; set; }
private readonly SystemConfig _systemConfig;
private readonly GlobalInfo _globalInfo;
#region
public ICommand ParameterAddCommand { get; set; }
public ICommand ParameterEditCommand { get; set; }
public ICommand ParameterDeleteCommand { get; set; }
public ICommand DeviceEditCommand { get; set; }
public ICommand ReconnnectCommand { get; set; }
public ICommand CloseCommand { get; set; }
#endregion
public ParametersManagerViewModel(IContainerProvider containerProvider, ScopedContext scopedContext, SystemConfig systemConfig, GlobalInfo globalInfo) : base(containerProvider)
{
_ScopedContext = scopedContext;
_systemConfig = systemConfig;
_globalInfo = globalInfo;
Program = _ScopedContext.Program;
ParameterAddCommand = new DelegateCommand(ParameterAdd);
ParameterEditCommand = new DelegateCommand(ParameterEdit);
ParameterDeleteCommand = new DelegateCommand(ParameterDelete);
DeviceEditCommand = new DelegateCommand(DeviceEdit);
}
#region
private void DeviceEdit()
{
if (!_globalInfo.IsAdmin) return;
if (SelectedDevice==null)
{
return;
}
var type = SelectedDevice.DeviceType.Split('.').Last();
if(type=="E36233A"|| type == "IT6724CReverse")
{
_dialogService.Show("Backfeed");
}
else
{
_dialogService.Show(type);
}
}
private void ParameterDelete()
{
if (!_globalInfo.IsAdmin) return;
Program.Parameters.Remove(SelectedParameter);
}
private void ParameterEdit()
{
if (!_globalInfo.IsAdmin) return;
var param = new DialogParameters
{
{ "Mode",SelectedParameter==null?"ADD":"Edit" },
{ "ScopedContext",_ScopedContext }
};
_dialogService.ShowDialog("ParameterSetting", param, (r) =>
{
if (r.Result == ButtonResult.OK)
{
_eventAggregator.GetEvent<ParamsChangedEvent>().Publish();
}
else
{
}
});
}
private void ParameterAdd()
{
if (!_globalInfo.IsAdmin) return;
var param = new DialogParameters
{
{ "Mode", "ADD" },
{ "ScopedContext",_ScopedContext }
};
_dialogService.ShowDialog("ParameterSetting", param, (r) =>
{
if (r.Result == ButtonResult.OK)
{
_eventAggregator.GetEvent<ParamsChangedEvent>().Publish();
}
else
{
}
});
}
#endregion
}
}

View File

@@ -0,0 +1,201 @@
using UIShare.UIViewModel;
using UIShare.PubEvent;
using Logger;
using Microsoft.IdentityModel.Logging;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using UIShare.ViewModelBase;
using Prism.Dialogs;
using Prism.Events;
using UIShare.GlobalVariable;
namespace TestingModule.ViewModels
{
public class SingleStepEditViewModel:NavigateViewModelBase
{
#region
private Guid _ID;
public Guid ID
{
get => _ID;
set => SetProperty(ref _ID, value);
}
private StepModel _SelectedStep;
public StepModel SelectedStep
{
get => _SelectedStep;
set => SetProperty(ref _SelectedStep, value);
}
public ProgramModel Program
{
get => _ScopedContext.Program;
set
{
if (_ScopedContext.Program != value)
{
_ScopedContext.Program = value;
RaisePropertyChanged();
}
}
}
#endregion
private ScopedContext _ScopedContext;
#region
public ICommand CancelEditCommand { get; set; }
public ICommand SaveStepCommand { get; set; }
#endregion
public SingleStepEditViewModel(IContainerProvider containerProvider, ScopedContext scopedContext) : base(containerProvider)
{
_ScopedContext = scopedContext;
_eventAggregator.GetEvent<EditSetpEvent>().Subscribe(EditSingleStep);
CancelEditCommand = new DelegateCommand(CancelEdit);
SaveStepCommand = new DelegateCommand(SaveStep);
_eventAggregator.GetEvent<DeletedStepEvent>().Subscribe(DisposeSelectedStep);
_eventAggregator.GetEvent<ParamsChangedEvent>().Subscribe(ParamsChanged);
}
#region
private void ParamsChanged()
{
CancelEdit();
}
private void DisposeSelectedStep(Guid id)
{
if (SelectedStep == null) return;
if(id== SelectedStep.ID)
SelectedStep = null;
}
private void CancelEdit()
{
SelectedStep = null;
}
private void SaveStep()
{
if (SelectedStep == null || (SelectedStep.Method == null && SelectedStep.SubProgram == null))
{
return;
}
var steps = _ScopedContext.SelectedStepList=="主程序"?_ScopedContext.Program.StepCollection: _ScopedContext.Program.ErrorStepCollection;
int index = steps.ToList().FindIndex(x => x.ID == ID);
if (index >= 0)
{
steps[index] = SelectedStep;
if (steps[index].Method != null)
{
if (steps[index].StepType == "循环开始")
{
try
{
steps[index].LoopCount = Convert.ToInt32(SelectedStep.Method!.Parameters[0].Value);
}
catch
{
LoggerHelper.ErrorWithNotify("循环指令参数设置错误:类型转换失败");
}
}
else
{ //设置步骤参数
(steps[index].OKGotoStepID, steps[index].NGGotoStepID) = GetOKNGGotoStepID(SelectedStep.GotoSettingString);
for (int i = 0; i < steps[index].Method.Parameters.Count; i++)
{
var editedParam = SelectedStep.Method!.Parameters[i];
var originalParam = steps[index].Method.Parameters[i];
if (editedParam.IsUseVar)
{
originalParam.VariableName = editedParam.VariableName;
originalParam.VariableID = _ScopedContext.Program.Parameters.FirstOrDefault(x => x.Name == editedParam.VariableName)!.ID;
}
originalParam.Value = editedParam.Value;
originalParam.IsUseVar = editedParam.IsUseVar;
originalParam.LowerLimit = editedParam.LowerLimit;
originalParam.UpperLimit = editedParam.UpperLimit;
}
var parameters = new DialogParameters
{
{ "Title", "提示" },
{ "Message", "保存成功!" },
{ "Icon", "info" },
{ "ShowOk", true }
};
_dialogService.ShowDialog("MessageBox", parameters);
}
}
else if (steps[index].SubProgram != null)
{
if (SelectedStep.SubProgram.Parameters.Where(x => x.VariableName == null && x.IsUseVar == true).FirstOrDefault() != null)
{
var parameters1 = new DialogParameters
{
{ "Title", "警告" },
{ "Message", "选中变量不得为空!" },
{ "Icon", "warn" },
{ "ShowOk", true },
};
_dialogService.ShowDialog("MessageBox",parameters1);
return;
}
(steps[index].OKGotoStepID, steps[index].NGGotoStepID) = GetOKNGGotoStepID(SelectedStep.GotoSettingString);
for (int i = 0; i < steps[index].SubProgram.Parameters.Count; i++)
{
var editedParam = SelectedStep.SubProgram!.Parameters[i];
var originalParam = steps[index].SubProgram.Parameters[i];
if (editedParam.IsUseVar)
{
originalParam.VariableName = editedParam.VariableName;
originalParam.VariableID = _ScopedContext.Program.Parameters.FirstOrDefault(x => x.Name == editedParam.VariableName)!.ID;
}
originalParam.Value = editedParam.Value;
originalParam.IsUseVar = editedParam.IsUseVar;
originalParam.LowerLimit = editedParam.LowerLimit;
originalParam.UpperLimit = editedParam.UpperLimit;
}
var parameters = new DialogParameters
{
{ "Title", "提示" },
{ "Message", "保存成功!" },
{ "Icon", "info" },
{ "ShowOk", true }
};
_dialogService.ShowDialog("MessageBox", parameters);
}
}
}
private (Guid,Guid) GetOKNGGotoStepID(string GotoSettingString)
{
if (string.IsNullOrWhiteSpace(GotoSettingString))
return (Guid.Empty, Guid.Empty);
var match = Regex.Match(GotoSettingString, @"^(\d+)\s*/\s*(\d+)$");
if (match.Success)
{
int ok = int.Parse(match.Groups[1].Value);
int ng = int.Parse(match.Groups[2].Value);
Guid okGuid = _ScopedContext.Program.StepCollection.ElementAtOrDefault(ok-1)?.ID ?? Guid.Empty;
Guid ngGuid = _ScopedContext.Program.StepCollection.ElementAtOrDefault(ng-1)?.ID ?? Guid.Empty;
return (okGuid, ngGuid);
}
return (Guid.Empty, Guid.Empty);
}
private void EditSingleStep()
{
if (_ScopedContext.SelectedStep == null) return;
ID = _ScopedContext.SelectedStep.ID;
SelectedStep = new StepModel(_ScopedContext.SelectedStep);
}
#endregion
}
}

View File

@@ -0,0 +1,237 @@
using UIShare.PubEvent;
using UIShare.UIViewModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Xml;
using UIShare.GlobalVariable;
using UIShare.ViewModelBase;
using Prism.Events;
namespace TestingModule.ViewModels
{
public class StepsManagerViewModel:NavigateViewModelBase
{
#region
private string _Title;
public string Title
{
get => _Title;
set => SetProperty(ref _Title, value);
}
private bool _Admin;
public bool Admin
{
get => _Admin;
set => SetProperty(ref _Admin, value);
}
private int _SelectedTabIndex;
public int SelectedTabIndex
{
get => _SelectedTabIndex;
set => SetProperty(ref _SelectedTabIndex, value);
}
private string _selectedTabHeader;
public string SelectedTabHeader
{
get { return _selectedTabHeader; }
set { SetProperty(ref _selectedTabHeader, value); }
}
private List<StepModel> _SelectedItems;
public List<StepModel> SelectedItems
{
get { return _SelectedItems; }
set { SetProperty(ref _SelectedItems, value); }
}
private StepModel _SelectedStep;
public StepModel SelectedStep
{
get => _SelectedStep;
set
{
if (SetProperty(ref _SelectedStep, value))
{
_ScopedContext.SelectedStep = value;
}
}
}
public ProgramModel Program
{
get => _ScopedContext.Program;
set
{
if (_ScopedContext.Program != value)
{
_ScopedContext.Program = value;
RaisePropertyChanged();
}
}
}
ScopedContext _ScopedContext { get; set; }
private readonly SystemConfig _systemConfig;
private readonly GlobalInfo _globalInfo;
private List<StepModel> tmpCopyList = new List<StepModel>();
#endregion
#region
public ICommand EditStepCommand { get;set; }
public ICommand CopyStepCommand { get;set; }
public ICommand PasteStepCommand { get;set; }
public ICommand DeleteStepCommand { get;set; }
public ICommand TabSelectionChangedCommand { get;set; }
public ICommand SelectionChangedCommand { get;set; }
#endregion
public StepsManagerViewModel(IContainerProvider containerProvider, ScopedContext scopedContext, SystemConfig systemConfig, GlobalInfo globalInfo) : base(containerProvider)
{
_ScopedContext = scopedContext;
_systemConfig = systemConfig;
_globalInfo = globalInfo;
EditStepCommand = new DelegateCommand(EditStep);
CopyStepCommand = new DelegateCommand(CopyStep);
PasteStepCommand = new DelegateCommand(PasteStep);
DeleteStepCommand = new DelegateCommand(DeleteStep);
TabSelectionChangedCommand = new DelegateCommand<string>(TabSelectionChanged);
SelectionChangedCommand = new DelegateCommand<object>(SelectionChanged);
Program.StepCollection.CollectionChanged += StepCollection_CollectionChanged;
Program.ErrorStepCollection.CollectionChanged += StepCollection_CollectionChanged;
Admin = _globalInfo.IsAdmin;
_eventAggregator.GetEvent<AlarmEvent>().Subscribe(() =>
{
SelectedTabIndex = 1;
});
}
private void SelectionChanged(object parameter)
{
var selectedList = parameter as IList;
if (selectedList != null)
{
SelectedItems = selectedList.Cast<StepModel>().ToList();
}
}
private void TabSelectionChanged(string SelectedTabHeader)
{
_ScopedContext.SelectedStepList = SelectedTabHeader;
}
#region
private void EditStep()
{
if (_globalInfo.IsAdmin && SelectedStep != null&& _ScopedContext.SelectedStep!=null)
{
_eventAggregator.GetEvent<EditSetpEvent>().Publish() ;
}
}
private void CopyStep()
{
if (_globalInfo.IsAdmin && SelectedItems.Any())
{
tmpCopyList.Clear();
foreach (var item in SelectedItems)
{
tmpCopyList.Add(item);
}
}
}
private void PasteStep()
{
// 权限校验并确保有可粘贴的内容
if (_globalInfo.IsAdmin && tmpCopyList.Any())
{
int insertIndex;
if (_ScopedContext.SelectedStepList == "主程序")
{
insertIndex = SelectedStep != null ? Program.StepCollection.IndexOf(SelectedStep) + 1 : Program.StepCollection.Count;
foreach (var item in tmpCopyList)
{
// 创建新副本,避免引用同一个对象,并赋予新 ID
var newStep = new StepModel(item) { ID = Guid.NewGuid() };
Program.StepCollection.Insert(insertIndex, newStep);
insertIndex++; // 递增索引,保证粘贴的多项顺序一致
}
}
else if (_ScopedContext.SelectedStepList == "错误程序")
{
insertIndex = SelectedStep != null ? Program.ErrorStepCollection.IndexOf(SelectedStep) + 1 : Program.ErrorStepCollection.Count;
foreach (var item in tmpCopyList)
{
var newStep = new StepModel(item) { ID = Guid.NewGuid() };
Program.ErrorStepCollection.Insert(insertIndex, newStep);
insertIndex++;
}
}
}
}
private void DeleteStep()
{
// 确保有选中的项
if (_globalInfo.IsAdmin && SelectedItems != null && SelectedItems.Any())
{
// 创建一个副本进行循环,防止在 Remove 过程中集合变化导致的问题
var toDelete = SelectedItems.ToList();
foreach (var item in toDelete)
{
_eventAggregator.GetEvent<DeletedStepEvent>().Publish(item.ID);
if (_ScopedContext.SelectedStepList == "主程序")
{
Program.StepCollection.Remove(item);
}
else if (_ScopedContext.SelectedStepList == "错误程序")
{
Program.ErrorStepCollection.Remove(item);
}
}
// 3. 清空 ViewModel 的选中状态,避免悬挂引用
SelectedStep = null;
SelectedItems.Clear();
_ScopedContext.SelectedStep = null;
}
}
#endregion
#region
private void StepCollection_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
var collection = sender as ObservableCollection<StepModel>;
// Add/Move/Remove 都会触发,这里判断具体情形
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add ||
e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Move||
e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
{
// 如果需要等 UI 更新完再处理,可也用 Dispatcher 延迟一小段时间
Application.Current?.Dispatcher.BeginInvoke(new Action(() =>
{
if(_ScopedContext.SelectedStepList=="主程序")
{
for (int i = 0; i < Program.StepCollection.Count; i++)
Program.StepCollection[i].Index = i + 1;
}
else if (_ScopedContext.SelectedStepList == "错误程序")
for (int i = 0; i < Program.ErrorStepCollection.Count; i++)
Program.ErrorStepCollection[i].Index = i + 1;
}), System.Windows.Threading.DispatcherPriority.Background);
}
}
#endregion
}
}

View File

@@ -0,0 +1,79 @@
<UserControl x:Class="TestingModule.Views.CommandTree"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:model="clr-namespace:UIShare.UIViewModel;assembly=UIShare"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<prism:InvokeCommandAction Command="{Binding LoadedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="439*" />
<ColumnDefinition Width="361*" />
</Grid.ColumnDefinitions>
<GroupBox Header="指令"
Grid.ColumnSpan="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- 搜索框 -->
<StackPanel Grid.Row="0"
Orientation="Horizontal"
Margin="10,0,7,12"
VerticalAlignment="Center">
<!--<TextBox MinWidth="150"
Height="25"
Margin="0,0,5,0"
VerticalContentAlignment="Center"
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"
materialDesign:HintAssist.Hint="搜索内容">
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<prism:InvokeCommandAction Command="{Binding SearchEnterCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>-->
</StackPanel>
<!-- TreeView -->
<TreeView Grid.Row="1"
ItemsSource="{Binding InstructionTree}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type model:InstructionNode}"
ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</TreeView.Resources>
<!-- 双击 -->
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<prism:InvokeCommandAction Command="{Binding TreeDoubleClickCommand}"
CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=TreeView}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<!-- 右键菜单 -->
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem Header="重新加载"
Command="{Binding ReloadCommand}" />
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</Grid>
</GroupBox>
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TestingModule.Views
{
/// <summary>
/// CommandTreeView.xaml 的交互逻辑
/// </summary>
public partial class CommandTree : UserControl
{
public CommandTree()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,136 @@
<UserControl x:Class="TestingModule.Views.Dialogs.ParameterSetting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
xmlns:local="clr-namespace:TestingModule.Views.Dialogs"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/"
Background="White"
xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
prism:ViewModelLocator.AutoWireViewModel="True"
Width="420"
Height="284"
mc:Ignorable="d">
<prism:Dialog.WindowStyle>
<Style BasedOn="{StaticResource DialogUserManageStyle}"
TargetType="Window" />
</prism:Dialog.WindowStyle>
<UserControl.Resources>
<converters:IsEnumTypeConverter x:Key="IsEnumTypeConverter" />
<converters:ParameterValueToStringConverter x:Key="ParameterValueToStringConverter" />
</UserControl.Resources>
<Grid>
<GroupBox Padding="10,15,10,0"
Header="{Binding Title}"
helpers:WindowDragHelper.EnableWindowDrag="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<ScrollViewer>
<StackPanel>
<StackPanel Height="30"
Margin="7"
Orientation="Horizontal">
<Label Width="60"
VerticalAlignment="Bottom"
Content="参数名称*" />
<TextBox Width="120"
Text="{Binding Parameter.Name}"
materialDesign:HintAssist.Hint="参数名称" />
</StackPanel>
<StackPanel Height="30"
Margin="7"
Orientation="Horizontal">
<Label Width="60"
VerticalAlignment="Bottom"
Content="参数类型*" />
<ComboBox Width="120"
VerticalAlignment="Bottom"
ItemsSource="{Binding Types}"
materialDesign:HintAssist.Hint="参数类型"
SelectedItem="{Binding Parameter.Type}"
/>
</StackPanel>
<StackPanel Height="30"
Margin="7"
Orientation="Horizontal">
<Label Width="60"
VerticalAlignment="Bottom"
Content="参数类别*" />
<ComboBox Width="120"
VerticalAlignment="Bottom"
ItemsSource="{Binding Categories}"
materialDesign:HintAssist.Hint="参数类别"
Text="{Binding Parameter.Category}" />
</StackPanel>
<StackPanel Height="30"
Margin="7"
Orientation="Horizontal">
<Label Width="60"
VerticalAlignment="Bottom"
Content="参数下限" />
<TextBox Width="120"
VerticalAlignment="Bottom"
Text="{Binding Parameter.LowerLimit}"
materialDesign:HintAssist.Hint="参数下限" />
</StackPanel>
<StackPanel Height="30"
Margin="7"
Orientation="Horizontal">
<Label Width="60"
VerticalAlignment="Bottom"
Content="参数上限" />
<TextBox Width="120"
VerticalAlignment="Bottom"
Text="{Binding Parameter.UpperLimit}"
materialDesign:HintAssist.Hint="参数名上限" />
</StackPanel>
<StackPanel Height="30"
Margin="7"
Orientation="Horizontal">
<Label Width="60"
VerticalAlignment="Bottom"
Content="参数值" />
<!-- 非枚举类型时显示文本框 -->
<TextBox MinWidth="120"
VerticalAlignment="Bottom"
Text="{Binding Parameter.Value, Converter={StaticResource ParameterValueToStringConverter}}"
materialDesign:HintAssist.Hint="参数值"
Visibility="{Binding Parameter.Type, Converter={StaticResource IsEnumTypeConverter}, ConverterParameter=Collapse}" />
<!-- 枚举类型时显示下拉框 -->
<!--<ComboBox MinWidth="120"
VerticalAlignment="Bottom"
ItemsSource="{Binding EnumValues}"
SelectedItem="{Binding Parameter.Value}"
Visibility="{Binding Parameter.Type, Converter={StaticResource IsEnumTypeConverter}}" />-->
<CheckBox Margin="10,0"
VerticalAlignment="Bottom"
Content="保存数据"
IsChecked="{Binding Parameter.IsSave}" />
</StackPanel>
</StackPanel>
</ScrollViewer>
<StackPanel Grid.Row="1"
Margin="5,10,5,15"
FlowDirection="RightToLeft"
Orientation="Horizontal">
<Button Content="取消"
Width="70"
Command="{Binding CancelCommand}" />
<Button Content="保存"
Width="70"
Margin="20,0"
Command="{Binding SaveCommand}" />
</StackPanel>
</Grid>
</GroupBox>
</Grid>
</UserControl>

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TestingModule.Views.Dialogs
{
/// <summary>
/// ParameterSetting.xaml 的交互逻辑
/// </summary>
public partial class ParameterSetting : UserControl
{
public ParameterSetting()
{
InitializeComponent();
}
private void ComboBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (sender is ComboBox comboBox && !comboBox.IsDropDownOpen)
{
comboBox.IsDropDownOpen = true;
e.Handled = true;
}
}
}
}

View File

@@ -0,0 +1,33 @@
<UserControl x:Class="TestingModule.Views.LogArea"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:prism="http://prismlibrary.com/"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800">
<Grid>
<GroupBox Header="系统运行日志">
<ListView x:Name="LogListView"
FontWeight="DemiBold"
ItemsSource="{Binding Logs}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="清空日志"
Command="{Binding ClearLogCommand}" />
</ContextMenu>
</ListView.ContextMenu>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Foreground="{Binding Color}"
Text="{Binding Message}"
TextWrapping="Wrap" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</GroupBox>
</Grid>
</UserControl>

View File

@@ -0,0 +1,34 @@
using TestingModule.ViewModels;
using System.Windows.Controls;
namespace TestingModule.Views
{
public partial class LogArea : UserControl
{
public LogArea()
{
InitializeComponent();
// 绑定 DataContext 后,订阅日志集合变化
this.Loaded += (s, e) =>
{
if (DataContext is LogAreaViewModel vm)
{
vm.Logs.CollectionChanged += Logs_CollectionChanged;
}
};
}
private void Logs_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
// 每次新增日志,滚动到最后一条
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
if (this.LogListView.Items.Count > 0)
{
this.LogListView.ScrollIntoView(this.LogListView.Items[^1]);
}
}
}
}
}

View File

@@ -0,0 +1,136 @@
<UserControl x:Class="TestingModule.Views.ParametersManager"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:prism="http://prismlibrary.com/"
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d">
<UserControl.Resources>
<CollectionViewSource x:Key="VisibleParameters"
Source="{Binding Program.Parameters}"
IsLiveFilteringRequested="True">
<CollectionViewSource.LiveFilteringProperties>
<sys:String>IsVisible</sys:String>
</CollectionViewSource.LiveFilteringProperties>
</CollectionViewSource>
<converters:ParameterCategoryToStringConverter x:Key="ParameterCategoryToStringConverter" />
<converters:ParameterValueToStringConverter x:Key="ParameterValueToStringConverter" />
</UserControl.Resources>
<Grid>
<GroupBox Header="设备/参数">
<TabControl>
<!-- 参数Tab -->
<TabItem Header="参数">
<DataGrid Padding="10"
Background="Transparent"
ItemsSource="{Binding Source={StaticResource VisibleParameters}}"
AutoGenerateColumns="False"
CanUserAddRows="False"
SelectionMode="Extended"
SelectionUnit="FullRow"
SelectedItem="{Binding SelectedParameter, Mode=TwoWay}">
<DataGrid.Columns>
<DataGridTextColumn Header="类别"
Binding="{Binding Category, Converter={StaticResource ParameterCategoryToStringConverter}}"
IsReadOnly="True" />
<DataGridTextColumn Header="参数名"
Binding="{Binding Name}"
IsReadOnly="True" />
<DataGridTextColumn Header="类型"
Binding="{Binding Type}"
IsReadOnly="True" />
<DataGridTextColumn Header="值"
MinWidth="20"
Binding="{Binding Value, Converter={StaticResource ParameterValueToStringConverter}}"
IsReadOnly="True" />
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="新增"
Command="{Binding ParameterAddCommand}" />
<MenuItem Header="编辑"
Command="{Binding ParameterEditCommand}" />
<MenuItem Header="删除"
Foreground="Red"
Command="{Binding ParameterDeleteCommand}"/>
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid>
</TabItem>
<!-- 设备Tab -->
<TabItem Header="设备">
<DataGrid Padding="10"
Background="Transparent"
ItemsSource="{Binding DeviceInfoModel}"
AutoGenerateColumns="False"
CanUserAddRows="False"
IsReadOnly="True"
SelectionMode="Extended"
SelectedItem="{Binding SelectedDevice, Mode=TwoWay}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="设备状态">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Ellipse Width="16"
Height="16"
StrokeThickness="1"
Stroke="DarkGray">
<Ellipse.Style>
<Style TargetType="Ellipse">
<Setter Property="Fill"
Value="Transparent" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsConnected}"
Value="True">
<Setter Property="Fill"
Value="LimeGreen" />
</DataTrigger>
<DataTrigger Binding="{Binding IsConnected}"
Value="False">
<Setter Property="Fill"
Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</Ellipse.Style>
</Ellipse>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="设备名称"
Binding="{Binding DeviceName}" />
<DataGridTemplateColumn Header="是否启用">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsEnabled}" IsEnabled="False" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="编辑"
Command="{Binding DeviceEditCommand}" />
<MenuItem Header="重新连接"
Command="{Binding ReconnnectCommand}" />
<MenuItem Header="关闭"
Command="{Binding CloseCommand}" />
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid>
</TabItem>
</TabControl>
</GroupBox>
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TestingModule.Views
{
/// <summary>
/// ParametersManager.xaml 的交互逻辑
/// </summary>
public partial class ParametersManager : UserControl
{
public ParametersManager()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,371 @@
<UserControl x:Class="TestingModule.Views.SingleStepEdit"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.Resources>
<converters:ParameterCategoryToVisibilityConverter x:Key="ParameterCategoryToVisibilityConverter" />
<converters:ParameterTypeToBoolConverter x:Key="ParameterTypeToBoolConverter" />
<converters:ParameterCategoryToStringConverter x:Key="ParameterCategoryToStringConverter" />
<converters:IsEnumTypeConverter x:Key="IsEnumTypeConverter" />
<converters:EnumValuesConverter x:Key="EnumValuesConverter" />
<converters:EnumValueConverter x:Key="EnumValueConverter" />
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<converters:FilteredParametersConverter x:Key="FilteredParametersConverter" />
</UserControl.Resources>
<Grid>
<GroupBox Header="单步编辑">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<!-- 名称 -->
<StackPanel Grid.Row="0"
Orientation="Horizontal"
Margin="7">
<Label Width="60"
Content="名称" />
<TextBox MinWidth="120"
materialDesign:HintAssist.Hint=""
Text="{Binding SelectedStep.Name}" />
</StackPanel>
<!-- 合格条件 -->
<StackPanel Grid.Row="1"
Orientation="Horizontal"
Margin="7">
<Label Width="60"
Content="合格条件" />
<TextBox MinWidth="120"
materialDesign:HintAssist.Hint=""
Text="{Binding SelectedStep.OKExpression}" />
</StackPanel>
<!-- 跳转 -->
<StackPanel Grid.Row="2"
Orientation="Horizontal"
Margin="7">
<Label Width="60"
Content="跳转"
ToolTip="格式OK跳转序号/NG跳转序号默认为0/0)" />
<TextBox MinWidth="120"
Text="{Binding SelectedStep.GotoSettingString}"
materialDesign:HintAssist.Hint="格式OK跳转序号/NG跳转序号默认为0/0)" />
</StackPanel>
<!-- 备注 -->
<StackPanel Grid.Row="3"
Orientation="Horizontal"
Margin="7">
<Label Width="60"
Content="备注" />
<TextBox MinWidth="120"
materialDesign:HintAssist.Hint=""
Text="{Binding SelectedStep.Description}" />
</StackPanel>
<!-- 参数编辑区 -->
<Grid Grid.Row="4">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Height="30"
Orientation="Horizontal">
<Label Margin="7,0"
VerticalAlignment="Bottom"
Content="参数" />
</StackPanel>
<ScrollViewer Grid.Row="1"
Margin="40,0,0,0"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<StackPanel>
<ItemsControl ItemsSource="{Binding SelectedStep.Method.Parameters}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="50" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"
Margin="7,7,0,7"
Orientation="Horizontal">
<TextBlock VerticalAlignment="Bottom"
Text="{Binding Name}" />
<TextBlock VerticalAlignment="Bottom"
Text="(" />
<TextBlock VerticalAlignment="Bottom"
Text="{Binding Type.Name}" />
<TextBlock VerticalAlignment="Bottom"
Text=")" />
</StackPanel>
<StackPanel Grid.Column="1"
Margin="7"
Orientation="Horizontal">
<TextBlock Margin="5,0"
VerticalAlignment="Bottom"
Text="{Binding Category, Converter={StaticResource ParameterCategoryToStringConverter}}" />
</StackPanel>
<StackPanel Grid.Column="2"
Margin="7"
Orientation="Horizontal">
<!-- 输入参数编辑 -->
<StackPanel Height="30"
IsEnabled="{Binding Type, Converter={StaticResource ParameterTypeToBoolConverter}}"
Orientation="Horizontal"
Visibility="{Binding Category, Converter={StaticResource ParameterCategoryToVisibilityConverter}}">
<CheckBox VerticalAlignment="Bottom" Margin="0 15 0 0"
IsChecked="{Binding IsUseVar}" />
<Grid>
<!-- 常量输入区域 -->
<Grid Visibility="{Binding IsUseVar, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=Inverse}">
<!-- 非枚举类型 -->
<TextBox Height="22"
MinWidth="120"
VerticalAlignment="Bottom"
Padding="0"
Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}"
materialDesign:HintAssist.Hint=""
Visibility="{Binding Type, Converter={StaticResource IsEnumTypeConverter}, ConverterParameter=Collapse}" />
<!-- 枚举类型 -->
<ComboBox Height="22"
MinWidth="120"
VerticalAlignment="Bottom"
materialDesign:HintAssist.Hint=""
ItemsSource="{Binding Type, Converter={StaticResource EnumValuesConverter}}"
Visibility="{Binding Type, Converter={StaticResource IsEnumTypeConverter}}">
<ComboBox.SelectedItem>
<MultiBinding Converter="{StaticResource EnumValueConverter}">
<Binding Path="Type" />
<Binding Path="Value" />
</MultiBinding>
</ComboBox.SelectedItem>
</ComboBox>
</Grid>
<!-- 变量选择框 -->
<ComboBox Height="22"
MinWidth="120"
materialDesign:HintAssist.Hint=""
VerticalAlignment="Bottom"
SelectedValue="{Binding VariableName}"
SelectedValuePath="Name"
Visibility="{Binding IsUseVar, Converter={StaticResource BooleanToVisibilityConverter}}">
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource FilteredParametersConverter}">
<Binding Path="Type" />
<Binding Path="DataContext.Program.Parameters"
RelativeSource="{RelativeSource AncestorType=UserControl}" />
</MultiBinding>
</ComboBox.ItemsSource>
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<TextBlock Text="(" />
<TextBlock Text="{Binding Type.Name, TargetNullValue=Unknown}" />
<TextBlock Text=")" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</StackPanel>
<!-- 输出参数编辑 -->
<StackPanel Height="30"
Orientation="Horizontal"
Visibility="{Binding Category, Converter={StaticResource ParameterCategoryToVisibilityConverter}, ConverterParameter=Inverse}">
<CheckBox VerticalAlignment="Bottom"
IsChecked="{Binding IsUseVar}"
Margin="0 15 0 0"
/>
<ComboBox Width="120"
Margin="0,0,0,0"
materialDesign:HintAssist.Hint=""
VerticalAlignment="Bottom"
SelectedValue="{Binding VariableName}"
SelectedValuePath="Name"
Visibility="{Binding Category, Converter={StaticResource ParameterCategoryToVisibilityConverter}, ConverterParameter=Inverse}">
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource FilteredParametersConverter}">
<Binding Path="Type" />
<Binding Path="DataContext.Program.Parameters"
RelativeSource="{RelativeSource AncestorType=UserControl}" />
</MultiBinding>
</ComboBox.ItemsSource>
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<TextBlock Text="(" />
<TextBlock Text="{Binding Type.Name, TargetNullValue=Unknown}" />
<TextBlock Text=")" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsControl ItemsSource="{Binding SelectedStep.SubProgram.Parameters}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Visibility="{Binding Category, Converter={StaticResource ParameterCategoryToVisibilityConverter}, ConverterParameter=Item}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="50" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"
Margin="7,7,0,7"
Orientation="Horizontal">
<TextBlock VerticalAlignment="Bottom"
Text="{Binding Name}" />
<TextBlock VerticalAlignment="Bottom"
Text="(" />
<TextBlock VerticalAlignment="Bottom"
Text="{Binding Type.Name}" />
<TextBlock VerticalAlignment="Bottom"
Text=")" />
</StackPanel>
<StackPanel Grid.Column="1"
Margin="7"
Orientation="Horizontal">
<TextBlock Margin="5,0"
VerticalAlignment="Bottom"
Text="{Binding Category, Converter={StaticResource ParameterCategoryToStringConverter}}" />
</StackPanel>
<StackPanel Grid.Column="2"
Margin="7"
Orientation="Horizontal">
<!-- 输入参数编辑 -->
<StackPanel Height="30"
Orientation="Horizontal"
Visibility="{Binding Category, Converter={StaticResource ParameterCategoryToVisibilityConverter}}">
<CheckBox VerticalAlignment="Bottom"
IsChecked="{Binding IsUseVar}" />
<Grid>
<!-- 常量输入区域 -->
<Grid Visibility="{Binding IsUseVar, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=Inverse}">
<!-- 非枚举类型 -->
<TextBox Height="22"
MinWidth="120"
materialDesign:HintAssist.Hint=""
VerticalAlignment="Bottom"
Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding Type, Converter={StaticResource IsEnumTypeConverter}, ConverterParameter=Collapse}" />
<!-- 枚举类型 -->
<ComboBox Height="22"
MinWidth="120"
materialDesign:HintAssist.Hint=""
VerticalAlignment="Bottom"
ItemsSource="{Binding Type, Converter={StaticResource EnumValuesConverter}}"
SelectedItem="{Binding Value}"
Visibility="{Binding Type, Converter={StaticResource IsEnumTypeConverter}}" />
</Grid>
<!-- 变量选择框 -->
<ComboBox Height="22"
MinWidth="120"
materialDesign:HintAssist.Hint=""
VerticalAlignment="Bottom"
ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=DataContext.Program.Parameters}"
SelectedValue="{Binding VariableName}"
SelectedValuePath="Name"
Visibility="{Binding IsUseVar, Converter={StaticResource BooleanToVisibilityConverter}}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<TextBlock Text="(" />
<TextBlock Text="{Binding Type.Name, TargetNullValue=Unknown}" />
<TextBlock Text=")" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</StackPanel>
<!-- 输出参数编辑 -->
<CheckBox VerticalAlignment="Bottom"
IsChecked="{Binding IsUseVar}"
Visibility="{Binding Category, Converter={StaticResource ParameterCategoryToVisibilityConverter}, ConverterParameter=Inverse}" />
<ComboBox Width="120"
Margin="0,0,0,0"
materialDesign:HintAssist.Hint=""
VerticalAlignment="Bottom"
ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=DataContext.Program.Parameters}"
SelectedValue="{Binding VariableName}"
SelectedValuePath="Name"
Visibility="{Binding Category, Converter={StaticResource ParameterCategoryToVisibilityConverter}, ConverterParameter=Inverse}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<TextBlock Text="(" />
<TextBlock Text="{Binding Type.Name, TargetNullValue=Unknown}" />
<TextBlock Text=")" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
</Grid>
<!-- 按钮 -->
<StackPanel Grid.Row="5"
Orientation="Horizontal"
FlowDirection="RightToLeft"
Margin="5,0">
<Button Width="90"
Content="取消"
Command="{Binding CancelEditCommand}" />
<Button Width="90"
Margin="20,0"
Content="保存"
Command="{Binding SaveStepCommand}" />
</StackPanel>
</Grid>
</GroupBox>
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TestingModule.Views
{
/// <summary>
/// SingleStepEdit.xaml 的交互逻辑
/// </summary>
public partial class SingleStepEdit : UserControl
{
public SingleStepEdit()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,244 @@
<UserControl x:Class="TestingModule.Views.StepsManager"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dd="urn:gong-wpf-dragdrop"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:behaviors="clr-namespace:UIShare.Behaviors;assembly=UIShare"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<Grid>
<GroupBox Header="程序编辑区域">
<TabControl SelectedIndex="{Binding SelectedTabIndex, Mode=TwoWay}">
<i:Interaction.Behaviors>
<behaviors:TabControlSelectionChangedBehavior Command="{Binding TabSelectionChangedCommand}"
CommandParameter="{Binding SelectedTabHeader}" />
</i:Interaction.Behaviors>
<TabItem Header="主程序">
<DataGrid dd:DragDrop.IsDragSource="{Binding Admin}"
dd:DragDrop.IsDropTarget="{Binding Admin}"
dd:DragDrop.UseDefaultDragAdorner="{Binding Admin}"
AutoGenerateColumns="False"
Background="Transparent"
CanUserAddRows="False"
CanUserSortColumns="False"
ItemsSource="{Binding Program.StepCollection}"
SelectedItem="{Binding SelectedStep, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
SelectionMode="Extended"
SelectionUnit="FullRow">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding SelectedItems, RelativeSource={RelativeSource AncestorType=DataGrid}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<!-- 行样式 -->
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Foreground"
Value="Black" />
<Style.Triggers>
<DataTrigger Binding="{Binding Result}"
Value="0">
<Setter Property="Background"
Value="DodgerBlue" />
<Setter Property="Foreground"
Value="White" />
</DataTrigger>
<DataTrigger Binding="{Binding Result}"
Value="1">
<Setter Property="Background"
Value="LimeGreen" />
<Setter Property="Foreground"
Value="White" />
</DataTrigger>
<DataTrigger Binding="{Binding Result}"
Value="2">
<Setter Property="Background"
Value="Red" />
<Setter Property="Foreground"
Value="White" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<!-- 列 -->
<DataGrid.Columns>
<DataGridCheckBoxColumn Width="58"
Binding="{Binding IsUsed, UpdateSourceTrigger=PropertyChanged}"
Header="启用" />
<DataGridTextColumn Binding="{Binding Index}"
Header="序号"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Name}"
Header="名称"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding StepType}"
Header="类型"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Method.FullName}"
Header="指令类型"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Method.Name}"
Header="指令"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding OKExpression}"
Header="合格条件"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding RunTime}"
Header="耗时(ms)"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Result}"
Header="结果"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Description}"
Header="备注" />
</DataGrid.Columns>
<!-- ContextMenu MVVM化 -->
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="编辑"
Command="{Binding EditStepCommand}" />
<MenuItem Header="复制"
Command="{Binding CopyStepCommand}" />
<MenuItem Header="粘贴"
Command="{Binding PasteStepCommand}" />
<MenuItem Header="删除"
Foreground="Red"
Command="{Binding DeleteStepCommand}" />
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid>
</TabItem>
<TabItem Header="错误程序">
<DataGrid dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.UseDefaultDragAdorner="True"
AutoGenerateColumns="False"
Background="Transparent"
CanUserAddRows="False"
CanUserSortColumns="False"
ItemsSource="{Binding Program.ErrorStepCollection}"
SelectedItem="{Binding SelectedStep, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
SelectionMode="Extended"
SelectionUnit="FullRow">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding SelectedItems, RelativeSource={RelativeSource AncestorType=DataGrid}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<!-- 行样式 -->
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Foreground"
Value="Black" />
<Style.Triggers>
<DataTrigger Binding="{Binding Result}"
Value="0">
<Setter Property="Background"
Value="DodgerBlue" />
<Setter Property="Foreground"
Value="White" />
</DataTrigger>
<DataTrigger Binding="{Binding Result}"
Value="1">
<Setter Property="Background"
Value="LimeGreen" />
<Setter Property="Foreground"
Value="White" />
</DataTrigger>
<DataTrigger Binding="{Binding Result}"
Value="2">
<Setter Property="Background"
Value="Red" />
<Setter Property="Foreground"
Value="White" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<!-- 列 -->
<DataGrid.Columns>
<DataGridCheckBoxColumn Width="58"
Binding="{Binding IsUsed, UpdateSourceTrigger=PropertyChanged}"
Header="启用" />
<DataGridTextColumn Binding="{Binding Index}"
Header="序号"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Name}"
Header="名称"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding StepType}"
Header="类型"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Method.FullName}"
Header="指令类型"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Method.Name}"
Header="指令"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding OKExpression}"
Header="合格条件"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding RunTime}"
Header="耗时(ms)"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Result}"
Header="结果"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Description}"
Header="备注" />
</DataGrid.Columns>
<!-- ContextMenu MVVM化 -->
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="编辑"
Command="{Binding EditStepCommand}" />
<MenuItem Header="复制"
Command="{Binding CopyStepCommand}" />
<MenuItem Header="粘贴"
Command="{Binding PasteStepCommand}" />
<MenuItem Header="删除"
Foreground="Red"
Command="{Binding DeleteStepCommand}" />
</ContextMenu>
</DataGrid.ContextMenu>
<!-- 键盘 删除键绑定 Delete 命令 -->
<!--<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewKeyDown">
<i:InvokeCommandAction Command="{Binding DeleteStepCommand}"
CommandParameter="{Binding SelectedStep}"
PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>-->
</DataGrid>
</TabItem>
</TabControl>
</GroupBox>
</Grid>
</UserControl>

View File

@@ -0,0 +1,31 @@
using UIShare.PubEvent;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TestingModule.Views
{
/// <summary>
/// StepsManager.xaml 的交互逻辑
/// </summary>
public partial class StepsManager : UserControl
{
public StepsManager()
{
InitializeComponent();
}
}
}