上下限监控

This commit is contained in:
hsc
2026-07-07 14:22:25 +08:00
parent 3b41459dcd
commit f5145d10e4
10 changed files with 417 additions and 5 deletions

View File

@@ -150,6 +150,7 @@ namespace ADP.ViewModels
public ICommand ShowDialogManagerViewCommand { get; set; }
public ICommand SelectCANSignalMonitorCommand { get; set; }
public ICommand SelectCANMessageCommand { get; set; }
public ICommand MonitorValueSettingCommand { get; set; }
public ICommand GetFileStringCommand { get; set; }
#endregion
@@ -182,6 +183,7 @@ namespace ADP.ViewModels
SetDefaultCommand = new DelegateCommand(SetDefault);
SelectCANSignalMonitorCommand = new DelegateCommand(SelectCANSignalMonitor);
SelectCANMessageCommand = new DelegateCommand(SelectCANMessage);
MonitorValueSettingCommand = new DelegateCommand(MonitorValueSetting);
GetFileStringCommand = new DelegateCommand(GetFileString);
_globalInfo.ContextDic.Add("default", new ScopedContext());
@@ -205,7 +207,7 @@ namespace ADP.ViewModels
_uiRefreshTimer.Start();
}
private void RefreshAllContextProperties()
{
RaisePropertyChanged(nameof(RunState));
@@ -232,12 +234,24 @@ namespace ADP.ViewModels
});
}
}
private void MonitorValueSetting()
{
if ( _globalInfo.CurrentScope == "default")
{
LoggerHelper.Warn("当前作用域未配置 CAN 设备,无法打开报文选择窗口。");
return;
}
_dialogService.ShowDialog("ValueLimitView", new DialogParameters
{
{ "Scope", _globalInfo.ScopeDic[_globalInfo.CurrentScope] }
}, _ => { });
}
private void SelectCANSignalMonitor()
{
var canfd = CurrentConfig?.CANFD;
if (canfd == null || _globalInfo.CurrentScope == "default")
{
LoggerHelper.Warn("当前作用域未配置 CAN 设备,无法打开报文选择窗口。");
return;
}

View File

@@ -167,7 +167,15 @@ Command="{Binding SelectCANSignalMonitorCommand}">
Foreground="Black" />
</MenuItem.Icon>
</MenuItem>
<!-- CAN报文选择 -->
<!-- 监控设置 -->
<MenuItem Header="监控设置"
Foreground="Black"
Command="{Binding MonitorValueSettingCommand}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Monitor"
Foreground="Black" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="CAN报文选择"
Foreground="Black"
Command="{Binding SelectCANMessageCommand}">
@@ -175,7 +183,7 @@ Command="{Binding SelectCANMessageCommand}">
<materialDesign:PackIcon Kind="Message"
Foreground="Black" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
<!-- 获得文件路径字符串 -->
<MenuItem Header="获得文件路径字符串"
Foreground="Black"

View File

View File

@@ -1,5 +1,6 @@
using MonitorModule.Views;
using MonitorModule.Views.Dialogs;
using System.Reflection;
namespace MonitorModule
@@ -16,6 +17,7 @@ namespace MonitorModule
{
containerRegistry.RegisterForNavigation<MonitorView>("MonitorView");
containerRegistry.RegisterForNavigation<RecordView>("RecordView");
containerRegistry.RegisterDialog<ValueLimitView>("ValueLimitView");
}
}

View File

