修改了添加设备界面和变量表界面
This commit is contained in:
@@ -28,21 +28,19 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
partial void OnDevicesChanged(List<Device> devices)
|
partial void OnDevicesChanged(List<Device> devices)
|
||||||
{
|
{
|
||||||
OnDeviceListChanged?.Invoke(devices);
|
OnDeviceListChanged?.Invoke(devices);
|
||||||
if (menuBeans!=null && Devices!=null)
|
if (menuBeans != null && Devices != null)
|
||||||
{
|
{
|
||||||
FillMenuData(MenuBeans,Devices);
|
FillMenuData(MenuBeans, Devices);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
partial void OnMenuBeansChanged(List<MenuBean> menuBeans)
|
partial void OnMenuBeansChanged(List<MenuBean> menuBeans)
|
||||||
{
|
{
|
||||||
OnMenuListChanged?.Invoke(menuBeans);
|
OnMenuListChanged?.Invoke(menuBeans);
|
||||||
if (MenuBeans!=null && Devices!=null)
|
if (MenuBeans != null && Devices != null)
|
||||||
{
|
{
|
||||||
FillMenuData(MenuBeans,Devices);
|
FillMenuData(MenuBeans, Devices);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +57,7 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
/// 给Menu菜单的Data填充数据
|
/// 给Menu菜单的Data填充数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="menuBeans"></param>
|
/// <param name="menuBeans"></param>
|
||||||
private void FillMenuData(List<MenuBean> menuBeans,List<Device> devices)
|
private void FillMenuData(List<MenuBean> menuBeans, List<Device> devices)
|
||||||
{
|
{
|
||||||
if (menuBeans == null || menuBeans.Count == 0)
|
if (menuBeans == null || menuBeans.Count == 0)
|
||||||
return;
|
return;
|
||||||
@@ -87,7 +85,7 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
|
|
||||||
if (menuBean.Items != null && menuBean.Items.Count > 0)
|
if (menuBean.Items != null && menuBean.Items.Count > 0)
|
||||||
{
|
{
|
||||||
FillMenuData(menuBean.Items,devices);
|
FillMenuData(menuBean.Items, devices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,20 +112,29 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
|||||||
return navgateVM;
|
return navgateVM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从设备列表中找到变量表VarTable对象
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vtableId">VarTable的ID</param>
|
||||||
|
/// <returns>如果找到择返回对象,否则返回null</returns>
|
||||||
private VariableTable FindVarTableForDevice(int vtableId)
|
private VariableTable FindVarTableForDevice(int vtableId)
|
||||||
{
|
{
|
||||||
VariableTable varTable = null;
|
VariableTable varTable = null;
|
||||||
foreach (var device in _devices)
|
foreach (var device in _devices)
|
||||||
{
|
{
|
||||||
varTable = device.VariableTables.FirstOrDefault(v => v.Id == vtableId);
|
varTable = device.VariableTables.FirstOrDefault(v => v.Id == vtableId);
|
||||||
if (varTable!=null)
|
if (varTable != null)
|
||||||
return varTable;
|
return varTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
return varTable;
|
return varTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 接受加载消息,收到消息后从数据库加载对应的数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">消息的类型,如加载菜单LoadMessage.Menu</param>
|
||||||
|
/// <exception cref="ArgumentException"></exception>
|
||||||
public async void Receive(LoadMessage message)
|
public async void Receive(LoadMessage message)
|
||||||
{
|
{
|
||||||
if (!(message.Value is LoadTypes))
|
if (!(message.Value is LoadTypes))
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using PMSWPF.Models;
|
using PMSWPF.Models;
|
||||||
|
|
||||||
@@ -7,7 +8,14 @@ partial class VariableTableViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private VariableTable variableTable;
|
private VariableTable variableTable;
|
||||||
|
[ObservableProperty]
|
||||||
|
private ObservableCollection<DataVariable> _dataVariables;
|
||||||
|
|
||||||
public override void OnLoaded()
|
public override void OnLoaded()
|
||||||
{
|
{
|
||||||
|
if (VariableTable.DataVariables!=null )
|
||||||
|
{
|
||||||
|
_dataVariables = new ObservableCollection<DataVariable>(VariableTable.DataVariables);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,72 +13,89 @@
|
|||||||
Title="{Binding Title}"
|
Title="{Binding Title}"
|
||||||
CloseButtonText="取消"
|
CloseButtonText="取消"
|
||||||
DefaultButton="Primary"
|
DefaultButton="Primary"
|
||||||
PrimaryButtonText="添加"
|
PrimaryButtonText="添加设备"
|
||||||
|
Background="#fff"
|
||||||
d:DataContext="{d:DesignInstance vmd:DeviceDialogViewModel}"
|
d:DataContext="{d:DesignInstance vmd:DeviceDialogViewModel}"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<ui:ContentDialog.Resources>
|
<ui:ContentDialog.Resources>
|
||||||
<ex:EnumBindingSource x:Key="deviceType" EnumType="{x:Type en:DeviceType}" />
|
<ex:EnumBindingSource x:Key="deviceType" EnumType="{x:Type en:DeviceType}" />
|
||||||
<ex:EnumBindingSource x:Key="protocolType" EnumType="{x:Type en:ProtocolType}" />
|
<ex:EnumBindingSource x:Key="protocolType" EnumType="{x:Type en:ProtocolType}" />
|
||||||
<vc:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
<vc:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
||||||
|
|
||||||
|
|
||||||
</ui:ContentDialog.Resources>
|
</ui:ContentDialog.Resources>
|
||||||
<ikw:SimpleStackPanel Width="260" Spacing="12">
|
|
||||||
<!-- 设备名称 -->
|
<Grid Width="480" Margin="10" >
|
||||||
<TextBlock Text="设备名称" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
<Grid.ColumnDefinitions>
|
||||||
<TextBox
|
<ColumnDefinition Width="1*"/>
|
||||||
Text="{Binding Device.Name, UpdateSourceTrigger=PropertyChanged}" />
|
<ColumnDefinition Width="1*"/>
|
||||||
<!-- 设备描述 -->
|
</Grid.ColumnDefinitions>
|
||||||
<TextBlock Text="设备描述" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
<!-- 左边列 -->
|
||||||
<TextBox
|
<ikw:SimpleStackPanel Grid.Column="0" Margin="10 10 20 10 " Spacing="12">
|
||||||
Text="{Binding Device.Description, UpdateSourceTrigger=PropertyChanged}" />
|
<!-- 设备名称 -->
|
||||||
<!-- 设备IP地址 -->
|
<TextBlock Text="设备名称" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
||||||
<TextBlock Text="设备IP地址" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
<TextBox
|
||||||
<TextBox
|
Text="{Binding Device.Name, UpdateSourceTrigger=PropertyChanged}" />
|
||||||
AcceptsReturn="True"
|
<!-- 设备IP地址 -->
|
||||||
Text="{Binding Device.Ip, UpdateSourceTrigger=PropertyChanged}" />
|
<TextBlock Text="设备IP地址" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
||||||
|
<TextBox
|
||||||
|
AcceptsReturn="True"
|
||||||
|
Text="{Binding Device.Ip, UpdateSourceTrigger=PropertyChanged}" />
|
||||||
|
|
||||||
<!-- 设备类型 -->
|
<!-- 设备类型 -->
|
||||||
<TextBlock Text="设备类型" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
<TextBlock Text="设备类型" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
||||||
<ComboBox SelectedItem="{Binding Device.DeviceType}"
|
<ComboBox SelectedItem="{Binding Device.DeviceType}"
|
||||||
ItemsSource="{Binding Source={StaticResource deviceType} }">
|
ItemsSource="{Binding Source={StaticResource deviceType} }">
|
||||||
<ComboBox.ItemTemplate>
|
<ComboBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ComboBox.ItemTemplate>
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
|
|
||||||
<!-- 通讯协议-->
|
<!-- 通讯协议-->
|
||||||
<TextBlock Text="设备通信协议" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
<TextBlock Text="设备通信协议" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
||||||
<ComboBox SelectedItem="{Binding Device.ProtocolType}"
|
<ComboBox SelectedItem="{Binding Device.ProtocolType}"
|
||||||
ItemsSource="{Binding Source={StaticResource protocolType} }">
|
ItemsSource="{Binding Source={StaticResource protocolType} }">
|
||||||
<ComboBox.ItemTemplate>
|
<ComboBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ComboBox.ItemTemplate>
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
<!-- 通讯协议-->
|
|
||||||
<CheckBox Content="是否启用" IsChecked="{Binding Device.IsActive}" />
|
|
||||||
<!-- <TextBox ui:ControlHelper.Header="PrimaryButtonText" -->
|
</ikw:SimpleStackPanel>
|
||||||
<!-- Text="{Binding ElementName=dialog, Path=PrimaryButtonText, UpdateSourceTrigger=PropertyChanged}" /> -->
|
<!-- 右边列 -->
|
||||||
<!-- <TextBox ui:ControlHelper.Header="SecondaryButtonText" -->
|
<ikw:SimpleStackPanel Margin="10" Grid.Column="1" Spacing="12">
|
||||||
<!-- Text="{Binding ElementName=dialog, Path=SecondaryButtonText, UpdateSourceTrigger=PropertyChanged}" /> -->
|
|
||||||
<!-- <TextBox ui:ControlHelper.Header="CloseButtonText" -->
|
<!-- 设备描述 -->
|
||||||
<!-- Text="{Binding ElementName=dialog, Path=CloseButtonText, UpdateSourceTrigger=PropertyChanged}" /> -->
|
<TextBlock Text="设备描述" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
||||||
<!-- <ComboBox -->
|
<TextBox
|
||||||
<!-- ui:ControlHelper.Header="DefaultButton" -->
|
Text="{Binding Device.Description, UpdateSourceTrigger=PropertyChanged}" />
|
||||||
<!-- ItemsSource="{Binding Source={x:Type ui:ContentDialogButton}}" -->
|
<!-- 设备IP地址 -->
|
||||||
<!-- SelectedItem="{Binding ElementName=dialog, Path=DefaultButton}" /> -->
|
<TextBlock Text="设备端口" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
||||||
<!-- -->
|
<TextBox
|
||||||
<!-- <CheckBox Content="IsShadowEnabled" IsChecked="{Binding ElementName=dialog, Path=IsShadowEnabled}" /> -->
|
AcceptsReturn="True"
|
||||||
<!-- <StackPanel> -->
|
Text="{Binding Device.Ip, UpdateSourceTrigger=PropertyChanged}" />
|
||||||
<!-- <Button Click="TryOpenAnother" Content="Try to open another ContentDialog" /> -->
|
|
||||||
<!-- <TextBlock -->
|
|
||||||
<!-- x:Name="ErrorText" -->
|
|
||||||
<!-- Margin="0,8,0,0" -->
|
<!-- 通讯协议-->
|
||||||
<!-- Foreground="{DynamicResource SystemControlErrorTextForegroundBrush}" -->
|
<TextBlock Text="设备通信协议" HorizontalAlignment="Left" Style="{StaticResource TextBlockSubTitle}" />
|
||||||
<!-- Visibility="Collapsed" /> -->
|
<ComboBox SelectedItem="{Binding Device.ProtocolType}"
|
||||||
<!-- </StackPanel> -->
|
ItemsSource="{Binding Source={StaticResource protocolType} }">
|
||||||
</ikw:SimpleStackPanel>
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
|
<!-- 通讯协议-->
|
||||||
|
|
||||||
|
<CheckBox FontSize="16" Content="是否启用" Margin="0 30 0 0" IsChecked="{Binding Device.IsActive}" />
|
||||||
|
|
||||||
|
</ikw:SimpleStackPanel>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
</ui:ContentDialog>
|
</ui:ContentDialog>
|
||||||
@@ -68,34 +68,4 @@ public partial class MainView : Window
|
|||||||
_viewModel.OnLoaded();
|
_viewModel.OnLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void NavigationView_OnItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
|
|
||||||
// {
|
|
||||||
// ViewModelBase navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
|
||||||
//
|
|
||||||
// switch (args.InvokedItem)
|
|
||||||
// {
|
|
||||||
// case "主页":
|
|
||||||
// // mainViewModel.NavgateTo<HomeViewModel>();
|
|
||||||
// navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
|
||||||
// _logger.LogInformation("导航到到主页面");
|
|
||||||
// break;
|
|
||||||
// case "设备":
|
|
||||||
// navgateVM = App.Current.Services.GetRequiredService<DevicesViewModel>();
|
|
||||||
// // mainViewModel.NavgateTo<DevicesViewModel>();
|
|
||||||
// _logger.LogInformation("导航到到设备页面");
|
|
||||||
// break;
|
|
||||||
// case "数据转换":
|
|
||||||
// navgateVM = App.Current.Services.GetRequiredService<DataTransformViewModel>();
|
|
||||||
// // mainViewModel.NavgateTo<DataTransformViewModel>();
|
|
||||||
// _logger.LogInformation("导航到到数据转换页面");
|
|
||||||
// break;
|
|
||||||
// case "设置":
|
|
||||||
// // mainViewModel.NavgateTo<SettingViewModel>();
|
|
||||||
// navgateVM = App.Current.Services.GetRequiredService<SettingViewModel>();
|
|
||||||
// _logger.LogInformation("导航到到设备页面");
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// MessageHelper.SendNavgatorMessage(navgateVM);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
@@ -4,25 +4,75 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
||||||
|
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||||
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
|
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
|
||||||
|
xmlns:controls="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DataContext="{d:DesignInstance vm:VariableTableViewModel}"
|
d:DataContext="{d:DesignInstance vm:VariableTableViewModel}"
|
||||||
d:DesignHeight="300" d:DesignWidth="300">
|
d:DesignHeight="600" d:DesignWidth="800">
|
||||||
<ikw:SimpleStackPanel Spacing="5">
|
<UserControl.Resources>
|
||||||
|
<!-- 标签字体的样式 -->
|
||||||
|
<Style TargetType="TextBlock" x:Key="VarTableLabelStyle">
|
||||||
|
<Setter Property="Foreground" Value="#555" />
|
||||||
|
<Setter Property="FontSize" Value="20" />
|
||||||
|
</Style>
|
||||||
|
<!-- 值字体的样式 -->
|
||||||
|
<Style TargetType="TextBlock" x:Key="VarTableValueStyle">
|
||||||
|
<Setter Property="FontWeight" Value="Bold" />
|
||||||
|
<Setter Property="FontSize" Value="16" />
|
||||||
|
<Setter Property="MinWidth" Value="120" />
|
||||||
|
<Setter Property="VerticalAlignment" Value="Center" />
|
||||||
|
</Style>
|
||||||
|
</UserControl.Resources>
|
||||||
|
|
||||||
|
<DockPanel>
|
||||||
|
|
||||||
|
<ikw:SimpleStackPanel Margin="10" DockPanel.Dock="Top">
|
||||||
|
<!-- 操作菜单 -->
|
||||||
|
<controls:CommandBar x:Name="PrimaryCommandBar"
|
||||||
|
DefaultLabelPosition="Right" IsOpen="False">
|
||||||
|
<ui:AppBarButton x:Name="AddButton"
|
||||||
|
Command="{Binding AddDeviceCommand}"
|
||||||
|
Label="Add">
|
||||||
|
<ui:AppBarButton.Icon>
|
||||||
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Add}" />
|
||||||
|
</ui:AppBarButton.Icon>
|
||||||
|
</ui:AppBarButton>
|
||||||
|
<ui:AppBarButton x:Name="EditButton"
|
||||||
|
Label="Edit">
|
||||||
|
<ui:AppBarButton.Icon>
|
||||||
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Edit}" />
|
||||||
|
</ui:AppBarButton.Icon>
|
||||||
|
|
||||||
|
</ui:AppBarButton>
|
||||||
|
<ui:AppBarButton x:Name="ShareButton"
|
||||||
|
Label="Share">
|
||||||
|
<ui:AppBarButton.Icon>
|
||||||
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Share}" />
|
||||||
|
</ui:AppBarButton.Icon>
|
||||||
|
</ui:AppBarButton>
|
||||||
|
<ui:CommandBar.SecondaryCommands>
|
||||||
|
<ui:AppBarButton x:Name="SettingsButton"
|
||||||
|
|
||||||
|
Icon="Setting" Label="Settings" />
|
||||||
|
</ui:CommandBar.SecondaryCommands>
|
||||||
|
</controls:CommandBar>
|
||||||
|
<!-- 变量表的名称描述等信息 -->
|
||||||
|
<ikw:SimpleStackPanel Margin="10" Orientation="Horizontal" Spacing="10">
|
||||||
|
<TextBlock Style="{StaticResource VarTableLabelStyle}" Text="变量表名称:" />
|
||||||
|
<TextBlock Style="{StaticResource VarTableValueStyle}" Text="{Binding VariableTable.Name}" />
|
||||||
|
<TextBlock Style="{StaticResource VarTableLabelStyle}" Text="变量表描述:" />
|
||||||
|
<TextBlock Style="{StaticResource VarTableValueStyle}" Text="{Binding VariableTable.Description}" />
|
||||||
|
<TextBlock Style="{StaticResource VarTableLabelStyle}" Text="所属设备:" />
|
||||||
|
<TextBlock Style="{StaticResource VarTableValueStyle}" Text="默认变量表" />
|
||||||
|
</ikw:SimpleStackPanel>
|
||||||
|
|
||||||
|
|
||||||
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="10">
|
|
||||||
<TextBlock Text="变量表名称:" /> <TextBlock Text="{Binding VariableTable.Name}" />
|
|
||||||
</ikw:SimpleStackPanel>
|
</ikw:SimpleStackPanel>
|
||||||
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="10">
|
|
||||||
<TextBlock Text="变量表描述:" /> <TextBlock Text="{Binding VariableTable.Description}" />
|
<DataGrid Margin="10" >
|
||||||
</ikw:SimpleStackPanel>
|
|
||||||
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="10">
|
|
||||||
<TextBlock Text="所属设备:" /> <TextBlock Text="默认变量表" />
|
|
||||||
</ikw:SimpleStackPanel>
|
|
||||||
<DataGrid>
|
|
||||||
|
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
</ikw:SimpleStackPanel>
|
</DockPanel>
|
||||||
|
|
||||||
|
|
||||||
</UserControl>
|
</UserControl>
|
||||||
Reference in New Issue
Block a user