This commit is contained in:
xyy
2026-04-12 16:46:55 +08:00
parent ea8e76bff4
commit e774c2374c
11 changed files with 303 additions and 47 deletions

View File

@@ -1,4 +1,6 @@
using MembranePoreTester.Communication;
using MembranePoreTester.Models;
using MembranePoreTester.Views;
using Microsoft.Extensions.Configuration;
using OfficeOpenXml;
using System;
@@ -9,18 +11,31 @@ namespace MembranePoreTester
{
public partial class App : Application
{
public static UserRole CurrentUserRole { get; set; } = UserRole.Operator;
public static IPlcService PlcService { get; private set; }
public static PlcConfiguration PlcConfig { get; private set; }
protected async override void OnStartup(StartupEventArgs e)
protected override async void OnStartup(StartupEventArgs e)
{
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
base.OnStartup(e);
// 防止在登录窗口关闭时应用程序因没有窗口而自动退出
ShutdownMode = ShutdownMode.OnExplicitShutdown;
// 显示登录窗口,验证用户身份
var loginWindow = new LoginWindow();
if (loginWindow.ShowDialog() != true)
{
Shutdown();
return;
}
// 登录成功后初始化数据库和PLC连接
using var db = new AppDbContext();
db.Database.EnsureCreated(); // 自动建表
db.Database.EnsureCreated();
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
@@ -43,6 +58,12 @@ namespace MembranePoreTester
{
MessageBox.Show($"PLC 连接失败:{ex.Message}");
}
// 启动主窗口,设置为应用程序的主窗口并恢复默认的退出模式
var mainWindow = new MainWindow();
MainWindow = mainWindow;
ShutdownMode = ShutdownMode.OnMainWindowClose;
mainWindow.Show();
}
protected override void OnExit(ExitEventArgs e)