@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using UIShare.GlobalVariable;
using UIShare.UIViewModel;
using UIShare.ViewModelBase;
namespace MonitorModule.ViewModels.Dialogs
{
public class ValueLimitViewModel : DialogViewModelBase
{
#region
private string _Title = "报警设置";
public string Title
{
get { return _Title; }
set { SetProperty(ref _Title, value); }
}
private ValueLimitVM _SelectValueLimitVM;
public ValueLimitVM SelectValueLimitVM
{
get => _SelectValueLimitVM;
set => SetProperty(ref _SelectValueLimitVM, value);
}
private ObservableCollection<ValueLimitVM> _ValueLimitList;
public ObservableCollection<ValueLimitVM> ValueLimitList
{
get => _ValueLimitList;
set => SetProperty(ref _ValueLimitList, value);
}
private ObservableCollection<string> _DeviceSingleList = new();
public ObservableCollection<string> DeviceSingleList
{
get => _DeviceSingleList;
set => SetProperty(ref _DeviceSingleList, value);
}
private string _SelectCurve;
public string SelectCurve
{
get => _SelectCurve;
set => SetProperty(ref _SelectCurve, value);
}
#endregion
#region
public ICommand SaveCommand { get; set; }
public ICommand CloseCommand { get; set; }
public ICommand SelectSignalCommand { get; set; }
public ICommand DeleteCommand { get; set; }
#endregion
private GlobalInfo _globalInfo { get; set; }
private SystemConfig _systemConfig { get; set; }
private IScopedProvider _scope { get; set; }
public ValueLimitViewModel(IContainerProvider containerProvider) : base(containerProvider)
{
_globalInfo = containerProvider.Resolve<GlobalInfo>();
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
SaveCommand = new DelegateCommand(OnSave);
CloseCommand = new DelegateCommand(OnClose);
SelectSignalCommand = new DelegateCommand(SelectSignal);
DeleteCommand = new DelegateCommand(Deletel);
InitData();
}
#region
private void Deletel()
{
if (SelectValueLimitVM == null)
{
return;
}
else
{
ValueLimitList.Remove(SelectValueLimitVM);
SelectValueLimitVM = null;
}
}
private void InitData()
{
//ValueLimitList = new(_systemConfig.ValueLimitList);
//foreach (var _PollingRead in _devices.PollingReadDic)
//{
// string deviceName = _PollingRead.Key;
// PollingRead pollingRead = _PollingRead.Value;
// var props = pollingRead.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
// .Where(p => p.PropertyType == typeof(double));
// foreach (var prop in props)
// {
// DeviceSingleList.Add(deviceName + "." + prop.Name);
// }
//}
//foreach (var Signal in _systemConfig.ConfigurationList)
//{
// DeviceSingleList.Add($"{Signal.Channel}/{Signal.MessageName}/{Signal.SignalName}");
//}
}
private void SelectSignal()
{
if (ValueLimitList.Where(x => x.SignalName == SelectCurve).Count() > 0)
{
return;
}
ValueLimitList.Add(new ValueLimitVM
{
SignalName = SelectCurve,
Upper = 9999,
Lower = -9999,
UpperExtreme = 9999,
LowerExtreme = -9999,
});
}
private void OnClose()
{
RequestClose.Invoke();
}
private void OnSave()
{
_systemConfig.ValueLimitList = ValueLimitList;
ConfigService.Save(_systemConfig);
}
#endregion
public override void OnDialogOpened(IDialogParameters parameters)
{
// 1. 优先执行基类的打开逻辑(如果基类有需要初始化的通用事务)
base.OnDialogOpened(parameters);
// 2. 解析参数
if (parameters != null && parameters.ContainsKey("Scope")) // 修复Prism 中应使用 ContainsKey
{
_scope = parameters.GetValue<IScopedProvider>("Scope");
_systemConfig= _scope.Resolve<SystemConfig>();
}
}
}
}

View File

@@ -0,0 +1,110 @@
<UserControl x:Class="MonitorModule.Views.Dialogs.ValueLimitView"
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:local="clr-namespace:MonitorModule.Views.Dialogs"
xmlns:oxy="http://oxyplot.org/wpf"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
xmlns:prism="http://prismlibrary.com/"
xmlns:cons="clr-namespace:UIShare.Converters;assembly=UIShare"
Background="White"
prism:ViewModelLocator.AutoWireViewModel="True"
Height="500"
Width="900">
<prism:Dialog.WindowStyle>
<Style BasedOn="{StaticResource DialogUserManageStyle}"
TargetType="Window" />
</prism:Dialog.WindowStyle>
<GroupBox Padding="0,0,0,0"
MouseLeftButtonDown="MouseLeftButtonDown">
<GroupBox.Header>
<Grid Margin="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="*" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="上下限设置"
Foreground="White"
VerticalAlignment="Center"
Margin="5,0,10,0" />
<Button Content="关闭"
Grid.Column="2"
Margin="150 0 0 0"
Width="60"
Command="{Binding CloseCommand}"
Height="25" />
</Grid>
</GroupBox.Header>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid SelectedItem="{Binding SelectValueLimitVM}"
SelectionUnit="FullRow"
AutoGenerateColumns="False"
CanUserAddRows="False"
IsReadOnly="False"
ItemsSource="{Binding ValueLimitList}"
Margin="0,0,0,10">
<DataGrid.Columns>
<DataGridTextColumn Header="信号名"
Binding="{Binding SignalName}"
Width="auto" />
<DataGridTextColumn Header="上限"
Binding="{Binding Upper, Mode=TwoWay}"
Width="auto" />
<DataGridTextColumn Header="下限"
Binding="{Binding Lower, Mode=TwoWay}"
Width="auto" />
<DataGridTextColumn Header="上极限"
Binding="{Binding UpperExtreme, Mode=TwoWay}"
Width="auto" />
<DataGridTextColumn Header="下极限"
Binding="{Binding LowerExtreme, Mode=TwoWay}"
Width="auto" />
<DataGridTextColumn Header="报警状态"
Binding="{Binding AlarmSatus}"
Width="auto" />
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="删除"
Foreground="Red"
Command="{Binding DeleteCommand}" />
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid>
<StackPanel Grid.Row="1"
Orientation="Horizontal"
HorizontalAlignment="Left"
Margin="0,10,0,0">
<Label Content="待添加监控值"
VerticalAlignment="Center" />
<ComboBox ItemsSource="{Binding DeviceSingleList}"
SelectedItem="{Binding SelectCurve}"
materialDesign:HintAssist.Hint=""
MinWidth="130"
VerticalAlignment="Center" />
<Button Content="添加"
Margin="10,0,10,0"
Command="{Binding SelectSignalCommand}" />
</StackPanel>
<StackPanel Grid.Row="1"
Orientation="Horizontal"
HorizontalAlignment="Right"
Margin="0,10,0,0">
<Button Content="保存"
Width="80"
Margin="0,0,10,0"
Command="{Binding SaveCommand}" />
</StackPanel>
</Grid>
</GroupBox>
</UserControl>

