完成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
|
||||
{
|
||||
public class PLC
|
||||
public class DbPLC
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
||||
public int id { get; set; }
|
||||
@@ -47,11 +47,11 @@ namespace PMSWPF.Data.Entities
|
||||
/// </summary>
|
||||
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.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();
|
||||
var tabExist = _db.DbMaintenance.IsAnyTable(nameof(PLC), false);
|
||||
var tabExist = _db.DbMaintenance.IsAnyTable(nameof(DbPLC), false);
|
||||
if (tabExist)
|
||||
{
|
||||
_db.CodeFirst.InitTables<PLC>();
|
||||
_db.CodeFirst.InitTables<DbPLC>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user