关闭事件

This commit is contained in:
tanglong 2026-01-21 14:48:51 +08:00
parent b99a03c940
commit 1f8ac07868
4 changed files with 11 additions and 90 deletions

View File

@ -32,9 +32,7 @@ public partial class App : Application
DebugTracker.Channels.Add(new DiagnosisDebugTrackChannel());
#endif
base.OnStartup(e);
// 创建 Host
// 1. 创建 Host
AppHost = Host.CreateDefaultBuilder()
.ConfigureAppConfiguration((context, config) =>
{
@ -48,81 +46,19 @@ public partial class App : Application
services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(connectionString));
// 初始化全局配置
AppSettings.Init(context.Configuration);
// 注入 MainWindow
services.AddSingleton<Main>();
var SSS = AppSettings.SchoolCode;
})
.Build();
// 启动 Host
// 2. 启动 Host
AppHost.Start();
//using (var scope = AppHost.Services.CreateScope())
//{
// var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
// //db.Database.EnsureDeleted(); // 删除数据库和表
// db.Database.EnsureCreated();
// //db.Database.ExecuteSqlRaw("DROP TABLE [JumpLongPoints]");
// if (!db.SixGroupPoints.Any())
// {
// db.SixGroupPoints.Add(new AiSportsMicrospaceDB.Entities.SixGroupPoints
// {
// Id = 1,
// Point1 = new AiSportsMicrospaceDB.Entities.Point { X = 0.21, Y = 0.88 },
// Point2 = new AiSportsMicrospaceDB.Entities.Point { X = 0.36, Y = 0.58 },
// Point3 = new AiSportsMicrospaceDB.Entities.Point { X = 0.50, Y = 0.88 },
// Point4 = new AiSportsMicrospaceDB.Entities.Point { X = 0.64, Y = 0.58 },
// Point5 = new AiSportsMicrospaceDB.Entities.Point { X = 0.78, Y = 0.88 },
// Point6 = new AiSportsMicrospaceDB.Entities.Point { X = 0.92, Y = 0.58 }
// });
// db.SaveChanges();
// }
// //if (!CheckTableExists(db , "JumpLongPoints"))
// //{
// // var createTableSql = @"
// // CREATE TABLE IF NOT EXISTS JumpLongPoints (
// // Id INTEGER PRIMARY KEY,
// // TopPoint1_X TEXT NOT NULL,
// // TopPoint2_X TEXT NOT NULL,
// // TopPoint3_X TEXT NOT NULL,
// // BottomPoint1_X TEXT NOT NULL,
// // BottomPoint2_X TEXT NOT NULL,
// // BottomPoint3_X TEXT NOT NULL,
// // TopPoint1_Y TEXT NOT NULL,
// // TopPoint2_Y TEXT NOT NULL,
// // TopPoint3_Y TEXT NOT NULL,
// // BottomPoint1_Y TEXT NOT NULL,
// // BottomPoint2_Y TEXT NOT NULL,
// // BottomPoint3_Y TEXT NOT NULL
// // )";
// // db.Database.ExecuteSqlRaw(createTableSql);
// //}
// if (!db.JumpLongPoints.Any())
// {
// db.JumpLongPoints.Add(new AiSportsMicrospaceDB.Entities.JumpLongPoints
// {
// Id = 1,
// TopPoint1 = new AiSportsMicrospaceDB.Entities.Point { X = 245, Y = 741 },
// TopPoint2 = new AiSportsMicrospaceDB.Entities.Point { X = 1498, Y = 730 },
// TopPoint3 = new AiSportsMicrospaceDB.Entities.Point { X = 1689, Y = 724 },
// BottomPoint1 = new AiSportsMicrospaceDB.Entities.Point { X = 191, Y = 918 },
// BottomPoint3 = new AiSportsMicrospaceDB.Entities.Point { X = 1722, Y = 909 },
// });
// db.SaveChanges();
// }
// //var mainWindow = new MainWindow(db);
// //mainWindow.Show();
//}
// 用 DI 创建窗口
// 3. 初始化全局配置
var configuration = AppHost.Services.GetRequiredService<IConfiguration>();
AppSettings.Init(configuration); // 这时 AppHost 已经有值了
// 4. 用 DI 创建窗口
var mainWin = AppHost.Services.GetRequiredService<Main>();
Current.MainWindow = mainWin;
mainWin.Show();
@ -131,20 +67,5 @@ public partial class App : Application
mainWin.SwitchPage(newPage, true);
}
//private bool CheckTableExists(AppDbContext dbContext , String name)
//{
// try
// {
// // 使用原始SQL检查表是否存在
// var sql = "SELECT count(*) FROM sqlite_master WHERE type='table' AND name=@name";
// var result = dbContext.Database.ExecuteSqlRaw(sql, new SqlServerParameter("@name", name));
// return result > 0;
// }
// catch
// {
// return false;
// }
//}
}

View File

@ -33,9 +33,9 @@ namespace Common
using var scope = App.AppHost.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
var groupData = db.GroupPoints.Where(x => x.Code == Code).Select(x => new { x.ControlPoint, x.AreaSize }).FirstOrDefault();
var groupData = db.GroupPoints.Where(x => x.Code == Code).FirstOrDefault();
if (groupData != null && groupData.ControlPoint != null && groupData.AreaSize != null)
if (groupData != null)
{
ControlPoint = groupData.ControlPoint;
AreaSize = groupData.AreaSize;

View File

@ -106,7 +106,7 @@ public partial class MainWindow : Window
});
// UI 线程显示
Application.Current.Dispatcher.Invoke(() =>
this.Dispatcher.BeginInvoke(() =>
{
if (videoImage == null) return;
@ -138,7 +138,7 @@ public partial class MainWindow : Window
var circlePositions = GenerateCirclePositionsStaggered(
roomWidth: 5, // 房间宽度(米)
roomHeight: 3, // 房间高度(米)
yOffset: 0.6, // 前排纵坐标
yOffset: 0.6, // 前排纵坐
yStep: 1.5, // 前后排间距
minDistance: 1.5, // 同排最小间距
minEdge: 1 // 两侧到边缘最小距离

View File

@ -109,7 +109,7 @@ namespace Wpf_AiSportsMicrospace.Views
return;
// 触发全局事件
Application.Current.Dispatcher.BeginInvoke(() =>
this.Dispatcher.BeginInvoke(() =>
{
HumanFrameUpdated?.Invoke(this, humans);
});