为系统配置添加上数据库

This commit is contained in:
YONGYE 2025-10-14 15:15:10 +08:00
parent 3c736f9d5b
commit 9f1db152eb
5 changed files with 50 additions and 73 deletions

View File

@ -31,7 +31,7 @@ public partial class MainWindow : Window
log = logService;
db = databaseService;
even = eventService;
menu = new MenuController(this);// 初始化菜单控制器
menu = new MenuController(this, log, db, even);// 初始化菜单控制器
sensorManager = new SensorChartManager(this, log, db, even)
{
Sensor1 = Sensor1,

View File

@ -8,6 +8,13 @@
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<Compile Remove="新文件夹\**" />
<EmbeddedResource Remove="新文件夹\**" />
<None Remove="新文件夹\**" />
<Page Remove="新文件夹\**" />
</ItemGroup>
<ItemGroup>
<None Remove="src\public\Icons\main1-file-icon.png" />
<None Remove="src\public\Icons\main2-config-icon.png" />
@ -67,7 +74,6 @@
<ItemGroup>
<Folder Include="src\public\Excel\" />
<Folder Include="新文件夹\" />
</ItemGroup>
</Project>

View File

@ -13,6 +13,14 @@
"Connection": "DataSource=LocalData.db",
"Remarks": "",
"Print": false
},
{
"Name": "D1",
"Enabled": true,
"Type": 2,
"Connection": "DataSource=D1.db",
"Remarks": "产品数据库",
"Print": true
}
]
}

View File

@ -1,4 +1,5 @@
using System.Windows;
using guoke;
using System.Windows;
using WpfApp.src.view;
using WpfApp.Utils;
@ -10,9 +11,14 @@ namespace WpfApp.src.controllers
public class MenuController
{
private readonly Window mainWindow;
public MenuController(Window window)
private readonly LogService log;
private readonly DatabaseService db;
private readonly EventService<GeneralEventArgs> even;
public MenuController(Window window, LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
{
log = logService;
db = databaseService;
even = eventService;
mainWindow = window;
}
@ -32,7 +38,7 @@ namespace WpfApp.src.controllers
/// </summary>
public void OpenConfigPage()
{
WindowHelper.ShowPageDialog(new ConfigPage(),
WindowHelper.ShowPageDialog(new ConfigPage(log, db, even),
"配置", 972, 648,
isResizable: false,
IconHelper.GetIconPath("main2-Config.ico"));

View File

@ -1,7 +1,9 @@
using guoke;
using SqlSugar;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using static WpfApp.MainWindow;
namespace WpfApp.src.view;
@ -13,12 +15,24 @@ public partial class ConfigPage : Page
// 等级数据字典,每个等级对应 LevelInfo
private Dictionary<string, LevelInfo> levelData;
private Dictionary<int, SensorToleranceData> sensorData;
private readonly LogService log;
private readonly DatabaseService db;
private readonly EventService<GeneralEventArgs> even;
public ConfigPage()
public ConfigPage(LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
{
InitializeComponent();
InitializeLevelData();
InitializeSensorData();
log = logService;
db = databaseService;
even = eventService;
SqlSugarScope scope = db.GetScope("D1");
scope.guokeCheckToCreate<Product>();
scope.guokeCheckToCreate<SensorSelection>();
scope.guokeCheckToCreate<SensorToleranceData>();
scope.guokeCheckToCreate<MainSensorSelection>();
scope.guokeCheckToCreate<LevelInfo>();
// 注册等级标签按钮点击事件
LevelTabUnder.Click += LevelTab_Click;
@ -256,40 +270,21 @@ public partial class ConfigPage : Page
/// <summary>
/// 产品信息数据类
/// </summary>
public class Product
[SugarTable("Product")]
public class Product : BaseTableModel
{
/// <summary>
/// 主键 ID
/// </summary>
public int Id { get; set; }
/// <summary>
/// 产品名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreatedTime { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdatedTime { get; set; }
}
/// <summary>
/// 传感器选择数据类
/// </summary>
public class SensorSelection
[SugarTable("SensorSelection")]
public class SensorSelection : BaseTableModel
{
/// <summary>
/// 主键 ID
/// </summary>
public int Id { get; set; }
/// <summary>
/// 传感器1 名称或编号
/// </summary>
@ -314,28 +309,14 @@ public class SensorSelection
/// 所属产品名称
/// </summary>
public string ProductName { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreatedTime { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdatedTime { get; set; }
}
/// <summary>
/// 传感器公差数据类
/// </summary>
public class SensorToleranceData
[SugarTable("SensorToleranceData")]
public class SensorToleranceData : BaseTableModel
{
/// <summary>
/// 主键 ID
/// </summary>
public int Id { get; set; }
/// <summary>
/// 传感器名称(如 “传感器1”
/// </summary>
@ -361,27 +342,14 @@ public class SensorToleranceData
/// </summary>
public string ProductName { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreatedTime { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdatedTime { get; set; }
}
/// <summary>
/// 主传感器选择数据类
/// </summary>
public class MainSensorSelection
[SugarTable("MainSensorSelection")]
public class MainSensorSelection : BaseTableModel
{
/// <summary>
/// 主键 ID
/// </summary>
public int Id { get; set; }
/// <summary>
/// 数字传感器1 是否为主传感器
/// </summary>
@ -406,24 +374,13 @@ public class MainSensorSelection
/// 所属产品名称
/// </summary>
public string ProductName { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreatedTime { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdatedTime { get; set; }
}
/// <summary>
/// 等级信息数据类
/// </summary>
[SugarTable("LevelInfo")]
public class LevelInfo
{
/// <summary>