清理引用,将NavigatorServices更改为使用Message来实现导航的切换
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace PMSWPF.Data
|
||||
{
|
||||
public class DbContext
|
||||
{
|
||||
private static SqlSugarClient _db;
|
||||
namespace PMSWPF.Data;
|
||||
|
||||
public static SqlSugarClient GetInstance()
|
||||
public class DbContext
|
||||
{
|
||||
private static SqlSugarClient _db;
|
||||
|
||||
public static SqlSugarClient GetInstance()
|
||||
{
|
||||
if (_db == null)
|
||||
{
|
||||
if (_db == null)
|
||||
var connectionString = "server=127.0.0.1;port=3306;user=root;password=Pgw15221236646; database=pmswpf;";
|
||||
_db = new SqlSugarClient(new ConnectionConfig
|
||||
{
|
||||
string connectionString = "server=127.0.0.1;port=3306;user=root;password=Pgw15221236646; database=pmswpf;";
|
||||
_db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = connectionString,
|
||||
DbType = DbType.MySql, // 根据实际数据库类型修改,如DbType.MySql等
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute
|
||||
});
|
||||
}
|
||||
return _db;
|
||||
ConnectionString = connectionString,
|
||||
DbType = DbType.MySql, // 根据实际数据库类型修改,如DbType.MySql等
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute
|
||||
});
|
||||
}
|
||||
|
||||
return _db;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,38 +3,46 @@ using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
namespace PMSWPF.Data.Entities;
|
||||
|
||||
[SugarTable("DataVariable")]
|
||||
public class DbDataVariable
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
||||
public int Id { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int ?VariableTableId { get; set; }
|
||||
[Navigate(NavigateType.ManyToOne, nameof(DbDataVariable.VariableTableId))]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
|
||||
public int Id { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)] public int? VariableTableId { get; set; }
|
||||
|
||||
[Navigate(NavigateType.ManyToOne, nameof(VariableTableId))]
|
||||
public DbVariableTable? VariableTable { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)] public string? Description { get; set; }
|
||||
|
||||
public string NodeId { get; set; }
|
||||
[SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
|
||||
|
||||
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public ProtocolType ProtocolType { get; set; }
|
||||
|
||||
public string DataType { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public List<DbMqtt>? Mqtts { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)] public List<DbMqtt>? Mqtts { get; set; }
|
||||
|
||||
public string DataValue { get; set; }
|
||||
public string DisplayValue { get; set; }
|
||||
public DateTime UpdateTime { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DbUser? UpdateUser { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)] public DbUser? UpdateUser { get; set; }
|
||||
|
||||
public string Converstion { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public bool IsSave { get; set; }
|
||||
public Double SaveRange { get; set; }
|
||||
public double SaveRange { get; set; }
|
||||
public bool IsAlarm { get; set; }
|
||||
public Double AlarmMin { get; set; }
|
||||
public Double AlarmMax { get; set; }
|
||||
[SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
|
||||
public double AlarmMin { get; set; }
|
||||
public double AlarmMax { get; set; }
|
||||
|
||||
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public SignalType SignalType { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Net.Sockets;
|
||||
using PMSWPF.Enums;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
@@ -10,22 +8,24 @@ namespace PMSWPF.Data.Entities;
|
||||
[SugarTable("Device")]
|
||||
public class DbDevice
|
||||
{
|
||||
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
||||
public int Id { get; set; }
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)] public string? Description { get; set; }
|
||||
|
||||
public string Ip { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public bool IsRuning { get; set; }
|
||||
[SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
|
||||
|
||||
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public DeviceType DeviceType { get; set; }
|
||||
|
||||
[Navigate(NavigateType.OneToMany, nameof(DbVariableTable.DeviceId))]
|
||||
|
||||
[Navigate(NavigateType.OneToMany, nameof(DbVariableTable.DeviceId))]
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public List<DbVariableTable>? VariableTables { get; set; }
|
||||
[SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
|
||||
public List<DbVariableTable>? VariableTables { get; set; }
|
||||
|
||||
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public ProtocolType ProtocolType { get; set; }
|
||||
|
||||
}
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace PMSWPF.Data.Entities;
|
||||
|
||||
|
||||
public class DbMqtt
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
|
||||
public int Id { get; set; }
|
||||
|
||||
}
|
||||
@@ -12,21 +12,20 @@ public class DbNlog
|
||||
// @Application, @Logged, @Level,@ThreadID, @Message,
|
||||
// @Logger, @Callsite, @Exception, @Url, @Action, @User
|
||||
// )
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
|
||||
public int Id { get; set; }
|
||||
|
||||
public DateTime LogTime { get; set; }
|
||||
public string Level { get; set; }
|
||||
public int ThreadID { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string ThreadName { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)] public string ThreadName { get; set; }
|
||||
|
||||
public string Logger { get; set; }
|
||||
public string Callsite { get; set; }
|
||||
public int CallsiteLineNumber { get; set; }
|
||||
public string Message { get; set; }
|
||||
[SugarColumn(IsNullable = true,ColumnDataType = "text")]
|
||||
public string Exception { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
[SugarColumn(IsNullable = true, ColumnDataType = "text")]
|
||||
public string Exception { get; set; }
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
namespace PMSWPF.Data.Entities;
|
||||
|
||||
[SugarTable("S7DataVariable")]
|
||||
public class DbS7DataVariable:DbDataVariable
|
||||
public class DbS7DataVariable : DbDataVariable
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@ namespace PMSWPF.Data.Entities;
|
||||
[SugarTable("User")]
|
||||
public class DbUser
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
|
||||
public int Id { get; set; }
|
||||
|
||||
}
|
||||
@@ -8,18 +8,21 @@ namespace PMSWPF.Data.Entities;
|
||||
[SugarTable("VariableTable")]
|
||||
public class DbVariableTable
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增
|
||||
public int Id { get; set; }
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? Description { get; set; }
|
||||
[SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
|
||||
|
||||
[SugarColumn(IsNullable = true)] public string? Description { get; set; }
|
||||
|
||||
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public ProtocolType ProtocolType { get; set; }
|
||||
|
||||
|
||||
[Navigate(NavigateType.OneToMany, nameof(DbDataVariable.VariableTableId))]
|
||||
public List<DbDataVariable>? DataVariables { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? DeviceId { get; set; }
|
||||
[Navigate(NavigateType.ManyToOne, nameof(DbVariableTable.DeviceId))]
|
||||
public Device? Device { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)] public int? DeviceId { get; set; }
|
||||
|
||||
[Navigate(NavigateType.ManyToOne, nameof(DeviceId))]
|
||||
public Device? Device { get; set; }
|
||||
}
|
||||
@@ -24,19 +24,19 @@ public class BaseRepositories
|
||||
|
||||
private void CheckDbTables()
|
||||
{
|
||||
if(!_db.DbMaintenance.IsAnyTable<DbNlog>())
|
||||
if (!_db.DbMaintenance.IsAnyTable<DbNlog>())
|
||||
_db.CodeFirst.InitTables<DbNlog>();
|
||||
if(!_db.DbMaintenance.IsAnyTable<DbDevice>())
|
||||
_db.CodeFirst.InitTables<DbDevice>();
|
||||
if(!_db.DbMaintenance.IsAnyTable<DbVariableTable>())
|
||||
_db.CodeFirst.InitTables<DbVariableTable>();
|
||||
if(!_db.DbMaintenance.IsAnyTable<DbDataVariable>())
|
||||
_db.CodeFirst.InitTables<DbDataVariable>();
|
||||
if(!_db.DbMaintenance.IsAnyTable<DbS7DataVariable>())
|
||||
_db.CodeFirst.InitTables<DbS7DataVariable>();
|
||||
if(!_db.DbMaintenance.IsAnyTable<DbUser>())
|
||||
_db.CodeFirst.InitTables<DbUser>();
|
||||
if(!_db.DbMaintenance.IsAnyTable<DbMqtt>())
|
||||
_db.CodeFirst.InitTables<DbMqtt>();
|
||||
if (!_db.DbMaintenance.IsAnyTable<DbDevice>())
|
||||
_db.CodeFirst.InitTables<DbDevice>();
|
||||
if (!_db.DbMaintenance.IsAnyTable<DbVariableTable>())
|
||||
_db.CodeFirst.InitTables<DbVariableTable>();
|
||||
if (!_db.DbMaintenance.IsAnyTable<DbDataVariable>())
|
||||
_db.CodeFirst.InitTables<DbDataVariable>();
|
||||
if (!_db.DbMaintenance.IsAnyTable<DbS7DataVariable>())
|
||||
_db.CodeFirst.InitTables<DbS7DataVariable>();
|
||||
if (!_db.DbMaintenance.IsAnyTable<DbUser>())
|
||||
_db.CodeFirst.InitTables<DbUser>();
|
||||
if (!_db.DbMaintenance.IsAnyTable<DbMqtt>())
|
||||
_db.CodeFirst.InitTables<DbMqtt>();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using PMSWPF.Data.Entities;
|
||||
using PMSWPF.Enums;
|
||||
using PMSWPF.Excptions;
|
||||
using PMSWPF.Extensions;
|
||||
using PMSWPF.Helper;
|
||||
@@ -7,52 +6,45 @@ using PMSWPF.Models;
|
||||
|
||||
namespace PMSWPF.Data.Repositories;
|
||||
|
||||
public class DevicesRepositories:BaseRepositories
|
||||
public class DevicesRepositories : BaseRepositories
|
||||
{
|
||||
public DevicesRepositories():base()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task<bool> Add(Device device)
|
||||
{
|
||||
var exist=await _db.Queryable<DbDevice>().Where(d=>d.Name==device.Name).FirstAsync();
|
||||
if (exist != null)
|
||||
{
|
||||
throw new DbExistException("设备名称已经存在。");
|
||||
}
|
||||
DbDevice dbDevice=new DbDevice();
|
||||
device.CopyTo<DbDevice>(dbDevice);
|
||||
dbDevice.VariableTables=new ();
|
||||
// 添加默认变量表
|
||||
DbVariableTable dbVariableTable=new DbVariableTable();
|
||||
dbVariableTable.Name = "默认变量表";
|
||||
dbVariableTable.Description = "默认变量表";
|
||||
dbVariableTable.ProtocolType = dbDevice.ProtocolType;
|
||||
dbDevice.VariableTables.Add(dbVariableTable);
|
||||
return await _db.InsertNav(dbDevice).Include(d=>d.VariableTables).ExecuteCommandAsync();
|
||||
|
||||
var exist = await _db.Queryable<DbDevice>().Where(d => d.Name == device.Name).FirstAsync();
|
||||
if (exist != null) throw new DbExistException("设备名称已经存在。");
|
||||
var dbDevice = new DbDevice();
|
||||
device.CopyTo(dbDevice);
|
||||
dbDevice.VariableTables = new List<DbVariableTable>();
|
||||
// 添加默认变量表
|
||||
var dbVariableTable = new DbVariableTable();
|
||||
dbVariableTable.Name = "默认变量表";
|
||||
dbVariableTable.Description = "默认变量表";
|
||||
dbVariableTable.ProtocolType = dbDevice.ProtocolType;
|
||||
dbDevice.VariableTables.Add(dbVariableTable);
|
||||
return await _db.InsertNav(dbDevice).Include(d => d.VariableTables).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<Device>> GetAll()
|
||||
{
|
||||
var dlist= await _db.Queryable<DbDevice>().Includes(d=>d.VariableTables).ToListAsync();
|
||||
List<Device> devices=new List<Device>();
|
||||
foreach (DbDevice dbDevice in dlist)
|
||||
{
|
||||
Device device = dbDevice.NewTo<Device>();
|
||||
device.VariableTables=CovertHelper.ConvertList<DbVariableTable,VariableTable>(dbDevice.VariableTables);
|
||||
devices.Add(device);
|
||||
}
|
||||
var dlist = await _db.Queryable<DbDevice>().Includes(d => d.VariableTables).ToListAsync();
|
||||
var devices = new List<Device>();
|
||||
foreach (var dbDevice in dlist)
|
||||
{
|
||||
var device = dbDevice.NewTo<Device>();
|
||||
device.VariableTables = CovertHelper.ConvertList<DbVariableTable, VariableTable>(dbDevice.VariableTables);
|
||||
devices.Add(device);
|
||||
}
|
||||
|
||||
return devices;
|
||||
return devices;
|
||||
}
|
||||
|
||||
public async Task<DbDevice> GetById(int id)
|
||||
{
|
||||
return await _db.Queryable<DbDevice>().FirstAsync(p=>p.Id == id);
|
||||
return await _db.Queryable<DbDevice>().FirstAsync(p => p.Id == id);
|
||||
}
|
||||
|
||||
public async Task<int> DeleteById(int id)
|
||||
{
|
||||
return await _db.Deleteable<DbDevice>(new DbDevice() { Id = id }).ExecuteCommandAsync();
|
||||
return await _db.Deleteable<DbDevice>(new DbDevice { Id = id }).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user