소스 검색

20251009002 值变更记录管理和异常信息记录管理功能添加

向羽 孟 1 개월 전
부모
커밋
b4bf2c0c6c

+ 267 - 0
MvvmScaffoldFrame48.DLL/AuditTrail/ErrorMessageRecordManagement.cs

@@ -0,0 +1,267 @@
+//异常信息记录管理
+using MvvmScaffoldFrame48.Model.AuditTrail;
+using System;
+using System.Collections.Generic;
+using System.Data.SQLite;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MvvmScaffoldFrame48.DLL.AuditTrail
+{
+    public class ErrorMessageRecordManagement
+    {
+        private readonly string _dbPath;
+
+        private string _connString;
+
+        private object locker = new object();
+
+        public ErrorMessageRecordManagement()
+        {
+            _dbPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\AuditTrail.db";
+            // 1. 获取文件夹路径
+            string directoryPath = Path.GetDirectoryName(_dbPath);
+
+            // 2. 检查文件夹是否存在
+            if (!Directory.Exists(directoryPath))
+            {
+                // 创建文件夹
+                Directory.CreateDirectory(directoryPath);
+            }
+            InitializeDatabase();
+        }
+
+        public ErrorMessageRecordManagement(string dbPath)
+        {
+            if (dbPath == null || dbPath == "")
+            {
+                _dbPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\AuditTrail.db";
+            }
+            else
+            {
+                _dbPath = dbPath;
+            }
+
+            // 1. 获取文件夹路径
+            string directoryPath = Path.GetDirectoryName(_dbPath);
+
+            // 2. 检查文件夹是否存在
+            if (!Directory.Exists(directoryPath))
+            {
+                // 创建文件夹
+                Directory.CreateDirectory(directoryPath);
+            }
+            InitializeDatabase();
+        }
+
+        /// <summary>
+        /// 初始化数据库和表
+        /// </summary>
+        private void InitializeDatabase()
+        {
+            if (!File.Exists(_dbPath))
+            {
+                SQLiteConnection.CreateFile(_dbPath);
+            }
+
+            _connString = $"Data Source={_dbPath};Version=3;" +
+                "Journal Mode=WAL;" +           // 使用WAL模式提高并发性
+                "Synchronous=Normal;" +         // 平衡性能和安全性
+                "Cache Size=10000;" +           // 增加缓存大小
+                "Pooling=true;" +               // 启用连接池
+                "Max Pool Size=100;";         // 设置最大连接池大小
+
+            using (var conn = new SQLiteConnection(_connString))
+            {
+                conn.Open();
+                string createTableSql = @"
+                    CREATE TABLE IF NOT EXISTS ErrorMessageRecord (
+                        ID INTEGER PRIMARY KEY AUTOINCREMENT,
+                        Category TEXT NOT NULL,
+                        MessageType TEXT NOT NULL,
+                        MessagePath TEXT NOT NULL,
+                        Message TEXT NOT NULL,
+                        DateTime TEXT NOT NULL,
+                        userID INTEGER NOT NULL,
+                        LogLevel INTEGER NOT NULL,
+                        IsDeleted INTEGER CHECK (IsDeleted IN (0, 1))
+                )";
+                new SQLiteCommand(createTableSql, conn).ExecuteNonQuery();
+            }
+        }
+
+        /// <summary>
+        /// 插入数据
+        /// </summary>
+        /// <param name="Message"></param>
+        public void InsertErrorMessageRecord(ErrorMessageRecordModel Message)
+        {
+            lock (locker)
+            {
+                using (var conn = new SQLiteConnection(_connString))
+                {
+                    conn.Open();
+                    string sql = "INSERT INTO ErrorMessageRecord(" +
+                        "Category,MessageType,MessagePath,Message,DateTime,userID,LogLevel,IsDeleted)" +
+                        " VALUES" +
+                        " (@Category, @MessageType,@MessagePath,@Message,@DateTime,@userID,@LogLevel,@IsDeleted)";
+                    var cmd = new SQLiteCommand(sql, conn);
+                    cmd.Parameters.AddWithValue("@Category", Message.Category);
+                    cmd.Parameters.AddWithValue("@MessageType", Message.MessageType);
+                    cmd.Parameters.AddWithValue("@MessagePath", Message.MessagePath);
+                    cmd.Parameters.AddWithValue("@Message", Message.Message);
+                    cmd.Parameters.AddWithValue("@DateTime", Message.DateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
+                    cmd.Parameters.AddWithValue("@userID", Message.userID);
+                    cmd.Parameters.AddWithValue("@LogLevel", Message.LogLevel);
+                    cmd.Parameters.AddWithValue("@IsDeleted", 0);
+                    cmd.ExecuteNonQuery();
+                }
+            }
+        }
+
+        /// <summary>
+        /// 查询所有数据
+        /// </summary>
+        /// <returns></returns>
+        public List<ErrorMessageRecordModel> GetAllErrorMessageRecord()
+        {
+            var ErrorMessages = new List<ErrorMessageRecordModel>();
+            using (var conn = new SQLiteConnection(_connString))
+            {
+                conn.Open();
+                string sql = "SELECT * FROM ErrorMessageRecord WHERE IsDeleted=0";
+                var cmd = new SQLiteCommand(sql, conn);
+                using (SQLiteDataReader reader = cmd.ExecuteReader())
+                {
+                    while (reader.Read())
+                    {
+                        ErrorMessages.Add(new ErrorMessageRecordModel
+                        {
+                            ID = Convert.ToInt32(reader["ID"]),
+                            Category = reader["Category"].ToString(),
+                            MessageType = reader["MessageType"].ToString(),
+                            MessagePath = reader["MessagePath"].ToString(),
+                            Message = reader["Message"].ToString(),
+                            // 解析时间字符串
+                            DateTime = DateTime.Parse(reader["DateTime"].ToString()),
+                            userID = Convert.ToInt32(reader["userID"]),
+                            LogLevel = Convert.ToInt32(reader["LogLevel"])
+                        });
+                    }
+                }
+            }
+            return ErrorMessages;
+        }
+
+        /// <summary>
+        /// 获取错误数据信息
+        /// </summary>
+        /// <param name="UserID">操作员ID</param>
+        /// <returns></returns>
+        public List<ErrorMessageRecordModel> GetErrorMessageRecordByID(int UserID)
+        {
+            var ErrorMessages = new List<ErrorMessageRecordModel>();
+            using (var conn = new SQLiteConnection(_connString))
+            {
+                conn.Open();
+                string sql = "SELECT * FROM ErrorMessageRecord WHERE userID=@userID AND IsDeleted=0";
+                var cmd = new SQLiteCommand(sql, conn);
+                cmd.Parameters.AddWithValue("@userID", UserID);
+                using (SQLiteDataReader reader = cmd.ExecuteReader())
+                {
+                    while (reader.Read())
+                    {
+                        ErrorMessages.Add(new ErrorMessageRecordModel
+                        {
+                            ID = Convert.ToInt32(reader["ID"]),
+                            Category = reader["Category"].ToString(),
+                            MessageType = reader["MessageType"].ToString(),
+                            MessagePath = reader["MessagePath"].ToString(),
+                            Message = reader["Message"].ToString(),
+                            // 解析时间字符串
+                            DateTime = DateTime.Parse(reader["DateTime"].ToString()),
+                            userID = Convert.ToInt32(reader["userID"]),
+                            LogLevel = Convert.ToInt32(reader["LogLevel"])
+                        });
+                    }
+                }
+            }
+            return ErrorMessages;
+        }
+
+        /// <summary>
+        /// 获取错误数据信息
+        /// </summary>
+        /// <param name="UserID">操作员ID</param>
+        /// <returns></returns>
+        public List<ErrorMessageRecordModel> GetErrorMessageRecordByDateTime(DateTime ErrorDateTime)
+        {
+            var ErrorMessages = new List<ErrorMessageRecordModel>();
+            using (var conn = new SQLiteConnection(_connString))
+            {
+                conn.Open();
+                string sql = "SELECT * FROM ErrorMessageRecord WHERE date(DateTime)=date(@DateTime) AND IsDeleted=0";
+                var cmd = new SQLiteCommand(sql, conn);
+                cmd.Parameters.AddWithValue("@DateTime", ErrorDateTime.ToString("yyyy-MM-dd"));
+                using (SQLiteDataReader reader = cmd.ExecuteReader())
+                {
+                    while (reader.Read())
+                    {
+                        ErrorMessages.Add(new ErrorMessageRecordModel
+                        {
+                            ID = Convert.ToInt32(reader["ID"]),
+                            Category = reader["Category"].ToString(),
+                            MessageType = reader["MessageType"].ToString(),
+                            MessagePath = reader["MessagePath"].ToString(),
+                            Message = reader["Message"].ToString(),
+                            // 解析时间字符串
+                            DateTime = DateTime.Parse(reader["DateTime"].ToString()),
+                            userID = Convert.ToInt32(reader["userID"]),
+                            LogLevel = Convert.ToInt32(reader["LogLevel"])
+                        });
+                    }
+                }
+            }
+            return ErrorMessages;
+        }
+
+        /// <summary>
+        /// 获取错误数据信息
+        /// </summary>
+        /// <param name="UserID">操作员ID</param>
+        /// <returns></returns>
+        public List<ErrorMessageRecordModel> GetErrorMessageRecordByDateTime(DateTime ErrorStartDateTime,DateTime ErrorEndDateTime)
+        {
+            var ErrorMessages = new List<ErrorMessageRecordModel>();
+            using (var conn = new SQLiteConnection(_connString))
+            {
+                conn.Open();
+                string sql = "SELECT * FROM ErrorMessageRecord WHERE date(DateTime)>=date(@ErrorStartDateTime) AND date(DateTime)<=date(@ErrorEndDateTime) AND IsDeleted=0";
+                var cmd = new SQLiteCommand(sql, conn);
+                cmd.Parameters.AddWithValue("@ErrorStartDateTime", ErrorStartDateTime.ToString("yyyy-MM-dd"));
+                cmd.Parameters.AddWithValue("@ErrorEndDateTime", ErrorEndDateTime.ToString("yyyy-MM-dd"));
+                using (SQLiteDataReader reader = cmd.ExecuteReader())
+                {
+                    while (reader.Read())
+                    {
+                        ErrorMessages.Add(new ErrorMessageRecordModel
+                        {
+                            ID = Convert.ToInt32(reader["ID"]),
+                            Category = reader["Category"].ToString(),
+                            MessageType = reader["MessageType"].ToString(),
+                            MessagePath = reader["MessagePath"].ToString(),
+                            Message = reader["Message"].ToString(),
+                            // 解析时间字符串
+                            DateTime = DateTime.Parse(reader["DateTime"].ToString()),
+                            userID = Convert.ToInt32(reader["userID"]),
+                            LogLevel = Convert.ToInt32(reader["LogLevel"])
+                        });
+                    }
+                }
+            }
+            return ErrorMessages;
+        }
+    }
+}

+ 259 - 0
MvvmScaffoldFrame48.DLL/AuditTrail/OperationRecordManagement.cs

@@ -0,0 +1,259 @@
+//值变更记录管理
+using MvvmScaffoldFrame48.Model.AuditTrail;
+using System;
+using System.Collections.Generic;
+using System.Data.SQLite;
+using System.IO;
+using System.Threading.Tasks;
+
+namespace MvvmScaffoldFrame48.DLL.AuditTrail
+{
+    public class OperationRecordManagement
+    {
+        private readonly string _dbPath;
+
+        private string _connString;
+
+        private object locker = new object();
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public OperationRecordManagement()
+        {
+            _dbPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\AuditTrail.db";
+            // 1. 获取文件夹路径
+            string directoryPath = Path.GetDirectoryName(_dbPath);
+
+            // 2. 检查文件夹是否存在
+            if (!Directory.Exists(directoryPath))
+            {
+                // 创建文件夹
+                Directory.CreateDirectory(directoryPath);
+            }
+            InitializeDatabase();
+        }
+
+        /// <summary>
+        /// 构造函数(指定数据库路径)
+        /// </summary>
+        /// <param name="dbPath"></param>
+        public OperationRecordManagement(string dbPath)
+        {
+            if(dbPath == null|| dbPath == "")
+            {
+                _dbPath = $"{AppDomain.CurrentDomain.BaseDirectory}DATA\\AuditTrail.db";
+            }
+            else
+            {
+                _dbPath = dbPath;
+            }
+
+            // 1. 获取文件夹路径
+            string directoryPath = Path.GetDirectoryName(_dbPath);
+
+            // 2. 检查文件夹是否存在
+            if (!Directory.Exists(directoryPath))
+            {
+                // 创建文件夹
+                Directory.CreateDirectory(directoryPath);
+            }
+            InitializeDatabase();
+        }
+
+        /// <summary>
+        /// 初始化数据库和表
+        /// </summary>
+        private void InitializeDatabase()
+        {
+            if (!File.Exists(_dbPath))
+            {
+                SQLiteConnection.CreateFile(_dbPath);
+            }
+
+            _connString = $"Data Source={_dbPath};Version=3;" +
+                "Journal Mode=WAL;" +           // 使用WAL模式提高并发性
+                "Synchronous=Normal;" +         // 平衡性能和安全性
+                "Cache Size=10000;" +           // 增加缓存大小
+                "Pooling=true;" +               // 启用连接池
+                "Max Pool Size=100;";         // 设置最大连接池大小
+
+            using (var conn = new SQLiteConnection(_connString))
+            {
+                conn.Open();
+                string createTableSql = @"
+                    CREATE TABLE IF NOT EXISTS OperationRecord (
+                        ID INTEGER PRIMARY KEY AUTOINCREMENT,
+                        Category TEXT NOT NULL,
+                        OldMessage TEXT NOT NULL,
+                        NewMessage TEXT NOT NULL,
+                        DateTime TEXT NOT NULL,
+                        userID INTEGER NOT NULL,
+                        IsDeleted INTEGER CHECK (IsDeleted IN (0, 1))
+                )";
+                new SQLiteCommand(createTableSql, conn).ExecuteNonQuery();
+            }
+        }
+
+        /// <summary>
+        /// 插入数据
+        /// </summary>
+        /// <param name="Message"></param>
+        public void InsertOperationRecord(OperationRecordModel Message)
+        {
+            lock (locker)
+            {
+                using (var conn = new SQLiteConnection(_connString))
+                {
+                    conn.Open();
+                    string sql = "INSERT INTO OperationRecord (Category,OldMessage,NewMessage,DateTime,userID,IsDeleted) VALUES (@Category, @OldMessage,@NewMessage, @DateTime, @userID,@IsDeleted)";
+                    var cmd = new SQLiteCommand(sql, conn);
+                    cmd.Parameters.AddWithValue("@Category", Message.Category);
+                    cmd.Parameters.AddWithValue("@OldMessage", Message.OldMessage);
+                    cmd.Parameters.AddWithValue("@NewMessage", Message.NewMessage);
+                    cmd.Parameters.AddWithValue("@DateTime", Message.DateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
+                    cmd.Parameters.AddWithValue("@userID", Message.userID); // 格式化为字符串
+                    cmd.Parameters.AddWithValue("@IsDeleted", Message.IsDeleted == true ? 1 : 0);
+                    cmd.ExecuteNonQuery();
+                }
+            }
+        }
+
+        /// <summary>
+        /// 查询所有数据
+        /// </summary>
+        /// <returns></returns>
+        public List<OperationRecordModel> GetAllOperationRecord()
+        {
+            var persons = new List<OperationRecordModel>();
+            using (var conn = new SQLiteConnection(_connString))
+            {
+                conn.Open();
+                string sql = "SELECT * FROM OperationRecord  WHERE IsDeleted=0";
+                var cmd = new SQLiteCommand(sql, conn);
+                using (SQLiteDataReader reader = cmd.ExecuteReader())
+                {
+                    while (reader.Read())
+                    {
+                        persons.Add(new OperationRecordModel
+                        {
+                            ID = Convert.ToInt32(reader["ID"]),
+                            Category = reader["Category"].ToString(),
+                            OldMessage = reader["OldMessage"].ToString(),
+                            NewMessage = reader["NewMessage"].ToString(),
+                            // 解析时间字符串
+                            DateTime = DateTime.Parse(reader["DateTime"].ToString()),
+                            userID = Convert.ToInt32(reader["userID"]),
+                            IsDeleted = Convert.ToInt32(reader["IsDeleted"]) == 1 ? true : false
+                        });
+                    }
+                }
+            }
+            return persons;
+        }
+
+        /// <summary>
+        /// 获取值改变信息
+        /// </summary>
+        /// <param name="UserID">操作员ID</param>
+        /// <returns></returns>
+        public List<OperationRecordModel> GetOperationRecordByID(int UserID)
+        {
+            var persons = new List<OperationRecordModel>();
+            using (var conn = new SQLiteConnection(_connString))
+            {
+                conn.Open();
+                string sql = "SELECT * FROM OperationRecord WHERE userID=@userID AND IsDeleted=0";
+                var cmd = new SQLiteCommand(sql, conn);
+                cmd.Parameters.AddWithValue("@userID", UserID);
+                using (SQLiteDataReader reader = cmd.ExecuteReader())
+                {
+                    while (reader.Read())
+                    {
+                        persons.Add(new OperationRecordModel
+                        {
+                            ID = Convert.ToInt32(reader["ID"]),
+                            Category = reader["Category"].ToString(),
+                            OldMessage = reader["OldMessage"].ToString(),
+                            NewMessage = reader["NewMessage"].ToString(),
+                            // 解析时间字符串
+                            DateTime = DateTime.Parse(reader["DateTime"].ToString()),
+                            userID = Convert.ToInt32(reader["userID"]),
+                            IsDeleted = Convert.ToInt32(reader["IsDeleted"]) == 1 ? true : false
+                        });
+                    }
+                }
+            }
+            return persons;
+        }
+
+        /// <summary>
+        /// 获取指定日期的值改变信息
+        /// </summary>
+        /// <param name="OperationDateTime"></param>
+        /// <returns></returns>
+        public List<OperationRecordModel> GetOperationRecordByDateTime(DateTime OperationDateTime)
+        {
+            var persons = new List<OperationRecordModel>();
+            using (var conn = new SQLiteConnection(_connString))
+            {
+                conn.Open();
+                string sql = "SELECT * FROM OperationRecord WHERE date(DateTime) = date(@DateTime) AND IsDeleted=0";
+                var cmd = new SQLiteCommand(sql, conn);
+                cmd.Parameters.AddWithValue("@DateTime", OperationDateTime.ToString("yyyy-MM-dd"));
+                using (SQLiteDataReader reader = cmd.ExecuteReader())
+                {
+                    while (reader.Read())
+                    {
+                        persons.Add(new OperationRecordModel
+                        {
+                            ID = Convert.ToInt32(reader["ID"]),
+                            Category = reader["Category"].ToString(),
+                            OldMessage = reader["OldMessage"].ToString(),
+                            NewMessage = reader["NewMessage"].ToString(),
+                            // 解析时间字符串
+                            DateTime = DateTime.Parse(reader["DateTime"].ToString()),
+                            userID = Convert.ToInt32(reader["userID"]),
+                            IsDeleted = Convert.ToInt32(reader["IsDeleted"]) == 1 ? true : false
+                        });
+                    }
+                }
+            }
+            return persons;
+        }
+
+        /// <summary>
+        /// 获取指定时间段内的值改变信息
+        /// </summary>
+        public List<OperationRecordModel> GetOperationRecordByDateTime(DateTime OperationStartDateTime, DateTime OperationEndDateTime)
+        {
+            var persons = new List<OperationRecordModel>();
+            using (var conn = new SQLiteConnection(_connString))
+            {
+                conn.Open();
+                string sql = "SELECT * FROM OperationRecord WHERE date(DateTime) >= date(@StartDateTime) AND date(DateTime) <= date(@EndDateTime) AND IsDeleted=0";
+                var cmd = new SQLiteCommand(sql, conn);
+                cmd.Parameters.AddWithValue("@StartDateTime", OperationStartDateTime.ToString("yyyy-MM-dd"));
+                cmd.Parameters.AddWithValue("@EndDateTime", OperationEndDateTime.ToString("yyyy-MM-dd"));
+                using (SQLiteDataReader reader = cmd.ExecuteReader())
+                {
+                    while (reader.Read())
+                    {
+                        persons.Add(new OperationRecordModel
+                        {
+                            ID = Convert.ToInt32(reader["ID"]),
+                            Category = reader["Category"].ToString(),
+                            OldMessage = reader["OldMessage"].ToString(),
+                            NewMessage = reader["NewMessage"].ToString(),
+                            // 解析时间字符串
+                            DateTime = DateTime.Parse(reader["DateTime"].ToString()),
+                            userID = Convert.ToInt32(reader["userID"]),
+                            IsDeleted = Convert.ToInt32(reader["IsDeleted"]) == 1 ? true : false
+                        });
+                    }
+                }
+            }
+            return persons;
+        }
+    }
+}

+ 27 - 0
MvvmScaffoldFrame48.DLL/MvvmScaffoldFrame48.Dll.csproj

@@ -21,6 +21,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x64</PlatformTarget>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -30,6 +31,24 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x64\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="MvCameraControl.Net, Version=4.5.0.2, Culture=neutral, PublicKeyToken=a3c7c5e3a730cd12, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
@@ -49,6 +68,8 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="AuditTrail\ErrorMessageRecordManagement.cs" />
+    <Compile Include="AuditTrail\OperationRecordManagement.cs" />
     <Compile Include="CameraTools\HikCamera.cs" />
     <Compile Include="CameraTools\HikVision.cs" />
     <Compile Include="CommunicationTools\ModbusTcpClient.cs" />
@@ -75,6 +96,12 @@
     <PackageReference Include="NModbus">
       <Version>3.0.81</Version>
     </PackageReference>
+    <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3">
+      <Version>3.0.2</Version>
+    </PackageReference>
+    <PackageReference Include="System.Data.SQLite">
+      <Version>2.0.2</Version>
+    </PackageReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 4 - 1
MvvmScaffoldFrame48.DLL/UserManager.cs

@@ -1,4 +1,7 @@
-using MvvmScaffoldFrame48.Model;
+using MvvmScaffoldFrame48.DLL.AuditTrail;
+using MvvmScaffoldFrame48.Model;
+using MvvmScaffoldFrame48.Model.AuditTrail;
+using System;
 using System.Collections.ObjectModel;
 
 namespace MvvmScaffoldFrame48.DLL

+ 47 - 0
MvvmScaffoldFrame48.MODEL/AuditTrail/ErrorMessageRecordModel.cs

@@ -0,0 +1,47 @@
+using System;
+
+namespace MvvmScaffoldFrame48.Model.AuditTrail
+{
+    public class ErrorMessageRecordModel
+    {
+        /// <summary>
+        /// ID
+        /// </summary>
+        public int ID { get; set;}
+
+        /// <summary>
+        /// 信息类别
+        /// </summary>
+        public string Category { get; set; }
+
+        /// <summary>
+        /// 信息类型
+        /// </summary>
+        public string MessageType { get; set; }
+
+        /// <summary>
+        /// 信息路径
+        /// </summary>
+        public string MessagePath { get; set; }
+
+        /// <summary>
+        /// 信息内容
+        /// </summary>
+        public string Message { get; set; }
+
+        /// <summary>
+        /// 记录时间
+        /// </summary>
+        public DateTime DateTime { get; set; }
+
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        public int userID { get; set; }
+
+        /// <summary>
+        /// 日志级别
+        /// </summary>
+        public int LogLevel { get; set; }
+    }
+}

+ 43 - 0
MvvmScaffoldFrame48.MODEL/AuditTrail/OperationRecordModel.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MvvmScaffoldFrame48.Model.AuditTrail
+{
+    public class OperationRecordModel
+    {
+
+        public int ID { get; set; }
+
+        /// <summary>
+        /// 信息类别
+        /// </summary>
+        public string Category { get; set; }
+
+        /// <summary>
+        /// 旧信息
+        /// </summary>
+        public string OldMessage { get; set; }
+
+        /// <summary>
+        /// 新信息
+        /// </summary>
+        public string NewMessage { get; set; }
+
+        /// <summary>
+        /// 记录时间
+        /// </summary>
+        public DateTime DateTime { get; set; }
+
+        /// <summary>
+        /// 操作员ID
+        /// </summary>
+        public int userID { get; set; }
+
+        /// <summary>
+        /// 是否删除
+        /// </summary>
+        public bool IsDeleted { get; set; }
+    }
+}

+ 21 - 0
MvvmScaffoldFrame48.MODEL/MvvmScaffoldFrame48.Model.csproj

@@ -21,6 +21,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x64</PlatformTarget>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -30,6 +31,24 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x64\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />
@@ -41,6 +60,8 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="AuditTrail\ErrorMessageRecordModel.cs" />
+    <Compile Include="AuditTrail\OperationRecordModel.cs" />
     <Compile Include="HikVisionCamera\CameraImageSizeCModel.cs" />
     <Compile Include="HikVisionCamera\CameraInfoModel.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

+ 20 - 0
MvvmScaffoldFrame48.VIEWMODEL/MainViewModel.cs

@@ -1,6 +1,9 @@
 // 演示类
 using MvvmScaffoldFrame48.DLL;
+using MvvmScaffoldFrame48.DLL.AuditTrail;
 using MvvmScaffoldFrame48.Model;
+using MvvmScaffoldFrame48.Model.AuditTrail;
+using System;
 using System.Collections.ObjectModel;
 using System.Windows.Input;
 
@@ -56,6 +59,23 @@ namespace MvvmScaffoldFrame48.ViewModel
             user.Name = Name;
             user.Email = Email;
             UserManager.AddUser(user);
+
+
+            OperationRecordManagement operationRecordManagement = new OperationRecordManagement();
+            operationRecordManagement.InsertOperationRecord(new OperationRecordModel()
+            {
+                Category = "用户管理",
+                OldMessage = "",
+                NewMessage = "添加用户:" + user.Name,
+                DateTime = DateTime.Now,
+                userID = 1,
+                IsDeleted = false
+            });
+            var OperationRecord = operationRecordManagement.GetAllOperationRecord();
+            foreach (var item in OperationRecord)
+            {
+                Console.WriteLine($"{item.Category}:{item.OldMessage}=>{item.NewMessage},Time:{item.DateTime.ToString("g")}");
+            }
         }
 
         private void Test(object obj)

+ 19 - 0
MvvmScaffoldFrame48.VIEWMODEL/MvvmScaffoldFrame48.ViewModel.csproj

@@ -21,6 +21,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x64</PlatformTarget>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -30,6 +31,24 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x64\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />

+ 19 - 1
MvvmScaffoldFrame48.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio Version 17
-VisualStudioVersion = 17.14.36109.1 d17.14
+VisualStudioVersion = 17.14.36109.1
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmScaffoldFrame48", "MvvmScaffoldFrame48\MvvmScaffoldFrame48.csproj", "{06B7CE96-EB5B-4495-9094-7F208D410A51}"
 EndProject
@@ -14,25 +14,43 @@ EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
+		Debug|x64 = Debug|x64
 		Release|Any CPU = Release|Any CPU
+		Release|x64 = Release|x64
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 		{06B7CE96-EB5B-4495-9094-7F208D410A51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{06B7CE96-EB5B-4495-9094-7F208D410A51}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{06B7CE96-EB5B-4495-9094-7F208D410A51}.Debug|x64.ActiveCfg = Debug|x64
+		{06B7CE96-EB5B-4495-9094-7F208D410A51}.Debug|x64.Build.0 = Debug|x64
 		{06B7CE96-EB5B-4495-9094-7F208D410A51}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{06B7CE96-EB5B-4495-9094-7F208D410A51}.Release|Any CPU.Build.0 = Release|Any CPU
+		{06B7CE96-EB5B-4495-9094-7F208D410A51}.Release|x64.ActiveCfg = Release|x64
+		{06B7CE96-EB5B-4495-9094-7F208D410A51}.Release|x64.Build.0 = Release|x64
 		{75C34EE7-6921-492E-B2D4-0314F2F38AB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{75C34EE7-6921-492E-B2D4-0314F2F38AB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{75C34EE7-6921-492E-B2D4-0314F2F38AB5}.Debug|x64.ActiveCfg = Debug|x64
+		{75C34EE7-6921-492E-B2D4-0314F2F38AB5}.Debug|x64.Build.0 = Debug|x64
 		{75C34EE7-6921-492E-B2D4-0314F2F38AB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{75C34EE7-6921-492E-B2D4-0314F2F38AB5}.Release|Any CPU.Build.0 = Release|Any CPU
+		{75C34EE7-6921-492E-B2D4-0314F2F38AB5}.Release|x64.ActiveCfg = Release|Any CPU
+		{75C34EE7-6921-492E-B2D4-0314F2F38AB5}.Release|x64.Build.0 = Release|Any CPU
 		{56156576-9627-4624-9E1D-26AA7714D1C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{56156576-9627-4624-9E1D-26AA7714D1C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{56156576-9627-4624-9E1D-26AA7714D1C7}.Debug|x64.ActiveCfg = Debug|x64
+		{56156576-9627-4624-9E1D-26AA7714D1C7}.Debug|x64.Build.0 = Debug|x64
 		{56156576-9627-4624-9E1D-26AA7714D1C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{56156576-9627-4624-9E1D-26AA7714D1C7}.Release|Any CPU.Build.0 = Release|Any CPU
+		{56156576-9627-4624-9E1D-26AA7714D1C7}.Release|x64.ActiveCfg = Release|Any CPU
+		{56156576-9627-4624-9E1D-26AA7714D1C7}.Release|x64.Build.0 = Release|Any CPU
 		{ACD4905A-4124-4A51-B9B1-C38D74B794F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{ACD4905A-4124-4A51-B9B1-C38D74B794F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{ACD4905A-4124-4A51-B9B1-C38D74B794F0}.Debug|x64.ActiveCfg = Debug|x64
+		{ACD4905A-4124-4A51-B9B1-C38D74B794F0}.Debug|x64.Build.0 = Debug|x64
 		{ACD4905A-4124-4A51-B9B1-C38D74B794F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{ACD4905A-4124-4A51-B9B1-C38D74B794F0}.Release|Any CPU.Build.0 = Release|Any CPU
+		{ACD4905A-4124-4A51-B9B1-C38D74B794F0}.Release|x64.ActiveCfg = Release|Any CPU
+		{ACD4905A-4124-4A51-B9B1-C38D74B794F0}.Release|x64.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 21 - 1
MvvmScaffoldFrame48/MvvmScaffoldFrame48.csproj

@@ -16,7 +16,7 @@
     <Deterministic>true</Deterministic>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
+    <PlatformTarget>x64</PlatformTarget>
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
@@ -34,6 +34,26 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x64\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Data" />