diff --git a/BPASmart.VariableManager/App.xaml b/BPASmart.VariableManager/App.xaml new file mode 100644 index 00000000..f2760f36 --- /dev/null +++ b/BPASmart.VariableManager/App.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmart.VariableManager/App.xaml.cs b/BPASmart.VariableManager/App.xaml.cs new file mode 100644 index 00000000..ab4d284b --- /dev/null +++ b/BPASmart.VariableManager/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace BPASmart.VariableManager +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/BPASmart.VariableManager/AssemblyInfo.cs b/BPASmart.VariableManager/AssemblyInfo.cs new file mode 100644 index 00000000..8b5504ec --- /dev/null +++ b/BPASmart.VariableManager/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/BPASmart.VariableManager/BPASmart.VariableManager.csproj b/BPASmart.VariableManager/BPASmart.VariableManager.csproj new file mode 100644 index 00000000..12fe325b --- /dev/null +++ b/BPASmart.VariableManager/BPASmart.VariableManager.csproj @@ -0,0 +1,51 @@ + + + + WinExe + net6.0-windows + enable + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmart.VariableManager/Converter/AlarmTypeTextConvert.cs b/BPASmart.VariableManager/Converter/AlarmTypeTextConvert.cs new file mode 100644 index 00000000..703fb6bb --- /dev/null +++ b/BPASmart.VariableManager/Converter/AlarmTypeTextConvert.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using BPASmart.VariableManager.Enums; +namespace BPASmart.VariableManager.Converter +{ + /// + /// 报警类型文本转换 + /// + public class AlarmTypeTextConvert : IValueConverter + { + //当值从绑定源传播给绑定目标时,调用方法Convert,绑定源是控件的数据,绑定目标是后台值 + //界面传递给后台数据 + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null) + { + if (value.ToString() == "Bool") + return EAlarmType.离散量报警.ToString(); + else + return EAlarmType.模拟量报警.ToString(); + } + return EAlarmType.无.ToString(); + } + + //当值从绑定目标传播给绑定源时,调用此方法ConvertBack + //从后台数据传递给界面 + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return value.ToString(); + } + } +} diff --git a/BPASmart.VariableManager/Converter/AnalogAlarmConvert.cs b/BPASmart.VariableManager/Converter/AnalogAlarmConvert.cs new file mode 100644 index 00000000..90d76abe --- /dev/null +++ b/BPASmart.VariableManager/Converter/AnalogAlarmConvert.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 BPASmart.VariableManager.Converter +{ + /// + /// 模拟量报警显示转换 + /// + public class AnalogAlarmConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null) + { + return value.ToString() != "Bool" ? Visibility.Visible : Visibility.Collapsed; + } + return Visibility.Visible; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/BPASmart.VariableManager/Converter/DiscreteAlarmConvert.cs b/BPASmart.VariableManager/Converter/DiscreteAlarmConvert.cs new file mode 100644 index 00000000..300f8bc7 --- /dev/null +++ b/BPASmart.VariableManager/Converter/DiscreteAlarmConvert.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 BPASmart.VariableManager.Converter +{ + /// + /// 离散量报警显示转换 + /// + public class DiscreteAlarmConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null) + { + return value.ToString() == "Bool" ? Visibility.Visible : Visibility.Collapsed; + } + return Visibility.Visible; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/BPASmart.VariableManager/Converter/IsEnableConvert.cs b/BPASmart.VariableManager/Converter/IsEnableConvert.cs new file mode 100644 index 00000000..50b364a4 --- /dev/null +++ b/BPASmart.VariableManager/Converter/IsEnableConvert.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.Data; + +namespace BPASmart.VariableManager.Converter +{ + public class IsEnableConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + bool returnValue = false; + if (value != null) + { + switch (value.ToString()) + { + case "无": + returnValue = false; + break; + case "离散量报警": + case "模拟量报警": + returnValue = true; + break; + default: + break; + } + } + return returnValue; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/BPASmart.VariableManager/Converter/TextDisplayConvert.cs b/BPASmart.VariableManager/Converter/TextDisplayConvert.cs new file mode 100644 index 00000000..4cd13dd0 --- /dev/null +++ b/BPASmart.VariableManager/Converter/TextDisplayConvert.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace BPASmart.VariableManager.Converter +{ + public class TextDisplayConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null && bool.TryParse(value.ToString(), out bool result)) + { + if (result) + { + return "取消报警"; + } + else + { + return "启用报警"; + } + } + return "启用报警"; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/BPASmart.VariableManager/Enums/DisplayFormat.cs b/BPASmart.VariableManager/Enums/DisplayFormat.cs new file mode 100644 index 00000000..9e1a8e93 --- /dev/null +++ b/BPASmart.VariableManager/Enums/DisplayFormat.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Enums +{ + internal enum DisplayFormat + { + 二进制, + 十进制, + 十六进制, + } +} diff --git a/BPASmart.VariableManager/Enums/EAlarmType.cs b/BPASmart.VariableManager/Enums/EAlarmType.cs new file mode 100644 index 00000000..70db0498 --- /dev/null +++ b/BPASmart.VariableManager/Enums/EAlarmType.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Enums +{ + /// + /// 报警类型 + /// + public enum EAlarmType + { + /// + /// 无报警 + /// + 无 = 1, + + /// + /// 模拟量报警 + /// + 模拟量报警 = 2, + + /// + /// 离散量报警 + /// + 离散量报警 = 3 + } +} diff --git a/BPASmart.VariableManager/Enums/EAlongTriggerType.cs b/BPASmart.VariableManager/Enums/EAlongTriggerType.cs new file mode 100644 index 00000000..1d8e4f90 --- /dev/null +++ b/BPASmart.VariableManager/Enums/EAlongTriggerType.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Enums +{ + /// + /// 沿触发类型枚举 + /// + public enum EAlongTriggerType + { + /// + /// 下降沿触发 + /// + 下降沿 = 1, + /// + /// 上升沿触发 + /// + 上升沿 = 2 + } + +} diff --git a/BPASmart.VariableManager/Enums/EAnalogAlarmType.cs b/BPASmart.VariableManager/Enums/EAnalogAlarmType.cs new file mode 100644 index 00000000..ef5381ac --- /dev/null +++ b/BPASmart.VariableManager/Enums/EAnalogAlarmType.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Enums +{ + /// + /// 模拟量报警类型 + /// + public enum EAnalogAlarmType + { + 高高报警 = 1, + 高报警 = 2, + 低报警 = 3, + 低低报警 = 4, + } +} diff --git a/BPASmart.VariableManager/Enums/EDataType.cs b/BPASmart.VariableManager/Enums/EDataType.cs new file mode 100644 index 00000000..840bc11e --- /dev/null +++ b/BPASmart.VariableManager/Enums/EDataType.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Enums +{ + /// + /// 数据类型枚举 + /// + public enum EDataType + { + Bool = 1, + Byte = 2, + Int = 3, + Word = 4, + Dint = 5, + Dword = 6, + Float = 7 + } +} diff --git a/BPASmart.VariableManager/Enums/EDeviceType.cs b/BPASmart.VariableManager/Enums/EDeviceType.cs new file mode 100644 index 00000000..2dd11cde --- /dev/null +++ b/BPASmart.VariableManager/Enums/EDeviceType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Enums +{ + public enum EDeviceType + { + Siemens, + ModbusRtu, + ModbusTcp, + SerialPort, + } +} diff --git a/BPASmart.VariableManager/Enums/EOperatorType.cs b/BPASmart.VariableManager/Enums/EOperatorType.cs new file mode 100644 index 00000000..b2a762c1 --- /dev/null +++ b/BPASmart.VariableManager/Enums/EOperatorType.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Enums +{ + /// + /// 判断操作符枚举 + /// + public enum EOperatorType + { + /// + /// 大于 + /// + P_GT = 1, + /// + /// 大于等于 + /// + P_GE = 2, + /// + /// 等于 + /// + P_EQ = 3, + /// + /// 不等于 + /// + P_NE = 4, + /// + /// 小于 + /// + P_LT = 5, + /// + /// 小于等于 + /// + P_LE = 6 + } +} diff --git a/BPASmart.VariableManager/Enums/EParity.cs b/BPASmart.VariableManager/Enums/EParity.cs new file mode 100644 index 00000000..8920cb62 --- /dev/null +++ b/BPASmart.VariableManager/Enums/EParity.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Enums +{ + public enum EParity + { + 无, + 奇校验, + 偶校验 + } +} diff --git a/BPASmart.VariableManager/Enums/ESiemensPlcType.cs b/BPASmart.VariableManager/Enums/ESiemensPlcType.cs new file mode 100644 index 00000000..5bfc6b99 --- /dev/null +++ b/BPASmart.VariableManager/Enums/ESiemensPlcType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Enums +{ + public enum ESiemensPlcType + { + S1200, + S1500, + S300_400, + S200_Smart + } +} diff --git a/BPASmart.VariableManager/Models/AlarmSet.cs b/BPASmart.VariableManager/Models/AlarmSet.cs new file mode 100644 index 00000000..eda317b5 --- /dev/null +++ b/BPASmart.VariableManager/Models/AlarmSet.cs @@ -0,0 +1,53 @@ +using BPASmart.VariableManager.Enums; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Models +{ + [Table(nameof(AlarmSet))] + public class AlarmSet + { + public AlarmSet() + { + AnalogAlarmModels.Clear(); + foreach (var item in Enum.GetNames(typeof(EAnalogAlarmType))) + { + AnalogAlarmModels.Add(new AnalogAlarmModel() + { + AlarmTag = item, + SortTag = (EAnalogAlarmType)Enum.Parse(typeof(EAnalogAlarmType), item) + }); + } + } + + [Key] + public int Id { get; set; } + + /// + /// 模拟量报警信息 + /// + public ObservableCollection AnalogAlarmModels { get; set; } = new ObservableCollection(); + + /// + /// 离散量报警信息 + /// + public DiscreteAlarmInfo DiscreteAlarmInfoSet { get; set; } = new DiscreteAlarmInfo(); + + /// + /// 设置外键 + /// + [ForeignKey("VariableInfoId")] + public int VariableInfoId { get; set; } + + /// + /// 设置导航属性 + /// + public VariableInfo VariableInfo { get; set; } + } +} diff --git a/BPASmart.VariableManager/Models/AnalogAlarmInfo.cs b/BPASmart.VariableManager/Models/AnalogAlarmInfo.cs new file mode 100644 index 00000000..7137165f --- /dev/null +++ b/BPASmart.VariableManager/Models/AnalogAlarmInfo.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Models +{ + /// + /// 模拟量报警信息 + /// + [Table(nameof(AnalogAlarmInfo))] + public class AnalogAlarmInfo + { + [Key] + public int Id { get; set; } + + /// + /// 高高报警 + /// + public AnalogAlarmModel Condition_HIHI_Value { get; set; } = new AnalogAlarmModel(); + /// + /// 高报警 + /// + public AnalogAlarmModel Condition_HI_Value { get; set; } = new AnalogAlarmModel(); + /// + /// 低低报警 + /// + public AnalogAlarmModel Condition_LOLO_Value { get; set; } = new AnalogAlarmModel(); + /// + /// 低报警 + /// + public AnalogAlarmModel Condition_LO_Value { get; set; } = new AnalogAlarmModel(); + + [ForeignKey("AlarmSetId")] + public int AlarmSetId { get; set; } + + public AlarmSet AlarmSet { get; set; } + + } +} diff --git a/BPASmart.VariableManager/Models/AnalogAlarmModel.cs b/BPASmart.VariableManager/Models/AnalogAlarmModel.cs new file mode 100644 index 00000000..4b329ce4 --- /dev/null +++ b/BPASmart.VariableManager/Models/AnalogAlarmModel.cs @@ -0,0 +1,56 @@ +using BPASmart.VariableManager.Enums; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Models +{ + /// + /// 模拟量报警模块 + /// + public class AnalogAlarmModel + { + [Key] + public int Id { get; set; } + + /// + /// 设定报警值 + /// + public int AlarmValue { get; set; } = 0; + + /// + /// 是否启用该报警 + /// + public bool IsEnable { get; set; } + + /// + /// 报警信息 + /// + public string AlarmInfo { get; set; } + + /// + /// 报警标签 + /// + public string AlarmTag { get; set; } + + /// + /// 排序标签 + /// + public EAnalogAlarmType SortTag { get; set; } + + /// + /// 设置外键 + /// + [ForeignKey("AlarmSetId")] + public int AlarmSetId { get; set; } + + /// + /// 设置导航属性 + /// + public AlarmSet AlarmSet { get; set; } + } +} diff --git a/BPASmart.VariableManager/Models/CommunicationModel.cs b/BPASmart.VariableManager/Models/CommunicationModel.cs new file mode 100644 index 00000000..0bd640fc --- /dev/null +++ b/BPASmart.VariableManager/Models/CommunicationModel.cs @@ -0,0 +1,44 @@ +using Microsoft.Toolkit.Mvvm.Input; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Models +{ + public class CommunicationModel : NoticeBase + { + public CommunicationModel() + { + RemoveCommand = new RelayCommand((o) => { if (RemoveAction != null) RemoveAction(o); }); + } + + public Action RemoveAction { get; set; } + + public Siemens CommSiemens { get { return _mCommSiemens; } set { _mCommSiemens = value; OnPropertyChanged(); } } + private Siemens _mCommSiemens = new Siemens(); + + public ModbusTcp CommModbusTcp { get { return _mCommModbusTcp; } set { _mCommModbusTcp = value; OnPropertyChanged(); } } + private ModbusTcp _mCommModbusTcp = new ModbusTcp(); + + public ModbusRtu CommModbusRtu { get { return _mCommModbusRtu; } set { _mCommModbusRtu = value; OnPropertyChanged(); } } + private ModbusRtu _mCommModbusRtu = new ModbusRtu(); + + /// + /// 是否激活 + /// + public bool IsActive { get { return _mIsActive; } set { _mIsActive = value; OnPropertyChanged(); } } + private bool _mIsActive; + + + /// + /// 新增设备名称 + /// + public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } } + private string _mDeviceName; + + + public RelayCommand RemoveCommand { get; set; } + } +} diff --git a/BPASmart.VariableManager/Models/CommunicationPar.cs b/BPASmart.VariableManager/Models/CommunicationPar.cs new file mode 100644 index 00000000..b0d91f09 --- /dev/null +++ b/BPASmart.VariableManager/Models/CommunicationPar.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Models +{ + internal class CommunicationPar + { + public List communicationSets = new List(); + } +} diff --git a/BPASmart.VariableManager/Models/CommunicationSet.cs b/BPASmart.VariableManager/Models/CommunicationSet.cs new file mode 100644 index 00000000..93e7ac88 --- /dev/null +++ b/BPASmart.VariableManager/Models/CommunicationSet.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System.Collections.ObjectModel; +using BPASmart.VariableManager.Enums; +using System.IO.Ports; +using Microsoft.Toolkit.Mvvm.Input; +using BPASmart.VariableManager.Models; + +namespace BPASmart.VariableManager.Models +{ + public class CommunicationSet : ObservableObject + { + + public CommunicationSet() + { + RemoveCommand = new RelayCommand((o) => { if (RemoveAction != null) RemoveAction(o); }); + } + + public Action RemoveAction { get; set; } + + public Siemens CommSiemens { get { return _mCommSiemens; } set { _mCommSiemens = value; OnPropertyChanged(); } } + private Siemens _mCommSiemens = new Siemens(); + + public ModbusTcp CommModbusTcp { get { return _mCommModbusTcp; } set { _mCommModbusTcp = value; OnPropertyChanged(); } } + private ModbusTcp _mCommModbusTcp = new ModbusTcp(); + + public ModbusRtu CommModbusRtu { get { return _mCommModbusRtu; } set { _mCommModbusRtu = value; OnPropertyChanged(); } } + private ModbusRtu _mCommModbusRtu = new ModbusRtu(); + + /// + /// 是否激活 + /// + public bool IsActive { get { return _mIsActive; } set { _mIsActive = value; OnPropertyChanged(); } } + private bool _mIsActive; + + + /// + /// 新增设备名称 + /// + public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } } + private string _mDeviceName; + + + public RelayCommand RemoveCommand { get; set; } + + } +} diff --git a/BPASmart.VariableManager/Models/DelegationNotifi.cs b/BPASmart.VariableManager/Models/DelegationNotifi.cs new file mode 100644 index 00000000..0a589349 --- /dev/null +++ b/BPASmart.VariableManager/Models/DelegationNotifi.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Models +{ + public class DelegationNotifi + { + private volatile static DelegationNotifi _Instance; + public static DelegationNotifi GetInstance => _Instance ?? (_Instance = new DelegationNotifi()); + private DelegationNotifi() { } + + /// + /// 新增设备时的数据验证 + /// + public Func AddDeviceVerify { get; set; } + + /// + /// 取消按钮通知 + /// + public Action Cancel { get; set; } + + /// + /// 确认按钮通知 + /// + public Action Confirm { get; set; } + + /// + /// 变量保存通知 + /// + public Action VariableSave { get; set; } + + /// + /// 变量名更改通知 + /// + public Action VarNameChanged { get; set; } + + } +} diff --git a/BPASmart.VariableManager/Models/DeviceManagermentResult.cs b/BPASmart.VariableManager/Models/DeviceManagermentResult.cs new file mode 100644 index 00000000..203f26a3 --- /dev/null +++ b/BPASmart.VariableManager/Models/DeviceManagermentResult.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Models +{ + public class DeviceManagermentResult + { + public string DeviceType { get; set; } + public string DeviceName { get; set; } + } +} diff --git a/BPASmart.VariableManager/Models/DeviceManagment.cs b/BPASmart.VariableManager/Models/DeviceManagment.cs new file mode 100644 index 00000000..d8dd31e9 --- /dev/null +++ b/BPASmart.VariableManager/Models/DeviceManagment.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; + +namespace BPASmart.VariableManager.Models +{ + public class DeviceManagment : ObservableObject + { + public string Content { get { return _mContent; } set { _mContent = value; OnPropertyChanged(); } } + private string _mContent; + + public string CommandParameter { get { return _mCommandParameter; } set { _mCommandParameter = value; OnPropertyChanged(); } } + private string _mCommandParameter; + + public RelayCommand NavChangedCommand { get; set; } + + } +} diff --git a/BPASmart.VariableManager/Models/DiscreteAlarmInfo.cs b/BPASmart.VariableManager/Models/DiscreteAlarmInfo.cs new file mode 100644 index 00000000..2fd63277 --- /dev/null +++ b/BPASmart.VariableManager/Models/DiscreteAlarmInfo.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPASmart.VariableManager.Enums; + +namespace BPASmart.VariableManager.Models +{ + /// + /// 布尔量报警信息 + /// + [Table(nameof(DiscreteAlarmInfo))] + public class DiscreteAlarmInfo + { + [Key] + public int Id { get; set; } + + /// + /// 沿报警(上升沿,下降沿) + /// + public string TrigAlarm { get; set; } + + /// + /// 报警信息 + /// + public string AlarmInfo { get; set; } + + /// + /// 设置外键 + /// + [ForeignKey("AlarmSetId")] + public int AlarmSetId { get; set; } + + /// + /// 设置导航属性 + /// + public AlarmSet AlarmSet { get; set; } + } +} diff --git a/BPASmart.VariableManager/Models/DynamicMenu.cs b/BPASmart.VariableManager/Models/DynamicMenu.cs new file mode 100644 index 00000000..e3a68eab --- /dev/null +++ b/BPASmart.VariableManager/Models/DynamicMenu.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Models +{ + public class DynamicMenu + { + /// + /// 通讯设备菜单管理 + /// + public List CommunDeviceManagments { get; set; } = new List(); + + /// + /// 变量菜单管理 + /// + public List VariableManagments { get; set; } = new List(); + + /// + /// 变量监控菜单管理 + /// + public List VariableMonitors { get; set; } = new List(); + } +} diff --git a/BPASmart.VariableManager/Models/ModbusRtu.cs b/BPASmart.VariableManager/Models/ModbusRtu.cs new file mode 100644 index 00000000..0e9442ec --- /dev/null +++ b/BPASmart.VariableManager/Models/ModbusRtu.cs @@ -0,0 +1,88 @@ +using BPASmart.VariableManager.Enums; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO.Ports; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace BPASmart.VariableManager.Models +{ + public class ModbusRtu + { + public ModbusRtu() + { + Init(); + } + + /// + /// 显示/隐藏设置 + /// + public Visibility ModbusRtuVisible { get; set; } = Visibility.Collapsed; + + /// + /// 串口端口 + /// + public string ComSerialPort { get; set; } + + /// + /// 波特率,110,300--115200(从300开始乘以2,直到结果等于115200) + /// + public string BaudRate { get; set; } = "9600"; + + /// + /// 数据位,默认为 8 + /// + public int DataBit { get; set; } = 8; + + /// + /// 停止位,默认为 1 + /// + public int StopBit { get; set; } = 1; + + /// + /// 站号,默认为 1 + /// + public int StationNo { get; set; } = 1; + + /// + /// 奇偶校验,无,奇校验,偶校验 + /// + public string Parity { get; set; } + + + public ObservableCollection Ports { get; set; } = new ObservableCollection(); + + public ObservableCollection BaudRates { get; set; } = new ObservableCollection(); + + public ObservableCollection Paritys { get; set; } = new ObservableCollection(); + + private void Init() + { + Ports.Clear(); + foreach (var item in SerialPort.GetPortNames()) + { + Ports.Add(item); + } + + + BaudRates.Clear(); + BaudRates.Add("110"); + int initValue = 300; + for (int i = 0; i < 17; i++) + { + BaudRates.Add(initValue.ToString()); + initValue *= 2; + } + + + Paritys.Clear(); + foreach (var item in Enum.GetNames(typeof(EParity))) + { + Paritys.Add(item); + } + } + } +} diff --git a/BPASmart.VariableManager/Models/ModbusTcp.cs b/BPASmart.VariableManager/Models/ModbusTcp.cs new file mode 100644 index 00000000..5de84ccd --- /dev/null +++ b/BPASmart.VariableManager/Models/ModbusTcp.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace BPASmart.VariableManager.Models +{ + public class ModbusTcp + { + /// + /// 显示/隐藏设置 + /// + public Visibility ModbusTcpVisible { get; set; } = Visibility.Collapsed; + + /// + /// IP地址 + /// + public string IP { get; set; } = "192.168.0.1"; + + /// + /// 端口号,默认 502 + /// + public int PortNum { get; set; } = 502; + + /// + /// 站号,默认为 1 + /// + public int StationNo { get; set; } = 1; + + } +} diff --git a/BPASmart.VariableManager/Models/NoticeBase.cs b/BPASmart.VariableManager/Models/NoticeBase.cs new file mode 100644 index 00000000..22b29370 --- /dev/null +++ b/BPASmart.VariableManager/Models/NoticeBase.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System.Collections.ObjectModel; + +namespace BPASmart.VariableManager +{ + public class NoticeBase : ObservableObject + { + } +} diff --git a/BPASmart.VariableManager/Models/PropBindInfo.cs b/BPASmart.VariableManager/Models/PropBindInfo.cs new file mode 100644 index 00000000..ae905a85 --- /dev/null +++ b/BPASmart.VariableManager/Models/PropBindInfo.cs @@ -0,0 +1,75 @@ +using BPASmart.VariableManager.Enums; +using Microsoft.Toolkit.Mvvm.Input; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.Models +{ + /// + /// 属性绑定信息 + /// + public class PropBindInfo : VariableInfo + { + public PropBindInfo() + { + ComboBoxItemInit(); + CancelCommand = new RelayCommand(() => { IsOpen = false; }); + ConfirmCommand = new RelayCommand(() => { IsOpen = false; }); + } + + /// + /// 数据类型下拉列表 + /// + public ObservableCollection dataType { get; set; } = new ObservableCollection(); + + /// + /// 报警类型下拉列表 + /// + public ObservableCollection alarmType { get; set; } = new ObservableCollection(); + + /// + /// 报警设置窗离散量报警类型 + /// + public ObservableCollection PopupDiscreteAlarmType { get; set; } = new ObservableCollection(); + + /// + /// 是否显示报警设置框 + /// + public bool IsOpen { get { return _mIsOpen; } set { _mIsOpen = value; OnPropertyChanged(); } } + private bool _mIsOpen; + + /// + /// 报警设置框取消操作 + /// + public RelayCommand CancelCommand { get; set; } + + /// + /// 报警设置框确认按钮 + /// + public RelayCommand ConfirmCommand { get; set; } + + + /// + /// 下拉列表初始化 + /// + private void ComboBoxItemInit() + { + dataType.Clear(); + alarmType.Clear(); + PopupDiscreteAlarmType.Clear(); + string[] DataTypeNames = Enum.GetNames(typeof(EDataType)); + foreach (var item in DataTypeNames) { dataType.Add(item); } + + string[] AlarmTypeNames = Enum.GetNames(typeof(EAlarmType)); + foreach (var item in AlarmTypeNames) { alarmType.Add(item); } + + string[] PopupAlarmTypes = Enum.GetNames(typeof(EAlongTriggerType)); + foreach (var item in PopupAlarmTypes) { PopupDiscreteAlarmType.Add(item); } + } + } +} diff --git a/BPASmart.VariableManager/Models/Siemens.cs b/BPASmart.VariableManager/Models/Siemens.cs new file mode 100644 index 00000000..429555ac --- /dev/null +++ b/BPASmart.VariableManager/Models/Siemens.cs @@ -0,0 +1,62 @@ +using BPASmart.VariableManager.Enums; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace BPASmart.VariableManager.Models +{ + public class Siemens + { + public Siemens() + { + Init(); + } + + /// + /// 显示/隐藏设置 + /// + public Visibility SiemensVisible { get; set; } = Visibility.Collapsed; + + /// + /// IP地址 + /// + public string IP { get; set; } = "192.168.0.1"; + + /// + /// 插槽号 + /// + public int Slot { get; set; } = 0; + + /// + /// 机架号 + /// + public int Rack { get; set; } = 0; + + /// + /// 端口号,默认 102 + /// + public int PortNum { get; set; } = 102; + + /// + /// PLC 类型 + /// + public string PlcType { get; set; } + + public ObservableCollection PlcTypes { get; set; } = new ObservableCollection(); + + private void Init() + { + PlcTypes.Clear(); + foreach (var item in Enum.GetNames(typeof(ESiemensPlcType))) + { + PlcTypes.Add(item.Substring(1)); + } + } + + + } +} diff --git a/BPASmart.VariableManager/Models/VarMonitorPropInfo.cs b/BPASmart.VariableManager/Models/VarMonitorPropInfo.cs new file mode 100644 index 00000000..2b8ef710 --- /dev/null +++ b/BPASmart.VariableManager/Models/VarMonitorPropInfo.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPASmart.VariableManager.Enums; +using Microsoft.Toolkit.Mvvm.ComponentModel; + + +namespace BPASmart.VariableManager.Models +{ + internal class VarMonitorPropInfo : VariableInfo + { + public VarMonitorPropInfo() + { + Init(); + } + + /// + /// 数据显示格式 + /// + public string DataDisplayFormat { get { return _mDataDisplayFormat; } set { _mDataDisplayFormat = value; OnPropertyChanged(); } } + private string _mDataDisplayFormat; + + /// + /// 修改值 + /// + public string ModifyValue { get { return _mModifyValue; } set { _mModifyValue = value; OnPropertyChanged(); } } + private string _mModifyValue; + + public ObservableCollection DisplayFormat { get; set; } = new ObservableCollection(); + + private void Init() + { + DisplayFormat.Clear(); + foreach (var item in Enum.GetNames(typeof(DisplayFormat))) + { + DisplayFormat.Add(item); + } + } + + } +} diff --git a/BPASmart.VariableManager/Models/VariableInfo.cs b/BPASmart.VariableManager/Models/VariableInfo.cs new file mode 100644 index 00000000..638d3e34 --- /dev/null +++ b/BPASmart.VariableManager/Models/VariableInfo.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPASmart.VariableManager.Models; +using BPASmart.VariableManager.Enums; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Newtonsoft.Json; + +namespace BPASmart.VariableManager.Models +{ + /// + /// 变量信息 + /// + [Table(nameof(VariableInfo))] + public class VariableInfo : ObservableObject + { + + [Key] + public int ID { get { return _mID; } set { _mID = value; OnPropertyChanged(); } } + private int _mID; + + /// + /// 变量名 + /// + public string VarName + { + get { return _mVarName; } + set + { + _mVarName = value; + OnPropertyChanged(); + if (DelegationNotifi.GetInstance.VarNameChanged != null) + DelegationNotifi.GetInstance.VarNameChanged(_mID); + } + } + private string _mVarName; + + /// + /// 地址 + /// + public string Address { get { return _mAddress; } set { _mAddress = value; OnPropertyChanged(); } } + private string _mAddress; + + /// + /// 数据类型 + /// + public string DataType { get { return _mDataType; } set { _mDataType = value; OnPropertyChanged(); } } + private string _mDataType; + + /// + /// 是否启用报警 + /// + public bool IsEnableAlarm { get { return _mIsEnableAlarm; } set { _mIsEnableAlarm = value; OnPropertyChanged(); } } + private bool _mIsEnableAlarm; + + /// + /// 当前值 + /// + public string CurrentValue { get { return _mCurrentValue; } set { _mCurrentValue = value; OnPropertyChanged(); } } + private string _mCurrentValue; + + /// + /// 报警设置信息 + /// + public AlarmSet AlarmSetProp { get { return _mAlarmSetProp; } set { _mAlarmSetProp = value; OnPropertyChanged(); } } + private AlarmSet _mAlarmSetProp = new AlarmSet(); + + + } +} diff --git a/BPASmart.VariableManager/Resources/Fonts/iconfont.ttf b/BPASmart.VariableManager/Resources/Fonts/iconfont.ttf new file mode 100644 index 00000000..a2d25446 Binary files /dev/null and b/BPASmart.VariableManager/Resources/Fonts/iconfont.ttf differ diff --git a/BPASmart.VariableManager/Resources/Images/HBL.png b/BPASmart.VariableManager/Resources/Images/HBL.png new file mode 100644 index 00000000..96504908 Binary files /dev/null and b/BPASmart.VariableManager/Resources/Images/HBL.png differ diff --git a/BPASmart.VariableManager/Resources/Images/WindowImages.png b/BPASmart.VariableManager/Resources/Images/WindowImages.png new file mode 100644 index 00000000..132a476e Binary files /dev/null and b/BPASmart.VariableManager/Resources/Images/WindowImages.png differ diff --git a/BPASmart.VariableManager/Resources/Images/leftImage.png b/BPASmart.VariableManager/Resources/Images/leftImage.png new file mode 100644 index 00000000..e9c3ae7c Binary files /dev/null and b/BPASmart.VariableManager/Resources/Images/leftImage.png differ diff --git a/BPASmart.VariableManager/Resources/Images/leftImageSub.png b/BPASmart.VariableManager/Resources/Images/leftImageSub.png new file mode 100644 index 00000000..b0909bd1 Binary files /dev/null and b/BPASmart.VariableManager/Resources/Images/leftImageSub.png differ diff --git a/BPASmart.VariableManager/Resources/Images/leftback.png b/BPASmart.VariableManager/Resources/Images/leftback.png new file mode 100644 index 00000000..fed54fb0 Binary files /dev/null and b/BPASmart.VariableManager/Resources/Images/leftback.png differ diff --git a/BPASmart.VariableManager/Resources/Images/topImage.png b/BPASmart.VariableManager/Resources/Images/topImage.png new file mode 100644 index 00000000..371d48a5 Binary files /dev/null and b/BPASmart.VariableManager/Resources/Images/topImage.png differ diff --git a/BPASmart.VariableManager/Resources/Images/激光线条.png b/BPASmart.VariableManager/Resources/Images/激光线条.png new file mode 100644 index 00000000..d23acad5 Binary files /dev/null and b/BPASmart.VariableManager/Resources/Images/激光线条.png differ diff --git a/BPASmart.VariableManager/Resources/Images/边框1.png b/BPASmart.VariableManager/Resources/Images/边框1.png new file mode 100644 index 00000000..9e2e08f4 Binary files /dev/null and b/BPASmart.VariableManager/Resources/Images/边框1.png differ diff --git a/BPASmart.VariableManager/Resources/Images/边角.png b/BPASmart.VariableManager/Resources/Images/边角.png new file mode 100644 index 00000000..1054f5fc Binary files /dev/null and b/BPASmart.VariableManager/Resources/Images/边角.png differ diff --git a/BPASmart.VariableManager/Resources/Images/阴影边框.png b/BPASmart.VariableManager/Resources/Images/阴影边框.png new file mode 100644 index 00000000..d0ce9a24 Binary files /dev/null and b/BPASmart.VariableManager/Resources/Images/阴影边框.png differ diff --git a/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs b/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs new file mode 100644 index 00000000..f4203e0c --- /dev/null +++ b/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System.Collections.ObjectModel; +using Microsoft.Toolkit.Mvvm.Input; +using BPASmart.VariableManager.Views; +using System.Windows; +using BPASmartClient.Helper; +using BPASmart.VariableManager.Models; +using BPASmart.VariableManager.Enums; + +namespace BPASmart.VariableManager.ViewModels +{ + public class CommunicationSetViewModel : ObservableObject + { + public CommunicationSetViewModel() + { + NewConnectCommand = new RelayCommand(() => { NewConnect(); }); + SaveConnectSetCommand = new RelayCommand(() => + { + Json.Data.communicationSets.Clear(); + foreach (var item in communicationSets) + { + item.RemoveAction = null; + Json.Data.communicationSets.Add(item); + } + Json.Save(); + }); + + Json.Read(); + foreach (var item in Json.Data.communicationSets) + { + item.RemoveAction = RemoveDevice; + communicationSets.Add(item); + } + + DelegationNotifi.GetInstance.AddDeviceVerify = new Func((p) => + { + return communicationSets.FirstOrDefault(s => s.DeviceName == p.DeviceName) == null; + }); + } + + public ObservableCollection communicationSets { get; set; } = new ObservableCollection(); + + public RelayCommand NewConnectCommand { get; set; } + + public RelayCommand SaveConnectSetCommand { get; set; } + + /// + /// 创建新连接 + /// + private void NewConnect() + { + DeviceManagermentSetView deviceManagermentSetView = new DeviceManagermentSetView(); + var result = deviceManagermentSetView.ShowDialog(); + var ResultTag = (DeviceManagermentResult)deviceManagermentSetView.Tag; + if (ResultTag != null) + { + if ((bool)result) + { + var obj = communicationSets.FirstOrDefault(p => p.DeviceName == ResultTag.DeviceName); + if (obj == null) + { + CommunicationModel communicationObj = new CommunicationModel(); + EDeviceType eDeviceType = (EDeviceType)Enum.Parse(typeof(EDeviceType), ResultTag.DeviceType); + switch (eDeviceType) + { + case EDeviceType.Siemens: + communicationObj.CommSiemens.SiemensVisible = Visibility.Visible; + break; + case EDeviceType.ModbusRtu: + communicationObj.CommModbusRtu.ModbusRtuVisible = Visibility.Visible; + break; + case EDeviceType.ModbusTcp: + communicationObj.CommModbusTcp.ModbusTcpVisible = Visibility.Visible; + break; + case EDeviceType.SerialPort: + break; + default: + break; + } + communicationObj.DeviceName = ResultTag.DeviceName; + communicationObj.RemoveAction = RemoveDevice; + communicationSets.Add(communicationObj); + } + } + } + deviceManagermentSetView = null; + } + + private void RemoveDevice(object o) + { + var result = communicationSets.FirstOrDefault(p => p.DeviceName == o.ToString()); + if (result != null) + { + communicationSets.Remove(result); + } + } + + } +} diff --git a/BPASmart.VariableManager/ViewModels/DeviceManagermentSetViewModel.cs b/BPASmart.VariableManager/ViewModels/DeviceManagermentSetViewModel.cs new file mode 100644 index 00000000..69d3a0ee --- /dev/null +++ b/BPASmart.VariableManager/ViewModels/DeviceManagermentSetViewModel.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System.Collections.Concurrent; +using System.Collections.ObjectModel; +using Microsoft.Toolkit.Mvvm.Input; +using Microsoft.Toolkit.Mvvm.Messaging; +using System.Diagnostics; +using BPASmart.VariableManager.Models; +using BPASmart.VariableManager.Enums; + +namespace BPASmart.VariableManager.ViewModels +{ + public class DeviceManagermentSetViewModel : ObservableObject + { + public DeviceManagermentSetViewModel() + { + Init(); + CancelCommand = new RelayCommand(() => + { + if (DelegationNotifi.GetInstance.Cancel != null) DelegationNotifi.GetInstance.Cancel(devcieManagerResult); + }); + ConfirmCommand = new RelayCommand(() => + { + if (DelegationNotifi.GetInstance.AddDeviceVerify != null) + { + if (DelegationNotifi.GetInstance.AddDeviceVerify(devcieManagerResult)) + { + if (DelegationNotifi.GetInstance.Confirm != null) DelegationNotifi.GetInstance.Confirm(devcieManagerResult); + } + else + { + LogInfo = $"警告:设备【{devcieManagerResult.DeviceName}】已存在,请重试"; + } + } + else + { + LogInfo = $"警告:设备添加失败!"; + } + + }); + } + + public ObservableCollection DeviceType { get; set; } = new ObservableCollection(); + + public RelayCommand CancelCommand { get; set; } + public RelayCommand ConfirmCommand { get; set; } + + private void Init() + { + DeviceType.Clear(); + foreach (var item in Enum.GetNames(typeof(EDeviceType))) { DeviceType.Add(item); } + } + + public DeviceManagermentResult devcieManagerResult { get { return _mdevcieManagerResult; } set { _mdevcieManagerResult = value; OnPropertyChanged(); } } + private DeviceManagermentResult _mdevcieManagerResult = new DeviceManagermentResult(); + + + public string LogInfo { get { return _mLogInfo; } set { _mLogInfo = value; OnPropertyChanged(); } } + private string _mLogInfo; + + + + + } +} diff --git a/BPASmart.VariableManager/ViewModels/MainViewModel.cs b/BPASmart.VariableManager/ViewModels/MainViewModel.cs new file mode 100644 index 00000000..12d13c25 --- /dev/null +++ b/BPASmart.VariableManager/ViewModels/MainViewModel.cs @@ -0,0 +1,130 @@ +using BPASmart.VariableManager.Models; +using BPASmartClient.Helper; +using Microsoft.Toolkit.Mvvm.Input; +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; +using System.Windows.Markup; + +namespace BPASmart.VariableManager.ViewModels +{ + public class MainViewModel : NoticeBase + { + public MainViewModel() + { + DoNavChanged("MessageLogView"); + DataInit(); + } + + private void DataInit() + { + //获取本地通讯参数 + Json.Read(); + + //设置【设备管理菜单】 + DeviceManagments.Add(new DeviceManagment() + { + CommandParameter = "CommunicationSetView", + Content = "设备管理", + NavChangedCommand = new RelayCommand(DoNavChanged) + }); + + //设置【变量管理菜单】 + foreach (var item in Json.Data.communicationSets) + { + string CommandParameter = string.Empty; + + VariableManagments.Add(new DeviceManagment() + { + CommandParameter = "VariableConfig", + Content = item.DeviceName, + NavChangedCommand = new RelayCommand(DoNavChanged) + }); + } + + //设置【变量监控菜单】 + foreach (var item in Json.Data.communicationSets) + { + VariableMonitors.Add(new DeviceManagment() + { + CommandParameter = "VariableMonitorView", + Content = item.DeviceName, + NavChangedCommand = new RelayCommand(DoNavChanged) + }); + } + + //设置【报警/消息日志菜单】 + MessageAlarmLog.Add(new DeviceManagment() + { + CommandParameter = "MessageLogView", + Content = "消息日志", + NavChangedCommand = new RelayCommand(DoNavChanged) + }); + MessageAlarmLog.Add(new DeviceManagment() + { + CommandParameter = "AlarmRecordView", + Content = "报警记录", + NavChangedCommand = new RelayCommand(DoNavChanged) + }); + + } + + /// + /// 设备管理菜单 + /// + public ObservableCollection DeviceManagments { get; set; } = new ObservableCollection(); + + /// + /// 变量管理菜单 + /// + public ObservableCollection VariableManagments { get; set; } = new ObservableCollection(); + + /// + /// 变量监控 + /// + public ObservableCollection VariableMonitors { get; set; } = new ObservableCollection(); + + /// + /// 消息报警日志 + /// + public ObservableCollection MessageAlarmLog { get; set; } = new ObservableCollection(); + + #region 导航栏界面切换 + private void DoNavChanged(object obj) + { + Type type = Type.GetType($"BPASmart.VariableManager.Views.{obj.ToString()}"); + if (type != null) + { + ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes); + MainContent = (FrameworkElement)cti.Invoke(null); + } + + } + #endregion + + #region 页面切换属性 + private FrameworkElement mainContent; + + public FrameworkElement MainContent + { + get { return mainContent; } + set { mainContent = value; OnPropertyChanged(); } + } + #endregion + + #region 界面名称显示属性 + private string _WinNameDisplay; + + public string WinNameDisplay + { + get { return _WinNameDisplay; } + set { _WinNameDisplay = value; OnPropertyChanged(); } + } + #endregion + } +} diff --git a/BPASmart.VariableManager/ViewModels/VariableConfig.cs b/BPASmart.VariableManager/ViewModels/VariableConfig.cs new file mode 100644 index 00000000..0111daeb --- /dev/null +++ b/BPASmart.VariableManager/ViewModels/VariableConfig.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPASmart.VariableManager.Enums; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using BPASmart.VariableManager.Models; +using System.Diagnostics; +using Microsoft.EntityFrameworkCore; + +namespace BPASmart.VariableManager.ViewModels +{ + internal class VariableConfig : ObservableObject + { + public VariableConfig() + { + DelegationNotifi.GetInstance.VariableSave = new Action(() => { SaveDataAsync(); }); + + DelegationNotifi.GetInstance.VarNameChanged = new Action((p) => + { + if ((p - 1) >= 0) + { + if (varialeInfos?.Count >= p) + { + if (varialeInfos.ElementAt(p - 1).VarName != null) + { + if (varialeInfos.ElementAt(p - 1).VarName.Length > 0) + { + if (varialeInfos.Count == p) AddRow(); + } + } + } + } + }); + GetLocalDataAsync(); + } + + /// + /// 异步获取本地数据 + /// + private Task GetLocalDataAsync() + { + //SqlHelper.GetInstance.Database.EnsureCreated(); + ////多表查询 + //var DataList = SqlHelper.GetInstance.DbObj.ToList(); + //App.Current.Dispatcher.Invoke(new Action(() => { varialeInfos.Clear(); })); + //foreach (var item in DataList) + //{ + // PropBindInfo propBindInfo = new PropBindInfo(); + // propBindInfo.ID = item.ID; + // propBindInfo.VarName = item.VarName; + // propBindInfo.Address = item.Address; + // propBindInfo.DataType = item.DataType; + // propBindInfo.IsEnableAlarm = item.IsEnableAlarm; + // propBindInfo.CurrentValue = item.CurrentValue; + // var result = item.AlarmSetProp.AnalogAlarmModels.Where(p => p.AlarmSetId == item.ID).ToList(); + // result = result?.OrderBy(p => p.SortTag).ToList(); + // propBindInfo.AlarmSetProp.AnalogAlarmModels.Clear(); + // result?.ForEach(p => { propBindInfo.AlarmSetProp.AnalogAlarmModels.Add(p); }); + // propBindInfo.AlarmSetProp.DiscreteAlarmInfoSet = item.AlarmSetProp.DiscreteAlarmInfoSet; + // App.Current?.Dispatcher.Invoke(new Action(() => { varialeInfos.Add(propBindInfo); })); + //} + //if (varialeInfos.Count <= 0) AddRow(); + return Task.FromResult(true); + } + + /// + /// 异步保存数据 + /// + /// + private Task SaveDataAsync() + { + //SqlHelper.GetInstance.DbObj.RemoveRange(SqlHelper.GetInstance.DbObj.ToArray()); + //foreach (var item in varialeInfos) + //{ + // SqlHelper.GetInstance.Add(new VariableInfo() + // { + // ID = item.ID, + // VarName = item.VarName, + // Address = item.Address, + // DataType = item.DataType, + // IsEnableAlarm = item.IsEnableAlarm, + // CurrentValue = item.CurrentValue, + // AlarmSetProp = item.AlarmSetProp, + + // }); + //} + //SqlHelper.GetInstance.Save(); + return Task.FromResult(true); + } + + /// + /// 添加行 + /// + private void AddRow() + { + App.Current.Dispatcher.Invoke(new Action(() => + { + varialeInfos.Add(new PropBindInfo() + { + ID = varialeInfos.Count + 1, + }); + })); + + } + + /// + /// 变量信息 + /// + public ObservableCollection varialeInfos { get; set; } = new ObservableCollection(); + + } +} diff --git a/BPASmart.VariableManager/ViewModels/VariableMonitorViewModel.cs b/BPASmart.VariableManager/ViewModels/VariableMonitorViewModel.cs new file mode 100644 index 00000000..2d54582d --- /dev/null +++ b/BPASmart.VariableManager/ViewModels/VariableMonitorViewModel.cs @@ -0,0 +1,75 @@ +using BPASmart.VariableManager.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager.ViewModels +{ + internal class VariableMonitorViewModel : ObservableObject + { + public VariableMonitorViewModel() + { + GetLocalDataAsync(); + } + + /// + /// 异步获取本地数据 + /// + private Task GetLocalDataAsync() + { + //var DataList = SqlHelper.GetInstance.DbObj.ToList(); + //App.Current.Dispatcher.Invoke(new Action(() => { varialeInfos.Clear(); })); + //foreach (var item in DataList) + //{ + // if (item.VarName?.Length > 0) + // { + // VarMonitorPropInfo varMonitorPropInfo = new VarMonitorPropInfo(); + // varMonitorPropInfo.ID = item.ID; + // varMonitorPropInfo.VarName = item.VarName; + // varMonitorPropInfo.Address = item.Address; + // varMonitorPropInfo.DataType = item.DataType; + // varMonitorPropInfo.DataDisplayFormat = TypeEnum.DisplayFormat.十进制.ToString(); + // App.Current?.Dispatcher.Invoke(new Action(() => { varialeInfos.Add(varMonitorPropInfo); })); + // } + //} + return Task.FromResult(true); + } + + /// + /// 异步保存数据 + /// + /// + private Task SaveDataAsync() + { + //SqlHelper.GetInstance.DbObj.RemoveRange(SqlHelper.GetInstance.DbObj.ToArray()); + //foreach (var item in varialeInfos) + //{ + // SqlHelper.GetInstance.Add(new VariableInfo() + // { + // ID = item.ID, + // VarName = item.VarName, + // Address = item.Address, + // DataType = item.DataType, + // IsEnableAlarm = item.IsEnableAlarm, + // CurrentValue = item.CurrentValue, + // AlarmSetProp = item.AlarmSetProp, + + // }); + //} + //SqlHelper.GetInstance.Save(); + return Task.FromResult(true); + } + + /// + /// 变量信息 + /// + public ObservableCollection varialeInfos { get; set; } = new ObservableCollection(); + + } +} + diff --git a/BPASmart.VariableManager/Views/CommunicationSetView.xaml b/BPASmart.VariableManager/Views/CommunicationSetView.xaml new file mode 100644 index 00000000..344cae6b --- /dev/null +++ b/BPASmart.VariableManager/Views/CommunicationSetView.xaml @@ -0,0 +1,486 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +