完成DbDevice的数据库操作
This commit is contained in:
11
Data/Entities/DbDevice.cs
Normal file
11
Data/Entities/DbDevice.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace PMSWPF.Data.Entities;
|
||||||
|
|
||||||
|
public class DbDevice
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public bool IsActive { get; set; }
|
||||||
|
public bool IsRuning { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ using SqlSugar.DbConvert;
|
|||||||
|
|
||||||
namespace PMSWPF.Data.Entities
|
namespace PMSWPF.Data.Entities
|
||||||
{
|
{
|
||||||
public class PLC
|
public class DbPLC
|
||||||
{
|
{
|
||||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
||||||
public int id { get; set; }
|
public int id { get; set; }
|
||||||
@@ -47,11 +47,11 @@ namespace PMSWPF.Data.Entities
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsEnable { get; set; }
|
public bool IsEnable { get; set; }
|
||||||
|
|
||||||
public PLC()
|
public DbPLC()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
public PLC(string name = "", string nodeID = "", string ip = "", string status = "", string connType = "")
|
public DbPLC(string name = "", string nodeID = "", string ip = "", string status = "", string connType = "")
|
||||||
{
|
{
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
this.NodeID = nodeID;
|
this.NodeID = nodeID;
|
||||||
13
Data/Repositories/BaseRepositories.cs
Normal file
13
Data/Repositories/BaseRepositories.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace PMSWPF.Data.Repositories;
|
||||||
|
|
||||||
|
public class BaseRepositories
|
||||||
|
{
|
||||||
|
protected readonly SqlSugarClient _db;
|
||||||
|
|
||||||
|
public BaseRepositories()
|
||||||
|
{
|
||||||
|
_db = DbContext.GetInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
29
Data/Repositories/DevicesRepositories.cs
Normal file
29
Data/Repositories/DevicesRepositories.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using PMSWPF.Data.Entities;
|
||||||
|
|
||||||
|
namespace PMSWPF.Data.Repositories;
|
||||||
|
|
||||||
|
public class DevicesRepositories:BaseRepositories
|
||||||
|
{
|
||||||
|
public DevicesRepositories()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> Add(DbPLC dbPLC)
|
||||||
|
{
|
||||||
|
return await _db.Insertable<DbPLC>(dbPLC).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<DbPLC>> GetAll()
|
||||||
|
{
|
||||||
|
return await _db.Queryable<DbPLC>().ToListAsync();
|
||||||
|
}
|
||||||
|
public async Task<DbPLC> GetById(int id)
|
||||||
|
{
|
||||||
|
return await _db.Queryable<DbPLC>().FirstAsync(p=>p.id == id);
|
||||||
|
}
|
||||||
|
public async Task<int> DeleteById(int id)
|
||||||
|
{
|
||||||
|
return await _db.Deleteable<DbPLC>(new DbPLC() { id = id }).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,10 +11,10 @@ namespace PMSWPF.Data.Repositories
|
|||||||
{
|
{
|
||||||
|
|
||||||
_db = DbContext.GetInstance();
|
_db = DbContext.GetInstance();
|
||||||
var tabExist = _db.DbMaintenance.IsAnyTable(nameof(PLC), false);
|
var tabExist = _db.DbMaintenance.IsAnyTable(nameof(DbPLC), false);
|
||||||
if (tabExist)
|
if (tabExist)
|
||||||
{
|
{
|
||||||
_db.CodeFirst.InitTables<PLC>();
|
_db.CodeFirst.InitTables<DbPLC>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
Models/Device.cs
Normal file
6
Models/Device.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PMSWPF.Models;
|
||||||
|
|
||||||
|
public class Device
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.193" />
|
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.193" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Models\" />
|
|
||||||
<Folder Include="Resources\" />
|
<Folder Include="Resources\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
namespace PMSWPF.ViewModels;
|
namespace PMSWPF.ViewModels;
|
||||||
|
|
||||||
public class DevicesViewModel:ViewModelBase
|
public class DevicesViewModel:ViewModelBase
|
||||||
|
{
|
||||||
|
public DevicesViewModel()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,7 +6,10 @@
|
|||||||
xmlns:local="clr-namespace:PMSWPF.Views"
|
xmlns:local="clr-namespace:PMSWPF.Views"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="300" d:DesignWidth="300">
|
d:DesignHeight="300" d:DesignWidth="300">
|
||||||
<Grid>
|
<StackPanel>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Button Content="添加"/>
|
||||||
|
</StackPanel>
|
||||||
<TextBlock Text="DevicesView" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
|
<TextBlock Text="DevicesView" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
|
||||||
</Grid>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -51,33 +51,33 @@
|
|||||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Switch}" />
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Switch}" />
|
||||||
</ui:NavigationViewItem.Icon>
|
</ui:NavigationViewItem.Icon>
|
||||||
</ui:NavigationViewItem>
|
</ui:NavigationViewItem>
|
||||||
<ui:NavigationViewItemHeader Content="Actions" />
|
<!-- <ui:NavigationViewItemHeader Content="Actions" /> -->
|
||||||
<ui:NavigationViewItem
|
<!-- <ui:NavigationViewItem -->
|
||||||
x:Name="SamplePage2Item"
|
<!-- x:Name="SamplePage2Item" -->
|
||||||
Content="Menu Item2"
|
<!-- Content="Menu Item2" -->
|
||||||
SelectsOnInvoked="True"
|
<!-- SelectsOnInvoked="True" -->
|
||||||
Tag="SamplePage2">
|
<!-- Tag="SamplePage2"> -->
|
||||||
<ui:NavigationViewItem.Icon>
|
<!-- <ui:NavigationViewItem.Icon> -->
|
||||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Save}" />
|
<!-- <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Save}" /> -->
|
||||||
</ui:NavigationViewItem.Icon>
|
<!-- </ui:NavigationViewItem.Icon> -->
|
||||||
</ui:NavigationViewItem>
|
<!-- </ui:NavigationViewItem> -->
|
||||||
<ui:NavigationViewItem
|
<!-- <ui:NavigationViewItem -->
|
||||||
x:Name="SamplePage3Item"
|
<!-- x:Name="SamplePage3Item" -->
|
||||||
Content="Menu Item3"
|
<!-- Content="Menu Item3" -->
|
||||||
Tag="SamplePage3">
|
<!-- Tag="SamplePage3"> -->
|
||||||
<ui:NavigationViewItem.Icon>
|
<!-- <ui:NavigationViewItem.Icon> -->
|
||||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Refresh}" />
|
<!-- <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Refresh}" /> -->
|
||||||
</ui:NavigationViewItem.Icon>
|
<!-- </ui:NavigationViewItem.Icon> -->
|
||||||
</ui:NavigationViewItem>
|
<!-- </ui:NavigationViewItem> -->
|
||||||
</ui:NavigationView.MenuItems>
|
</ui:NavigationView.MenuItems>
|
||||||
|
|
||||||
<ui:NavigationView.PaneCustomContent>
|
<!-- <ui:NavigationView.PaneCustomContent> -->
|
||||||
<ui:HyperlinkButton
|
<!-- <ui:HyperlinkButton -->
|
||||||
x:Name="PaneHyperlink"
|
<!-- x:Name="PaneHyperlink" -->
|
||||||
Margin="12,0"
|
<!-- Margin="12,0" -->
|
||||||
Content="More info"
|
<!-- Content="More info" -->
|
||||||
Visibility="Collapsed" />
|
<!-- Visibility="Collapsed" /> -->
|
||||||
</ui:NavigationView.PaneCustomContent>
|
<!-- </ui:NavigationView.PaneCustomContent> -->
|
||||||
|
|
||||||
|
|
||||||
<ui:NavigationView.AutoSuggestBox>
|
<ui:NavigationView.AutoSuggestBox>
|
||||||
@@ -90,8 +90,11 @@
|
|||||||
|
|
||||||
|
|
||||||
<ui:NavigationView.PaneFooter>
|
<ui:NavigationView.PaneFooter>
|
||||||
|
|
||||||
<StackPanel
|
<StackPanel
|
||||||
x:Name="FooterStackPanel"
|
x:Name="FooterStackPanel"
|
||||||
|
Margin="0"
|
||||||
|
|
||||||
Orientation="Vertical"
|
Orientation="Vertical"
|
||||||
Visibility="Visible">
|
Visibility="Visible">
|
||||||
<ui:NavigationViewItem Content="设置">
|
<ui:NavigationViewItem Content="设置">
|
||||||
|
|||||||
Reference in New Issue
Block a user