154 lines
4.9 KiB
C#
154 lines
4.9 KiB
C#
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.src.controllers;
|
|
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;
|
|
private readonly MenuController menu;
|
|
|
|
public MainWindow(LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
|
|
{
|
|
InitializeComponent();
|
|
|
|
log = logService;
|
|
db = databaseService;
|
|
even = eventService;
|
|
// 初始化菜单控制器
|
|
menu = new MenuController(this);
|
|
|
|
// 记录窗口初始化日志
|
|
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 菜单点击按钮绑定
|
|
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
|
|
|
|
|
|
|
|
#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
|
|
} |