上下限监控
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
153
MonitorModule/ViewModels/Dialogs/ValueLimitViewModel.cs
Normal file
153
MonitorModule/ViewModels/Dialogs/ValueLimitViewModel.cs
Normal 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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
110
MonitorModule/Views/Dialogs/ValueLimitView.xaml
Normal file
110
MonitorModule/Views/Dialogs/ValueLimitView.xaml
Normal 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>
|
||||
36
MonitorModule/Views/Dialogs/ValueLimitView.xaml.cs
Normal file
36
MonitorModule/Views/Dialogs/ValueLimitView.xaml.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user