diff --git a/App.xaml b/App.xaml
index e99c47f..aaa37d3 100644
--- a/App.xaml
+++ b/App.xaml
@@ -2,21 +2,19 @@
x:Class="PMSWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
- xmlns:local="clr-namespace:PMSWPF"
- >
+ xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern">
-
-
+
+
-
-
-
+
+
+
-
+
-
+
\ No newline at end of file
diff --git a/App.xaml.cs b/App.xaml.cs
index 55e9ea4..7a0c16d 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -1,8 +1,5 @@
-using System.Configuration;
-using System.Data;
-using System.Windows;
+using System.Windows;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog;
using NLog.Extensions.Logging;
@@ -12,72 +9,73 @@ using PMSWPF.Data.Repositories;
using PMSWPF.Services;
using PMSWPF.ViewModels;
using PMSWPF.Views;
+using LogLevel = Microsoft.Extensions.Logging.LogLevel;
-namespace PMSWPF
+namespace PMSWPF;
+
+///
+/// Interaction logic for App.xaml
+///
+public partial class App : Application
{
- ///
- /// Interaction logic for App.xaml
- ///
- public partial class App : Application
+ public App()
{
- public new static App Current => (App)Application.Current;
- public IServiceProvider Services { get; }
+ var container = new ServiceCollection();
- public App()
+ var nlog = LogManager.Setup().LoadConfigurationFromFile("Config/nlog.config").GetCurrentClassLogger();
+
+ container.AddLogging(loggingBuilder =>
{
- var container = new ServiceCollection();
-
- var nlog = LogManager.Setup().LoadConfigurationFromFile("Config/nlog.config").GetCurrentClassLogger();
-
- container.AddLogging(loggingBuilder =>
- {
- loggingBuilder.ClearProviders();
- loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
- loggingBuilder.AddNLog();
- });
+ loggingBuilder.ClearProviders();
+ loggingBuilder.SetMinimumLevel(LogLevel.Trace);
+ loggingBuilder.AddNLog();
+ });
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
- container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ container.AddSingleton();
+ Services = container.BuildServiceProvider();
+ // 启动服务
+ Services.GetRequiredService();
+ }
- Services = container.BuildServiceProvider();
- // 启动服务
- Services.GetRequiredService();
- }
+ public new static App Current => (App)Application.Current;
+ public IServiceProvider Services { get; }
- protected override void OnStartup(StartupEventArgs e)
- {
- base.OnStartup(e);
- InitDB();
+ protected override void OnStartup(StartupEventArgs e)
+ {
+ base.OnStartup(e);
+ InitDB();
- MainWindow = Services.GetRequiredService();
- MainWindow.Show();
- }
+ MainWindow = Services.GetRequiredService();
+ MainWindow.Show();
+ }
- private void InitDB()
- {
- var _db = DbContext.GetInstance();
- _db.DbMaintenance.CreateDatabase();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- }
+ private void InitDB()
+ {
+ var _db = DbContext.GetInstance();
+ _db.DbMaintenance.CreateDatabase();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
}
}
\ No newline at end of file
diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs
index b0ec827..4a05c7d 100644
--- a/AssemblyInfo.cs
+++ b/AssemblyInfo.cs
@@ -1,10 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
- ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
- //(used if a resource is not found in the page,
- // or application resource dictionaries)
- ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
- //(used if a resource is not found in the page,
- // app, or any theme specific resource dictionaries)
-)]
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
\ No newline at end of file
diff --git a/Config/nlog.config b/Config/nlog.config
index ea10872..4922575 100644
--- a/Config/nlog.config
+++ b/Config/nlog.config
@@ -1,60 +1,60 @@
-
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
- INSERT INTO nlog (
- LogTime, Level, ThreadID,ThreadName,Callsite,CallsiteLineNumber,Message,
- Logger, Exception
- ) VALUES (
- @LogTime, @Level,@ThreadID,@ThreadName,@Callsite,@CallsiteLineNumber,@Message,
- @Logger, @Exception
- )
-
+
+
+ INSERT INTO nlog (
+ LogTime, Level, ThreadID,ThreadName,Callsite,CallsiteLineNumber,Message,
+ Logger, Exception
+ ) VALUES (
+ @LogTime, @Level,@ThreadID,@ThreadName,@Callsite,@CallsiteLineNumber,@Message,
+ @Logger, @Exception
+ )
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Data/DbContext.cs b/Data/DbContext.cs
index b2b4caa..c6cdf44 100644
--- a/Data/DbContext.cs
+++ b/Data/DbContext.cs
@@ -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;
}
-}
+}
\ No newline at end of file
diff --git a/Data/Entities/DbDataVariable.cs b/Data/Entities/DbDataVariable.cs
index 96feb25..74a16d4 100644
--- a/Data/Entities/DbDataVariable.cs
+++ b/Data/Entities/DbDataVariable.cs
@@ -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? Mqtts { get; set; }
+
+ [SugarColumn(IsNullable = true)] public List? 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; }
-
}
\ No newline at end of file
diff --git a/Data/Entities/DbDevice.cs b/Data/Entities/DbDevice.cs
index 5a7a0e2..5b8b7d7 100644
--- a/Data/Entities/DbDevice.cs
+++ b/Data/Entities/DbDevice.cs
@@ -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? VariableTables { get; set; }
- [SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
+ public List? VariableTables { get; set; }
+
+ [SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
public ProtocolType ProtocolType { get; set; }
-
}
\ No newline at end of file
diff --git a/Data/Entities/DbMqtt.cs b/Data/Entities/DbMqtt.cs
index 02a5308..5364531 100644
--- a/Data/Entities/DbMqtt.cs
+++ b/Data/Entities/DbMqtt.cs
@@ -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; }
-
}
\ No newline at end of file
diff --git a/Data/Entities/DbNlog.cs b/Data/Entities/DbNlog.cs
index 2a9874c..9771f03 100644
--- a/Data/Entities/DbNlog.cs
+++ b/Data/Entities/DbNlog.cs
@@ -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; }
}
\ No newline at end of file
diff --git a/Data/Entities/DbS7DataVariable.cs b/Data/Entities/DbS7DataVariable.cs
index 2a2ccba..33cb430 100644
--- a/Data/Entities/DbS7DataVariable.cs
+++ b/Data/Entities/DbS7DataVariable.cs
@@ -3,8 +3,6 @@
namespace PMSWPF.Data.Entities;
[SugarTable("S7DataVariable")]
-public class DbS7DataVariable:DbDataVariable
+public class DbS7DataVariable : DbDataVariable
{
-
-
}
\ No newline at end of file
diff --git a/Data/Entities/DbUser.cs b/Data/Entities/DbUser.cs
index 1de1165..e312267 100644
--- a/Data/Entities/DbUser.cs
+++ b/Data/Entities/DbUser.cs
@@ -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; }
-
}
\ No newline at end of file
diff --git a/Data/Entities/DbVariableTable.cs b/Data/Entities/DbVariableTable.cs
index feb4139..d294abf 100644
--- a/Data/Entities/DbVariableTable.cs
+++ b/Data/Entities/DbVariableTable.cs
@@ -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? 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; }
}
\ No newline at end of file
diff --git a/Data/Repositories/BaseRepositories.cs b/Data/Repositories/BaseRepositories.cs
index 9bf24b7..28016d9 100644
--- a/Data/Repositories/BaseRepositories.cs
+++ b/Data/Repositories/BaseRepositories.cs
@@ -24,19 +24,19 @@ public class BaseRepositories
private void CheckDbTables()
{
- if(!_db.DbMaintenance.IsAnyTable())
+ if (!_db.DbMaintenance.IsAnyTable())
_db.CodeFirst.InitTables();
- if(!_db.DbMaintenance.IsAnyTable())
- _db.CodeFirst.InitTables();
- if(!_db.DbMaintenance.IsAnyTable())
- _db.CodeFirst.InitTables();
- if(!_db.DbMaintenance.IsAnyTable())
- _db.CodeFirst.InitTables();
- if(!_db.DbMaintenance.IsAnyTable())
- _db.CodeFirst.InitTables();
- if(!_db.DbMaintenance.IsAnyTable())
- _db.CodeFirst.InitTables();
- if(!_db.DbMaintenance.IsAnyTable())
- _db.CodeFirst.InitTables();
+ if (!_db.DbMaintenance.IsAnyTable())
+ _db.CodeFirst.InitTables();
+ if (!_db.DbMaintenance.IsAnyTable())
+ _db.CodeFirst.InitTables();
+ if (!_db.DbMaintenance.IsAnyTable())
+ _db.CodeFirst.InitTables();
+ if (!_db.DbMaintenance.IsAnyTable())
+ _db.CodeFirst.InitTables();
+ if (!_db.DbMaintenance.IsAnyTable())
+ _db.CodeFirst.InitTables();
+ if (!_db.DbMaintenance.IsAnyTable())
+ _db.CodeFirst.InitTables();
}
}
\ No newline at end of file
diff --git a/Data/Repositories/DevicesRepositories.cs b/Data/Repositories/DevicesRepositories.cs
index a095ed3..05498e5 100644
--- a/Data/Repositories/DevicesRepositories.cs
+++ b/Data/Repositories/DevicesRepositories.cs
@@ -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 Add(Device device)
{
- var exist=await _db.Queryable().Where(d=>d.Name==device.Name).FirstAsync();
- if (exist != null)
- {
- throw new DbExistException("设备名称已经存在。");
- }
- DbDevice dbDevice=new DbDevice();
- device.CopyTo(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().Where(d => d.Name == device.Name).FirstAsync();
+ if (exist != null) throw new DbExistException("设备名称已经存在。");
+ var dbDevice = new DbDevice();
+ device.CopyTo(dbDevice);
+ dbDevice.VariableTables = new List();
+ // 添加默认变量表
+ 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> GetAll()
{
- var dlist= await _db.Queryable().Includes(d=>d.VariableTables).ToListAsync();
- List devices=new List();
- foreach (DbDevice dbDevice in dlist)
- {
- Device device = dbDevice.NewTo();
- device.VariableTables=CovertHelper.ConvertList(dbDevice.VariableTables);
- devices.Add(device);
- }
+ var dlist = await _db.Queryable().Includes(d => d.VariableTables).ToListAsync();
+ var devices = new List();
+ foreach (var dbDevice in dlist)
+ {
+ var device = dbDevice.NewTo();
+ device.VariableTables = CovertHelper.ConvertList(dbDevice.VariableTables);
+ devices.Add(device);
+ }
- return devices;
+ return devices;
}
+
public async Task GetById(int id)
{
- return await _db.Queryable().FirstAsync(p=>p.Id == id);
+ return await _db.Queryable().FirstAsync(p => p.Id == id);
}
+
public async Task DeleteById(int id)
{
- return await _db.Deleteable(new DbDevice() { Id = id }).ExecuteCommandAsync();
+ return await _db.Deleteable(new DbDevice { Id = id }).ExecuteCommandAsync();
}
}
\ No newline at end of file
diff --git a/Enums/Brand.cs b/Enums/Brand.cs
index 6d12e2f..335b7b9 100644
--- a/Enums/Brand.cs
+++ b/Enums/Brand.cs
@@ -1,18 +1,17 @@
-namespace PMSWPF.Enums
+namespace PMSWPF.Enums;
+
+///
+/// PLC品牌
+///
+public enum PlcBrand
{
///
- /// PLC品牌
+ /// 西门子
///
- public enum PlcBrand
- {
- ///
- /// 西门子
- ///
- Siemens = 0,
- ///
- /// 三菱
- ///
- Melsec = 1,
+ Siemens = 0,
- }
-}
+ ///
+ /// 三菱
+ ///
+ Melsec = 1
+}
\ No newline at end of file
diff --git a/Enums/DeviceType.cs b/Enums/DeviceType.cs
index bb5a36f..a140f11 100644
--- a/Enums/DeviceType.cs
+++ b/Enums/DeviceType.cs
@@ -4,10 +4,6 @@ namespace PMSWPF.Enums;
public enum DeviceType
{
- [Description("西门子PLC")]
- SiemensPLC,
- [Description("三菱PLC")]
- MelsecPLC
-
-
+ [Description("西门子PLC")] SiemensPLC,
+ [Description("三菱PLC")] MelsecPLC
}
\ No newline at end of file
diff --git a/Enums/NotificationType.cs b/Enums/NotificationType.cs
index 5ea17f2..80cb9a5 100644
--- a/Enums/NotificationType.cs
+++ b/Enums/NotificationType.cs
@@ -9,5 +9,4 @@ public enum NotificationType
Success,
Clear,
Ask
-
}
\ No newline at end of file
diff --git a/Enums/ProtocolType.cs b/Enums/ProtocolType.cs
index 0f37636..5ce676e 100644
--- a/Enums/ProtocolType.cs
+++ b/Enums/ProtocolType.cs
@@ -4,12 +4,8 @@ namespace PMSWPF.Enums;
public enum ProtocolType
{
- [Description("S7协议")]
- S7 ,
- [Description("OpcUA协议")]
- OpcUA ,
- [Description("ModbusRtu协议")]
- ModbusRtu ,
- [Description("ModbusTcp协议")]
- ModbusTcp
+ [Description("S7协议")] S7,
+ [Description("OpcUA协议")] OpcUA,
+ [Description("ModbusRtu协议")] ModbusRtu,
+ [Description("ModbusTcp协议")] ModbusTcp
}
\ No newline at end of file
diff --git a/Enums/SignalType.cs b/Enums/SignalType.cs
index 0714f0c..c18bd58 100644
--- a/Enums/SignalType.cs
+++ b/Enums/SignalType.cs
@@ -4,25 +4,14 @@ namespace PMSWPF.Enums;
public enum SignalType
{
- [Description("启动信号")]
- StartSignal,
- [Description("停止信号")]
- StopSignal,
- [Description("报警信号")]
- AlarmSignal,
- [Description("准备信号")]
- ReadySignal,
- [Description("复位信号")]
- ResetSignal,
- [Description("运行信号")]
- RunSignal,
- [Description("设定频率")]
- SetHZSignal,
- [Description("当前频率")]
- GetHZSignal,
- [Description("当前电流")]
- CurrentASignal,
- [Description("其他信号")]
- OtherASignal
-
+ [Description("启动信号")] StartSignal,
+ [Description("停止信号")] StopSignal,
+ [Description("报警信号")] AlarmSignal,
+ [Description("准备信号")] ReadySignal,
+ [Description("复位信号")] ResetSignal,
+ [Description("运行信号")] RunSignal,
+ [Description("设定频率")] SetHZSignal,
+ [Description("当前频率")] GetHZSignal,
+ [Description("当前电流")] CurrentASignal,
+ [Description("其他信号")] OtherASignal
}
\ No newline at end of file
diff --git a/Exceptions/DbExistException.cs b/Exceptions/DbExistException.cs
index 45ba436..0680d77 100644
--- a/Exceptions/DbExistException.cs
+++ b/Exceptions/DbExistException.cs
@@ -1,10 +1,16 @@
namespace PMSWPF.Excptions;
-public class DbExistException: Exception
+public class DbExistException : Exception
{
- public DbExistException() : base() { }
+ public DbExistException()
+ {
+ }
- public DbExistException(string message) : base(message) { }
+ public DbExistException(string message) : base(message)
+ {
+ }
- public DbExistException(string message, System.Exception innerException) : base(message, innerException) { }
+ public DbExistException(string message, Exception innerException) : base(message, innerException)
+ {
+ }
}
\ No newline at end of file
diff --git a/Extensions/EnumBindingSourceExtension.cs b/Extensions/EnumBindingSourceExtension.cs
index 99c2557..4323603 100644
--- a/Extensions/EnumBindingSourceExtension.cs
+++ b/Extensions/EnumBindingSourceExtension.cs
@@ -2,10 +2,19 @@
namespace PMSWPF.Extensions;
-class EnumBindingSourceExtension : MarkupExtension
+internal class EnumBindingSourceExtension : MarkupExtension
{
private Type? _enumType;
+ public EnumBindingSourceExtension()
+ {
+ }
+
+ public EnumBindingSourceExtension(Type enumType)
+ {
+ EnumType = enumType;
+ }
+
public Type? EnumType
{
get => _enumType;
@@ -15,7 +24,7 @@ class EnumBindingSourceExtension : MarkupExtension
{
if (value != null)
{
- Type enumType = Nullable.GetUnderlyingType(value) ?? value;
+ var enumType = Nullable.GetUnderlyingType(value) ?? value;
if (!enumType.IsEnum)
throw new ArgumentException("Type must be for an Enum.");
}
@@ -25,13 +34,6 @@ class EnumBindingSourceExtension : MarkupExtension
}
}
- public EnumBindingSourceExtension() { }
-
- public EnumBindingSourceExtension(Type enumType)
- {
- EnumType = enumType;
- }
-
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (_enumType == null)
diff --git a/Extensions/ObjectExtensions.cs b/Extensions/ObjectExtensions.cs
index 23e565a..deeaa79 100644
--- a/Extensions/ObjectExtensions.cs
+++ b/Extensions/ObjectExtensions.cs
@@ -1,52 +1,53 @@
-using System.Reflection;
-
-namespace PMSWPF.Extensions;
+namespace PMSWPF.Extensions;
public static class ObjectExtensions
{
///
- /// 对象转换,将source对象上的所有属性的值,都转换到target对象上
+ /// 对象转换,将source对象上的所有属性的值,都转换到target对象上
///
///
///
///
- public static void CopyTo(this Object source ,T target)
+ public static void CopyTo(this object source, T target)
{
var sourceType = source.GetType();
var targetType = target.GetType();
- var sourceProperties = sourceType.GetProperties();
- foreach (PropertyInfo sourceProperty in sourceProperties)
- {
- PropertyInfo targetProperty = targetType.GetProperty(sourceProperty.Name);
- if (targetProperty!= null && targetProperty.CanWrite && sourceProperty.CanRead && targetProperty.PropertyType == sourceProperty.PropertyType)
- {
- object value = sourceProperty.GetValue(source, null);
- targetProperty.SetValue(target, value, null);
- }
- }
- }
-
- ///
- /// 创建一个泛型对象,将source对象上的所有属性的值,都转换到新创建对象上
- ///
- ///
- ///
- ///
- public static T NewTo(this Object source ) where T : new()
- {
- T target = new T();
- var sourceType = source.GetType();
- var targetType = target.GetType();
var sourceProperties = sourceType.GetProperties();
- foreach (PropertyInfo sourceProperty in sourceProperties)
+ foreach (var sourceProperty in sourceProperties)
{
- PropertyInfo targetProperty = targetType.GetProperty(sourceProperty.Name);
- if (targetProperty!= null && targetProperty.CanWrite && sourceProperty.CanRead && targetProperty.PropertyType == sourceProperty.PropertyType)
+ var targetProperty = targetType.GetProperty(sourceProperty.Name);
+ if (targetProperty != null && targetProperty.CanWrite && sourceProperty.CanRead &&
+ targetProperty.PropertyType == sourceProperty.PropertyType)
{
- object value = sourceProperty.GetValue(source, null);
+ var value = sourceProperty.GetValue(source, null);
targetProperty.SetValue(target, value, null);
}
}
+ }
+
+ ///
+ /// 创建一个泛型对象,将source对象上的所有属性的值,都转换到新创建对象上
+ ///
+ ///
+ ///
+ ///
+ public static T NewTo(this object source) where T : new()
+ {
+ var target = new T();
+ var sourceType = source.GetType();
+ var targetType = target.GetType();
+ var sourceProperties = sourceType.GetProperties();
+ foreach (var sourceProperty in sourceProperties)
+ {
+ var targetProperty = targetType.GetProperty(sourceProperty.Name);
+ if (targetProperty != null && targetProperty.CanWrite && sourceProperty.CanRead &&
+ targetProperty.PropertyType == sourceProperty.PropertyType)
+ {
+ var value = sourceProperty.GetValue(source, null);
+ targetProperty.SetValue(target, value, null);
+ }
+ }
+
return target;
}
}
\ No newline at end of file
diff --git a/Extensions/TaskExtensions.cs b/Extensions/TaskExtensions.cs
index 1886586..c666eb1 100644
--- a/Extensions/TaskExtensions.cs
+++ b/Extensions/TaskExtensions.cs
@@ -2,8 +2,7 @@
public static class TaskExtensions
{
-
- public static async Task Await(this Task task,Action onError=null,Action onComplete=null)
+ public static async Task Await(this Task task, Action onError = null, Action onComplete = null)
{
try
{
@@ -15,5 +14,4 @@ public static class TaskExtensions
onError?.Invoke(e);
}
}
-
}
\ No newline at end of file
diff --git a/Helper/CovertHelper.cs b/Helper/CovertHelper.cs
index e919700..1119739 100644
--- a/Helper/CovertHelper.cs
+++ b/Helper/CovertHelper.cs
@@ -6,28 +6,31 @@ public class CovertHelper
{
public static List ConvertList(List sourceList)
{
- List targetList = new List();
- Type sourceType = typeof(TSource);
- Type targetType = typeof(TTarget);
+ var targetList = new List();
+ var sourceType = typeof(TSource);
+ var targetType = typeof(TTarget);
// 获取源类型和目标类型的公共属性
- PropertyInfo[] sourceProperties = sourceType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
- PropertyInfo[] targetProperties = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
+ var sourceProperties = sourceType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
+ var targetProperties = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
- foreach (TSource sourceObject in sourceList)
+ foreach (var sourceObject in sourceList)
{
- TTarget targetObject = Activator.CreateInstance();
- foreach (PropertyInfo targetProperty in targetProperties)
+ var targetObject = Activator.CreateInstance();
+ foreach (var targetProperty in targetProperties)
{
- PropertyInfo sourceProperty = sourceProperties.FirstOrDefault(p => p.Name == targetProperty.Name && p.PropertyType == targetProperty.PropertyType);
- if (sourceProperty!= null)
+ var sourceProperty = sourceProperties.FirstOrDefault(p =>
+ p.Name == targetProperty.Name && p.PropertyType == targetProperty.PropertyType);
+ if (sourceProperty != null)
{
- object value = sourceProperty.GetValue(sourceObject);
+ var value = sourceProperty.GetValue(sourceObject);
targetProperty.SetValue(targetObject, value);
}
}
+
targetList.Add(targetObject);
}
+
return targetList;
}
}
\ No newline at end of file
diff --git a/Helper/NotificationHelper.cs b/Helper/NotificationHelper.cs
index c52821f..0e085fe 100644
--- a/Helper/NotificationHelper.cs
+++ b/Helper/NotificationHelper.cs
@@ -6,7 +6,8 @@ namespace PMSWPF.Helper;
public class NotificationHelper
{
- public static void ShowMessage(string msg, NotificationType notificationType=NotificationType.Info,bool isGlobal = false)
+ public static void ShowMessage(string msg, NotificationType notificationType = NotificationType.Info,
+ bool isGlobal = false)
{
WeakReferenceMessenger.Default.Send(
new NotificationMessage(msg, notificationType));
diff --git a/Helper/SqlSugarHelper.cs b/Helper/SqlSugarHelper.cs
index c2f3c86..442c8ff 100644
--- a/Helper/SqlSugarHelper.cs
+++ b/Helper/SqlSugarHelper.cs
@@ -1,26 +1,17 @@
using PMSWPF.Data;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-namespace PMSWPF.Helper
+namespace PMSWPF.Helper;
+
+public class SqlSugarHelper
{
- public class SqlSugarHelper
+ private DbContext _db;
+
+ public SqlSugarHelper()
{
- private DbContext _db;
-
- public SqlSugarHelper() {
- _db=new DbContext();
-
- }
-
- public void InitTables()
- {
-
- }
-
-
+ _db = new DbContext();
}
-}
+
+ public void InitTables()
+ {
+ }
+}
\ No newline at end of file
diff --git a/Message/MyMessage.cs b/Message/MyMessage.cs
index d791d4c..a49d562 100644
--- a/Message/MyMessage.cs
+++ b/Message/MyMessage.cs
@@ -1,20 +1,12 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using CommunityToolkit.Mvvm.Messaging.Messages;
+using CommunityToolkit.Mvvm.Messaging.Messages;
-namespace PMSWPF.Message
+namespace PMSWPF.Message;
+
+public class MyMessage : ValueChangedMessage
{
- public class MyMessage : ValueChangedMessage
+ public MyMessage(int value) : base(value)
{
- private int count;
-
- public MyMessage(int value) : base(value)
- {
- }
-
- public int Count { get => count; set => count = value; }
}
-}
+
+ public int Count { get; set; }
+}
\ No newline at end of file
diff --git a/Message/NavgatorMessage.cs b/Message/NavgatorMessage.cs
new file mode 100644
index 0000000..05fd36c
--- /dev/null
+++ b/Message/NavgatorMessage.cs
@@ -0,0 +1,11 @@
+using CommunityToolkit.Mvvm.Messaging.Messages;
+using PMSWPF.ViewModels;
+
+namespace PMSWPF.Message;
+
+public class NavgatorMessage : ValueChangedMessage
+{
+ public NavgatorMessage(ViewModelBase value) : base(value)
+ {
+ }
+}
\ No newline at end of file
diff --git a/Message/NotificationMessage.cs b/Message/NotificationMessage.cs
index cc02d3f..0d8ac65 100644
--- a/Message/NotificationMessage.cs
+++ b/Message/NotificationMessage.cs
@@ -3,13 +3,15 @@ using PMSWPF.Enums;
namespace PMSWPF.Message;
-public class NotificationMessage:ValueChangedMessage
+public class NotificationMessage : ValueChangedMessage
{
+ public NotificationMessage(string msg, NotificationType type = NotificationType.Info, bool isGlobal = false) :
+ base(msg)
+ {
+ Type = type;
+ IsGlobal = isGlobal;
+ }
+
public NotificationType Type { get; set; }
public bool IsGlobal { get; set; }
- public NotificationMessage(string msg,NotificationType type=NotificationType.Info,bool isGlobal=false) : base(msg)
- {
- this.Type = type;
- this.IsGlobal = isGlobal;
- }
}
\ No newline at end of file
diff --git a/Message/ReqMessage.cs b/Message/ReqMessage.cs
index fb7a5ee..47a8bbc 100644
--- a/Message/ReqMessage.cs
+++ b/Message/ReqMessage.cs
@@ -1,13 +1,13 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
-namespace PMSWPF.Message
+namespace PMSWPF.Message;
+
+public class ReqMessage : RequestMessage
{
- public class ReqMessage : RequestMessage
+ public ReqMessage(int count)
{
- public int Count { get; set; }
- public ReqMessage(int count)
- {
- Count = count;
- }
+ Count = count;
}
-}
+
+ public int Count { get; set; }
+}
\ No newline at end of file
diff --git a/Models/DataVariable.cs b/Models/DataVariable.cs
index 2781095..0a894a1 100644
--- a/Models/DataVariable.cs
+++ b/Models/DataVariable.cs
@@ -4,7 +4,7 @@ namespace PMSWPF.Models;
public class DataVariable
{
- public int Id { get; set; }
+ public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string NodeId { get; set; }
@@ -17,11 +17,11 @@ public class DataVariable
public User 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; }
+ public double AlarmMin { get; set; }
+ public double AlarmMax { get; set; }
public SignalType SignalType { get; set; }
}
\ No newline at end of file
diff --git a/Models/Device.cs b/Models/Device.cs
index 4be18c6..80e9aef 100644
--- a/Models/Device.cs
+++ b/Models/Device.cs
@@ -1,4 +1,3 @@
-using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using PMSWPF.Enums;
using SqlSugar;
@@ -6,24 +5,23 @@ using SqlSugar.DbConvert;
namespace PMSWPF.Models;
-public partial class Device:ObservableObject
+public partial class Device : ObservableObject
{
- [ObservableProperty]
- private int id;
- [ObservableProperty]
- private string name;
- [ObservableProperty]
- private string description ;
- [ObservableProperty]
- private string ip ;
- [ObservableProperty]
- private bool isActive =true;
- [ObservableProperty]
- private bool isRuning ;
- [SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
+ [ObservableProperty] private string description;
+
+ [ObservableProperty] private int id;
+
+ [ObservableProperty] private string ip;
+
+ [ObservableProperty] private bool isActive = true;
+
+ [ObservableProperty] private bool isRuning;
+
+ [ObservableProperty] private string name;
+
+ [SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
public DeviceType DeviceType { get; set; }
- public List? VariableTables { get; set; }
+ public List? VariableTables { get; set; }
public ProtocolType ProtocolType { get; set; }
-
}
\ No newline at end of file
diff --git a/Models/Mqtt.cs b/Models/Mqtt.cs
index ffc2850..9ae0512 100644
--- a/Models/Mqtt.cs
+++ b/Models/Mqtt.cs
@@ -2,5 +2,4 @@
public class Mqtt
{
-
}
\ No newline at end of file
diff --git a/Models/User.cs b/Models/User.cs
index 0854dc8..b42c81c 100644
--- a/Models/User.cs
+++ b/Models/User.cs
@@ -2,5 +2,4 @@
public class User
{
-
}
\ No newline at end of file
diff --git a/Models/VariableTable.cs b/Models/VariableTable.cs
index 3fd9412..ad2e151 100644
--- a/Models/VariableTable.cs
+++ b/Models/VariableTable.cs
@@ -4,11 +4,9 @@ namespace PMSWPF.Models;
public class VariableTable
{
-
- public int Id { get; set; }
+ public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public ProtocolType ProtocolType { get; set; }
public List DataVariables { get; set; }
-
}
\ No newline at end of file
diff --git a/PMSWPF.csproj b/PMSWPF.csproj
index c17faff..ebf9543 100644
--- a/PMSWPF.csproj
+++ b/PMSWPF.csproj
@@ -1,29 +1,29 @@
-
- WinExe
- net8.0-windows
- enable
- enable
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Always
-
-
+
+ WinExe
+ net8.0-windows
+ enable
+ enable
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Always
+
+
diff --git a/Resources/DevicesItemTemplateDictionary.xaml b/Resources/DevicesItemTemplateDictionary.xaml
index a664071..63b9319 100644
--- a/Resources/DevicesItemTemplateDictionary.xaml
+++ b/Resources/DevicesItemTemplateDictionary.xaml
@@ -1,7 +1,5 @@
-
+
\ No newline at end of file
diff --git a/Services/DemoBackgroundService.cs b/Services/DemoBackgroundService.cs
index e1c28cb..a11b621 100644
--- a/Services/DemoBackgroundService.cs
+++ b/Services/DemoBackgroundService.cs
@@ -1,37 +1,21 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using CommunityToolkit.Mvvm.ComponentModel;
-using CommunityToolkit.Mvvm.Messaging;
-using Microsoft.Extensions.Hosting;
-using PMSWPF.Message;
+using Microsoft.Extensions.Hosting;
-namespace PMSWPF.Services
+namespace PMSWPF.Services;
+
+internal class DemoBackgroundService : BackgroundService
{
- internal class DemoBackgroundService : BackgroundService
+ private int count = 0;
+
+
+ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
- int count = 0;
-
- public DemoBackgroundService()
- {
-
- }
-
-
-
- protected override async Task ExecuteAsync(CancellationToken stoppingToken)
- {
-
- while (!stoppingToken.IsCancellationRequested)
- {
- await Task.Delay(1000);
- count += 1;
- var msg = new MyMessage(35) { Count = count };
- WeakReferenceMessenger.Default.Send(msg);
- Console.WriteLine("Hello");
- }
- }
+ // while (!stoppingToken.IsCancellationRequested)
+ // {
+ // await Task.Delay(1000);
+ // count += 1;
+ // var msg = new MyMessage(35) { Count = count };
+ // WeakReferenceMessenger.Default.Send(msg);
+ // Console.WriteLine("Hello");
+ // }
}
-}
+}
\ No newline at end of file
diff --git a/Services/DeviceDialogService.cs b/Services/DeviceDialogService.cs
index 25a66d0..24ea1b2 100644
--- a/Services/DeviceDialogService.cs
+++ b/Services/DeviceDialogService.cs
@@ -9,23 +9,17 @@ public class DeviceDialogService : IDeviceDialogService
{
public async Task ShowAddDeviceDialog()
{
- Device device = new Device();
- DeviceDialogViewModel ddvm = new DeviceDialogViewModel(device)
+ var device = new Device();
+ var ddvm = new DeviceDialogViewModel(device)
{
Title = "添加设备"
};
- DeviceDialog dialog = new DeviceDialog(ddvm);
- var res=await dialog.ShowAsync();
- if (res == ContentDialogResult.Primary)
- {
- return device;
- }
- else
- {
- return null;
- }
+ var dialog = new DeviceDialog(ddvm);
+ var res = await dialog.ShowAsync();
+ if (res == ContentDialogResult.Primary) return device;
+ return null;
}
public void ShowMessageDialog(string title, string message)
diff --git a/Services/GrowlNotificationService.cs b/Services/GrowlNotificationService.cs
index bba300c..a3eac47 100644
--- a/Services/GrowlNotificationService.cs
+++ b/Services/GrowlNotificationService.cs
@@ -1,5 +1,4 @@
-using System.Windows.Interop;
-using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using HandyControl.Controls;
using PMSWPF.Enums;
@@ -8,21 +7,23 @@ using Notification = PMSWPF.Models.Notification;
namespace PMSWPF.Services;
-public class GrowlNotificationService :ObservableRecipient,IRecipient
+public class GrowlNotificationService : ObservableRecipient, IRecipient
{
public GrowlNotificationService()
{
IsActive = true;
}
+
+ public void Receive(NotificationMessage message)
+ {
+ Show(message.Value, message.Type, message.IsGlobal);
+ }
+
public void Show(Notification notification)
{
- if (notification == null )
- {
- return;
- }
+ if (notification == null) return;
if (notification.IsGlobal)
- {
switch (notification.Type)
{
case NotificationType.Info:
@@ -47,10 +48,7 @@ public class GrowlNotificationService :ObservableRecipient,IRecipient
{
private ViewModelBase currentViewModel;
+ public NavgatorServices()
+ {
+ IsActive = true;
+ }
+
public ViewModelBase CurrentViewModel
{
- get { return currentViewModel; }
+ get => currentViewModel;
set
{
- currentViewModel = value;
+ currentViewModel = value;
OnViewModelChanged?.Invoke();
currentViewModel.OnLoaded();
}
}
- public event Action OnViewModelChanged ;
+ public void Receive(NavgatorMessage message)
+ {
+ CurrentViewModel = message.Value;
+ }
+
+ public event Action OnViewModelChanged;
public void NavigateTo() where T : ViewModelBase
{
diff --git a/ValueConverts/EnumDescriptionConverter.cs b/ValueConverts/EnumDescriptionConverter.cs
index 254fb0f..abd7a86 100644
--- a/ValueConverts/EnumDescriptionConverter.cs
+++ b/ValueConverts/EnumDescriptionConverter.cs
@@ -24,12 +24,11 @@ public class EnumDescriptionConverter : IValueConverter
{
var fi = enumObj.GetType().GetField(enumObj.ToString());
- DescriptionAttribute[] attributes =
+ var attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attributes != null && attributes.Length > 0)
return attributes[0].Description;
- else
- return enumObj.ToString();
+ return enumObj.ToString();
}
}
\ No newline at end of file
diff --git a/ViewModels/DataTransformViewModel.cs b/ViewModels/DataTransformViewModel.cs
index f75088e..3182508 100644
--- a/ViewModels/DataTransformViewModel.cs
+++ b/ViewModels/DataTransformViewModel.cs
@@ -1,9 +1,8 @@
namespace PMSWPF.ViewModels;
-public class DataTransformViewModel:ViewModelBase
+public class DataTransformViewModel : ViewModelBase
{
public override void OnLoaded()
{
-
}
}
\ No newline at end of file
diff --git a/ViewModels/DevicesViewModel.cs b/ViewModels/DevicesViewModel.cs
index e8015ee..28782df 100644
--- a/ViewModels/DevicesViewModel.cs
+++ b/ViewModels/DevicesViewModel.cs
@@ -1,23 +1,13 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
-using CommunityToolkit.Mvvm.Messaging;
-using HandyControl.Controls;
-using HandyControl.Data;
using Microsoft.Extensions.Logging;
-using PMSWPF.Data.Entities;
using PMSWPF.Data.Repositories;
using PMSWPF.Enums;
using PMSWPF.Excptions;
-using PMSWPF.Extensions;
using PMSWPF.Helper;
-using PMSWPF.Message;
using PMSWPF.Models;
using PMSWPF.Services;
-using PMSWPF.ViewModels.Dialogs;
-using PMSWPF.Views.Dialogs;
-using MessageBox = System.Windows.MessageBox;
-using Notification = PMSWPF.Models.Notification;
namespace PMSWPF.ViewModels;
@@ -26,11 +16,12 @@ public partial class DevicesViewModel : ViewModelBase
private readonly IDeviceDialogService _deviceDialogService;
private readonly DevicesRepositories _devicesRepositories;
private readonly ILogger _logger;
- [ObservableProperty]
- private ObservableCollection _devices ;
- public DevicesViewModel(IDeviceDialogService deviceDialogService, DevicesRepositories devicesRepositories,ILogger logger
- )
+ [ObservableProperty] private ObservableCollection _devices;
+
+ public DevicesViewModel(IDeviceDialogService deviceDialogService, DevicesRepositories devicesRepositories,
+ ILogger logger
+ )
{
_deviceDialogService = deviceDialogService;
_devicesRepositories = devicesRepositories;
@@ -40,17 +31,16 @@ public partial class DevicesViewModel : ViewModelBase
public async Task OnLoadedAsync()
{
var ds = await _devicesRepositories.GetAll();
- Devices=new ObservableCollection(ds);
-
+ Devices = new ObservableCollection(ds);
}
[RelayCommand]
- public async void AddDevice()
+ public async void AddDevice()
{
Device device = null;
try
{
- device= await _deviceDialogService.ShowAddDeviceDialog();
+ device = await _deviceDialogService.ShowAddDeviceDialog();
if (device != null)
{
var isOk = await _devicesRepositories.Add(device);
@@ -78,9 +68,14 @@ public partial class DevicesViewModel : ViewModelBase
}
}
+ [RelayCommand]
+ public void NavigateVt()
+ {
+ }
+
+
public override async void OnLoaded()
{
- // OnLoadedAsync().Await((e) => { _deviceDialogService.ShowMessageDialog("", e.Message); }, () => { });
await OnLoadedAsync();
}
}
\ No newline at end of file
diff --git a/ViewModels/Dialogs/DeviceDialogViewModel.cs b/ViewModels/Dialogs/DeviceDialogViewModel.cs
index 4d138ac..71cb80d 100644
--- a/ViewModels/Dialogs/DeviceDialogViewModel.cs
+++ b/ViewModels/Dialogs/DeviceDialogViewModel.cs
@@ -1,30 +1,28 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
-using PMSWPF.Enums;
using PMSWPF.Extensions;
using PMSWPF.Models;
namespace PMSWPF.ViewModels.Dialogs;
-public partial class DeviceDialogViewModel:ObservableObject
+public partial class DeviceDialogViewModel : ObservableObject
{
private readonly Device _saveDevice;
- [ObservableProperty]
- private string title="添加设备";
- [ObservableProperty]
- private Device device;
+ [ObservableProperty] private Device device;
+
+ [ObservableProperty] private string title = "添加设备";
public DeviceDialogViewModel(Device saveDevice)
{
_saveDevice = saveDevice;
- this.device = new Device();
+ device = new Device();
}
[RelayCommand]
public void AddDevice()
{
- this.device.CopyTo(_saveDevice);
+ device.CopyTo(_saveDevice);
}
}
\ No newline at end of file
diff --git a/ViewModels/HomeViewModel.cs b/ViewModels/HomeViewModel.cs
index 59662f4..ad95147 100644
--- a/ViewModels/HomeViewModel.cs
+++ b/ViewModels/HomeViewModel.cs
@@ -1,9 +1,8 @@
namespace PMSWPF.ViewModels;
-public class HomeViewModel:ViewModelBase
+public class HomeViewModel : ViewModelBase
{
public override void OnLoaded()
{
-
}
}
\ No newline at end of file
diff --git a/ViewModels/MainViewModel.cs b/ViewModels/MainViewModel.cs
index 95232cf..54878ad 100644
--- a/ViewModels/MainViewModel.cs
+++ b/ViewModels/MainViewModel.cs
@@ -1,42 +1,23 @@
using CommunityToolkit.Mvvm.ComponentModel;
-using CommunityToolkit.Mvvm.Messaging;
-using PMSWPF.Data.Entities;
-using PMSWPF.Message;
-using System.Collections.ObjectModel;
using PMSWPF.Services;
-namespace PMSWPF.ViewModels
+namespace PMSWPF.ViewModels;
+
+public partial class MainViewModel : ViewModelBase
{
- public partial class MainViewModel : ObservableRecipient, IRecipient
+ private readonly NavgatorServices _navgatorServices;
+
+ [ObservableProperty] private ViewModelBase currentViewModel;
+
+ public MainViewModel(NavgatorServices navgatorServices)
{
- private readonly NavgatorServices _navgatorServices;
-
- [ObservableProperty]
- private ViewModelBase currentViewModel;
- public MainViewModel(NavgatorServices navgatorServices)
- {
- _navgatorServices = navgatorServices;
- _navgatorServices.OnViewModelChanged += () =>
- {
- CurrentViewModel = _navgatorServices.CurrentViewModel;
- };
- IsActive = true;
- CurrentViewModel = new HomeViewModel();
- }
-
- public void NavgateTo() where T : ViewModelBase
- {
- _navgatorServices.NavigateTo();
- }
-
- string text = "Hello Count:";
-
- [ObservableProperty]
- string message;
-
- public void Receive(MyMessage message)
- {
- Message = text + message.Count;
- }
+ _navgatorServices = navgatorServices;
+ _navgatorServices.OnViewModelChanged += () => { CurrentViewModel = _navgatorServices.CurrentViewModel; };
+ CurrentViewModel = new HomeViewModel();
}
-}
+
+
+ public override void OnLoaded()
+ {
+ }
+}
\ No newline at end of file
diff --git a/ViewModels/SettingViewModel.cs b/ViewModels/SettingViewModel.cs
index 5c3c1d6..b77a439 100644
--- a/ViewModels/SettingViewModel.cs
+++ b/ViewModels/SettingViewModel.cs
@@ -1,9 +1,8 @@
namespace PMSWPF.ViewModels;
-public class SettingViewModel:ViewModelBase
+public class SettingViewModel : ViewModelBase
{
public override void OnLoaded()
{
-
}
}
\ No newline at end of file
diff --git a/ViewModels/VariableTableViewModel.cs b/ViewModels/VariableTableViewModel.cs
new file mode 100644
index 0000000..3d73a63
--- /dev/null
+++ b/ViewModels/VariableTableViewModel.cs
@@ -0,0 +1,8 @@
+namespace PMSWPF.ViewModels;
+
+public class VariableTableViewModel : ViewModelBase
+{
+ public override void OnLoaded()
+ {
+ }
+}
\ No newline at end of file
diff --git a/ViewModels/ViewModelBase.cs b/ViewModels/ViewModelBase.cs
index a3020fd..6bf7cbf 100644
--- a/ViewModels/ViewModelBase.cs
+++ b/ViewModels/ViewModelBase.cs
@@ -2,12 +2,7 @@
namespace PMSWPF.ViewModels;
-public abstract partial class ViewModelBase:ObservableObject
+public abstract class ViewModelBase : ObservableObject
{
- public ViewModelBase()
- {
-
- }
-
public abstract void OnLoaded();
}
\ No newline at end of file
diff --git a/Views/DataTransformView.xaml b/Views/DataTransformView.xaml
index 75e7a0f..b2cc873 100644
--- a/Views/DataTransformView.xaml
+++ b/Views/DataTransformView.xaml
@@ -3,10 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:local="clr-namespace:PMSWPF.Views"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
-
+
-
+
\ No newline at end of file
diff --git a/Views/DevicesView.xaml b/Views/DevicesView.xaml
index 4128646..2af27a4 100644
--- a/Views/DevicesView.xaml
+++ b/Views/DevicesView.xaml
@@ -5,70 +5,70 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
- xmlns:local="clr-namespace:PMSWPF.Views"
- xmlns:dl="clr-namespace:PMSWPF.Views.Dialogs"
- xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
- xmlns:hc="https://handyorg.github.io/handycontrol"
d:DataContext="{d:DesignInstance vm:DevicesViewModel}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
-
-
-
-
+
+
+
+
-
+
-
-
+
+
+
+
+
+
-
+
-
-
+
+
+ Label="Add">
-
+
+ Label="Edit">
-
+
+ Label="Share">
-
+
+
+ Icon="Setting" Label="Settings" />
-
-
+
+
-
+
-
-
+
+
\ No newline at end of file
diff --git a/Views/DevicesView.xaml.cs b/Views/DevicesView.xaml.cs
index 051b0f3..c4e326d 100644
--- a/Views/DevicesView.xaml.cs
+++ b/Views/DevicesView.xaml.cs
@@ -1,7 +1,6 @@
using System.Windows;
using System.Windows.Controls;
using iNKORE.UI.WPF.Modern.Controls;
-using PMSWPF.ViewModels;
namespace PMSWPF.Views;
@@ -10,17 +9,15 @@ public partial class DevicesView : UserControl
public DevicesView()
{
InitializeComponent();
-
}
private void BasicGridView_ItemClick(object sender, ItemClickEventArgs e)
{
-
}
private async void DevicesView_OnLoaded(object sender, RoutedEventArgs e)
{
- // var devicesViewModel = (DevicesViewModel)this.DataContext;
- // await devicesViewModel.OnLoadedAsync();
+ // var devicesViewModel = (DevicesViewModel)this.DataContext;
+ // await devicesViewModel.OnLoadedAsync();
}
}
\ No newline at end of file
diff --git a/Views/Dialogs/DeviceDialog.xaml b/Views/Dialogs/DeviceDialog.xaml
index ecd7fc5..170c022 100644
--- a/Views/Dialogs/DeviceDialog.xaml
+++ b/Views/Dialogs/DeviceDialog.xaml
@@ -19,41 +19,43 @@
d:DataContext="{d:DesignInstance vmd:DeviceDialogViewModel}"
mc:Ignorable="d">
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
+
diff --git a/Views/Dialogs/DeviceDialog.xaml.cs b/Views/Dialogs/DeviceDialog.xaml.cs
index 93afa14..c1cc7a3 100644
--- a/Views/Dialogs/DeviceDialog.xaml.cs
+++ b/Views/Dialogs/DeviceDialog.xaml.cs
@@ -1,18 +1,15 @@
using System.Windows;
-using System.Windows.Controls;
using iNKORE.UI.WPF.Modern.Controls;
-using PMSWPF.Models;
using PMSWPF.ViewModels.Dialogs;
namespace PMSWPF.Views.Dialogs;
public partial class DeviceDialog
{
-
public DeviceDialog(DeviceDialogViewModel viewModel)
{
InitializeComponent();
- this.DataContext = viewModel;
+ DataContext = viewModel;
}
private void OnPrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
@@ -44,5 +41,4 @@ public partial class DeviceDialog
// ErrorText.Text = string.Empty;
// ErrorText.Visibility = Visibility.Collapsed;
}
-}
-
+}
\ No newline at end of file
diff --git a/Views/HomeView.xaml b/Views/HomeView.xaml
index 42a767d..13f8253 100644
--- a/Views/HomeView.xaml
+++ b/Views/HomeView.xaml
@@ -3,10 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:local="clr-namespace:PMSWPF.Views"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
-
+
-
+
\ No newline at end of file
diff --git a/Views/MainView.xaml b/Views/MainView.xaml
index a27cf8d..9863dec 100644
--- a/Views/MainView.xaml
+++ b/Views/MainView.xaml
@@ -4,8 +4,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
- xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
- xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:PMSWPF.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
@@ -13,24 +11,24 @@
Title="设备管理系统"
Width="1080"
Height="800"
-
+
ui:WindowHelper.UseModernWindowStyle="True"
ui:WindowHelper.SystemBackdropType="Mica"
d:DataContext="{d:DesignInstance vm:MainViewModel}"
mc:Ignorable="d">
-
+
-
+
@@ -76,31 +74,30 @@
-
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
\ No newline at end of file
diff --git a/Views/MainView.xaml.cs b/Views/MainView.xaml.cs
index 7f89f02..ef0b1aa 100644
--- a/Views/MainView.xaml.cs
+++ b/Views/MainView.xaml.cs
@@ -1,65 +1,62 @@
using System.Windows;
-using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using iNKORE.UI.WPF.Modern.Controls;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PMSWPF.Message;
using PMSWPF.ViewModels;
-namespace PMSWPF.Views
+namespace PMSWPF.Views;
+
+///
+/// MainView.xaml 的交互逻辑
+///
+public partial class MainView : Window
{
- ///
- /// MainView.xaml 的交互逻辑
- ///
- public partial class MainView : Window
+ private readonly ILogger _logger;
+
+ public MainView(MainViewModel viewModel, ILogger logger)
{
- private readonly ILogger _logger;
-
- public MainView(MainViewModel viewModel, ILogger logger)
- {
-
- _logger = logger;
- InitializeComponent();
- this.DataContext=viewModel;
- _logger.LogInformation("主界面加载成功");
-
-
- }
-
- ///
- /// 左边菜单项被点击的事件,切换右边的视图
- ///
- ///
- ///
- private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
- {
- NavigationViewItem? item = args.SelectedItem as NavigationViewItem;
- MainViewModel mainViewModel = (MainViewModel)this.DataContext ;
- switch (item.Tag)
- {
- case "Home":
- mainViewModel.NavgateTo();
- _logger.LogInformation("导航到到主页面");
- break;
- case "Devices":
-
- mainViewModel.NavgateTo();
- _logger.LogInformation("导航到到设备页面");
- break;
- case "DataTransform":
- mainViewModel.NavgateTo();
- _logger.LogInformation("导航到到数据转换页面");
- break;
- case "Setting":
- mainViewModel.NavgateTo();
- _logger.LogInformation("导航到到设备页面");
- break;
- default:
- mainViewModel.NavgateTo();
- _logger.LogInformation("没有设置Tag,默认导航到主页面。");
- break;
-
- }
- }
+ _logger = logger;
+ InitializeComponent();
+ DataContext = viewModel;
+ _logger.LogInformation("主界面加载成功");
}
-}
+
+ ///
+ /// 左边菜单项被点击的事件,切换右边的视图
+ ///
+ ///
+ ///
+ private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
+ {
+ var item = args.SelectedItem as NavigationViewItem;
+ ViewModelBase navgateVM = App.Current.Services.GetRequiredService();
+ switch (item.Tag)
+ {
+ case "Home":
+ // mainViewModel.NavgateTo();
+ navgateVM = App.Current.Services.GetRequiredService();
+ _logger.LogInformation("导航到到主页面");
+ break;
+ case "Devices":
+ navgateVM = App.Current.Services.GetRequiredService();
+ // mainViewModel.NavgateTo();
+ _logger.LogInformation("导航到到设备页面");
+ break;
+ case "DataTransform":
+ navgateVM = App.Current.Services.GetRequiredService();
+ // mainViewModel.NavgateTo();
+ _logger.LogInformation("导航到到数据转换页面");
+ break;
+ case "Setting":
+ // mainViewModel.NavgateTo();
+ navgateVM = App.Current.Services.GetRequiredService();
+ _logger.LogInformation("导航到到设备页面");
+ break;
+ }
+
+ var nm = new NavgatorMessage(navgateVM);
+ WeakReferenceMessenger.Default.Send(nm);
+ }
+}
\ No newline at end of file
diff --git a/Views/SettingView.xaml b/Views/SettingView.xaml
index f9d1218..b6a8c67 100644
--- a/Views/SettingView.xaml
+++ b/Views/SettingView.xaml
@@ -3,10 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:local="clr-namespace:PMSWPF.Views"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
-
-
-
-
+
+
\ No newline at end of file
diff --git a/Views/VariableTableView.xaml b/Views/VariableTableView.xaml
new file mode 100644
index 0000000..6c1b186
--- /dev/null
+++ b/Views/VariableTableView.xaml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Views/VariableTableView.xaml.cs b/Views/VariableTableView.xaml.cs
new file mode 100644
index 0000000..eea4ae2
--- /dev/null
+++ b/Views/VariableTableView.xaml.cs
@@ -0,0 +1,13 @@
+using System.Windows.Controls;
+using PMSWPF.ViewModels;
+
+namespace PMSWPF.Views;
+
+public partial class VariableTableView : UserControl
+{
+ public VariableTableView(VariableTableViewModel viewModel)
+ {
+ InitializeComponent();
+ DataContext = viewModel;
+ }
+}
\ No newline at end of file