View File

@@ -0,0 +1,36 @@
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 MonitorModule.Views.Dialogs
{
/// <summary>
/// ValueLimitView.xaml 的交互逻辑
/// </summary>
public partial class ValueLimitView : UserControl
{
public ValueLimitView()
{
InitializeComponent();
}
private void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Window.GetWindow(this)?.DragMove();
}
}
}
}

View File

@@ -333,7 +333,7 @@ namespace TestingModule.ViewModels
foreach (var type in validTypes)
{
//拦截没有在设备列表中的设备类型
//if (SystemConfig.Instance.DeviceList.Where(x=>x.Remark==type.Name).ToList().Count==0 && type.FullName.Contains("DeviceCommand.Device"))
//if (_systemConfig.DeviceList.Where(x=>x.Remark==type.Name).ToList().Count==0 && type.FullName.Contains("DeviceCommand.Device"))
//{
// continue;
//}

View File

@@ -32,6 +32,7 @@ namespace UIShare.GlobalVariable
public ObservableCollection<SharedParameter> SharedParameterList = new();
public ObservableCollection<CANSignalConfig> ConfigurationList = new();
public ObservableCollection<AutoDBCLoadItem> dbcAutoLoadList = new();
public ObservableCollection<ValueLimitVM> ValueLimitList = new();
public ZLGCANFD CANFD = new();
[JsonIgnore]
public ObservableCollection<ParameterVM> ParameterList = new()

View File

@@ -0,0 +1,88 @@
using Prism.Mvvm;
namespace UIShare.UIViewModel
{
// 继承 BindableBase 使得属性变更时能实时通知 UI 刷新
public class ValueLimitVM : BindableBase
{
private string _signalName = string.Empty;
private double _upper;
private double _lower;
private double _upperExtreme;
private double _lowerExtreme;
private bool _isAlarm = false;
private AlarmStatus _alarmStatus = AlarmStatus.;
/// <summary>
/// 信号名
/// </summary>
public string SignalName
{
get => _signalName;
set => SetProperty(ref _signalName, value);
}
/// <summary>
/// 上限
/// </summary>
public double Upper
{
get => _upper;
set => SetProperty(ref _upper, value);
}
/// <summary>
/// 下限
/// </summary>
public double Lower
{
get => _lower;
set => SetProperty(ref _lower, value);
}
/// <summary>
/// 上极限
/// </summary>
public double UpperExtreme
{
get => _upperExtreme;
set => SetProperty(ref _upperExtreme, value);
}
/// <summary>
/// 下极限
/// </summary>
public double LowerExtreme
{
get => _lowerExtreme;
set => SetProperty(ref _lowerExtreme, value);
}
/// <summary>
/// 是否报警
/// </summary>
public bool IsAlarm
{
get => _isAlarm;
set => SetProperty(ref _isAlarm, value);
}
/// <summary>
/// 警报状态类型
/// </summary>
public AlarmStatus AlarmSatus
{
get => _alarmStatus;
set => SetProperty(ref _alarmStatus, value);
}
}
public enum AlarmStatus
{
= 0, // 未报警
= 1, // 超上限
= 2, // 超下限
= 3, // 超上极限
= 4, // 超下极限
}
}