diff --git a/Model/Entity/Base/BaseEntity.cs b/Model/Entity/Base/BaseEntity.cs new file mode 100644 index 0000000..bb72bd5 --- /dev/null +++ b/Model/Entity/Base/BaseEntity.cs @@ -0,0 +1,74 @@ +using System.Reflection; + +namespace SparkClient.Model.Entity.Base; + +public abstract class BaseEntity +{ + public Guid GUID { get; set; } + public static string TableName => throw new NotImplementedException("Table name is not implemented."); + // 获取字段映射的实际名称 + private static Dictionary GetFieldMappings() + { + var properties = typeof(BaseEntity).GetProperties(BindingFlags.Public | BindingFlags.Instance); + return properties + .Where(p => Attribute.IsDefined(p, typeof(DbFieldAttribute))) + .ToDictionary( + p => p.Name, + p => ((DbFieldAttribute)p.GetCustomAttribute(typeof(DbFieldAttribute))).FieldName + ); + } + + // 生成 Insert 语句 + public string GenerateInsertSQL() + { + var mappings = GetFieldMappings(); + var columns = string.Join(", ", mappings.Values); + var values = string.Join(", ", mappings.Keys.Select(k => $"@{k}")); + return $"INSERT INTO {TableName} ({columns}) VALUES ({values});"; + } + + // 生成 Update 语句 + public string GenerateUpdateSQL(Dictionary fieldsToUpdate = null) + { + if (fieldsToUpdate == null || fieldsToUpdate.Count == 0) + { + // 默认根据 ID 更新所有字段 + var mappings = GetFieldMappings(); + var setClause = string.Join(", ", mappings.Values.Select(f => $"{f} = @{f}")); + return $"UPDATE {TableName} SET {setClause} WHERE id = @id;"; + } + else + { + // 根据传入的字段更新 + var setClause = string.Join(", ", fieldsToUpdate.Keys.Select(f => $"{f} = @{f}")); + return $"UPDATE {TableName} SET {setClause} WHERE id = @id;"; + } + } + + // 生成 Delete 语句 + public string GenerateDeleteSQL(Dictionary conditions = null) + { + if (conditions == null || conditions.Count == 0) + { + // 默认根据 ID 删除 + return $"DELETE FROM {TableName} WHERE id = @id;"; + } + else + { + // 根据传入条件删除 + var whereClause = string.Join(" AND ", conditions.Keys.Select(f => $"{f} = @{f}")); + return $"DELETE FROM {TableName} WHERE {whereClause};"; + } + } +} + +[AttributeUsage(AttributeTargets.Property)] +public class DbFieldAttribute : Attribute +{ + public string FieldName { get; } + + public DbFieldAttribute(string fieldName) + { + FieldName = fieldName; + } +} diff --git a/Model/Entity/SystemSettingEntity.cs b/Model/Entity/SystemSettingEntity.cs new file mode 100644 index 0000000..912236e --- /dev/null +++ b/Model/Entity/SystemSettingEntity.cs @@ -0,0 +1,31 @@ +using SparkClient.Model.Entity.Base; + +namespace SparkClient.Model.Entity; + +/// +/// 系统设置实体 +/// + +public class SystemSettingEntity : BaseEntity +{ + public static string TableName = "SYSTEM_SETTING"; + /// + /// 设置编号 + /// + [DbField("SETID")] + public string SetId { get; set; } + /// + /// 设置名称 + /// + [DbField("NAME")] + public string SetName { get; set; } + /// + /// 设置值 + /// + [DbField("VALUE")] + public string SetValue { get; set; } + + +} + + diff --git a/Views/HelperPage.xaml.cs b/Views/HelperPage.xaml.cs index ae6834a..2473f17 100644 --- a/Views/HelperPage.xaml.cs +++ b/Views/HelperPage.xaml.cs @@ -1,5 +1,6 @@ using System.Windows; using System.Windows.Controls; +using Microsoft.Web.WebView2.Core; namespace SparkClient.Views; @@ -8,7 +9,13 @@ public partial class HelperPage public HelperPage() { InitializeComponent(); - Console.Out.WriteLine(AppDomain.CurrentDomain.BaseDirectory + @"\Resource\Document\Helper.pdf"); + PdfWebViewer.Source = new Uri(AppDomain.CurrentDomain.BaseDirectory + @"Resource\Document\Helper.pdf"); + + + + } + + } \ No newline at end of file