2025-09-30 14:31:53 +08:00
|
|
|
using guoke;
|
2025-10-10 15:58:01 +08:00
|
|
|
using LiveCharts;
|
|
|
|
|
using LiveCharts.Wpf;
|
2025-09-30 14:31:53 +08:00
|
|
|
using SqlSugar;
|
2025-09-30 14:37:47 +08:00
|
|
|
using System.Windows;
|
2025-10-11 09:21:00 +08:00
|
|
|
using System.Windows.Controls;
|
2025-10-13 15:19:35 +08:00
|
|
|
using WpfApp.Services;
|
2025-10-11 09:21:00 +08:00
|
|
|
using WpfApp.src.components;
|
2025-10-13 15:00:50 +08:00
|
|
|
using WpfApp.src.controllers;
|
2025-10-11 15:36:43 +08:00
|
|
|
using WpfApp.Utils;
|
2025-10-10 15:58:01 +08:00
|
|
|
|
2025-10-11 15:36:43 +08:00
|
|
|
namespace WpfApp;
|
2025-09-30 14:31:53 +08:00
|
|
|
|
2025-10-11 15:36:43 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
private readonly LogService log;
|
|
|
|
|
private readonly DatabaseService db;
|
|
|
|
|
private readonly EventService<GeneralEventArgs> even;
|
2025-10-13 15:00:50 +08:00
|
|
|
private readonly MenuController menu;
|
2025-10-13 15:19:35 +08:00
|
|
|
private readonly ChartManager chartManager;
|
|
|
|
|
private readonly CancellationTokenSource chartCts = new CancellationTokenSource();
|
2025-10-10 15:58:01 +08:00
|
|
|
|
2025-10-11 15:36:43 +08:00
|
|
|
public MainWindow(LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2025-10-10 15:58:01 +08:00
|
|
|
|
2025-10-11 15:36:43 +08:00
|
|
|
log = logService;
|
|
|
|
|
db = databaseService;
|
|
|
|
|
even = eventService;
|
2025-10-13 15:19:35 +08:00
|
|
|
menu = new MenuController(this);// 初始化菜单控制器
|
2025-10-10 15:58:01 +08:00
|
|
|
|
2025-10-11 15:36:43 +08:00
|
|
|
// 记录窗口初始化日志
|
|
|
|
|
log.Info("MainWindow", "主窗口已通过依赖注入初始化");
|
|
|
|
|
log.Info("窗体启动");
|
|
|
|
|
even.AddEventHandler("GeneralEvent", (m, d) =>
|
|
|
|
|
{
|
|
|
|
|
log.Info($"接收到事件:{d.Data}");
|
|
|
|
|
});
|
2025-10-13 15:19:35 +08:00
|
|
|
|
|
|
|
|
WindowHelper.SetWindowTitle(this, "FMSDGAUGE"); // 设置标题
|
2025-10-10 15:58:01 +08:00
|
|
|
|
2025-10-13 15:19:35 +08:00
|
|
|
chartManager = new ChartManager(Dispatcher);
|
|
|
|
|
chartManager.InitCharts(myChart, myChart1, myChart2); // 初始化图表
|
|
|
|
|
|
|
|
|
|
// 启动实时数据刷新
|
|
|
|
|
chartManager.StartAutoUpdate(myChart, chartCts.Token);
|
|
|
|
|
chartManager.StartAutoUpdate(myChart1, chartCts.Token);
|
|
|
|
|
chartManager.StartAutoUpdate(myChart2, chartCts.Token);
|
2025-09-30 14:31:53 +08:00
|
|
|
|
2025-10-11 15:36:43 +08:00
|
|
|
}
|
2025-10-10 17:49:48 +08:00
|
|
|
|
2025-10-11 15:36:43 +08:00
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SqlSugarScope scope = db.GetScope("LocalData");
|
|
|
|
|
scope.guokeCheckToCreate<aaa>();//检查并创建表
|
|
|
|
|
even.TriggerEvent("GeneralEvent", this, new GeneralEventArgs("测试", 1));
|
|
|
|
|
}
|
|
|
|
|
public class aaa : BaseTableModel
|
|
|
|
|
{
|
2025-10-10 17:49:48 +08:00
|
|
|
|
2025-10-11 15:36:43 +08:00
|
|
|
}
|
2025-10-10 17:49:48 +08:00
|
|
|
|
2025-10-10 15:58:01 +08:00
|
|
|
|
|
|
|
|
|
2025-10-13 15:00:50 +08:00
|
|
|
#region 菜单点击按钮绑定
|
|
|
|
|
private void OnFilePageButtonClick(object sender, RoutedEventArgs e) => menu.OpenFilePage();
|
|
|
|
|
private void OnConfigPageButtonClick(object sender, RoutedEventArgs e) => menu.OpenConfigPage();
|
|
|
|
|
private void OnStandardPageButtonClick(object sender, RoutedEventArgs e) => menu.OpenStandardPage();
|
|
|
|
|
private void OnGaugePageButtonClick(object sender, RoutedEventArgs e) => menu.OpenGaugePage();
|
|
|
|
|
private void OnCgCgkPageButtonClick(object sender, RoutedEventArgs e) => menu.OpenCgCgkPage();
|
|
|
|
|
private void OnSysSetPageButtonClick(object sender, RoutedEventArgs e) => menu.OpenSysSetPage();
|
|
|
|
|
#endregion
|
2025-10-10 15:58:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-11 15:36:43 +08:00
|
|
|
#region 关闭和测试按钮
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按钮点击触发关闭页面
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2025-10-13 15:19:35 +08:00
|
|
|
private void OnCloseMainWindowButtonClick(object sender, RoutedEventArgs e) => WindowHelper.CloseWindow(this);
|
2025-10-10 15:58:01 +08:00
|
|
|
|
|
|
|
|
|
2025-10-11 15:36:43 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 测试按钮
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void OnDemoButtonClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//LineBarChartDemo lineBarChartDemo = new LineBarChartDemo();
|
|
|
|
|
//lineBarChartDemo.Show();
|
|
|
|
|
}
|
2025-10-13 15:19:35 +08:00
|
|
|
#endregion
|
2025-10-11 15:36:43 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 等级选择下拉框变化事件处理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void LevelComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (sender is ComboBox comboBox && comboBox.SelectedItem is ComboBoxItem selectedItem)
|
2025-10-11 09:21:00 +08:00
|
|
|
{
|
2025-10-11 15:36:43 +08:00
|
|
|
// 根据选择的Tag确定等级
|
|
|
|
|
SensorLevel selectedLevel = SensorLevel.Medium; // 默认值
|
|
|
|
|
switch (selectedItem.Tag?.ToString())
|
2025-10-11 09:21:00 +08:00
|
|
|
{
|
2025-10-11 15:36:43 +08:00
|
|
|
case "Low":
|
|
|
|
|
selectedLevel = SensorLevel.Low;
|
|
|
|
|
break;
|
|
|
|
|
case "Medium":
|
|
|
|
|
selectedLevel = SensorLevel.Medium;
|
|
|
|
|
break;
|
|
|
|
|
case "High":
|
|
|
|
|
selectedLevel = SensorLevel.High;
|
|
|
|
|
break;
|
2025-10-11 09:21:00 +08:00
|
|
|
}
|
2025-10-11 15:36:43 +08:00
|
|
|
|
|
|
|
|
// 更新所有传感器图表的等级
|
|
|
|
|
Sensor1.Level = selectedLevel;
|
|
|
|
|
Sensor2.Level = selectedLevel;
|
|
|
|
|
Sensor3.Level = selectedLevel;
|
2025-10-11 09:21:00 +08:00
|
|
|
}
|
2025-09-30 14:31:53 +08:00
|
|
|
}
|
2025-10-13 15:19:35 +08:00
|
|
|
|
2025-09-30 14:31:53 +08:00
|
|
|
}
|