实现了添加设备的功能,并写了Object对象的扩展CopyTo方法,实现了数据表的创建。

This commit is contained in:
2025-06-12 18:41:46 +08:00
parent ea15ea594a
commit 6ee5f10aed
11 changed files with 154 additions and 36 deletions

View File

@@ -1,10 +1,16 @@
using SqlSugar;
namespace PMSWPF.Data.Entities;
[SugarTable("Device")]
public class DbDevice
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Ip { get; set; }
public bool IsActive { get; set; }
public bool IsRuning { get; set; }

View File

@@ -1,17 +1,29 @@
using PMSWPF.Data.Entities;
using PMSWPF.Excptions;
namespace PMSWPF.Data.Repositories;
public class DevicesRepositories:BaseRepositories
{
public DevicesRepositories()
public DevicesRepositories():base()
{
var tableExist= _db.DbMaintenance.IsAnyTable<DbDevice>();
if (!tableExist)
{
_db.CodeFirst.InitTables<DbDevice>();
}
}
public async Task<int> Add(DbDevice dbDevice)
{
return await _db.Insertable<DbDevice>(dbDevice).ExecuteCommandAsync();
var exist=await _db.Queryable<DbDevice>().Where(d=>d.Name==dbDevice.Name).FirstAsync();
if (exist != null)
{
throw new DbExistException("设备名称已经存在。");
}
var res= await _db.Insertable<DbDevice>(dbDevice).ExecuteCommandAsync();
return res;
}
public async Task<List<DbDevice>> GetAll()