WpfApp/MainWindow.xaml.cs
2025-10-11 15:36:43 +08:00

299 lines
9.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using guoke;
using LiveCharts;
using LiveCharts.Wpf;
using SqlSugar;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Navigation;
using WpfApp.src.components;
using WpfApp.src.config;
using WpfApp.src.view;
using WpfApp.Utils;
namespace WpfApp;
/// <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;
public MainWindow(LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
{
InitializeComponent();
log = logService;
db = databaseService;
even = eventService;
// 记录窗口初始化日志
log.Info("MainWindow", "主窗口已通过依赖注入初始化");
log.Info("窗体启动");
even.AddEventHandler("GeneralEvent", (m, d) =>
{
log.Info($"接收到事件:{d.Data}");
});
SetWindowTitle("FMSDGAUGE");
var labels = new[] { "13:27 23", "13:27 45", "13:27 49", "13:27 50", "13:27 55" };
var config1 = new ChartConfig
{
ColumnData = new List<double> { 20, 10, 12, 5, 9 },
Labels = new List<string>(labels),
LineConfigs = new List<LineConfig>
{
new LineConfig { Title = "标准1", Values = new List<double> { 5,5,5,5,5 }, Stroke = Brushes.Blue },
new LineConfig { Title = "标准2", Values = new List<double> { 10,10,10,10,10 }, Stroke = Brushes.Green },
new LineConfig { Title = "标准3", Values = new List<double> { 30,30,30,30,30 }, Stroke = Brushes.Red, Unit = "A" }
}
};
InitChart.InitCartesianChart(myChart, config1);
InitChart.InitCartesianChart(myChart1, config1);
InitChart.InitCartesianChart(myChart2, config1);
}
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
{
}
/// <summary>
/// 设置窗体标题的函数
/// </summary>
/// <param name="newTitle"></param>
public void SetWindowTitle(string newTitle)
{
this.Title = newTitle;
}
#region
// 在 MainWindow 内部
/// <summary>
/// 按钮点击触发文件页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnFilePageButtonClick(object sender, RoutedEventArgs e)
{
FilePage filePage = new FilePage();
NavigationWindow navWin = new NavigationWindow();
navWin.Width = 810;
navWin.Height = 600;
navWin.ResizeMode = ResizeMode.NoResize;
navWin.Content = filePage;
navWin.ShowsNavigationUI = false;
navWin.Title = "记录列表";
// ✅ 新增:设定父窗口、样式与居中弹出
navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
navWin.WindowStyle = WindowStyle.ToolWindow;
// ✅ 改这里Show() 改为 ShowDialog() 实现模态窗口
navWin.ShowDialog();
}
/// <summary>
/// 按钮点击触发配置页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnConfigPageButtonClick(object sender, RoutedEventArgs e)
{
ConfigPage configPage = new ConfigPage();
NavigationWindow navWin = new NavigationWindow();
navWin.Content = configPage;
navWin.ShowsNavigationUI = false;
navWin.Width = 972;
navWin.Height = 648;
navWin.Title = "配置";
navWin.ResizeMode = ResizeMode.NoResize;
// ✅ 新增:设定父窗口、样式与居中弹出
navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
navWin.WindowStyle = WindowStyle.ToolWindow;
// ✅ 改这里Show() 改为 ShowDialog() 实现模态窗口
navWin.ShowDialog();
}
/// <summary>
/// 按钮点击触发标准基准页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnStandardPageButtonClick(object sender, RoutedEventArgs e)
{
StandardPage standardPage = new StandardPage();
NavigationWindow navWin = new NavigationWindow();
navWin.Width = 972;
navWin.Height = 648;
//navWin.ResizeMode = ResizeMode.NoResize;
navWin.Content = standardPage;
navWin.ShowsNavigationUI = false;
navWin.Title = "主标定";
// ✅ 新增:设定父窗口、样式与居中弹出
navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
navWin.WindowStyle = WindowStyle.ToolWindow;
// ✅ 改这里Show() 改为 ShowDialog() 实现模态窗口
navWin.ShowDialog();
}
/// <summary>
/// 按钮点击触发Gauge页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnGaugePageButtonClick(object sender, RoutedEventArgs e)
{
GaugePage gaugePage = new GaugePage();
NavigationWindow navWin = new NavigationWindow();
navWin.Content = gaugePage;
navWin.ShowsNavigationUI = false;
navWin.Width = 1080;
navWin.Height = 720;
navWin.Title = "Gauge R&&R";
// ✅ 新增:设定父窗口、样式与居中弹出
navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
navWin.WindowStyle = WindowStyle.ToolWindow;
// ✅ 改这里Show() 改为 ShowDialog() 实现模态窗口
navWin.ShowDialog();
}
/// <summary>
/// 按钮点击触发CgCgk页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnCgCgkPageButtonClick(object sender, RoutedEventArgs e)
{
CgCgkPage cgCgkPage = new CgCgkPage();
NavigationWindow navWin = new NavigationWindow();
navWin.Content = cgCgkPage;
navWin.ShowsNavigationUI = false;
navWin.Title = "CgCgk";
// ✅ 新增:设定父窗口、样式与居中弹出
navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
navWin.WindowStyle = WindowStyle.ToolWindow;
// ✅ 改这里Show() 改为 ShowDialog() 实现模态窗口
navWin.ShowDialog();
}
/// <summary>
/// 按钮点击触发系统设置页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnSysSetPageButtonClick(object sender, RoutedEventArgs e)
{
SysSetPage sysSetPage = new SysSetPage();
NavigationWindow navWin = new NavigationWindow();
navWin.Width = 810;
navWin.Height = 600;
navWin.ResizeMode = ResizeMode.NoResize;
navWin.Content = sysSetPage;
navWin.ShowsNavigationUI = false;
navWin.Title = "系统设置";
// ✅ 新增:设定父窗口、样式与居中弹出
navWin.Owner = Application.Current.MainWindow; // 绑定主窗口
navWin.WindowStartupLocation = WindowStartupLocation.CenterOwner; // 居中弹出
navWin.WindowStyle = WindowStyle.ToolWindow;
// ✅ 改这里Show() 改为 ShowDialog() 实现模态窗口
navWin.ShowDialog();
}
#endregion
#region
/// <summary>
/// 按钮点击触发关闭页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnCloseMainWindowButtonClick(object sender, RoutedEventArgs e)
{
this.Close();
}
/// <summary>
/// 测试按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnDemoButtonClick(object sender, RoutedEventArgs e)
{
//LineBarChartDemo lineBarChartDemo = new LineBarChartDemo();
//lineBarChartDemo.Show();
}
/// <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)
{
// 根据选择的Tag确定等级
SensorLevel selectedLevel = SensorLevel.Medium; // 默认值
switch (selectedItem.Tag?.ToString())
{
case "Low":
selectedLevel = SensorLevel.Low;
break;
case "Medium":
selectedLevel = SensorLevel.Medium;
break;
case "High":
selectedLevel = SensorLevel.High;
break;
}
// 更新所有传感器图表的等级
Sensor1.Level = selectedLevel;
Sensor2.Level = selectedLevel;
Sensor3.Level = selectedLevel;
}
}
#endregion
}