修改了设备展示界面
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Net.Sockets;
|
||||
using PMSWPF.Enums;
|
||||
using SqlSugar;
|
||||
|
||||
@@ -22,11 +22,12 @@ public class DevicesRepositories:BaseRepositories
|
||||
}
|
||||
DbDevice dbDevice=new DbDevice();
|
||||
device.CopyTo<DbDevice>(dbDevice);
|
||||
dbDevice.VariableTables=new List<DbVariableTable>();
|
||||
dbDevice.VariableTables=new ();
|
||||
// 添加默认变量表
|
||||
DbVariableTable dbVariableTable=new DbVariableTable();
|
||||
dbVariableTable.Name = "默认变量表";
|
||||
dbVariableTable.Description = "默认变量表";
|
||||
dbVariableTable.ProtocolType = ProtocolType.S7;
|
||||
dbVariableTable.ProtocolType = dbDevice.ProtocolType;
|
||||
dbDevice.VariableTables.Add(dbVariableTable);
|
||||
return await _db.InsertNav(dbDevice).Include(d=>d.VariableTables).ExecuteCommandAsync();
|
||||
|
||||
@@ -34,7 +35,7 @@ public class DevicesRepositories:BaseRepositories
|
||||
|
||||
public async Task<List<DbDevice>> GetAll()
|
||||
{
|
||||
return await _db.Queryable<DbDevice>().ToListAsync();
|
||||
return await _db.Queryable<DbDevice>().Includes(d=>d.VariableTables).ToListAsync();
|
||||
}
|
||||
public async Task<DbDevice> GetById(int id)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ public static class ObjectExtensions
|
||||
/// <param name="source"></param>
|
||||
/// <param name="target"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public static void NewTo<T>(this Object source ) where T : new()
|
||||
public static T NewTo<T>(this Object source ) where T : new()
|
||||
{
|
||||
T target = new T();
|
||||
var sourceType = source.GetType();
|
||||
@@ -47,5 +47,6 @@ public static class ObjectExtensions
|
||||
targetProperty.SetValue(target, value, null);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using PMSWPF.Enums;
|
||||
using SqlSugar;
|
||||
@@ -22,7 +23,7 @@ public partial class Device:ObservableObject
|
||||
[SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
|
||||
public DeviceType DeviceType { get; set; }
|
||||
|
||||
public List<DataVariable>? DataVariables { get; set; }
|
||||
public List<VariableTable>? VariableTables { get; set; }
|
||||
public ProtocolType ProtocolType { get; set; }
|
||||
|
||||
}
|
||||
@@ -3,14 +3,5 @@
|
||||
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<DataTemplate x:Key="DeviceItemTemplate">
|
||||
<Border Background="#eee" CornerRadius="10" Margin="3" Padding="10" >
|
||||
<ikw:SimpleStackPanel Spacing="10" Width="300" Height="200">
|
||||
<TextBlock FontSize="26" FontWeight="Bold" Text="{Binding Name }" />
|
||||
<TextBlock Text="{Binding Description }" />
|
||||
<TextBlock Text="{Binding Ip }" />
|
||||
</ikw:SimpleStackPanel>
|
||||
</Border>
|
||||
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
@@ -41,6 +41,18 @@ public partial class DevicesViewModel : ViewModelBase
|
||||
{
|
||||
Device device = new Device();
|
||||
dbDevice.CopyTo(device);
|
||||
foreach (var dbVariableTable in dbDevice.VariableTables)
|
||||
{
|
||||
|
||||
if (device.VariableTables == null)
|
||||
{
|
||||
device.VariableTables=new List<VariableTable>();
|
||||
}
|
||||
|
||||
var table = dbVariableTable.NewTo<VariableTable>();
|
||||
device.VariableTables.Add(table);
|
||||
}
|
||||
|
||||
_devices.Add(device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,60 @@
|
||||
d:DataContext="{d:DesignInstance vm:DevicesViewModel}"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<UserControl.Resources>
|
||||
<DataTemplate x:Key="DeviceItemTemplate">
|
||||
<Border Background="#eee" CornerRadius="10" Margin="3" Padding="10" >
|
||||
<ikw:SimpleStackPanel Spacing="10" Width="300" Height="200">
|
||||
<DockPanel >
|
||||
<ui:ToggleSwitch
|
||||
DockPanel.Dock="Right"
|
||||
Margin="20 0 0 0 "
|
||||
IsOn="{Binding IsActive}"
|
||||
OffContent="停止" OnContent="启动"/>
|
||||
<TextBlock FontSize="24" FontWeight="Bold" Text="{Binding Name }" />
|
||||
</DockPanel>
|
||||
|
||||
<StackPanel ZIndex="1" >
|
||||
<StackPanel Margin="10 5" Orientation="Horizontal">
|
||||
<Button Margin="5" Command="{Binding AddDeviceCommand}" Content="添加"/>
|
||||
</StackPanel>
|
||||
<TextBlock Text="{Binding Description }" />
|
||||
<TextBlock Text="{Binding Ip }" />
|
||||
<ListBox ItemsSource="{Binding }">
|
||||
|
||||
</ListBox>
|
||||
</ikw:SimpleStackPanel>
|
||||
</Border>
|
||||
|
||||
</DataTemplate>
|
||||
</UserControl.Resources>
|
||||
|
||||
<StackPanel >
|
||||
|
||||
<ui: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>
|
||||
</ui:CommandBar>
|
||||
|
||||
|
||||
<ui:GridView x:Name="BasicGridView"
|
||||
|
||||
Reference in New Issue
Block a user