diff --git a/BOB/App.xaml b/BOB/App.xaml index 21d7209..5a6c6e5 100644 --- a/BOB/App.xaml +++ b/BOB/App.xaml @@ -25,6 +25,66 @@ + + diff --git a/BOB/App.xaml.cs b/BOB/App.xaml.cs index 6c7466b..a132772 100644 --- a/BOB/App.xaml.cs +++ b/BOB/App.xaml.cs @@ -34,11 +34,12 @@ namespace BOB containerRegistry.RegisterForNavigation("MainView"); //注册弹窗 containerRegistry.RegisterDialog("MessageBox"); + containerRegistry.RegisterDialog("ParameterSetting"); + containerRegistry.RegisterDialog("DeviceSetting"); //注册全局变量 containerRegistry.RegisterSingleton(); } - } diff --git a/Common/Converters/BooleanToVisibilityConverter.cs b/BOB/Converters/BooleanToVisibilityConverter.cs similarity index 50% rename from Common/Converters/BooleanToVisibilityConverter.cs rename to BOB/Converters/BooleanToVisibilityConverter.cs index 5790936..1dd2e23 100644 --- a/Common/Converters/BooleanToVisibilityConverter.cs +++ b/BOB/Converters/BooleanToVisibilityConverter.cs @@ -7,30 +7,27 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Data; -namespace Common.Converters +namespace BOB.Converters { public class BooleanToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - bool input = value is bool b && b; - bool invert = parameter?.ToString()?.ToLower() == "invert"; - - if (invert) - input = !input; - - return input ? Visibility.Visible : Visibility.Collapsed; + if (value is bool boolValue) + { + // 处理反转逻辑 + if (parameter?.ToString() == "Inverse") + { + boolValue = !boolValue; + } + return boolValue ? Visibility.Visible : Visibility.Collapsed; + } + return Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - bool output = value is Visibility v && v == Visibility.Visible; - bool invert = parameter?.ToString()?.ToLower() == "invert"; - - if (invert) - output = !output; - - return output; + throw new NotImplementedException(); } } } diff --git a/BOB/Converters/DeviceNameConverter.cs b/BOB/Converters/DeviceNameConverter.cs new file mode 100644 index 0000000..c01ff01 --- /dev/null +++ b/BOB/Converters/DeviceNameConverter.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace BOB.Converters +{ + public class DeviceNameConverter : IValueConverter + { + private readonly string[] specialName = { "奇偶" }; + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is string name) + { + if (specialName.Contains(name)) + { + if (parameter?.ToString() == "Inverse") + { + return Visibility.Visible; + } + else if (parameter?.ToString() == "Items") + { + switch (name) + { + case "奇偶": + return new List { "无", "奇", "偶" }; + } + } + return Visibility.Collapsed; + } + } + if (parameter?.ToString() == "Inverse") + { + return Visibility.Collapsed; + } + return Visibility.Visible; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/BOB/Converters/EnumValueConverter.cs b/BOB/Converters/EnumValueConverter.cs new file mode 100644 index 0000000..f343478 --- /dev/null +++ b/BOB/Converters/EnumValueConverter.cs @@ -0,0 +1,82 @@ +using System; +using System.Globalization; +using System.Linq; +using System.Windows.Data; + +namespace BOB.Converters +{ + public class EnumValueConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + // 验证输入参数 + if (values.Length < 2 || values[0] == null || values[1] == null) + { + return null; + } + + try + { + // 获取枚举类型 + Type enumType = values[0] as Type; + if (enumType == null || !enumType.IsEnum) + { + return null; + } + + // 获取数值 + object value = values[1]; + + // 确保数值类型匹配枚举的底层类型 + Type underlyingType = Enum.GetUnderlyingType(enumType); + object convertedValue; + + try + { + convertedValue = System.Convert.ChangeType(value, underlyingType); + } + catch + { + // 如果转换失败,尝试直接使用原始值 + convertedValue = value; + } + + // 将数值转换为枚举值 + return Enum.ToObject(enumType, convertedValue); + } + catch + { + // 发生任何异常时返回null + return null; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + if (value == null) + { + return [null, null]; + } + + try + { + // 获取枚举值的底层数值 + Type enumType = value.GetType(); + if (!enumType.IsEnum) + { + return [null, null]; + } + + Type underlyingType = Enum.GetUnderlyingType(enumType); + object numericValue = System.Convert.ChangeType(value, underlyingType); + + // 返回枚举类型和对应的数值 + return [enumType, numericValue]; + } + catch + { + return [null, null]; + } + } + } +} \ No newline at end of file diff --git a/BOB/Converters/EnumValuesConverter.cs b/BOB/Converters/EnumValuesConverter.cs new file mode 100644 index 0000000..a61c605 --- /dev/null +++ b/BOB/Converters/EnumValuesConverter.cs @@ -0,0 +1,23 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace BOB.Converters +{ + public class EnumValuesConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is Type type && type.IsEnum) + { + return Enum.GetValues(type); + } + return null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/BOB/Converters/FilteredParametersConverter.cs b/BOB/Converters/FilteredParametersConverter.cs new file mode 100644 index 0000000..b2a1de7 --- /dev/null +++ b/BOB/Converters/FilteredParametersConverter.cs @@ -0,0 +1,74 @@ + +using BOB.Models; +using System; +using System.Globalization; +using System.Linq; +using System.Windows.Data; + +namespace BOB.Converters +{ + public class FilteredParametersConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length < 2 || values[0] == null || values[1] == null) + return null; + + Type currentParamType = values[0] as Type; + var allParameters = values[1] as System.Collections.IEnumerable; + + if (currentParamType == null || allParameters == null) + return allParameters; + + // 过滤出类型匹配的参数 + return allParameters.Cast() + .Where(p => IsTypeMatch(currentParamType, p.Type)) + .ToList(); + } + + private bool IsTypeMatch(Type currentType, Type candidateType) + { + if (candidateType == null) return false; + + // 如果候选参数类型是 object,则匹配所有类型 + if (candidateType == typeof(object)) return true; + + // 如果类型完全相同,则匹配 + if (candidateType == currentType) return true; + + // 处理数值类型的兼容性 + if (IsNumericType(currentType) && IsNumericType(candidateType)) + return true; + + return false; + } + + private bool IsNumericType(Type type) + { + if (type == null) return false; + + switch (Type.GetTypeCode(type)) + { + case TypeCode.Byte: + case TypeCode.SByte: + case TypeCode.UInt16: + case TypeCode.UInt32: + case TypeCode.UInt64: + case TypeCode.Int16: + case TypeCode.Int32: + case TypeCode.Int64: + case TypeCode.Decimal: + case TypeCode.Double: + case TypeCode.Single: + return true; + default: + return false; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/BOB/Converters/IsEnumTypeConverter .cs b/BOB/Converters/IsEnumTypeConverter .cs new file mode 100644 index 0000000..d2de271 --- /dev/null +++ b/BOB/Converters/IsEnumTypeConverter .cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace BOB.Converters +{ + public class IsEnumTypeConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is Type type) + { + // 检查是否为枚举类型 + bool isEnum = type.IsEnum; + + // 根据参数决定返回值类型 + if (parameter is string strParam && strParam == "Collapse") + { + return isEnum ? Visibility.Collapsed : Visibility.Visible; + } + return isEnum ? Visibility.Visible : Visibility.Collapsed; + } + return Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/BOB/Converters/ParameterCategoryToStringConverter.cs b/BOB/Converters/ParameterCategoryToStringConverter.cs new file mode 100644 index 0000000..9bff572 --- /dev/null +++ b/BOB/Converters/ParameterCategoryToStringConverter.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using static BOB.Models.ParameterModel; + + +namespace BOB.Converters +{ + public class ParameterCategoryToStringConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + + if (value is ParameterCategory category) + { + switch (category) + { + case ParameterCategory.Input: + return "输入"; + case ParameterCategory.Output: + return "输出"; + case ParameterCategory.Temp: + return "缓存"; + default: + return "未知"; + } + } + return "未知"; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/BOB/Converters/ParameterCategoryToVisibilityConverter.cs b/BOB/Converters/ParameterCategoryToVisibilityConverter.cs new file mode 100644 index 0000000..162a53b --- /dev/null +++ b/BOB/Converters/ParameterCategoryToVisibilityConverter.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using static BOB.Models.ParameterModel; + +namespace BOB.Converters +{ + public class ParameterCategoryToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is ParameterCategory category) + { + if (parameter?.ToString() == "Item") + { + if (category == ParameterCategory.Temp) { return Visibility.Collapsed; } + else { return Visibility.Visible; } + } + bool boolValue = category == ParameterCategory.Input; + if (parameter?.ToString() == "Inverse") + { + boolValue = !boolValue; + } + return boolValue ? Visibility.Visible : Visibility.Collapsed; + } + return Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/BOB/Converters/ParameterTypeToBoolConverter.cs b/BOB/Converters/ParameterTypeToBoolConverter.cs new file mode 100644 index 0000000..12addda --- /dev/null +++ b/BOB/Converters/ParameterTypeToBoolConverter.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace BOB.Converters +{ + public class ParameterTypeToBoolConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if(value is Type type) + { + if(type == typeof(CancellationToken)) + { + return false; + } + } + return true; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/BOB/Converters/ParameterValueToStringConverter.cs b/BOB/Converters/ParameterValueToStringConverter.cs new file mode 100644 index 0000000..40bf6e6 --- /dev/null +++ b/BOB/Converters/ParameterValueToStringConverter.cs @@ -0,0 +1,38 @@ +using ControlzEx.Standard; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace BOB.Converters +{ + public class ParameterValueToStringConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is IEnumerable enumerable && !(value is string)) + { + var elements = enumerable.Cast().Select(item => item?.ToString() ?? "null"); + return $"[{string.Join(", ", elements)}]"; + } + else if(value != null) + { + return value.ToString()!; + } + return ""; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null) + { + return value.ToString()!; + } + return ""; + } + } +} diff --git a/BOB/Converters/StringToVisibilityConverter.cs b/BOB/Converters/StringToVisibilityConverter.cs new file mode 100644 index 0000000..c1c9486 --- /dev/null +++ b/BOB/Converters/StringToVisibilityConverter.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace BOB.Converters +{ + public class StringToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if(value is string str) + { + if (string.IsNullOrEmpty(str)) + { + return Visibility.Collapsed; + } + else + { + return Visibility.Visible; + } + } + return Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/BOB/GlobalVariables.cs b/BOB/GlobalVariables.cs index 8149e0e..f729377 100644 --- a/BOB/GlobalVariables.cs +++ b/BOB/GlobalVariables.cs @@ -12,7 +12,10 @@ namespace BOB public ProgramModel Program = new(); public bool IsAdmin=true; public String UserName="hsc"; + public String Title = "主程序"; public string CurrentFilePath; public StepModel SelectedStep; + public ParameterModel SelectedParameter; + public DeviceModel SelectedDevice; } } diff --git a/BOB/Models/DeviceConnectSettingModel.cs b/BOB/Models/DeviceConnectSettingModel.cs new file mode 100644 index 0000000..8d2ea36 --- /dev/null +++ b/BOB/Models/DeviceConnectSettingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BOB.Models +{ + public class DeviceConnectSettingModel + { + public string Name { get; set; } = ""; + + public string Value { get; set; } = ""; + } +} diff --git a/BOB/ViewModels/Dialogs/DeviceSettingViewModel.cs b/BOB/ViewModels/Dialogs/DeviceSettingViewModel.cs new file mode 100644 index 0000000..bf4e81c --- /dev/null +++ b/BOB/ViewModels/Dialogs/DeviceSettingViewModel.cs @@ -0,0 +1,192 @@ +using BOB.Models; +using Newtonsoft.Json; +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 static BOB.Models.ParameterModel; + +namespace BOB.ViewModels.Dialogs +{ + public class DeviceSettingViewModel : BindableBase, IDialogAware + { + #region 属性 + private string _title = "设备设置界面"; + public string Title + { + get => _title; + set => SetProperty(ref _title, value); + } + private ObservableCollection _types = ["串口", "Tcp", "ModbusRtu", "ModbusTcp", "CAN", "Udp"]; + public ObservableCollection Types + { + get => _types; + set => SetProperty(ref _types, value); + } + + private string _Mode; + public string Mode + { + get => _Mode; + set => SetProperty(ref _Mode, value); + } + private bool _IsAdd; + public bool IsAdd + { + get => _IsAdd; + set => SetProperty(ref _IsAdd, value); + } + + private ProgramModel _program; + public ProgramModel Program + { + get => _program; + set => SetProperty(ref _program, value); + } + private DeviceModel _Device; + public DeviceModel Device + { + get => _Device; + set => SetProperty(ref _Device, value); + } + private ObservableCollection _DeviceConnectSettings=new(); + public ObservableCollection DeviceConnectSettings + { + get => _DeviceConnectSettings; + set => SetProperty(ref _DeviceConnectSettings, value); + } + + #endregion + public DialogCloseListener RequestClose { get; set; } + private GlobalVariables _globalVariables; + public ICommand CancelCommand { get; set; } + public ICommand SaveCommand { get; set; } + public ICommand SelectionChangedCommand { get; set; } + public DeviceSettingViewModel(GlobalVariables globalVariables) + { + _globalVariables = globalVariables; + CancelCommand = new DelegateCommand(Cancel); + SaveCommand = new DelegateCommand(Save); + SelectionChangedCommand = new DelegateCommand(SelectionChanged); + } + + private void SelectionChanged() + { + if (Device == null) return; + DeviceConnectSettings.Clear(); + switch (Device!.Type) + { + case "Tcp": + case "ModbusTcp": + DeviceConnectSettings.Add(new() + { + Name = "IP地址", + Value = "127.0.0.1" + }); + DeviceConnectSettings.Add(new() + { + Name = "端口号", + Value = "502" + }); + break; + case "串口": + case "ModbusRtu": + DeviceConnectSettings.Add(new() + { + Name = "COM口", + Value = "COM1" + }); + DeviceConnectSettings.Add(new() + { + Name = "波特率", + Value = "9600" + }); + DeviceConnectSettings.Add(new() + { + Name = "数据位", + Value = "8" + }); + DeviceConnectSettings.Add(new() + { + Name = "停止位", + Value = "1" + }); + DeviceConnectSettings.Add(new() + { + Name = "奇偶", + Value = "无" + }); + break; + case "Udp": + DeviceConnectSettings.Add(new() + { + Name = "远程IP地址", + Value = "127.0.0.1" + }); + DeviceConnectSettings.Add(new() + { + Name = "远程端口号", + Value = "8080" + }); + DeviceConnectSettings.Add(new() + { + Name = "本地端口号", + Value = "0" + }); + break; + } + DeviceConnectSettings.Add(new() + { + Name = "读超时", + Value = "3000" + }); + DeviceConnectSettings.Add(new() + { + Name = "写超时", + Value = "3000" + }); + } + + private void Save() + { + + } + + private void Cancel() + { + RequestClose.Invoke(); + } + #region Prism Dialog 规范 + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + + } + + public void OnDialogOpened(IDialogParameters parameters) + { + Program = _globalVariables.Program; + Mode = parameters.GetValue("Mode"); + if(Mode == "ADD") + { + Device = new(); + IsAdd = true; + Device.Type = "TCP"; + SelectionChanged(); + } + else + { + Device = _globalVariables.SelectedDevice; + IsAdd = false; + } + } + #endregion + } +} diff --git a/BOB/ViewModels/Dialogs/ParameterSettingViewModel.cs b/BOB/ViewModels/Dialogs/ParameterSettingViewModel.cs new file mode 100644 index 0000000..1786512 --- /dev/null +++ b/BOB/ViewModels/Dialogs/ParameterSettingViewModel.cs @@ -0,0 +1,108 @@ +using BOB.Models; +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 static BOB.Models.ParameterModel; + +namespace BOB.ViewModels.Dialogs +{ + public class ParameterSettingViewModel : BindableBase, IDialogAware + { + #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 _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 Types + { + get => _types; + set => SetProperty(ref _types, value); + } + + private ObservableCollection _categories = new ObservableCollection( + Enum.GetNames(typeof(ParameterCategory)) + ); + public ObservableCollection 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 GlobalVariables _globalVariables; + public ICommand CancelCommand { get; set; } + public ICommand SaveCommand { get; set; } + public ParameterSettingViewModel(GlobalVariables globalVariables) + { + _globalVariables = globalVariables; + CancelCommand = new DelegateCommand(Cancel); + SaveCommand = new DelegateCommand(Save); + } + + private void Save() + { + + } + + private void Cancel() + { + RequestClose.Invoke(); + } + #region Prism Dialog 规范 + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + + } + + public void OnDialogOpened(IDialogParameters parameters) + { + Program=_globalVariables.Program; + Parameter = _globalVariables.SelectedParameter; + Mode = parameters.GetValue("Mode"); + } + #endregion + } +} diff --git a/BOB/ViewModels/ParametersManagerViewModel.cs b/BOB/ViewModels/ParametersManagerViewModel.cs index 98e5c59..e6a2fc2 100644 --- a/BOB/ViewModels/ParametersManagerViewModel.cs +++ b/BOB/ViewModels/ParametersManagerViewModel.cs @@ -1,16 +1,129 @@ -using System; +using BOB.Models; +using MaterialDesignThemes.Wpf; +using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; +using System.Xml; namespace BOB.ViewModels { - public class ParametersManagerViewModel + public class ParametersManagerViewModel:BindableBase,IDialogAware { - public ParametersManagerViewModel() + #region 属性 + private ProgramModel _program; + public ProgramModel Program + { + get => _program; + set => SetProperty(ref _program, value); + } + private ParameterModel _SelectedParameter; + public ParameterModel SelectedParameter + { + get => _SelectedParameter; + set => SetProperty(ref _SelectedParameter, value); + } + private DeviceModel _SelectedDevice; + public DeviceModel SelectedDevice + { + get => _SelectedDevice; + set => SetProperty(ref _SelectedDevice, value); + } + #endregion + public DialogCloseListener RequestClose { get; set; } + GlobalVariables _GlobalVariables { get; set; } + IDialogService _dialogService { get; set; } + public ICommand ParameterAddCommand { get; set; } + public ICommand ParameterEditCommand { get; set; } + public ICommand ParameterDeleteCommand { get; set; } + public ICommand DeviceAddCommand { get; set; } + public ICommand DeviceEditCommand { get; set; } + public ICommand DeviceDeleteCommand { get; set; } + + + + public ParametersManagerViewModel(GlobalVariables GlobalVariables,IDialogService dialogService) + { + _GlobalVariables = GlobalVariables; + _dialogService= dialogService; + Program = _GlobalVariables.Program; + ParameterAddCommand = new DelegateCommand(ParameterAdd); + ParameterEditCommand = new DelegateCommand(ParameterEdit); + ParameterDeleteCommand = new DelegateCommand(ParameterDelete); + DeviceAddCommand = new DelegateCommand(DeviceAdd); + DeviceEditCommand = new DelegateCommand(DeviceEdit); + DeviceDeleteCommand = new DelegateCommand(DeviceDelete); + + + } + #region 委托命令 + + private void DeviceDelete() { } + + private void DeviceEdit() + { + var param = new DialogParameters + { + { "Mode", _GlobalVariables.SelectedDevice==null?"ADD":"Edit" } + }; + _dialogService.ShowDialog("DeviceSetting", param); + + } + + private void DeviceAdd() + { + var param = new DialogParameters + { + { "Mode", "ADD" } + }; + _dialogService.ShowDialog("DeviceSetting", param); + } + + private void ParameterDelete() + { + + } + + private void ParameterEdit() + { + var param = new DialogParameters + { + { "Mode", _GlobalVariables.SelectedParameter==null?"ADD":"Edit" } + }; + _dialogService.ShowDialog("ParameterSetting", param); + } + + private void ParameterAdd() + { + var param = new DialogParameters + { + { "Mode", "ADD" } + }; + _dialogService.ShowDialog("ParameterSetting", param); + } + #endregion + #region Prism Dialog 规范 + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() + { + + } + + public void OnDialogOpened(IDialogParameters parameters) + { + + } + #endregion } } diff --git a/BOB/ViewModels/ShellViewModel.cs b/BOB/ViewModels/ShellViewModel.cs index cb77620..b68d966 100644 --- a/BOB/ViewModels/ShellViewModel.cs +++ b/BOB/ViewModels/ShellViewModel.cs @@ -1,5 +1,6 @@ using BOB.Views; using Common.PubEvents; +using Logger; using MaterialDesignThemes.Wpf; using System; using System.Collections.Generic; @@ -7,6 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Documents; using System.Windows.Input; namespace BOB.ViewModels @@ -28,16 +30,46 @@ namespace BOB.ViewModels public ICommand MinimizeCommand { get; set; } public ICommand MaximizeCommand { get; set; } public ICommand CloseCommand { get; set; } + public ICommand RunningCommand { get; set; } + public ICommand RunSingleCommand { get; set; } + public ICommand ResotrationCommand { get; set; } + public ICommand StopCommand { get; set; } #endregion private IEventAggregator _eventAggregator; - public ShellViewModel(IEventAggregator eventAggregator, IContainerProvider containerProvider) + private GlobalVariables _globalVariables; + public ShellViewModel(IEventAggregator eventAggregator, IContainerProvider containerProvider,GlobalVariables globalVariables) { _eventAggregator= eventAggregator; + _globalVariables= globalVariables; LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen); MinimizeCommand = new DelegateCommand(MinimizeWindow); MaximizeCommand = new DelegateCommand(MaximizeWindow); CloseCommand = new DelegateCommand(CloseWindow); + RunningCommand = new DelegateCommand(Running); + RunSingleCommand = new DelegateCommand(RunSingle); + ResotrationCommand = new DelegateCommand(Resotration); + StopCommand = new DelegateCommand(Stop); + } + + private void Stop(Window window) + { + LoggerHelper.InfoWithNotify(_globalVariables.UserName+"执行停止命令"); + } + + private void Resotration(Window window) + { + LoggerHelper.InfoWithNotify(_globalVariables.UserName + "执行复位命令"); + } + + private void RunSingle(Window window) + { + LoggerHelper.InfoWithNotify(_globalVariables.UserName + "执行单步执行命令"); + } + + private void Running(Window window) + { + LoggerHelper.InfoWithNotify(_globalVariables.UserName + "执行运行命令"); } private void LeftDrawerOpen() diff --git a/BOB/ViewModels/SingleStepEditViewModel.cs b/BOB/ViewModels/SingleStepEditViewModel.cs index 5ac345f..1b4dcff 100644 --- a/BOB/ViewModels/SingleStepEditViewModel.cs +++ b/BOB/ViewModels/SingleStepEditViewModel.cs @@ -1,16 +1,58 @@ -using System; +using BOB.Models; +using Common.PubEvent; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; namespace BOB.ViewModels { - public class SingleStepEditViewModel + public class SingleStepEditViewModel:BindableBase { - public SingleStepEditViewModel() + #region 属性 + private StepModel _SelectedStep; + public StepModel SelectedStep { - + get => _SelectedStep; + set => SetProperty(ref _SelectedStep, value); + } + + #endregion + private GlobalVariables _globalVariables; + private IEventAggregator _eventAggregator; + public ICommand CancelEditCommand { get; set; } + public ICommand SaveStepCommand { get; set; } + public SingleStepEditViewModel(GlobalVariables globalVariables,IEventAggregator eventAggregator) + { + _globalVariables= globalVariables; + _eventAggregator= eventAggregator; + _eventAggregator.GetEvent().Subscribe(EditSingleSetp); + CancelEditCommand = new DelegateCommand(CancelEdit); + SaveStepCommand = new DelegateCommand(SaveStep); + _eventAggregator.GetEvent().Subscribe(DisposeSelectedStep); + } + + private void DisposeSelectedStep(Guid id) + { + if(id== SelectedStep.ID) + SelectedStep = null; + } + + private void CancelEdit() + { + + } + + private void SaveStep() + { + + } + + private void EditSingleSetp() + { + SelectedStep = new StepModel(_globalVariables.SelectedStep); } } } diff --git a/BOB/ViewModels/StepsManagerViewModel.cs b/BOB/ViewModels/StepsManagerViewModel.cs index 63e8b33..6a31b34 100644 --- a/BOB/ViewModels/StepsManagerViewModel.cs +++ b/BOB/ViewModels/StepsManagerViewModel.cs @@ -16,43 +16,29 @@ namespace BOB.ViewModels public class StepsManagerViewModel:BindableBase { #region 属性 - private string _Title; public string Title { - get => _Title; - private set - { - SetProperty(ref _Title, value); - } + get => _globalVariables.Title; + set => SetProperty(ref _globalVariables.Title, value); } - private StepModel _SelectedStep; public StepModel SelectedStep { - get => _SelectedStep; - set - { - if (SetProperty(ref _SelectedStep, value)) - { - GlobalVariables.SelectedStep = value; - } - } + get => _globalVariables.SelectedStep; + set => SetProperty(ref _globalVariables.SelectedStep, value); } - - private ProgramModel _program = new(); public ProgramModel Program { - get => _program; - set => SetProperty(ref _program, value); + get => _globalVariables.Program; + set => SetProperty(ref _globalVariables.Program, value); } - private bool _IsAdmin = new(); public bool IsAdmin { - get => _IsAdmin; - set => SetProperty(ref _IsAdmin, value); + get => _globalVariables.IsAdmin; + set => SetProperty(ref _globalVariables.IsAdmin, value); } - GlobalVariables GlobalVariables { get; set; } + GlobalVariables _globalVariables { get; set; } private List tmpCopyList = new List(); - private IEventAggregator eventAggregator; + private IEventAggregator _eventAggregator; #endregion public ICommand EditStepCommand { get;set; } @@ -61,22 +47,21 @@ namespace BOB.ViewModels public ICommand DeleteStepCommand { get;set; } public StepsManagerViewModel(GlobalVariables _GlobalVariables,IEventAggregator eventAggregator) { - eventAggregator = eventAggregator; - GlobalVariables = _GlobalVariables; - Program = GlobalVariables.Program; - IsAdmin = GlobalVariables.IsAdmin; + _eventAggregator = eventAggregator; + _globalVariables = _GlobalVariables; EditStepCommand = new DelegateCommand(EditStep); CopyStepCommand = new DelegateCommand(CopyStep); PasteStepCommand = new DelegateCommand(PasteStep); DeleteStepCommand = new DelegateCommand(DeleteStep); Program.StepCollection.CollectionChanged += StepCollection_CollectionChanged; + } #region 委托命令 private void EditStep() { - if (IsAdmin && SelectedStep != null) + if (IsAdmin && SelectedStep != null&& _globalVariables.SelectedStep!=null) { - var stepToEdit = SelectedStep; + _eventAggregator.GetEvent().Publish() ; } } private void CopyStep() @@ -104,10 +89,13 @@ namespace BOB.ViewModels if (IsAdmin && SelectedStep != null) { var tmpList = new List { SelectedStep }; + _eventAggregator.GetEvent().Publish(SelectedStep.ID); foreach (var item in tmpList) { Program.StepCollection.Remove(item); } + _globalVariables.SelectedStep = null; + } } #endregion diff --git a/BOB/Views/Dialogs/DeviceSetting.xaml b/BOB/Views/Dialogs/DeviceSetting.xaml new file mode 100644 index 0000000..f855325 --- /dev/null +++ b/BOB/Views/Dialogs/DeviceSetting.xaml @@ -0,0 +1,124 @@ + + +