Compare commits
23 Commits
main
...
main-v1-yo
| Author | SHA1 | Date | |
|---|---|---|---|
| dcd1e247ee | |||
| bd849e7de0 | |||
| 56be63db49 | |||
| 57f870ae49 | |||
| 9f1db152eb | |||
| 3c736f9d5b | |||
| a2fffbff37 | |||
| 4b5ac96b7c | |||
| 465d76d0db | |||
| 48f2e586e8 | |||
| b802f2e89b | |||
| f8e65d8e52 | |||
| f770f4b9fd | |||
| b19325cd2a | |||
| 6e14f38a41 | |||
| 3a11035329 | |||
| f990cea469 | |||
| 4f1f1a7259 | |||
| 0a2798497f | |||
| 18a63a1c1d | |||
| db162f3be3 | |||
| ec3c068817 | |||
| e9d9e67851 |
|
|
@ -22,7 +22,9 @@ namespace WpfApp
|
|||
/// <returns>如果硬件已绑定且匹配返回true,否则返回false</returns>
|
||||
private static bool CheckHardwareBinding()
|
||||
{
|
||||
string storedHardwareId = "8f07378cbfb5247c6481694a0ba0cb0b74739eddcc91f591623409a45803ee69";
|
||||
//string storedHardwareId = "8f07378cbfb5247c6481694a0ba0cb0b74739eddcc91f591623409a45803ee69";
|
||||
string storedHardwareId = "2703a031ecb416bd4ef9b91a5bd5f8698f745bb9efcbf7da35d251d0491b9cd8";
|
||||
|
||||
return HardwareInfo.ValidateHardwareId(storedHardwareId);
|
||||
}
|
||||
/// <summary>
|
||||
|
|
@ -59,6 +61,7 @@ namespace WpfApp
|
|||
if (!CheckHardwareBinding())
|
||||
{
|
||||
MessageBox.Show("检测到硬件环境发生变化,应用程序无法启动!", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
Console.WriteLine($"硬件环境序列号:{HardwareInfo.GetHardwareId()}");
|
||||
LogService.Log.Info($"硬件环境序列号:{HardwareInfo.GetHardwareId()}");
|
||||
Shutdown(); // 退出应用程序
|
||||
return;
|
||||
|
|
|
|||
378
MainWindow.xaml
|
|
@ -1,13 +1,383 @@
|
|||
<Window x:Class="WpfApp.MainWindow"
|
||||
<Window x:Class="WpfApp.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:WpfApp"
|
||||
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
|
||||
xmlns:local="clr-namespace:WpfApp.src.components"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
Title="MainWindow" Height="800" Width="1200"
|
||||
Icon="/src/public/Icons/programIcons/FMSDGAUGE-main.ico"
|
||||
>
|
||||
|
||||
<Grid>
|
||||
<Button Content="Button" HorizontalAlignment="Left" Margin="135,125,0,0" VerticalAlignment="Top" Click="Button_Click"/>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 顶部工具栏 -->
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- 中间内容 -->
|
||||
<RowDefinition Height="49"/>
|
||||
<!-- 底部状态栏 -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 使用 DockPanel 可以方便地将 ToolBar 放在顶部 -->
|
||||
|
||||
<!-- 工具栏放在顶部 -->
|
||||
<ToolBar Grid.Row="0">
|
||||
<Button Click="OnFilePageButtonClick">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="pack://application:,,,/src/public/Icons/main1-file-icon.png" Width="16" Height="16" />
|
||||
<TextBlock Text="文件" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Click="OnConfigPageButtonClick">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="pack://application:,,,/src/public/Icons/main2-config-icon.png" Width="16" Height="16" />
|
||||
<TextBlock Text="配置" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Click="OnStandardPageButtonClick">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="pack://application:,,,/src/public/Icons/main3-standard-icon.png" Width="16" Height="16" />
|
||||
<TextBlock Text="标定" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<!--<Button Click="OnDetectionPageButtonClick">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="pack://application:,,,/src/public/Icons/main4-detection-icon.png" Width="16" Height="16" />
|
||||
<TextBlock Text="检测" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>-->
|
||||
|
||||
<Button Click="OnGaugePageButtonClick">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="pack://application:,,,/src/public/Icons/main5-gauge-icon.png" Width="16" Height="16" />
|
||||
<TextBlock Text="Gauge R&P" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button Click="OnCgCgkPageButtonClick">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="pack://application:,,,/src/public/Icons/main6-cgCgk-icon.png" Width="16" Height="16" />
|
||||
<TextBlock Text="CgCgk" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button Click="OnSysSetPageButtonClick">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="pack://application:,,,/src/public/Icons/main7-sysSet-icon.png" Width="16" Height="16" />
|
||||
<TextBlock Text="系统设定" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button Click="OnCloseMainWindowButtonClick">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="pack://application:,,,/src/public/Icons/main8-exit-icon.png" Width="16" Height="16" />
|
||||
<TextBlock Text="退出" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Click="OnDemoButtonClick">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="pack://application:,,,/src/public/Icons/main8-exit-icon.png" Width="16" Height="16" />
|
||||
<TextBlock Text="测试" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
|
||||
</ToolBar>
|
||||
|
||||
<!-- 中间部分 -->
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 顶部数据表格区域 -->
|
||||
<Border Grid.Row="0" Background="White" BorderBrush="#CCCCCC" BorderThickness="1" Margin="10">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="35"/>
|
||||
<RowDefinition Height="35"/>
|
||||
<RowDefinition Height="35"/>
|
||||
<RowDefinition Height="35"/>
|
||||
<RowDefinition Height="35"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 表头 -->
|
||||
<Border Grid.Row="0" Grid.Column="0" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="检测" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="1" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1" Background="#D4B896">
|
||||
<TextBlock Text="传感器1" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="2" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1" Background="#D4B896">
|
||||
<TextBlock Text="传感器2" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="3" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1" Background="#D4B896">
|
||||
<TextBlock Text="传感器3" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="4" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1" Background="#D4B896">
|
||||
<TextBlock Text="传感器4" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="5" BorderBrush="#CCCCCC" BorderThickness="0,0,0,1" Background="#D4B896">
|
||||
<TextBlock Text="等级" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
|
||||
</Border>
|
||||
|
||||
<!-- 数据行 -->
|
||||
<!-- 体积直径 -->
|
||||
<Border Grid.Row="1" Grid.Column="0" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="体积直径" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="1" Grid.Column="1" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="72.9323" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="1" Grid.Column="2" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="1" Grid.Column="3" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="72.1638" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="1" Grid.Column="4" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="1" Grid.Column="5" BorderBrush="#CCCCCC" BorderThickness="0,0,0,1">
|
||||
<TextBlock Text="OK" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" FontSize="55"/>
|
||||
</Border>
|
||||
|
||||
|
||||
<!-- 实际直径 -->
|
||||
<Border Grid.Row="2" Grid.Column="0" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="实际直径" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="2" Grid.Column="1" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="-0.0007" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="2" Grid.Column="2" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="-39.9913" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="2" Grid.Column="3" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="-0.0114" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="2" Grid.Column="4" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<!-- <Border Grid.Row="2" Grid.Column="5" BorderBrush="#CCCCCC" BorderThickness="0,0,0,1">
|
||||
</Border> -->
|
||||
|
||||
<!-- 确认直径 -->
|
||||
<Border Grid.Row="3" Grid.Column="0" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1">
|
||||
<TextBlock Text="确认直径" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="3" Grid.Column="1" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1" Background="#90EE90">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="3" Grid.Column="2" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1" Background="#90EE90">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="3" Grid.Column="3" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1" Background="#90EE90">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="3" Grid.Column="4" BorderBrush="#CCCCCC" BorderThickness="0,0,1,1" Background="#90EE90">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<!-- <Border Grid.Row="3" Grid.Column="5" BorderBrush="#CCCCCC" BorderThickness="0,0,0,1">
|
||||
</Border> -->
|
||||
|
||||
<!-- 确认数据 -->
|
||||
<Border Grid.Row="4" Grid.Column="0" BorderBrush="#CCCCCC" BorderThickness="0,0,1,0">
|
||||
<TextBlock Text="确认数据" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="4" Grid.Column="1" BorderBrush="#CCCCCC" BorderThickness="0,0,1,0" Background="#90EE90">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="4" Grid.Column="2" BorderBrush="#CCCCCC" BorderThickness="0,0,1,0" Background="#90EE90">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="4" Grid.Column="3" BorderBrush="#CCCCCC" BorderThickness="0,0,1,0" Background="#90EE90">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<Border Grid.Row="4" Grid.Column="4" BorderBrush="#CCCCCC" BorderThickness="0,0,1,0" Background="#90EE90">
|
||||
<TextBlock Text="0.0000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<!-- <Border Grid.Row="4" Grid.Column="5" BorderBrush="#CCCCCC" BorderThickness="0,0,0,0">
|
||||
</Border> -->
|
||||
|
||||
<!-- 等级列合并 -->
|
||||
<Border Grid.Row="1" Grid.Column="5" Grid.RowSpan="4"
|
||||
BorderBrush="#CCCCCC" BorderThickness="0,0,0,0" Background="#C1FFC1">
|
||||
<TextBlock Text="OK"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="Green"
|
||||
FontSize="66"
|
||||
FontWeight="Bold"
|
||||
TextAlignment="Center"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
</Border>
|
||||
|
||||
<!-- 中间柱状图区域 -->
|
||||
<Grid Grid.Row="1" Margin="10" Background="#F8F6E7">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="4*"/>
|
||||
<!-- 左侧:传感器柱状图 -->
|
||||
<ColumnDefinition Width="3*"/>
|
||||
<!-- 右侧:文本占位 -->
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 左侧:水平排列三个传感器柱状图 -->
|
||||
<Grid Grid.Column="0" Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<local:SensorChart x:Name="Sensor1" SensorName="传感器1" Value="-40" Grid.Column="0" Margin="2"/>
|
||||
<local:SensorChart x:Name="Sensor2" SensorName="传感器2" Value="40" Grid.Column="1" Margin="2"/>
|
||||
<local:SensorChart x:Name="Sensor3" SensorName="传感器3" Value="-40" Grid.Column="2" Margin="2"/>
|
||||
</Grid>
|
||||
|
||||
<!-- 右侧:曲线 -->
|
||||
<Grid Grid.Column="1" Background="White" Margin="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- 传感器1 -->
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- 传感器2 -->
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- 传感器3 -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 图1:传感器1 -->
|
||||
<Grid Grid.Row="0" Margin="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 标题 -->
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- 图表 -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="传感器1"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Foreground="Black"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,5"/>
|
||||
|
||||
<lvc:CartesianChart Grid.Row="1"
|
||||
x:Name="myChart1"
|
||||
Margin="0,0,0,5">
|
||||
</lvc:CartesianChart>
|
||||
</Grid>
|
||||
|
||||
<!-- 图2:传感器2 -->
|
||||
<Grid Grid.Row="1" Margin="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="传感器2"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Foreground="Black"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,5"/>
|
||||
|
||||
<lvc:CartesianChart Grid.Row="1"
|
||||
x:Name="myChart2"
|
||||
Margin="0,0,0,5"/>
|
||||
</Grid>
|
||||
|
||||
<!-- 图3:传感器3 -->
|
||||
<Grid Grid.Row="2" Margin="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="传感器3"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Foreground="Black"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,5"/>
|
||||
|
||||
<lvc:CartesianChart Grid.Row="1"
|
||||
x:Name="myChart3"
|
||||
Margin="0,0,0,5"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<!-- 底部 StatusBar + 控制按钮自适应 -->
|
||||
<StatusBar Grid.Row="2">
|
||||
<!-- 左侧状态显示 -->
|
||||
<StatusBarItem>
|
||||
<TextBlock Text="连接成功!当前记录: DFPV C15TDE" />
|
||||
</StatusBarItem>
|
||||
<StatusBarItem>
|
||||
<ProgressBar Width="100" Height="20" Value="50" />
|
||||
</StatusBarItem>
|
||||
|
||||
<!-- 右侧控制按钮组 -->
|
||||
<StatusBarItem HorizontalAlignment="Right">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 左侧保存/申请类型 -->
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,10,0">
|
||||
<TextBlock Text="像素/每微米:" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<ComboBox x:Name="LevelComboBox" Width="80" Height="25" VerticalAlignment="Center" SelectionChanged="LevelComboBox_SelectionChanged">
|
||||
<ComboBoxItem Content="低等" Tag="Low"/>
|
||||
<ComboBoxItem Content="中等" Tag="Medium" IsSelected="True"/>
|
||||
<ComboBoxItem Content="高等" Tag="High"/>
|
||||
</ComboBox>
|
||||
<!--<RadioButton Content="日志记录" VerticalAlignment="Center" Margin="10,0,0,0" Foreground="Black"/>-->
|
||||
</StackPanel>
|
||||
|
||||
<!-- 中间状态显示 -->
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,10,0">
|
||||
<!--<Button Content="保存至Cg&Cgk" Width="100" Height="30" Margin="5,0"/>
|
||||
<Button Content="保存至R&R" Width="80" Height="30" Margin="5,0"/>-->
|
||||
</StackPanel>
|
||||
|
||||
<!-- 右侧按钮组 -->
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
|
||||
<Button x:Name="BtnSensorControl"
|
||||
Content="检测开始"
|
||||
Width="70" Height="30"
|
||||
Margin="5,0"
|
||||
Background="#E6F3FF"
|
||||
Click="BtnSensorControl_Click"/>
|
||||
|
||||
<Button Content="保存" Width="50" Height="30" Margin="5,0"/>
|
||||
<Button Content="完成" Width="50" Height="30" Margin="5,0" Background="#90EE90"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StatusBarItem>
|
||||
</StatusBar>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
using guoke;
|
||||
using SqlSugar;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using WpfApp.Services;
|
||||
using WpfApp.src.components;
|
||||
using WpfApp.src.controllers;
|
||||
using WpfApp.Utils;
|
||||
|
||||
namespace WpfApp;
|
||||
|
||||
namespace WpfApp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
|
|
@ -12,6 +17,12 @@ namespace WpfApp
|
|||
private readonly LogService log;
|
||||
private readonly DatabaseService db;
|
||||
private readonly EventService<GeneralEventArgs> even;
|
||||
private readonly MenuController menu;
|
||||
private readonly ChartManager chartManager;
|
||||
private readonly CancellationTokenSource chartCts = new CancellationTokenSource();
|
||||
private readonly SensorChartManager sensorManager;
|
||||
|
||||
private bool isDetecting = false; // 传感器检测状态
|
||||
|
||||
public MainWindow(LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
|
||||
{
|
||||
|
|
@ -20,6 +31,15 @@ namespace WpfApp
|
|||
log = logService;
|
||||
db = databaseService;
|
||||
even = eventService;
|
||||
menu = new MenuController(this, log, db, even);// 初始化菜单控制器
|
||||
sensorManager = new SensorChartManager(this, log, db, even)
|
||||
{
|
||||
Sensor1 = Sensor1,
|
||||
Sensor2 = Sensor2,
|
||||
Sensor3 = Sensor3
|
||||
};
|
||||
|
||||
sensorManager.Stop();
|
||||
|
||||
// 记录窗口初始化日志
|
||||
log.Info("MainWindow", "主窗口已通过依赖注入初始化");
|
||||
|
|
@ -28,6 +48,15 @@ namespace WpfApp
|
|||
{
|
||||
log.Info($"接收到事件:{d.Data}");
|
||||
});
|
||||
|
||||
WindowHelper.SetWindowTitle(this, "FMSDGAUGE"); // 设置标题
|
||||
|
||||
chartManager = new ChartManager(Dispatcher, log, db, even);
|
||||
chartManager.InitChart(myChart1);
|
||||
chartManager.InitChart(myChart2);
|
||||
chartManager.InitChart(myChart3);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
|
|
@ -36,9 +65,75 @@ namespace WpfApp
|
|||
scope.guokeCheckToCreate<aaa>();//检查并创建表
|
||||
even.TriggerEvent("GeneralEvent", this, new GeneralEventArgs("测试", 1));
|
||||
}
|
||||
public class aaa : BaseTableModel
|
||||
public class aaa : BaseTableModel{}
|
||||
|
||||
#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 关闭和测试按钮
|
||||
private void OnCloseMainWindowButtonClick(object sender, RoutedEventArgs e) => WindowHelper.CloseWindow(this); /// 按钮点击触发关闭页面
|
||||
private void OnDemoButtonClick(object sender, RoutedEventArgs e){} /// 测试按钮
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 控制传感器的采集开始和结束
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnSensorControl_Click(object sender, RoutedEventArgs e) {
|
||||
if (!isDetecting)
|
||||
{
|
||||
// 开始检测
|
||||
// 清空之前图表数据
|
||||
chartManager.ClearAllCharts();
|
||||
sensorManager.Start();
|
||||
BtnSensorControl.Content = "检测确定";
|
||||
isDetecting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 停止检测
|
||||
sensorManager.Stop();
|
||||
BtnSensorControl.Content = "检测开始";
|
||||
isDetecting = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
195
Services/ChartManager.cs
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
using guoke;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Wpf;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace WpfApp.Services;
|
||||
|
||||
public class ChartManager
|
||||
{
|
||||
private readonly Dispatcher dispatcher;
|
||||
private readonly LogService log;
|
||||
private readonly DatabaseService db;
|
||||
private readonly EventService<GeneralEventArgs> even;
|
||||
|
||||
private const string SENSOR_DATA_EVENT = "SensorDataUpdate";
|
||||
|
||||
// 最大保留点数
|
||||
private const int MAX_POINTS = 20;
|
||||
|
||||
// 每个图表的数据封装
|
||||
private class ChartData
|
||||
{
|
||||
public ColumnSeries ColumnSeries;
|
||||
public ChartValues<double> StandardMin = new ChartValues<double>();
|
||||
public ChartValues<double> StandardAvg = new ChartValues<double>();
|
||||
public ChartValues<double> StandardMax = new ChartValues<double>();
|
||||
public List<string> Labels = new List<string>();
|
||||
}
|
||||
|
||||
// 管理多个图表
|
||||
private Dictionary<CartesianChart, ChartData> charts = new Dictionary<CartesianChart, ChartData>();
|
||||
|
||||
public ChartManager(Dispatcher uiDispatcher,
|
||||
LogService logService,
|
||||
DatabaseService databaseService,
|
||||
EventService<GeneralEventArgs> eventService)
|
||||
{
|
||||
dispatcher = uiDispatcher;
|
||||
log = logService;
|
||||
db = databaseService;
|
||||
even = eventService;
|
||||
|
||||
SubscribeToSensorDataEvents();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化图表(一次性设置标准线和柱状图)
|
||||
/// </summary>
|
||||
public void InitChart(CartesianChart chart)
|
||||
{
|
||||
dispatcher.Invoke(() =>
|
||||
{
|
||||
if (chart == null) return;
|
||||
|
||||
// 如果已经初始化过,先清除
|
||||
if (charts.ContainsKey(chart))
|
||||
{
|
||||
charts.Remove(chart);
|
||||
}
|
||||
|
||||
var data = new ChartData();
|
||||
data.ColumnSeries = new ColumnSeries
|
||||
{
|
||||
Title = "实时值",
|
||||
Values = new ChartValues<double>()
|
||||
};
|
||||
|
||||
var line1 = new LineSeries { Title = "标准下限", Values = data.StandardMin };
|
||||
var line2 = new LineSeries { Title = "标准均值", Values = data.StandardAvg };
|
||||
var line3 = new LineSeries { Title = "标准上限", Values = data.StandardMax };
|
||||
|
||||
chart.Series = new SeriesCollection { data.ColumnSeries, line1, line2, line3 };
|
||||
|
||||
chart.AxisX.Clear();
|
||||
chart.AxisY.Clear();
|
||||
|
||||
chart.AxisX.Add(new Axis
|
||||
{
|
||||
Title = "时间",
|
||||
Labels = data.Labels
|
||||
});
|
||||
|
||||
chart.AxisY.Add(new Axis
|
||||
{
|
||||
Title = "数值"
|
||||
});
|
||||
|
||||
charts[chart] = data;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收到传感器实时数据(单点更新)
|
||||
/// </summary>
|
||||
private void OnSensorDataReceived(object sender, GeneralEventArgs e)
|
||||
{
|
||||
if (e is SensorDataEventArgs sensorArgs)
|
||||
{
|
||||
string chartTitle = sensorArgs.ChartTitle; // 例如 "myChart1"
|
||||
double value = sensorArgs.SensorValue;
|
||||
string timeLabel = DateTime.Now.ToString("HH:mm:ss");
|
||||
|
||||
// 找到对应图表并更新
|
||||
foreach (var chart in charts.Keys)
|
||||
{
|
||||
if (chart.Name == chartTitle)
|
||||
{
|
||||
UpdateChartPoint(chart, timeLabel, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新单个图表的数据点(柱状图 + 标准线 + X轴标签)
|
||||
/// </summary>
|
||||
public void UpdateChartPoint(CartesianChart chart, string label, double value)
|
||||
{
|
||||
if (chart == null || !charts.TryGetValue(chart, out var data))
|
||||
return;
|
||||
|
||||
dispatcher.Invoke(() =>
|
||||
{
|
||||
// 保留四位小数
|
||||
double roundedValue = Math.Round(value, 4);
|
||||
data.ColumnSeries.Values.Add(roundedValue);
|
||||
// 对标准线固定值,强制 double
|
||||
data.StandardMin.Add(Math.Round((double)5, 4));
|
||||
data.StandardAvg.Add(Math.Round((double)10, 4));
|
||||
data.StandardMax.Add(Math.Round((double)30, 4));
|
||||
data.Labels.Add(label);
|
||||
|
||||
// 超过最大点数时,移除最旧的数据
|
||||
if (data.ColumnSeries.Values.Count > MAX_POINTS)
|
||||
{
|
||||
data.ColumnSeries.Values.RemoveAt(0);
|
||||
data.StandardMin.RemoveAt(0);
|
||||
data.StandardAvg.RemoveAt(0);
|
||||
data.StandardMax.RemoveAt(0);
|
||||
data.Labels.RemoveAt(0);
|
||||
}
|
||||
|
||||
// 刷新 X 轴标签
|
||||
chart.AxisX[0].Labels = new List<string>(data.Labels);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手动添加数据到指定图表
|
||||
/// </summary>
|
||||
public void AddData(CartesianChart chart, double value, string label)
|
||||
{
|
||||
UpdateChartPoint(chart, label, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手动清除指定图表的数据
|
||||
/// </summary>
|
||||
public void ClearChart(CartesianChart chart)
|
||||
{
|
||||
if (chart == null || !charts.TryGetValue(chart, out var data))
|
||||
return;
|
||||
|
||||
dispatcher.Invoke(() =>
|
||||
{
|
||||
data.ColumnSeries.Values.Clear();
|
||||
data.StandardMin.Clear();
|
||||
data.StandardAvg.Clear();
|
||||
data.StandardMax.Clear();
|
||||
data.Labels.Clear();
|
||||
chart.AxisX[0].Labels.Clear();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除所有图表
|
||||
/// </summary>
|
||||
public void ClearAllCharts()
|
||||
{
|
||||
foreach (var chart in charts.Keys)
|
||||
{
|
||||
ClearChart(chart);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订阅传感器数据事件
|
||||
/// </summary>
|
||||
private void SubscribeToSensorDataEvents()
|
||||
{
|
||||
even?.AddEventHandler(SENSOR_DATA_EVENT, OnSensorDataReceived);
|
||||
}
|
||||
}
|
||||
95
Services/SensorChartManager.cs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
using guoke;
|
||||
using System.Windows;
|
||||
using WpfApp.src.components;
|
||||
|
||||
namespace WpfApp.Services;
|
||||
|
||||
/// <summary>
|
||||
/// SensorChart 管理器 - 负责传感器数据采集和更新
|
||||
/// </summary>
|
||||
public class SensorChartManager
|
||||
{
|
||||
private readonly Window dispatcherOwner;
|
||||
private CancellationTokenSource cts;
|
||||
private readonly Random rand = new Random();
|
||||
private readonly LogService log;
|
||||
private readonly DatabaseService db;
|
||||
private readonly EventService<GeneralEventArgs> even;
|
||||
|
||||
// 事件名称常量
|
||||
private const string SENSOR_DATA_EVENT = "SensorDataUpdate";
|
||||
|
||||
|
||||
// 绑定的传感器控件
|
||||
public SensorChart Sensor1 { get; set; }
|
||||
public SensorChart Sensor2 { get; set; }
|
||||
public SensorChart Sensor3 { get; set; }
|
||||
|
||||
public SensorChartManager(Window owner, LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
|
||||
{
|
||||
dispatcherOwner = owner;
|
||||
log = logService;
|
||||
db = databaseService;
|
||||
even = eventService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动模拟数据采集
|
||||
/// </summary>
|
||||
public void Start()
|
||||
{
|
||||
if (Sensor1 == null || Sensor2 == null || Sensor3 == null)
|
||||
throw new InvalidOperationException("请先绑定传感器控件");
|
||||
|
||||
cts = new CancellationTokenSource();
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
while (!cts.Token.IsCancellationRequested)
|
||||
{
|
||||
// 模拟数据
|
||||
double s1 = rand.NextDouble() * 100 - 50;
|
||||
double s2 = rand.NextDouble() * 100 - 50;
|
||||
double s3 = rand.NextDouble() * 100 - 50;
|
||||
|
||||
// 更新 UI
|
||||
dispatcherOwner.Dispatcher.Invoke(() =>
|
||||
{
|
||||
Sensor1.SetSensorData("传感器1", s1);
|
||||
Sensor2.SetSensorData("传感器2", s2);
|
||||
Sensor3.SetSensorData("传感器3", s3);
|
||||
|
||||
// 通过事件将传感器数据传递到ChartManager
|
||||
PublishSensorData("传感器1", s1, "myChart1");
|
||||
PublishSensorData("传感器2", s2, "myChart2");
|
||||
PublishSensorData("传感器3", s3, "myChart3");
|
||||
});
|
||||
|
||||
await Task.Delay(1000); // 每1000毫秒采集一次
|
||||
}
|
||||
}, cts.Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止采集
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
cts?.Cancel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发布传感器数据事件
|
||||
/// </summary>
|
||||
/// <param name="sensorTitle">传感器标题</param>
|
||||
/// <param name="sensorValue">传感器值</param>
|
||||
/// <param name="chartTitle">图表标题</param>
|
||||
private void PublishSensorData(string sensorTitle, double sensorValue, string chartTitle)
|
||||
{
|
||||
if (even != null)
|
||||
{
|
||||
var eventArgs = new SensorDataEventArgs(sensorTitle, sensorValue, chartTitle);
|
||||
even.TriggerEvent(SENSOR_DATA_EVENT, this, eventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Services/SensorDataEventArgs.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using guoke;
|
||||
|
||||
namespace WpfApp.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 传感器数据事件参数类,用于传递传感器的实时数据
|
||||
/// </summary>
|
||||
public class SensorDataEventArgs : GeneralEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 传感器标题/名称
|
||||
/// </summary>
|
||||
public string SensorTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 传感器实时值
|
||||
/// </summary>
|
||||
public double SensorValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图表标题,用于区分不同的图表
|
||||
/// </summary>
|
||||
public string ChartTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 初始化传感器数据事件参数
|
||||
/// </summary>
|
||||
/// <param name="sensorTitle">传感器标题</param>
|
||||
/// <param name="sensorValue">传感器实时值</param>
|
||||
/// <param name="chartTitle">图表标题</param>
|
||||
public SensorDataEventArgs(string sensorTitle, double sensorValue, string chartTitle)
|
||||
: base($"传感器数据更新: {sensorTitle}", sensorValue)
|
||||
{
|
||||
SensorTitle = sensorTitle;
|
||||
SensorValue = sensorValue;
|
||||
ChartTitle = chartTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
141
Utils/ExcelHelper.cs
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using unvell.ReoGrid;
|
||||
|
||||
namespace WpfApp.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Excel 操作静态工具类(基于 ReoGrid)
|
||||
/// </summary>
|
||||
public static class ExcelHelper
|
||||
{
|
||||
private static ReoGridControl reoGridControl;
|
||||
private static Worksheet currentSheet;
|
||||
|
||||
static ExcelHelper()
|
||||
{
|
||||
reoGridControl = new ReoGridControl();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从模板加载 Excel 文件
|
||||
/// </summary>
|
||||
public static void LoadTemplate(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
throw new FileNotFoundException($"模板文件不存在: {filePath}");
|
||||
|
||||
reoGridControl.Load(filePath);
|
||||
currentSheet = reoGridControl.CurrentWorksheet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换到指定工作表
|
||||
/// </summary>
|
||||
public static void SelectSheet(string sheetName)
|
||||
{
|
||||
if (reoGridControl == null)
|
||||
throw new InvalidOperationException("请先调用 LoadTemplate 方法加载文件。");
|
||||
|
||||
var sheet = reoGridControl.Worksheets[sheetName];
|
||||
if (sheet == null)
|
||||
throw new ArgumentException($"未找到名为 '{sheetName}' 的工作表。");
|
||||
|
||||
currentSheet = sheet;
|
||||
reoGridControl.CurrentWorksheet = sheet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前工作表名称
|
||||
/// </summary>
|
||||
public static string GetCurrentSheetName()
|
||||
{
|
||||
return currentSheet?.Name ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取单元格
|
||||
/// </summary>
|
||||
public static object ReadCell(string cellName)
|
||||
{
|
||||
return currentSheet?.GetCellData(cellName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置单元格值
|
||||
/// </summary>
|
||||
public static void WriteCell(string cellName, object value)
|
||||
{
|
||||
currentSheet?.SetCellData(cellName, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量写入单元格
|
||||
/// </summary>
|
||||
public static void WriteCells(Dictionary<string, object> cellValues)
|
||||
{
|
||||
foreach (var kv in cellValues)
|
||||
{
|
||||
currentSheet?.SetCellData(kv.Key, kv.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在指定行插入数据(从 startColumn 开始)
|
||||
/// </summary>
|
||||
public static void InsertRowData(int rowIndex, int startColumn, IList<object> values)
|
||||
{
|
||||
if (currentSheet == null)
|
||||
throw new InvalidOperationException("请先加载模板并选择工作表。");
|
||||
|
||||
for (int i = 0; i < values.Count; i++)
|
||||
{
|
||||
currentSheet[rowIndex, startColumn + i] = values[i];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存为新文件
|
||||
/// </summary>
|
||||
public static void SaveAs(string savePath)
|
||||
{
|
||||
if (reoGridControl == null)
|
||||
throw new InvalidOperationException("请先调用 LoadTemplate 方法加载文件。");
|
||||
|
||||
reoGridControl.Save(savePath, unvell.ReoGrid.IO.FileFormat.Excel2007);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开 Excel 文件(并显示到 ReoGrid 控件)
|
||||
/// </summary>
|
||||
/// <param name="filePath">Excel 文件路径</param>
|
||||
/// <param name="reoGridHost">用于显示的 ReoGridControl 容器</param>
|
||||
public static void OpenExcel(string filePath, ReoGridControl reoGridHost)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
throw new FileNotFoundException($"文件不存在: {filePath}");
|
||||
|
||||
// 替换当前控件引用
|
||||
reoGridControl?.Dispose();
|
||||
reoGridControl = reoGridHost;
|
||||
|
||||
// 加载 Excel 文件
|
||||
reoGridControl.Load(filePath);
|
||||
|
||||
// 默认显示第一个工作表
|
||||
currentSheet = reoGridControl.CurrentWorksheet;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 清理资源
|
||||
/// </summary>
|
||||
public static void Dispose()
|
||||
{
|
||||
reoGridControl?.Dispose();
|
||||
reoGridControl = null;
|
||||
currentSheet = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
86
Utils/IconHelper.cs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace WpfApp.Utils
|
||||
{
|
||||
public static class IconHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取图标路径(智能搜索)
|
||||
/// </summary>
|
||||
/// <param name="iconFileName">图标文件名,例如 "FMSDGAUGE-main.ico",为空使用默认图标</param>
|
||||
/// <param name="externalDirs">可选外部搜索目录</param>
|
||||
/// <returns>图标绝对路径</returns>
|
||||
public static string GetIconPath(string iconFileName = null, string[] externalDirs = null)
|
||||
{
|
||||
// 默认图标文件名
|
||||
string defaultIconName = "FMSDGAUGE-main.ico";
|
||||
iconFileName ??= defaultIconName;
|
||||
|
||||
// 默认项目图标目录(相对于 EXE)
|
||||
string projectIconDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\src\public");
|
||||
|
||||
// 先搜索项目目录
|
||||
string path = SearchDirectory(projectIconDir, iconFileName);
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
return path;
|
||||
|
||||
// 再搜索外部目录
|
||||
if (externalDirs != null)
|
||||
{
|
||||
foreach (var dir in externalDirs)
|
||||
{
|
||||
path = SearchDirectory(dir, iconFileName);
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
// 都没找到就抛异常
|
||||
throw new FileNotFoundException($"找不到图标文件: {iconFileName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取图标目录路径(智能推断)
|
||||
/// </summary>
|
||||
/// <param name="externalDirs">可选外部搜索目录</param>
|
||||
/// <returns>图标目录的绝对路径</returns>
|
||||
public static string GetIconDirectoryPath(string[] externalDirs = null)
|
||||
{
|
||||
// 默认项目图标目录(相对于 EXE)
|
||||
string projectIconDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\src\public");
|
||||
string fullPath = Path.GetFullPath(projectIconDir);
|
||||
|
||||
if (Directory.Exists(fullPath))
|
||||
return fullPath;
|
||||
|
||||
// 如果外部目录存在则返回第一个有效路径
|
||||
if (externalDirs != null)
|
||||
{
|
||||
foreach (var dir in externalDirs)
|
||||
{
|
||||
if (Directory.Exists(dir))
|
||||
return Path.GetFullPath(dir);
|
||||
}
|
||||
}
|
||||
|
||||
// 否则抛异常
|
||||
throw new DirectoryNotFoundException($"找不到图标目录: {fullPath}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在指定目录及子目录搜索文件
|
||||
/// </summary>
|
||||
private static string SearchDirectory(string rootDir, string fileName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rootDir) || !Directory.Exists(rootDir))
|
||||
return null;
|
||||
|
||||
var files = Directory.GetFiles(rootDir, fileName, SearchOption.AllDirectories);
|
||||
if (files.Length > 0)
|
||||
return Path.GetFullPath(files[0]);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
58
Utils/InitChart.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
using LiveCharts;
|
||||
using LiveCharts.Wpf;
|
||||
using System.Windows.Media;
|
||||
using WpfApp.src.config;
|
||||
|
||||
namespace WpfApp.Utils;
|
||||
|
||||
public static class InitChart
|
||||
{
|
||||
public static void InitCartesianChart(CartesianChart chart, ChartConfig config)
|
||||
{
|
||||
chart.Series = new SeriesCollection();
|
||||
|
||||
// 柱状图
|
||||
if (config.ColumnData != null && config.ColumnData.Count > 0)
|
||||
{
|
||||
chart.Series.Add(new ColumnSeries
|
||||
{
|
||||
Title = "柱状数据",
|
||||
Values = new ChartValues<double>(config.ColumnData)
|
||||
});
|
||||
}
|
||||
|
||||
// 标准线条
|
||||
foreach (var line in config.LineConfigs)
|
||||
{
|
||||
var lineSeries = new LineSeries
|
||||
{
|
||||
Title = line.Title,
|
||||
Values = new ChartValues<double>(line.Values),
|
||||
Stroke = line.Stroke ?? Brushes.Black,
|
||||
StrokeThickness = 2,
|
||||
Fill = Brushes.Transparent,
|
||||
DataLabels = line.ShowLabel,
|
||||
};
|
||||
|
||||
if (line.ShowLabel)
|
||||
lineSeries.LabelPoint = value => $"{value.Y:0.##} {line.Unit}";
|
||||
|
||||
chart.Series.Add(lineSeries);
|
||||
}
|
||||
|
||||
// X轴
|
||||
chart.AxisX.Clear();
|
||||
chart.AxisX.Add(new Axis
|
||||
{
|
||||
Title = config.XTitle ?? "",
|
||||
Labels = config.Labels
|
||||
});
|
||||
|
||||
// Y轴
|
||||
chart.AxisY.Clear();
|
||||
chart.AxisY.Add(new Axis
|
||||
{
|
||||
Title = config.YTitle ?? ""
|
||||
});
|
||||
}
|
||||
}
|
||||
71
Utils/WindowHelper.cs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace WpfApp.Utils
|
||||
{
|
||||
public static class WindowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 通用窗口打开方法
|
||||
/// </summary>
|
||||
/// <param name="page">要显示的页面实例</param>
|
||||
/// <param name="title">窗口标题</param>
|
||||
/// <param name="width">窗口宽度</param>
|
||||
/// <param name="height">窗口高度</param>
|
||||
/// <param name="isResizable">是否允许调整大小</param>
|
||||
/// <param name="iconPath">可选图标路径,如果为空使用默认图标</param>
|
||||
public static void ShowPageDialog(Page page, string title, double width = 900, double height = 600, bool isResizable = false, string iconPath = null)
|
||||
{
|
||||
var navWin = new NavigationWindow
|
||||
{
|
||||
Content = page,
|
||||
Title = title,
|
||||
Width = width,
|
||||
Height = height,
|
||||
ShowsNavigationUI = false,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterOwner,
|
||||
WindowStyle = WindowStyle.ToolWindow,
|
||||
Owner = Application.Current.MainWindow,
|
||||
ResizeMode = isResizable ? ResizeMode.CanResize : ResizeMode.NoResize
|
||||
};
|
||||
string defaultIconPath = iconPath == null ? IconHelper.GetIconPath("FMSDGAUGE-main.ico") : iconPath;
|
||||
|
||||
try
|
||||
{
|
||||
navWin.Icon = new BitmapImage(new Uri(System.IO.Path.GetFullPath(defaultIconPath), UriKind.Absolute));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"设置图标失败: {ex.Message}");
|
||||
}
|
||||
|
||||
|
||||
navWin.ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定窗口的标题
|
||||
/// </summary>
|
||||
/// <param name="window">目标窗口</param>
|
||||
/// <param name="newTitle">新标题</param>
|
||||
public static void SetWindowTitle(Window window, string newTitle)
|
||||
{
|
||||
if (window != null)
|
||||
{
|
||||
window.Title = newTitle;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭窗口
|
||||
/// </summary>
|
||||
/// <param name="window"></param>
|
||||
public static void CloseWindow(Window window)
|
||||
{
|
||||
window?.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,12 +8,62 @@
|
|||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="新文件夹\**" />
|
||||
<EmbeddedResource Remove="新文件夹\**" />
|
||||
<None Remove="新文件夹\**" />
|
||||
<Page Remove="新文件夹\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="src\public\Icons\main1-file-icon.png" />
|
||||
<None Remove="src\public\Icons\main2-config-icon.png" />
|
||||
<None Remove="src\public\Icons\main3-standard-icon.png" />
|
||||
<None Remove="src\public\Icons\main4-detection-icon.png" />
|
||||
<None Remove="src\public\Icons\main5-gauge-icon.png" />
|
||||
<None Remove="src\public\Icons\main6-cgCgk-icon.png" />
|
||||
<None Remove="src\public\Icons\main7-sysSet-icon.png" />
|
||||
<None Remove="src\public\Icons\main8-exit-icon.png" />
|
||||
<None Remove="src\public\Icons\programIcons\CgCgk.png" />
|
||||
<None Remove="src\public\Icons\programIcons\FMSDGAUGE-main.ico" />
|
||||
<None Remove="src\public\Icons\programIcons\FMSDGAUGE.png" />
|
||||
<None Remove="src\public\Icons\programIcons\main1-File.ico" />
|
||||
<None Remove="src\public\Icons\programIcons\main2-Config.ico" />
|
||||
<None Remove="src\public\Icons\programIcons\main3-Standard.ico" />
|
||||
<None Remove="src\public\Icons\programIcons\main4-Gauge.ico" />
|
||||
<None Remove="src\public\Icons\programIcons\main5-CgCgk.ico" />
|
||||
<None Remove="src\public\Icons\programIcons\main6-SysSet.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="src\public\Icons\main6-cgCgk-icon.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="src\public\Icons\main1-file-icon.png" />
|
||||
<Resource Include="src\public\Icons\main2-config-icon.png" />
|
||||
<Resource Include="src\public\Icons\main3-standard-icon.png" />
|
||||
<Resource Include="src\public\Icons\main4-detection-icon.png" />
|
||||
<Resource Include="src\public\Icons\main5-gauge-icon.png" />
|
||||
<Resource Include="src\public\Icons\main7-sysSet-icon.png" />
|
||||
<Resource Include="src\public\Icons\main8-exit-icon.png" />
|
||||
<Resource Include="src\public\Icons\programIcons\FMSDGAUGE-main.ico" />
|
||||
<Resource Include="src\public\Icons\programIcons\main1-File.ico" />
|
||||
<Resource Include="src\public\Icons\programIcons\main2-Config.ico" />
|
||||
<Resource Include="src\public\Icons\programIcons\main3-Standard.ico" />
|
||||
<Resource Include="src\public\Icons\programIcons\main4-Gauge.ico" />
|
||||
<Resource Include="src\public\Icons\programIcons\main5-CgCgk.ico" />
|
||||
<Resource Include="src\public\Icons\programIcons\main6-SysSet.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HslCommunication" Version="12.5.1" />
|
||||
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.205" />
|
||||
<PackageReference Include="System.Management" Version="8.0.0" />
|
||||
<PackageReference Include="unvell.ReoGridWPF.dll" Version="3.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -22,4 +72,8 @@
|
|||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="src\public\Excel\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,14 @@
|
|||
"Connection": "DataSource=LocalData.db",
|
||||
"Remarks": "",
|
||||
"Print": false
|
||||
},
|
||||
{
|
||||
"Name": "D1",
|
||||
"Enabled": true,
|
||||
"Type": 2,
|
||||
"Connection": "DataSource=D1.db",
|
||||
"Remarks": "产品数据库",
|
||||
"Print": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
135
src/components/SensorChart.xaml
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
<UserControl x:Class="WpfApp.src.components.SensorChart"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:WpfApp.src.components"
|
||||
mc:Ignorable="d" d:DesignWidth="200" >
|
||||
<Border Background="White" BorderBrush="#CCCCCC" BorderThickness="1">
|
||||
<Grid Margin="0,0,0,-1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题栏 -->
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="{Binding SensorName, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
FontWeight="Bold"
|
||||
Background="{Binding HeaderBackground, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
|
||||
|
||||
<!-- 等级选择栏 -->
|
||||
<Grid Grid.Row="1" Margin="25,2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="等级:"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="10"
|
||||
Margin="0,0,5,0"/>
|
||||
|
||||
<ComboBox Grid.Column="1"
|
||||
Name="LevelComboBox"
|
||||
Height="20"
|
||||
FontSize="10"
|
||||
SelectedValue="{Binding Level, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
SelectedValuePath="Tag">
|
||||
<ComboBoxItem Content="低" Tag="{x:Static local:SensorLevel.Low}"/>
|
||||
<ComboBoxItem Content="中" Tag="{x:Static local:SensorLevel.Medium}" IsSelected="True"/>
|
||||
<ComboBoxItem Content="高" Tag="{x:Static local:SensorLevel.High}"/>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
|
||||
<!-- 图表区域 -->
|
||||
<Viewbox Grid.Row="2" Stretch="Uniform">
|
||||
<Canvas Width="160" Height="440" Grid.Row="1" Background="White" Margin="20,20,20,3" Name="ChartCanvas">
|
||||
<!-- 柱状图容器边框 - 左边界线 -->
|
||||
<Line X1="40" Y1="20" X2="40" Y2="420" Stroke="Black" StrokeThickness="1"/>
|
||||
<!-- 右边界线 -->
|
||||
<Line X1="120" Y1="20" X2="120" Y2="420" Stroke="Black" StrokeThickness="1"/>
|
||||
<!-- 顶部边界线 -->
|
||||
<Line X1="40" Y1="20" X2="120" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<!-- 底部边界线 -->
|
||||
<Line X1="40" Y1="420" X2="120" Y2="420" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
<!-- 动态刻度线 -->
|
||||
<ItemsControl ItemsSource="{Binding ScaleLines}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="0"/>
|
||||
<Setter Property="Canvas.Top" Value="0"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Canvas>
|
||||
<!-- 刻度线 -->
|
||||
<Line X1="{Binding X1}" Y1="{Binding Y1}"
|
||||
X2="{Binding X2}" Y2="{Binding Y2}"
|
||||
Stroke="Black"
|
||||
StrokeThickness="{Binding StrokeThickness}"/>
|
||||
<!-- 刻度标签 -->
|
||||
<TextBlock Canvas.Left="{Binding LabelX}"
|
||||
Canvas.Top="{Binding LabelY}"
|
||||
Text="{Binding Label}"
|
||||
FontSize="10">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsMainScale}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Canvas>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<!-- 柱状图数据 - 紧贴左右边界 -->
|
||||
<Rectangle Name="DataBar"
|
||||
Canvas.Left="40"
|
||||
Canvas.Top="{Binding BarTop, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
Width="80"
|
||||
Height="{Binding BarHeight, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
Fill="Blue"
|
||||
Opacity="0.7"/>
|
||||
|
||||
<!-- 红色标记线 -->
|
||||
<ItemsControl Name="RedLines" ItemsSource="{Binding RedLinePositions, RelativeSource={RelativeSource AncestorType=UserControl}}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Line X1="40" Y1="{Binding}" X2="120" Y2="{Binding}" Stroke="Red" StrokeThickness="2"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Top" Value="0"/>
|
||||
<Setter Property="Canvas.Left" Value="0"/>
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
</ItemsControl>
|
||||
</Canvas>
|
||||
</Viewbox>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
409
src/components/SensorChart.xaml.cs
Normal file
|
|
@ -0,0 +1,409 @@
|
|||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace WpfApp.src.components;
|
||||
|
||||
/// <summary>
|
||||
/// 刻度线数据结构
|
||||
/// </summary>
|
||||
public class ScaleLine
|
||||
{
|
||||
public double Y1 { get; set; }
|
||||
public double Y2 { get; set; }
|
||||
public double X1 { get; set; }
|
||||
public double X2 { get; set; }
|
||||
public double StrokeThickness { get; set; }
|
||||
public string Label { get; set; }
|
||||
public double LabelX { get; set; }
|
||||
public double LabelY { get; set; }
|
||||
public bool IsMainScale { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SensorChart.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SensorChart : UserControl, INotifyPropertyChanged
|
||||
{
|
||||
public SensorChart()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
|
||||
// 设置默认值
|
||||
SensorName = "传感器";
|
||||
HeaderBackground = new SolidColorBrush(Color.FromRgb(230, 243, 255)); // #E6F3FF
|
||||
Value = 0;
|
||||
RedLineValues = new List<double>();
|
||||
Level = SensorLevel.Medium; // 默认中等
|
||||
|
||||
// 生成初始刻度
|
||||
GenerateScaleLines();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
#region 依赖属性
|
||||
|
||||
// 传感器名称
|
||||
public static readonly DependencyProperty SensorNameProperty =
|
||||
DependencyProperty.Register("SensorName", typeof(string), typeof(SensorChart),
|
||||
new PropertyMetadata("传感器", OnSensorNameChanged));
|
||||
|
||||
public string SensorName
|
||||
{
|
||||
get { return (string)GetValue(SensorNameProperty); }
|
||||
set { SetValue(SensorNameProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnSensorNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var control = d as SensorChart;
|
||||
control?.OnPropertyChanged(nameof(SensorName));
|
||||
}
|
||||
|
||||
// 标题背景色
|
||||
public static readonly DependencyProperty HeaderBackgroundProperty =
|
||||
DependencyProperty.Register("HeaderBackground", typeof(Brush), typeof(SensorChart),
|
||||
new PropertyMetadata(new SolidColorBrush(Color.FromRgb(230, 243, 255)), OnHeaderBackgroundChanged));
|
||||
|
||||
public Brush HeaderBackground
|
||||
{
|
||||
get { return (Brush)GetValue(HeaderBackgroundProperty); }
|
||||
set { SetValue(HeaderBackgroundProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnHeaderBackgroundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var control = d as SensorChart;
|
||||
control?.OnPropertyChanged(nameof(HeaderBackground));
|
||||
}
|
||||
|
||||
// 数值
|
||||
public static readonly DependencyProperty ValueProperty =
|
||||
DependencyProperty.Register("Value", typeof(double), typeof(SensorChart),
|
||||
new PropertyMetadata(0.0, OnValueChanged));
|
||||
|
||||
public double Value
|
||||
{
|
||||
get { return (double)GetValue(ValueProperty); }
|
||||
set { SetValue(ValueProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var control = d as SensorChart;
|
||||
control?.UpdateBarPosition();
|
||||
}
|
||||
|
||||
// 红线数值列表
|
||||
public static readonly DependencyProperty RedLineValuesProperty =
|
||||
DependencyProperty.Register("RedLineValues", typeof(List<double>), typeof(SensorChart),
|
||||
new PropertyMetadata(new List<double>(), OnRedLineValuesChanged));
|
||||
|
||||
public List<double> RedLineValues
|
||||
{
|
||||
get { return (List<double>)GetValue(RedLineValuesProperty); }
|
||||
set { SetValue(RedLineValuesProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnRedLineValuesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var control = d as SensorChart;
|
||||
control?.UpdateRedLinePositions();
|
||||
}
|
||||
|
||||
// 传感器等级
|
||||
public static readonly DependencyProperty LevelProperty =
|
||||
DependencyProperty.Register("Level", typeof(SensorLevel), typeof(SensorChart),
|
||||
new PropertyMetadata(SensorLevel.Medium, OnLevelChanged));
|
||||
|
||||
public SensorLevel Level
|
||||
{
|
||||
get { return (SensorLevel)GetValue(LevelProperty); }
|
||||
set { SetValue(LevelProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnLevelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var control = d as SensorChart;
|
||||
control?.OnLevelChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 计算属性
|
||||
|
||||
private double _barTop;
|
||||
public double BarTop
|
||||
{
|
||||
get { return _barTop; }
|
||||
private set
|
||||
{
|
||||
_barTop = value;
|
||||
OnPropertyChanged(nameof(BarTop));
|
||||
}
|
||||
}
|
||||
|
||||
private double _barHeight;
|
||||
public double BarHeight
|
||||
{
|
||||
get { return _barHeight; }
|
||||
private set
|
||||
{
|
||||
_barHeight = value;
|
||||
OnPropertyChanged(nameof(BarHeight));
|
||||
}
|
||||
}
|
||||
|
||||
private List<double> _redLinePositions = new List<double>();
|
||||
public List<double> RedLinePositions
|
||||
{
|
||||
get { return _redLinePositions; }
|
||||
private set
|
||||
{
|
||||
_redLinePositions = value;
|
||||
OnPropertyChanged(nameof(RedLinePositions));
|
||||
}
|
||||
}
|
||||
|
||||
private List<ScaleLine> _scaleLines = new List<ScaleLine>();
|
||||
public List<ScaleLine> ScaleLines
|
||||
{
|
||||
get { return _scaleLines; }
|
||||
private set
|
||||
{
|
||||
_scaleLines = value;
|
||||
OnPropertyChanged(nameof(ScaleLines));
|
||||
}
|
||||
}
|
||||
|
||||
// 当前等级的最小值
|
||||
public double MinValue
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Level)
|
||||
{
|
||||
case SensorLevel.Low: return -20;
|
||||
case SensorLevel.Medium: return -40;
|
||||
case SensorLevel.High: return -60;
|
||||
default: return -40;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 当前等级的最大值
|
||||
public double MaxValue
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Level)
|
||||
{
|
||||
case SensorLevel.Low: return 20;
|
||||
case SensorLevel.Medium: return 40;
|
||||
case SensorLevel.High: return 60;
|
||||
default: return 40;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 私有方法
|
||||
|
||||
/// <summary>
|
||||
/// 等级改变时的处理
|
||||
/// </summary>
|
||||
private void OnLevelChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(Level));
|
||||
OnPropertyChanged(nameof(MinValue));
|
||||
OnPropertyChanged(nameof(MaxValue));
|
||||
GenerateScaleLines();
|
||||
UpdateBarPosition();
|
||||
UpdateRedLinePositions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成刻度线
|
||||
/// </summary>
|
||||
private void GenerateScaleLines()
|
||||
{
|
||||
var lines = new List<ScaleLine>();
|
||||
double minVal = MinValue;
|
||||
double maxVal = MaxValue;
|
||||
|
||||
// 根据等级确定刻度间隔
|
||||
double mainInterval = (maxVal - minVal) / 8; // 8个主刻度间隔
|
||||
double subInterval = mainInterval / 4; // 每个主刻度间隔4个小刻度
|
||||
|
||||
// 生成主刻度线
|
||||
for (int i = 0; i <= 8; i++)
|
||||
{
|
||||
double value = maxVal - i * mainInterval;
|
||||
double y = ValueToY(value);
|
||||
|
||||
lines.Add(new ScaleLine
|
||||
{
|
||||
X1 = 40,
|
||||
Y1 = y,
|
||||
X2 = 130,
|
||||
Y2 = y,
|
||||
StrokeThickness = 1,
|
||||
Label = value.ToString("0"),
|
||||
LabelX = 135,
|
||||
LabelY = y - 5,
|
||||
IsMainScale = true
|
||||
});
|
||||
|
||||
// 生成小刻度线(除了最后一个主刻度)
|
||||
if (i < 8)
|
||||
{
|
||||
for (int j = 1; j < 4; j++)
|
||||
{
|
||||
double subValue = value - j * subInterval;
|
||||
double subY = ValueToY(subValue);
|
||||
|
||||
lines.Add(new ScaleLine
|
||||
{
|
||||
X1 = 40,
|
||||
Y1 = subY,
|
||||
X2 = 125,
|
||||
Y2 = subY,
|
||||
StrokeThickness = 0.5,
|
||||
Label = "",
|
||||
LabelX = 0,
|
||||
LabelY = 0,
|
||||
IsMainScale = false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScaleLines = lines;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将数值转换为Y坐标位置
|
||||
/// 根据当前等级动态计算刻度范围
|
||||
/// </summary>
|
||||
/// <param name="value">数值</param>
|
||||
/// <returns>Y坐标</returns>
|
||||
private double ValueToY(double value)
|
||||
{
|
||||
double minVal = MinValue;
|
||||
double maxVal = MaxValue;
|
||||
|
||||
// 限制数值范围
|
||||
value = Math.Max(minVal, Math.Min(maxVal, value));
|
||||
|
||||
// 线性映射:maxVal对应Y=20,minVal对应Y=420
|
||||
double range = maxVal - minVal;
|
||||
return 220 - ((value - minVal) / range - 0.5) * 400;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新柱状图位置
|
||||
/// </summary>
|
||||
private void UpdateBarPosition()
|
||||
{
|
||||
if (Value >= 0)
|
||||
{
|
||||
// 正值:从0线向上
|
||||
BarTop = ValueToY(Value);
|
||||
BarHeight = ValueToY(0) - ValueToY(Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 负值:从0线向下
|
||||
BarTop = ValueToY(0);
|
||||
BarHeight = ValueToY(Value) - ValueToY(0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新红线位置
|
||||
/// </summary>
|
||||
private void UpdateRedLinePositions()
|
||||
{
|
||||
var positions = new List<double>();
|
||||
if (RedLineValues != null)
|
||||
{
|
||||
foreach (var value in RedLineValues)
|
||||
{
|
||||
positions.Add(ValueToY(value));
|
||||
}
|
||||
}
|
||||
RedLinePositions = positions;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 公共方法
|
||||
|
||||
/// <summary>
|
||||
/// 设置传感器数据
|
||||
/// </summary>
|
||||
/// <param name="name">传感器名称</param>
|
||||
/// <param name="value">数值</param>
|
||||
/// <param name="redLines">红线数值列表</param>
|
||||
/// <param name="headerColor">标题背景色</param>
|
||||
/// <param name="level">传感器等级</param>
|
||||
public void SetSensorData(string name, double value, List<double> redLines = null, Color? headerColor = null, SensorLevel? level = null)
|
||||
{
|
||||
SensorName = name;
|
||||
Value = value;
|
||||
|
||||
if (redLines != null)
|
||||
{
|
||||
RedLineValues = new List<double>(redLines);
|
||||
}
|
||||
|
||||
if (headerColor.HasValue)
|
||||
{
|
||||
HeaderBackground = new SolidColorBrush(headerColor.Value);
|
||||
}
|
||||
|
||||
if (level.HasValue)
|
||||
{
|
||||
Level = level.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加红线
|
||||
/// </summary>
|
||||
/// <param name="value">红线数值</param>
|
||||
public void AddRedLine(double value)
|
||||
{
|
||||
var lines = new List<double>(RedLineValues) { value };
|
||||
RedLineValues = lines;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除所有红线
|
||||
/// </summary>
|
||||
public void ClearRedLines()
|
||||
{
|
||||
RedLineValues = new List<double>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 传感器等级枚举
|
||||
/// </summary>
|
||||
public enum SensorLevel
|
||||
{
|
||||
Low, // 低等:-20到20
|
||||
Medium, // 中等:-40到40
|
||||
High // 高等:-60到60
|
||||
}
|
||||
36
src/config/ChartConfig.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System.Windows.Media;
|
||||
|
||||
namespace WpfApp.src.config;
|
||||
|
||||
public class ChartConfig
|
||||
{
|
||||
public List<double> ColumnData { get; set; } = new();
|
||||
public List<LineConfig> LineConfigs { get; set; } = new();
|
||||
public List<string> Labels { get; set; } = new();
|
||||
public string XTitle { get; set; }
|
||||
public string YTitle { get; set; }
|
||||
}
|
||||
|
||||
public class LineConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 曲线标题
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// 曲线的值
|
||||
/// </summary>
|
||||
public List<double> Values { get; set; }
|
||||
/// <summary>
|
||||
/// 曲线颜色
|
||||
/// </summary>
|
||||
public Brush Stroke { get; set; } = Brushes.Black;
|
||||
/// <summary>
|
||||
/// 是否显示数据点上的标签
|
||||
/// </summary>
|
||||
public bool ShowLabel { get; set; } = true;
|
||||
/// <summary>
|
||||
/// 单位
|
||||
/// </summary>
|
||||
public string Unit { get; set; } = "Hz";
|
||||
}
|
||||
91
src/controllers/MenuController.cs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
using guoke;
|
||||
using System.Windows;
|
||||
using WpfApp.src.view;
|
||||
using WpfApp.Utils;
|
||||
|
||||
namespace WpfApp.src.controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单控制器 - 统一管理菜单打开逻辑
|
||||
/// </summary>
|
||||
public class MenuController
|
||||
{
|
||||
private readonly Window mainWindow;
|
||||
private readonly LogService log;
|
||||
private readonly DatabaseService db;
|
||||
private readonly EventService<GeneralEventArgs> even;
|
||||
public MenuController(Window window, LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
|
||||
{
|
||||
log = logService;
|
||||
db = databaseService;
|
||||
even = eventService;
|
||||
mainWindow = window;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开文件记录列表页面
|
||||
/// </summary>
|
||||
public void OpenFilePage()
|
||||
{
|
||||
WindowHelper.ShowPageDialog(new FilePage(),
|
||||
"记录列表", 810, 600,
|
||||
isResizable: false,
|
||||
IconHelper.GetIconPath("main1-File.ico"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开配置页面
|
||||
/// </summary>
|
||||
public void OpenConfigPage()
|
||||
{
|
||||
WindowHelper.ShowPageDialog(new ConfigPage(log, db, even),
|
||||
"配置", 972, 648,
|
||||
isResizable: false,
|
||||
IconHelper.GetIconPath("main2-Config.ico"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开主标定页面
|
||||
/// </summary>
|
||||
public void OpenStandardPage()
|
||||
{
|
||||
WindowHelper.ShowPageDialog(new StandardPage(),
|
||||
"主标定", 972, 648,
|
||||
isResizable: true,
|
||||
IconHelper.GetIconPath("main3-Standard.ico"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开 Gauge R&R 页面
|
||||
/// </summary>
|
||||
public void OpenGaugePage()
|
||||
{
|
||||
WindowHelper.ShowPageDialog(new GaugePage(),
|
||||
"Gauge R&&R", 1080, 720,
|
||||
isResizable: false,
|
||||
IconHelper.GetIconPath("main4-Gauge.ico"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开 CgCgk 页面
|
||||
/// </summary>
|
||||
public void OpenCgCgkPage()
|
||||
{
|
||||
WindowHelper.ShowPageDialog(new CgCgkPage(),
|
||||
"CgCgk", 972, 648,
|
||||
isResizable: true,
|
||||
IconHelper.GetIconPath("main5-CgCgk.ico"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开系统设置页面
|
||||
/// </summary>
|
||||
public void OpenSysSetPage()
|
||||
{
|
||||
WindowHelper.ShowPageDialog(new SysSetPage(),
|
||||
"系统设置", 810, 600,
|
||||
isResizable: false,
|
||||
IconHelper.GetIconPath("main6-SysSet.ico"));
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
src/public/Excel/Report_2025_10_13.xlsx
Normal file
BIN
src/public/Excel/demo.xlsx
Normal file
BIN
src/public/Icons/main1-file-icon.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
src/public/Icons/main2-config-icon.png
Normal file
|
After Width: | Height: | Size: 4.1 KiB |
BIN
src/public/Icons/main3-standard-icon.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
src/public/Icons/main4-detection-icon.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
src/public/Icons/main5-gauge-icon.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
src/public/Icons/main6-cgCgk-icon.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
src/public/Icons/main7-sysSet-icon.png
Normal file
|
After Width: | Height: | Size: 8.9 KiB |
BIN
src/public/Icons/main8-exit-icon.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
src/public/Icons/programIcons/FMSDGAUGE-main.ico
Normal file
|
After Width: | Height: | Size: 102 KiB |
BIN
src/public/Icons/programIcons/main1-File.ico
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
src/public/Icons/programIcons/main2-Config.ico
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
src/public/Icons/programIcons/main3-Standard.ico
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
src/public/Icons/programIcons/main4-Gauge.ico
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
src/public/Icons/programIcons/main5-CgCgk.ico
Normal file
|
After Width: | Height: | Size: 101 KiB |
BIN
src/public/Icons/programIcons/main6-SysSet.ico
Normal file
|
After Width: | Height: | Size: 103 KiB |
29
src/view/CgCgkPage.xaml
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<Page x:Class="WpfApp.src.view.CgCgkPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:rg="clr-namespace:unvell.ReoGrid;assembly=unvell.ReoGrid"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:WpfApp.src.view"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
Title="CgCgkPage"
|
||||
>
|
||||
|
||||
<Grid x:Name="MainGrid">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 按钮行,高度自适应 -->
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- Excel控件行,填满剩余空间 -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 按钮 -->
|
||||
<Button Grid.Row="0" Content="操作 Excel" Click="OnCgCgkPageButtonClick" HorizontalAlignment="Left" VerticalAlignment="Top" />
|
||||
|
||||
<!-- Excel 显示控件 -->
|
||||
<rg:ReoGridControl Grid.Row="1" x:Name="grid"/>
|
||||
</Grid>
|
||||
|
||||
|
||||
</Page>
|
||||
35
src/view/CgCgkPage.xaml.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
namespace WpfApp.src.view;
|
||||
using WpfApp.Utils;
|
||||
using unvell.ReoGrid;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// CgCgkPage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class CgCgkPage : Page
|
||||
{
|
||||
public CgCgkPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnCgCgkPageButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ExcelHelper.LoadTemplate(IconHelper.GetIconPath("demo.xlsx"));
|
||||
ExcelHelper.SelectSheet("表2");
|
||||
ExcelHelper.InsertRowData(5, 0, new List<object> { "传感器1", 25.6, 101.3, DateTime.Now });
|
||||
ExcelHelper.WriteCell("B2", "测试人员");
|
||||
ExcelHelper.WriteCell("C3", DateTime.Now.ToString("yyyy-MM-dd"));
|
||||
ExcelHelper.SaveAs(IconHelper.GetIconDirectoryPath() + "\\Excel\\Report_2025_10_13.xlsx");
|
||||
|
||||
// 在页面控件上显示保存后的 Excel
|
||||
grid.Load(IconHelper.GetIconPath("Report_2025_10_13.xlsx"));
|
||||
|
||||
// 不要 Dispose,否则控件被销毁
|
||||
// ExcelHelper.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
243
src/view/ConfigPage.xaml
Normal file
|
|
@ -0,0 +1,243 @@
|
|||
<Page x:Class="WpfApp.src.view.ConfigPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="800" d:DesignWidth="1200"
|
||||
Title="ConfigPage">
|
||||
|
||||
<Grid Background="#F0F0F0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- 主内容 -->
|
||||
<RowDefinition Height="60"/>
|
||||
<!-- 底部按钮固定高度 -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 主内容区域 -->
|
||||
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" Margin="10">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<!-- 左侧1:1 -->
|
||||
<ColumnDefinition Width="*"/>
|
||||
<!-- 右侧1:1 -->
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 左侧区域 -->
|
||||
<Grid Grid.Column="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="1*"/>
|
||||
<!-- 产品名称 -->
|
||||
<RowDefinition Height="3*"/>
|
||||
<!-- 传感器选择 -->
|
||||
<RowDefinition Height="7*"/>
|
||||
<!-- 公差设定 -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 产品名称 -->
|
||||
<Border Grid.Row="0" Background="White" BorderBrush="#CCCCCC" BorderThickness="1" Margin="5" Padding="10">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="产品名称" FontWeight="Bold" VerticalAlignment="Center" Margin="0,0,10,0"/>
|
||||
<TextBox Grid.Column="1" x:Name="ProductNameTextBox" Text="DFPV C15TE" Height="30" Background="#E6F3FF" VerticalContentAlignment="Center"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 传感器选择 -->
|
||||
<Border Grid.Row="1" Background="White" BorderBrush="#CCCCCC" BorderThickness="1" Margin="5" Padding="10">
|
||||
<StackPanel>
|
||||
<Border Background="#4472C4" Padding="5" Margin="0,0,0,10">
|
||||
<TextBlock Text="传感器选择" Foreground="White" FontWeight="Bold" HorizontalAlignment="Left"/>
|
||||
</Border>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox x:Name="chkDigitalSensor1" Grid.Row="0" Grid.Column="0" Content="数字传感器1" IsChecked="True" Margin="5"/>
|
||||
<CheckBox x:Name="chkDigitalSensor2" Grid.Row="0" Grid.Column="1" Content="数字传感器2" IsChecked="True" Margin="5"/>
|
||||
<CheckBox x:Name="chkDigitalSensor3" Grid.Row="1" Grid.Column="0" Content="数字传感器3" IsChecked="True" Margin="5"/>
|
||||
<CheckBox x:Name="chkDigitalSensor4" Grid.Row="1" Grid.Column="1" Content="数字传感器4" Margin="5"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 公差设定 -->
|
||||
<Border Grid.Row="2" Background="White" BorderBrush="#CCCCCC" BorderThickness="1" Margin="5" Padding="10">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Border Grid.Row="0" Background="#4472C4" Padding="5" Margin="0,0,0,10">
|
||||
<TextBlock Text="公差设定" Foreground="White" FontWeight="Bold" HorizontalAlignment="Left"/>
|
||||
</Border>
|
||||
|
||||
<!-- 传感器标签页 -->
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,0,0,10">
|
||||
<Button x:Name="SensorTab1" Content="传感器1" Width="80" Height="30" Background="#E6F3FF" Click="SensorTab_Click" Tag="1"/>
|
||||
<Button x:Name="SensorTab2" Content="传感器2" Width="80" Height="30" Background="#F0F0F0" Click="SensorTab_Click" Tag="2"/>
|
||||
<Button x:Name="SensorTab3" Content="传感器3" Width="80" Height="30" Background="#F0F0F0" Click="SensorTab_Click" Tag="3"/>
|
||||
<Button x:Name="SensorTab4" Content="传感器4" Width="80" Height="30" Background="#F0F0F0" Click="SensorTab_Click" Tag="4"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 公差数值输入 -->
|
||||
<StackPanel Grid.Row="2" x:Name="ToleranceInputPanel">
|
||||
<Grid Margin="0,10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="最大公差(微米)" VerticalAlignment="Center" Margin="0,5"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" x:Name="MaxToleranceTextBox" Text="9.00" Height="30" Margin="5" Background="#E6F3FF"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="基准尺寸(毫米)" VerticalAlignment="Center" Margin="0,5"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" x:Name="BaseToleranceTextBox" Text="72.9410" Height="30" Margin="5" Background="#E6F3FF"/>
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="最小公差(微米)" VerticalAlignment="Center" Margin="0,5"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" x:Name="MinToleranceTextBox" Text="-9.00" Height="30" Margin="5" Background="#E6F3FF"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<!-- 右侧区域 -->
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="3*"/>
|
||||
<!-- 主传感器选择 -->
|
||||
<RowDefinition Height="7*"/>
|
||||
<!-- 等级信息设定 -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 主传感器选择 -->
|
||||
<Border Grid.Row="0" Background="White" BorderBrush="#CCCCCC" BorderThickness="1" Margin="5" Padding="10">
|
||||
<StackPanel>
|
||||
<Border Background="#4472C4" Padding="5" Margin="0,0,0,10">
|
||||
<TextBlock Text="主传感器选择" Foreground="White" FontWeight="Bold" HorizontalAlignment="Left"/>
|
||||
</Border>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<RadioButton x:Name="chkDigitalMainSensor1" Grid.Row="0" Grid.Column="0" Content="数字传感器1" IsChecked="True" GroupName="MainSensor" Margin="5"/>
|
||||
<RadioButton x:Name="chkDigitalMainSensor2" Grid.Row="0" Grid.Column="1" Content="数字传感器2" GroupName="MainSensor" Margin="5"/>
|
||||
<RadioButton x:Name="chkDigitalMainSensor3" Grid.Row="1" Grid.Column="0" Content="数字传感器3" GroupName="MainSensor" Margin="5"/>
|
||||
<RadioButton x:Name="chkDigitalMainSensor4" Grid.Row="1" Grid.Column="1" Content="数字传感器4" GroupName="MainSensor" Margin="5"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 等级信息设定 -->
|
||||
<Border Grid.Row="1" Background="White" BorderBrush="#CCCCCC" BorderThickness="1" Margin="5" Padding="10">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 标题 -->
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 分页栏 -->
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- 内容区 -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题 -->
|
||||
<Border Grid.Row="0" Background="#4472C4" Padding="5" Margin="0,0,0,10">
|
||||
<TextBlock Text="等级信息设定(毫米)" Foreground="White" FontWeight="Bold" HorizontalAlignment="Left"/>
|
||||
</Border>
|
||||
|
||||
<!-- 等级标签页 -->
|
||||
<Grid Grid.Row="1" Margin="0,0,0,10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Grid.Column="0" x:Name="LevelTabUnder" Content="Under" Height="30" Background="#E6F3FF" Tag="Under"/>
|
||||
<Button Grid.Column="1" x:Name="LevelTabA" Content="A" Height="30" Background="#F0F0F0" Tag="A"/>
|
||||
<Button Grid.Column="2" x:Name="LevelTabB" Content="B" Height="30" Background="#F0F0F0" Tag="B"/>
|
||||
<Button Grid.Column="3" x:Name="LevelTabC" Content="C" Height="30" Background="#F0F0F0" Tag="C"/>
|
||||
<Button Grid.Column="4" x:Name="LevelTabD" Content="D" Height="30" Background="#F0F0F0" Tag="D"/>
|
||||
<Button Grid.Column="5" x:Name="LevelTabE" Content="E" Height="30" Background="#F0F0F0" Tag="E"/>
|
||||
<Button Grid.Column="6" x:Name="LevelTabF" Content="F" Height="30" Background="#F0F0F0" Tag="F"/>
|
||||
<Button Grid.Column="7" x:Name="LevelTabG" Content="G" Height="30" Background="#F0F0F0" Tag="G"/>
|
||||
<Button Grid.Column="8" x:Name="LevelTabOver" Content="Over" Height="30" Background="#F0F0F0" Tag="Over"/>
|
||||
</Grid>
|
||||
|
||||
|
||||
<!-- 等级信息输入区 -->
|
||||
<StackPanel Grid.Row="2" x:Name="LevelInfoPanel" HorizontalAlignment="Center">
|
||||
<Grid Margin="0,5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="60"/>
|
||||
<ColumnDefinition Width="40"/>
|
||||
<ColumnDefinition Width="120"/>
|
||||
<ColumnDefinition Width="60"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 按钮行 -->
|
||||
<Button Grid.Row="0" Grid.Column="0" Content="低" Width="50" Height="25"
|
||||
Background="#333333" Foreground="White" HorizontalAlignment="Center" Margin="0,30,0,0"/>
|
||||
<Button Grid.Row="0" Grid.Column="2" Content="高" Width="50" Height="25"
|
||||
Background="#333333" Foreground="White" HorizontalAlignment="Center" Margin="0,30,0,0"/>
|
||||
<Button Grid.Row="0" Grid.Column="3" Content="标记" Width="50" Height="25"
|
||||
Background="#333333" Foreground="White" HorizontalAlignment="Center" Margin="0,30,0,0"/>
|
||||
|
||||
<!-- 数值行 -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" x:Name="LowerLimitTextBlock" Text="下限" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,30,0,0" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="<" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="16" Margin="0,30,0,0"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="2" x:Name="HighLimitTextBox" Text="-0.0090" Height="30" Background="#E6F3FF" HorizontalAlignment="Center" Width="100" Margin="0,30,0,0"/>
|
||||
<Border Grid.Row="1" Grid.Column="3" Background="#CCCCCC" Height="30" Width="50" Margin="0,30,0,0">
|
||||
<TextBlock x:Name="UnitMarkTextBlock" Text="NG" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- 底部按钮区域 -->
|
||||
<Border Grid.Row="1" Background="#E0E0E0" BorderBrush="#CCCCCC" BorderThickness="0,1,0,0">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="20,0">
|
||||
<Button Click="CreateOrUpdateData_Click" Content="保存" Width="80" Height="35" Background="#90EE90" Margin="10,0"/>
|
||||
<Button Content="取消" Width="80" Height="35" Background="#F0F0F0" Margin="10,0"/>
|
||||
<Button Content="完成" Width="80" Height="35" Background="#F0F0F0" Margin="10,0"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Page>
|
||||
508
src/view/ConfigPage.xaml.cs
Normal file
|
|
@ -0,0 +1,508 @@
|
|||
using guoke;
|
||||
using SqlSugar;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using WpfApp.src.model;
|
||||
namespace WpfApp.src.view;
|
||||
|
||||
/// <summary>
|
||||
/// ConfigPage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ConfigPage : Page
|
||||
{
|
||||
// 等级数据字典,每个等级对应 LevelInfo
|
||||
private Dictionary<string, LevelInfo> levelData;
|
||||
private Dictionary<int, SensorToleranceData> sensorData;
|
||||
private readonly LogService log;
|
||||
private readonly DatabaseService db;
|
||||
private readonly EventService<GeneralEventArgs> even;
|
||||
|
||||
public ConfigPage(LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
|
||||
{
|
||||
InitializeComponent();
|
||||
log = logService;
|
||||
db = databaseService;
|
||||
even = eventService;
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
scope.guokeCheckToCreate<Product>();
|
||||
scope.guokeCheckToCreate<SensorSelection>();
|
||||
scope.guokeCheckToCreate<SensorToleranceData>();
|
||||
scope.guokeCheckToCreate<MainSensorSelection>();
|
||||
scope.guokeCheckToCreate<LevelInfo>();
|
||||
|
||||
// 传感器选择
|
||||
LoadSensorSelectionFromDb();
|
||||
// 传感器公差
|
||||
InitializeSensorData();
|
||||
// 主传感器选择
|
||||
LoadMainSensorSelectionFromDb();
|
||||
// 等级
|
||||
InitializeLevelData();
|
||||
// 加载产品名称
|
||||
LoadProductGroupName();
|
||||
|
||||
|
||||
// 注册等级标签按钮点击事件
|
||||
LevelTabUnder.Click += LevelTab_Click;
|
||||
LevelTabA.Click += LevelTab_Click;
|
||||
LevelTabB.Click += LevelTab_Click;
|
||||
LevelTabC.Click += LevelTab_Click;
|
||||
LevelTabD.Click += LevelTab_Click;
|
||||
LevelTabE.Click += LevelTab_Click;
|
||||
LevelTabF.Click += LevelTab_Click;
|
||||
LevelTabG.Click += LevelTab_Click;
|
||||
LevelTabOver.Click += LevelTab_Click;
|
||||
}
|
||||
|
||||
#region 第一部分 组名
|
||||
// 加载产品名称
|
||||
private void LoadProductGroupName() {
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
var ProductGroupName = scope.Queryable<Product>().First();
|
||||
if (ProductGroupName != null) {
|
||||
LoadProductGroup(ProductGroupName);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadProductGroup(Product product)
|
||||
{
|
||||
ProductNameTextBox.Text = product.Name;
|
||||
}
|
||||
|
||||
private void SaveProductGroupNameToDb()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 第二部分 多选
|
||||
// 从数据库加载传感器选择
|
||||
private void LoadSensorSelectionFromDb()
|
||||
{
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
// 假设只取第一个产品的主传感器数据
|
||||
var mainSensor = scope.Queryable<SensorSelection>().First();
|
||||
if (mainSensor != null)
|
||||
{
|
||||
LoadSensorSelection(mainSensor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 每次 CheckBox 状态改变保存到数据库
|
||||
private void Sensor_CheckedChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SaveSensorToDb();
|
||||
}
|
||||
/// <summary>
|
||||
/// 将数据库中的主传感器数据加载到界面 CheckBox
|
||||
/// </summary>
|
||||
private void LoadSensorSelection(SensorSelection data)
|
||||
{
|
||||
chkDigitalSensor1.IsChecked = data.Sensor1;
|
||||
chkDigitalSensor2.IsChecked = data.Sensor2;
|
||||
chkDigitalSensor3.IsChecked = data.Sensor3;
|
||||
chkDigitalSensor4.IsChecked = data.Sensor4;
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存界面 CheckBox 状态到数据库
|
||||
/// </summary>
|
||||
private void SaveSensorToDb()
|
||||
{
|
||||
var data = new SensorSelection
|
||||
{
|
||||
Sensor1 = chkDigitalSensor1.IsChecked == true,
|
||||
Sensor2 = chkDigitalSensor2.IsChecked == true,
|
||||
Sensor3 = chkDigitalSensor3.IsChecked == true,
|
||||
Sensor4 = chkDigitalSensor4.IsChecked == true,
|
||||
ProductName = "默认产品名" // 可以根据实际情况设置
|
||||
};
|
||||
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
|
||||
// 如果数据库已存在该产品的主传感器数据,则更新,否则插入
|
||||
var exist = scope.Queryable<SensorSelection>()
|
||||
.Where(s => s.ProductName == data.ProductName)
|
||||
.First();
|
||||
|
||||
if (exist != null)
|
||||
{
|
||||
data.Id = exist.Id; // 设置 Id 才能更新
|
||||
scope.Updateable(data).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
scope.Insertable(data).ExecuteCommand();
|
||||
}
|
||||
|
||||
log.Info($"保存传感器选择:{data.ProductName}");
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 第三部分 公差
|
||||
// 初始化传感器数据
|
||||
private void InitializeSensorData()
|
||||
{
|
||||
sensorData = new Dictionary<int, SensorToleranceData>();
|
||||
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
if (scope == null)
|
||||
{
|
||||
MessageBox.Show("SqlSugarScope 获取失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
string productName = "DFPV C15TE"; // TODO: 根据实际选择的产品替换
|
||||
|
||||
// 查询数据库
|
||||
var sensors = scope.Queryable<SensorToleranceData>()
|
||||
.Where(s => s.ProductName == productName)
|
||||
.ToList();
|
||||
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
var sensor = sensors.FirstOrDefault(s => s.SensorName == $"传感器{i}");
|
||||
sensorData[i] = sensor ?? new SensorToleranceData
|
||||
{
|
||||
SensorName = $"传感器{i}",
|
||||
MaxTolerance = "0.00",
|
||||
BaseTolerance = "0.00",
|
||||
MinTolerance = "0.00",
|
||||
ProductName = productName
|
||||
};
|
||||
}
|
||||
|
||||
// 加载第一个传感器数据到界面
|
||||
LoadSensorData(1);
|
||||
}
|
||||
|
||||
// 标签切换事件(只加载,不保存)
|
||||
private void SensorTab_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button clickedButton && int.TryParse(clickedButton.Tag?.ToString(), out int sensorIndex))
|
||||
{
|
||||
UpdateTabStyles(sensorIndex);
|
||||
LoadSensorData(sensorIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新标签页样式
|
||||
private void UpdateTabStyles(int selectedIndex)
|
||||
{
|
||||
var buttons = new[] { SensorTab1, SensorTab2, SensorTab3, SensorTab4 };
|
||||
for (int i = 0; i < buttons.Length; i++)
|
||||
{
|
||||
buttons[i].Background = (i + 1 == selectedIndex)
|
||||
? new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"))
|
||||
: new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||||
}
|
||||
}
|
||||
|
||||
// 加载数据到界面
|
||||
private void LoadSensorData(int sensorIndex)
|
||||
{
|
||||
if (sensorData.ContainsKey(sensorIndex) &&
|
||||
MaxToleranceTextBox != null &&
|
||||
BaseToleranceTextBox != null &&
|
||||
MinToleranceTextBox != null)
|
||||
{
|
||||
var data = sensorData[sensorIndex];
|
||||
MaxToleranceTextBox.Text = data.MaxTolerance;
|
||||
BaseToleranceTextBox.Text = data.BaseTolerance;
|
||||
MinToleranceTextBox.Text = data.MinTolerance;
|
||||
}
|
||||
}
|
||||
|
||||
// 保存按钮事件
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
int currentSensorIndex = GetCurrentSelectedSensorIndex();
|
||||
|
||||
// 保存当前界面数据到字典
|
||||
if (sensorData.ContainsKey(currentSensorIndex))
|
||||
{
|
||||
sensorData[currentSensorIndex].MaxTolerance = MaxToleranceTextBox.Text;
|
||||
sensorData[currentSensorIndex].BaseTolerance = BaseToleranceTextBox.Text;
|
||||
sensorData[currentSensorIndex].MinTolerance = MinToleranceTextBox.Text;
|
||||
}
|
||||
|
||||
// 写回数据库
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
foreach (var sensor in sensorData.Values)
|
||||
{
|
||||
var exist = scope.Queryable<SensorToleranceData>()
|
||||
.Where(s => s.ProductName == sensor.ProductName && s.SensorName == sensor.SensorName)
|
||||
.First();
|
||||
if (exist != null)
|
||||
{
|
||||
sensor.Id = exist.Id;
|
||||
scope.Updateable(sensor).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
scope.Insertable(sensor).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("保存成功!");
|
||||
}
|
||||
|
||||
// 获取当前选中的传感器索引
|
||||
private int GetCurrentSelectedSensorIndex()
|
||||
{
|
||||
if (SensorTab1.Background is SolidColorBrush brush1 && brush1.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 1;
|
||||
if (SensorTab2.Background is SolidColorBrush brush2 && brush2.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 2;
|
||||
if (SensorTab3.Background is SolidColorBrush brush3 && brush3.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 3;
|
||||
if (SensorTab4.Background is SolidColorBrush brush4 && brush4.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 4;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 保存传感器公差数据到数据库
|
||||
private void SaveSensorToleranceDataToDb()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 第四部分 单选
|
||||
// 主传感器
|
||||
private void LoadMainSensorSelectionFromDb()
|
||||
{
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
// 假设只取第一个产品的主传感器数据
|
||||
var mainSensor = scope.Queryable<MainSensorSelection>().First();
|
||||
if (mainSensor != null)
|
||||
{
|
||||
LoadMainSensorSelection(mainSensor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将数据库中的主传感器数据加载到界面 CheckBox
|
||||
/// </summary>
|
||||
private void LoadMainSensorSelection(MainSensorSelection data)
|
||||
{
|
||||
chkDigitalMainSensor1.IsChecked = data.DigitalSensor1;
|
||||
chkDigitalMainSensor2.IsChecked = data.DigitalSensor2;
|
||||
chkDigitalMainSensor3.IsChecked = data.DigitalSensor3;
|
||||
chkDigitalMainSensor4.IsChecked = data.DigitalSensor4;
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存界面 CheckBox 状态到数据库
|
||||
/// </summary>
|
||||
private void SaveMainSensorToDb()
|
||||
{
|
||||
var data = new MainSensorSelection
|
||||
{
|
||||
DigitalSensor1 = chkDigitalMainSensor1.IsChecked == true,
|
||||
DigitalSensor2 = chkDigitalMainSensor2.IsChecked == true,
|
||||
DigitalSensor3 = chkDigitalMainSensor3.IsChecked == true,
|
||||
DigitalSensor4 = chkDigitalMainSensor4.IsChecked == true,
|
||||
ProductName = "默认产品名" // 可以根据实际情况设置
|
||||
};
|
||||
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
|
||||
// 如果数据库已存在该产品的主传感器数据,则更新,否则插入
|
||||
var exist = scope.Queryable<SensorSelection>()
|
||||
.Where(s => s.ProductName == data.ProductName)
|
||||
.First();
|
||||
|
||||
if (exist != null)
|
||||
{
|
||||
data.Id = exist.Id; // 设置 Id 才能更新
|
||||
scope.Updateable(data).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
scope.Insertable(data).ExecuteCommand();
|
||||
}
|
||||
|
||||
log.Info($"保存传感器选择:{data.ProductName}");
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 第五部分 等级
|
||||
|
||||
// 初始化等级数据
|
||||
private void InitializeLevelData()
|
||||
{
|
||||
levelData = new Dictionary<string, LevelInfo>();
|
||||
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
if (scope == null)
|
||||
{
|
||||
MessageBox.Show("SqlSugarScope 获取失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
string productName = "DFPV C15TE"; // TODO: 根据实际选择的产品替换
|
||||
string[] tabs = { "Under", "A", "B", "C", "D", "E", "F", "G", "Over" };
|
||||
|
||||
// 从数据库查询该产品的等级数据
|
||||
var sensorsRank = scope.Queryable<LevelInfo>()
|
||||
.Where(s => s.ProductName == productName)
|
||||
.ToList();
|
||||
|
||||
// 初始化每个等级
|
||||
foreach (var tab in tabs)
|
||||
{
|
||||
var sensorRank = sensorsRank.FirstOrDefault(s => s.Name == tab);
|
||||
if (sensorRank != null)
|
||||
{
|
||||
levelData[tab] = sensorRank;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 没有数据库记录则初始化默认值
|
||||
levelData[tab] = new LevelInfo
|
||||
{
|
||||
Name = tab,
|
||||
Low = "0.0",
|
||||
High = "0.0",
|
||||
Mark = "NG",
|
||||
Status = "NG",
|
||||
ProductName = productName
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 默认加载第一个等级
|
||||
LoadLevelData(tabs[0]);
|
||||
}
|
||||
|
||||
// 加载数据到界面
|
||||
private void LoadLevelData(string sensorIndex)
|
||||
{
|
||||
if (!levelData.ContainsKey(sensorIndex))
|
||||
return;
|
||||
|
||||
var data = levelData[sensorIndex];
|
||||
|
||||
// 加强防护,防止 NullReferenceException
|
||||
if (LowerLimitTextBlock != null)
|
||||
LowerLimitTextBlock.Text = data.Low ?? "下限";
|
||||
|
||||
if (HighLimitTextBox != null)
|
||||
HighLimitTextBox.Text = data.High ?? "0.0";
|
||||
|
||||
if (UnitMarkTextBlock != null)
|
||||
UnitMarkTextBlock.Text = data.Mark ?? "NG";
|
||||
}
|
||||
|
||||
// 等级标签按钮点击事件
|
||||
private void LevelTab_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button btn && btn.Tag is string tabName)
|
||||
{
|
||||
// 保存当前等级修改
|
||||
SaveCurrentLevelData();
|
||||
|
||||
// 更新标签样式
|
||||
UpdateTabStyles(btn);
|
||||
|
||||
// 加载新等级
|
||||
LoadLevelData(tabName);
|
||||
}
|
||||
}
|
||||
|
||||
// 保存当前显示的等级数据
|
||||
private void SaveCurrentLevelData()
|
||||
{
|
||||
string currentTab = GetCurrentSelectedTab();
|
||||
if (currentTab == null || !levelData.ContainsKey(currentTab))
|
||||
return;
|
||||
|
||||
var data = levelData[currentTab];
|
||||
|
||||
// 直接取命名控件的值最稳妥
|
||||
if (LowerLimitTextBlock != null)
|
||||
data.Low = LowerLimitTextBlock.Text ?? "0.0";
|
||||
|
||||
if (HighLimitTextBox != null)
|
||||
data.High = HighLimitTextBox.Text ?? "0.0";
|
||||
|
||||
if (UnitMarkTextBlock != null)
|
||||
data.Mark = UnitMarkTextBlock.Text ?? "NG";
|
||||
}
|
||||
|
||||
// 获取当前选中的标签名
|
||||
private string GetCurrentSelectedTab()
|
||||
{
|
||||
if (LevelTabUnder?.Parent is Grid grid)
|
||||
{
|
||||
foreach (var child in grid.Children)
|
||||
{
|
||||
if (child is Button b && b.Background is SolidColorBrush brush)
|
||||
{
|
||||
var activeColor = (Color)ColorConverter.ConvertFromString("#E6F3FF");
|
||||
if (brush.Color == activeColor)
|
||||
return b.Tag?.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 更新等级标签按钮样式
|
||||
private void UpdateTabStyles(Button selectedBtn)
|
||||
{
|
||||
if (selectedBtn?.Parent is Grid grid)
|
||||
{
|
||||
foreach (var child in grid.Children)
|
||||
{
|
||||
if (child is Button b)
|
||||
{
|
||||
b.Background = (b == selectedBtn)
|
||||
? new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF")) // 选中浅蓝
|
||||
: new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0")); // 未选灰
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 保存等级数据到数据库
|
||||
private void SaveLevelDataToDb()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 新建||更新数据
|
||||
private void CreateOrUpdateData_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MessageBox.Show("保存数据!");
|
||||
// 这里分成四个部分 进行保存判定
|
||||
/*
|
||||
第一部分 默认选择的都是当前数据库数据表中的第一组的数据
|
||||
1、如果没做任何修改 点击修改 应当不往数据库更新数据
|
||||
2、如果仅对数据做了修改那应该更新 组号一样的数据
|
||||
3、如果仅对组号进行了修改那么应当 新建一条组数据 然后 相关联的应当也新增记录
|
||||
4、如果对组号和数据都进行了修改 都新增记录 组号也是修改后的
|
||||
*/
|
||||
// 1-保存产品组名称到数据库
|
||||
SaveProductGroupNameToDb();
|
||||
// 2-保存多选传感器的状态到数据库
|
||||
SaveSensorToDb();
|
||||
// 3-保存传感器公差数据到数据库
|
||||
SaveSensorToleranceDataToDb();
|
||||
// 4-保存单选主传感器的状态到数据库
|
||||
SaveMainSensorToDb();
|
||||
// 5-
|
||||
SaveLevelDataToDb();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
101
src/view/FilePage.xaml
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<Page x:Class="WpfApp.src.view.FilePage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:WpfApp.src.view"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
Title="记录列表">
|
||||
|
||||
<Grid Background="#E6F3FF">
|
||||
<!-- 定义行 -->
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="50"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 顶部搜索区域 -->
|
||||
<Grid Grid.Row="0" Margin="10,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="60"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Column="0" Text="名称" VerticalAlignment="Center"
|
||||
FontSize="14" Foreground="#333333"/>
|
||||
<TextBox Grid.Column="1" Name="SearchTextBox" Margin="5,0"
|
||||
VerticalAlignment="Center" Height="30"
|
||||
BorderBrush="#CCCCCC" BorderThickness="1"/>
|
||||
<Button Grid.Column="2" Content="查找" Margin="5,0" Height="30"
|
||||
Background="#4A90E2" Foreground="White" BorderThickness="0"
|
||||
FontSize="12" Click="SearchButton_Click"/>
|
||||
<Button Grid.Column="3" Content="删除" Margin="5,0" Height="30"
|
||||
Background="#E74C3C" Foreground="White" BorderThickness="0"
|
||||
FontSize="12" Click="DeleteButton_Click"/>
|
||||
</Grid>
|
||||
|
||||
<!-- 主要列表区域 -->
|
||||
<Border Grid.Row="1" Margin="10,5" BorderBrush="#FFFFE0" BorderThickness="1"
|
||||
Background="#FFFFE0">
|
||||
<ListBox Name="RecordListBox"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
BorderThickness="0"
|
||||
SelectionMode="Single">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<Border Name="ItemBorder"
|
||||
Background="{TemplateBinding Background}"
|
||||
Padding="8,4">
|
||||
<ContentPresenter/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter TargetName="ItemBorder" Property="Background" Value="#4169E1"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="ItemBorder" Property="Background" Value="#6495ED"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}" Foreground="Black" FontSize="12"
|
||||
FontFamily="Consolas" Padding="5,2"/>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Border>
|
||||
|
||||
<!-- 底部按钮区域 -->
|
||||
<Grid Grid.Row="2" Margin="10,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Grid.Column="1" Content="选择" Margin="5,0" Height="35"
|
||||
Background="#4A90E2" Foreground="White" BorderThickness="0"
|
||||
FontSize="14" Click="SelectButton_Click"/>
|
||||
<Button Grid.Column="2" Content="关闭" Margin="5,0" Height="35"
|
||||
Background="#95A5A6" Foreground="White" BorderThickness="0"
|
||||
FontSize="14" Click="CloseButton_Click"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Page>
|
||||
140
src/view/FilePage.xaml.cs
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Navigation;
|
||||
namespace WpfApp.src.view;
|
||||
|
||||
/// <summary>
|
||||
/// FilePage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class FilePage : Page
|
||||
{
|
||||
public FilePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
LoadSampleData();
|
||||
}
|
||||
|
||||
private void LoadSampleData()
|
||||
{
|
||||
// 清空现有项目
|
||||
RecordListBox.Items.Clear();
|
||||
|
||||
// 添加示例数据
|
||||
var records = new List<string>
|
||||
{
|
||||
"1. GGG[2021-11-17 7:39:50]",
|
||||
"2. MTU SG2000[2021-12-2 7:41:55]",
|
||||
"3. JX493ZQ4[2022-1-8 11:22:42]",
|
||||
"4. JX493ZQ5A[2022-2-15 1:26:38]",
|
||||
"5. FOTON D01[2022-9-1 9:06:43]",
|
||||
"6. PUMA2.0[2022-9-15 8:47:59]",
|
||||
"7. PUMA2.2[2022-9-21 7:50:39]",
|
||||
"8. SAIC D20[2022-10-10 8:27:46]",
|
||||
"9. WEICHAI WP2H[2023-3-30 8:46:02]",
|
||||
"10. JMC PUMA UPG 2.0[2023-7-10 17:07:07]",
|
||||
"11. BFCEC ISF2.8L F2020 NS6[2023-7-10 17:21:50]",
|
||||
"12. 12[2023-8-21 14:44:10]",
|
||||
"13. GME T4[2023-10-2 8:55:38]",
|
||||
"14. GW EN01[2023-10-4 8:12:50]",
|
||||
"15. GAC P26 2.0PMI[2023-11-9 7:44:42]",
|
||||
"16. NU PE2.0 TGDI[2024-5-2 11:07:36]",
|
||||
"17. M254 E20[2024-7-2 10:08:06]",
|
||||
"18. NU PE2.0MPI[2024-10-29 10:45:14]"
|
||||
};
|
||||
|
||||
foreach (var record in records)
|
||||
{
|
||||
RecordListBox.Items.Add(record);
|
||||
}
|
||||
}
|
||||
|
||||
private void SearchButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string searchText = SearchTextBox.Text.Trim();
|
||||
if (string.IsNullOrEmpty(searchText))
|
||||
{
|
||||
LoadSampleData(); // 重新加载所有数据
|
||||
return;
|
||||
}
|
||||
|
||||
// 过滤数据
|
||||
RecordListBox.Items.Clear();
|
||||
var allRecords = new List<string>
|
||||
{
|
||||
"1. GGG[2021-11-17 7:39:50]",
|
||||
"2. MTU SG2000[2021-12-2 7:41:55]",
|
||||
"3. JX493ZQ4[2022-1-8 11:22:42]",
|
||||
"4. JX493ZQ5A[2022-2-15 1:26:38]",
|
||||
"5. FOTON D01[2022-9-1 9:06:43]",
|
||||
"6. PUMA2.0[2022-9-15 8:47:59]",
|
||||
"7. PUMA2.2[2022-9-21 7:50:39]",
|
||||
"8. SAIC D20[2022-10-10 8:27:46]",
|
||||
"9. WEICHAI WP2H[2023-3-30 8:46:02]",
|
||||
"10. JMC PUMA UPG 2.0[2023-7-10 17:07:07]",
|
||||
"11. BFCEC ISF2.8L F2020 NS6[2023-7-10 17:21:50]",
|
||||
"12. 12[2023-8-21 14:44:10]",
|
||||
"13. GME T4[2023-10-2 8:55:38]",
|
||||
"14. GW EN01[2023-10-4 8:12:50]",
|
||||
"15. GAC P26 2.0PMI[2023-11-9 7:44:42]",
|
||||
"16. NU PE2.0 TGDI[2024-5-2 11:07:36]",
|
||||
"17. M254 E20[2024-7-2 10:08:06]",
|
||||
"18. NU PE2.0MPI[2024-10-29 10:45:14]"
|
||||
};
|
||||
|
||||
var filteredRecords = allRecords.Where(r => r.ToLower().Contains(searchText.ToLower())).ToList();
|
||||
foreach (var record in filteredRecords)
|
||||
{
|
||||
RecordListBox.Items.Add(record);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (RecordListBox.SelectedItem != null)
|
||||
{
|
||||
var result = MessageBox.Show("确定要删除选中的记录吗?", "确认删除",
|
||||
MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
RecordListBox.Items.Remove(RecordListBox.SelectedItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请先选择要删除的记录。", "提示",
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (RecordListBox.SelectedItem != null)
|
||||
{
|
||||
string selectedRecord = RecordListBox.SelectedItem.ToString();
|
||||
MessageBox.Show($"已选择记录:{selectedRecord}", "选择确认",
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
// 这里可以添加实际的选择逻辑,比如返回到主界面或执行其他操作
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请先选择一条记录。", "提示",
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 关闭当前页面或返回上一页
|
||||
if (NavigationService.CanGoBack)
|
||||
{
|
||||
NavigationService.GoBack();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果无法返回,可以关闭窗口或执行其他操作
|
||||
Window.GetWindow(this)?.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
267
src/view/GaugePage.xaml
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
<Page x:Class="WpfApp.src.view.GaugePage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:WpfApp.src.view"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="800" d:DesignWidth="1200"
|
||||
Title="GaugePage">
|
||||
|
||||
<Grid Background="White" >
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="60"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 主要内容区域 -->
|
||||
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" Margin="10">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 顶部信息输入区域 -->
|
||||
<Border Grid.Row="0" Background="White" BorderBrush="#CCCCCC" Margin="5" Padding="15">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 一行四等分 -->
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 第一行 -->
|
||||
<Grid Grid.Row="0" Grid.Column="0" Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<!-- 标题固定宽 -->
|
||||
<ColumnDefinition Width="*"/>
|
||||
<!-- 输入框自适应 -->
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="零件名称" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox Grid.Column="1" Height="25" Background="#E6F3FF" VerticalAlignment="Center" Margin="0,0,25,0"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="0" Grid.Column="1" Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="量具编号" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox Grid.Column="1" Height="25" Background="#E6F3FF" VerticalAlignment="Center" Margin="0,0,25,0"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="0" Grid.Column="2" Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="量具名称" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox Grid.Column="1" Height="25" Background="#E6F3FF" VerticalAlignment="Center" Margin="0,0,25,0"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="0" Grid.Column="3" Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="量具地址" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox Grid.Column="1" Height="25" Background="#E6F3FF" VerticalAlignment="Center" Margin="0,0,25,0"/>
|
||||
</Grid>
|
||||
|
||||
<!-- 第二行 -->
|
||||
<Grid Grid.Row="1" Grid.Column="0" Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="操作者A" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox Grid.Column="1" Height="25" Background="#E6F3FF" VerticalAlignment="Center" Margin="0,0,25,0"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="1" Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="操作者B" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox Grid.Column="1" Height="25" Background="#E6F3FF" VerticalAlignment="Center" Margin="0,0,25,0"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="2" Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="操作者C" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox Grid.Column="1" Height="25" Background="#E6F3FF" VerticalAlignment="Center" Margin="0,0,25,0"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="3" Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="100"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="过程总变差(6σ)" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox Grid.Column="1" Height="25" Background="#E6F3FF" VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Column="2" Text="mm" VerticalAlignment="Center" Margin="5,0,0,0"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 传感器其它参数配置区域 -->
|
||||
|
||||
<GroupBox Header="其它参数" Margin="5" FontWeight="Bold" Grid.Row="1" Background="White">
|
||||
<Grid>
|
||||
<!-- 行定义:表头 + 三个传感器 -->
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 列定义:左侧传感器列 + 四等分输入框 -->
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<!-- 传感器列 -->
|
||||
<ColumnDefinition Width="*"/>
|
||||
<!-- 特性 -->
|
||||
<ColumnDefinition Width="*"/>
|
||||
<!-- 基本尺寸 -->
|
||||
<ColumnDefinition Width="*"/>
|
||||
<!-- 上偏差 -->
|
||||
<ColumnDefinition Width="*"/>
|
||||
<!-- 下偏差 -->
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 表头 -->
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Text="特性" HorizontalAlignment="Center" FontWeight="Bold" Margin="5"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="2" Text="基本尺寸" HorizontalAlignment="Center" FontWeight="Bold" Margin="5"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="3" Text="上偏差" HorizontalAlignment="Center" FontWeight="Bold" Margin="5"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="4" Text="下偏差" HorizontalAlignment="Center" FontWeight="Bold" Margin="5"/>
|
||||
|
||||
<!-- 传感器1 -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="传感器1:" VerticalAlignment="Center" Margin="5" Width="70"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Height="25" Margin="5,5,25,5" Background="#E6F3FF" />
|
||||
<TextBox Grid.Row="1" Grid.Column="2" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="3" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="4" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
|
||||
<!-- 传感器2 -->
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="传感器2:" VerticalAlignment="Center" Margin="5" Width="70"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="3" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="4" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
|
||||
<!-- 传感器3 -->
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Text="传感器3:" VerticalAlignment="Center" Margin="5" Width="70"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="1" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="2" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="3" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="4" Height="25" Margin="5,5,25,5" Background="#E6F3FF"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
|
||||
<!-- 传感器选择和操作者选择区域 -->
|
||||
<Border Grid.Row="2" Background="White" BorderBrush="#CCCCCC" >
|
||||
<Grid Margin="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 传感器选择 -->
|
||||
<GroupBox Header="传感器选择" Grid.Column="0" Margin="10,0,160,0" FontWeight="Bold">
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<RadioButton Content="传感器1" IsChecked="True" GroupName="Sensor" Grid.Column="0" HorizontalAlignment="Center"/>
|
||||
<RadioButton Content="传感器2" GroupName="Sensor" Grid.Column="1" HorizontalAlignment="Center"/>
|
||||
<RadioButton Content="传感器3" GroupName="Sensor" Grid.Column="2" HorizontalAlignment="Center"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 操作者选择 -->
|
||||
<GroupBox Header="操作者选择" Grid.Column="1" Margin="160,0,10,0" FontWeight="Bold">
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<RadioButton Content="A" IsChecked="True" GroupName="Operator" Grid.Column="0" HorizontalAlignment="Center"/>
|
||||
<RadioButton Content="B" GroupName="Operator" Grid.Column="1" HorizontalAlignment="Center"/>
|
||||
<RadioButton Content="C" GroupName="Operator" Grid.Column="2" HorizontalAlignment="Center"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
|
||||
<!-- 数据表格区域 -->
|
||||
<Border Grid.Row="3" Background="White" BorderBrush="#CCCCCC" BorderThickness="1" Margin="5" Padding="10">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
||||
<!-- 数据表格 十等分 DataGrid -->
|
||||
<DataGrid Grid.Row="1"
|
||||
x:Name="DataInputGrid"
|
||||
AutoGenerateColumns="False"
|
||||
CanUserAddRows="True"
|
||||
CanUserDeleteRows="True"
|
||||
GridLinesVisibility="All"
|
||||
HeadersVisibility="All"
|
||||
Background="White"
|
||||
AlternatingRowBackground="#F8F8F8"
|
||||
MinHeight="200">
|
||||
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="1" Binding="{Binding Column1}" Width="*"/>
|
||||
<DataGridTextColumn Header="2" Binding="{Binding Column2}" Width="*"/>
|
||||
<DataGridTextColumn Header="3" Binding="{Binding Column3}" Width="*"/>
|
||||
<DataGridTextColumn Header="4" Binding="{Binding Column4}" Width="*"/>
|
||||
<DataGridTextColumn Header="5" Binding="{Binding Column5}" Width="*"/>
|
||||
<DataGridTextColumn Header="6" Binding="{Binding Column6}" Width="*"/>
|
||||
<DataGridTextColumn Header="7" Binding="{Binding Column7}" Width="*"/>
|
||||
<DataGridTextColumn Header="8" Binding="{Binding Column8}" Width="*"/>
|
||||
<DataGridTextColumn Header="9" Binding="{Binding Column9}" Width="*"/>
|
||||
<DataGridTextColumn Header="10" Binding="{Binding Column10}" Width="*"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- 底部按钮区域 -->
|
||||
<Border Grid.Row="1" Background="#E0E0E0" BorderBrush="#CCCCCC" BorderThickness="0,1,0,0">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="20,0">
|
||||
<Button Content="导出报表" Width="80" Height="35" Background="#90EE90" Margin="10,0"/>
|
||||
<Button Content="参数设定" Width="80" Height="35" Background="#F0F0F0" Margin="10,0"/>
|
||||
<Button Content="取消" Width="80" Height="35" Background="#F0F0F0" Margin="10,0"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Page>
|
||||
28
src/view/GaugePage.xaml.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace WpfApp.src.view
|
||||
{
|
||||
/// <summary>
|
||||
/// GaugePage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class GaugePage : Page
|
||||
{
|
||||
public GaugePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
259
src/view/StandardPage.xaml
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
<Page x:Class="WpfApp.src.view.StandardPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:WpfApp.src.components"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="600" d:DesignWidth="1000"
|
||||
Title="StandardPage">
|
||||
|
||||
<Grid>
|
||||
<!--<Grid>-->
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="60"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="80"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题区域 -->
|
||||
<Border Grid.Row="0" Background="#4A90E2" Margin="10,10,10,0" CornerRadius="5">
|
||||
<TextBlock Text="主标定" FontSize="24" FontWeight="Bold" Foreground="White"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
|
||||
<!-- 传感器区域 -->
|
||||
<Grid Grid.Row="1" Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 传感器1 -->
|
||||
<Border Grid.Column="0" Background="#F8F6E7" Margin="5" CornerRadius="8" Padding="10">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 传感器标题 -->
|
||||
<Border Grid.Row="0" Background="#4A90E2" CornerRadius="5">
|
||||
<TextBlock Text="传感器1" FontSize="16" FontWeight="Bold" Foreground="White"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
|
||||
<!-- 输入值 -->
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="输入值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightBlue" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="72.936" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 传感器值 -->
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="传感器值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightBlue" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="0.7205" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 设定值 -->
|
||||
<StackPanel Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="设定值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightGreen" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="0.7205" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 柱状图区域 -->
|
||||
<Border Grid.Row="4" Background="#F8F6E7" CornerRadius="5" Margin="0,10,0,0" Padding="5">
|
||||
|
||||
<!-- 传感器1 - 蓝色柱状图,类似图片中的样式 -->
|
||||
<local:SensorChart Grid.Column="0"
|
||||
x:Name="Sensor1"
|
||||
SensorName="传感器1"
|
||||
Value="-40"
|
||||
Margin="5,5,5,-1"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 传感器2 -->
|
||||
<Border Grid.Column="1" Background="#F8F6E7" Margin="5" CornerRadius="8" Padding="10">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 传感器标题 -->
|
||||
<Border Grid.Row="0" Background="#4A90E2" CornerRadius="5">
|
||||
<TextBlock Text="传感器2" FontSize="16" FontWeight="Bold" Foreground="White"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
|
||||
<!-- 输入值 -->
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="输入值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightBlue" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="0" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 传感器值 -->
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="传感器值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightBlue" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="0.0000" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 设定值 -->
|
||||
<StackPanel Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="设定值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightGreen" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="0.0000" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 柱状图区域 -->
|
||||
<Border Grid.Row="4" Background="#F8F6E7" CornerRadius="5" Margin="0,10,0,0" Padding="5">
|
||||
<!-- 传感器1 - 蓝色柱状图,类似图片中的样式 -->
|
||||
<local:SensorChart Grid.Column="0"
|
||||
x:Name="Sensor2"
|
||||
SensorName="传感器2"
|
||||
Value="-40"
|
||||
Margin="5,5,5,-1"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 传感器3 -->
|
||||
<Border Grid.Column="2" Background="#F8F6E7" Margin="5" CornerRadius="8" Padding="10">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 传感器标题 -->
|
||||
<Border Grid.Row="0" Background="#4A90E2" CornerRadius="5">
|
||||
<TextBlock Text="传感器3" FontSize="16" FontWeight="Bold" Foreground="White"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
|
||||
<!-- 输入值 -->
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="输入值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightBlue" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="72.168" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 传感器值 -->
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="传感器值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightBlue" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="0.7352" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 设定值 -->
|
||||
<StackPanel Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="设定值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightGreen" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="0.7352" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 柱状图区域 -->
|
||||
<Border Grid.Row="4" Background="#F8F6E7" CornerRadius="5" Margin="0,10,0,0" Padding="5">
|
||||
<!-- 传感器1 - 蓝色柱状图,类似图片中的样式 -->
|
||||
<local:SensorChart Grid.Column="0"
|
||||
x:Name="Sensor3"
|
||||
SensorName="传感器3"
|
||||
Value="-40"
|
||||
Margin="5,5,5,-1"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 传感器4 -->
|
||||
<Border Grid.Column="3" Background="#F8F6E7" Margin="5" CornerRadius="8" Padding="10">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 传感器标题 -->
|
||||
<Border Grid.Row="0" Background="#4A90E2" CornerRadius="5">
|
||||
<TextBlock Text="传感器4" FontSize="16" FontWeight="Bold" Foreground="White"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
|
||||
<!-- 输入值 -->
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="输入值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightBlue" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="0" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 传感器值 -->
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="传感器值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightBlue" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="0.0000" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 设定值 -->
|
||||
<StackPanel Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="设定值" FontSize="12" Foreground="Black" Width="50" VerticalAlignment="Center"/>
|
||||
<Border Background="LightGreen" CornerRadius="3" Padding="5,2" MinWidth="80">
|
||||
<TextBlock Text="0.0000" FontSize="12" Foreground="Black" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 柱状图区域 -->
|
||||
<Border Grid.Row="4" Background="#F8F6E7" CornerRadius="5" Margin="0,10,0,0" Padding="5">
|
||||
<!-- 传感器1 - 蓝色柱状图,类似图片中的样式 -->
|
||||
<local:SensorChart Grid.Column="0"
|
||||
x:Name="Sensor4"
|
||||
SensorName="传感器4"
|
||||
Value="-40"
|
||||
Margin="5,5,5,-1"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<!-- 底部按钮区域 -->
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center" Margin="0,0,20,0">
|
||||
<Button Content="开始标定" Width="100" Height="40" Margin="10,0"
|
||||
Background="#4A90E2" Foreground="White" FontSize="14" FontWeight="Bold"
|
||||
BorderBrush="Transparent"/>
|
||||
<Button Content="关闭" Width="80" Height="40" Margin="10,0"
|
||||
Background="#4A90E2" Foreground="White" FontSize="14" FontWeight="Bold"
|
||||
BorderBrush="Transparent"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Page>
|
||||
28
src/view/StandardPage.xaml.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace WpfApp.src.view
|
||||
{
|
||||
/// <summary>
|
||||
/// StandardPage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class StandardPage : Page
|
||||
{
|
||||
public StandardPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
283
src/view/SysSetPage.xaml
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
<Page x:Class="WpfApp.src.view.SysSetPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:WpfApp.src.view"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
Title="SysSetPage">
|
||||
|
||||
<Grid Background="#F0F0F0">
|
||||
<!-- 标题栏 -->
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题 -->
|
||||
<Border Grid.Row="0" Background="#4472C4" CornerRadius="5,5,0,0">
|
||||
<TextBlock Text="系统设置(传感器设置)"
|
||||
Foreground="White"
|
||||
FontSize="14"
|
||||
FontWeight="Bold"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="10,0"/>
|
||||
</Border>
|
||||
|
||||
<!-- TabControl -->
|
||||
<TabControl Grid.Row="1" Background="White" BorderThickness="1" BorderBrush="#CCCCCC">
|
||||
<!-- 设置页面 -->
|
||||
<TabItem Header="设置" FontSize="12">
|
||||
<Grid Background="White" Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 通道选择 -->
|
||||
<GroupBox Header="通道选择" FontWeight="Bold">
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,10">
|
||||
<TextBlock Text="通道:" VerticalAlignment="Center" Margin="0,0,10,0" FontSize="12"/>
|
||||
<ComboBox Name="ChannelComboBox"
|
||||
Width="300"
|
||||
Height="25"
|
||||
FontSize="12"
|
||||
SelectedIndex="0">
|
||||
<ComboBoxItem Content="OrbitPCICard1,Channel1 ,Type:3"/>
|
||||
<ComboBoxItem Content="OrbitPCICard1,Channel2 ,Type:3"/>
|
||||
<ComboBoxItem Content="OrbitPCICard1,Channel3 ,Type:3"/>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 传感器配置区域 -->
|
||||
<Border Grid.Row="2" Background="White" BorderBrush="#CCCCCC" BorderThickness="1" Margin="5" Padding="15">
|
||||
<GroupBox Header="传感器配置" FontWeight="Bold" FontSize="13">
|
||||
<Grid Margin="10">
|
||||
<!-- 行定义 -->
|
||||
<Grid.RowDefinitions>
|
||||
<!-- 第一组 -->
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 标题 -->
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 第二组 -->
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 标题 -->
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 列定义:左列为传感器名 + 三等分输入列 -->
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="69"/>
|
||||
<!-- 左列传感器 -->
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<!-- ID -->
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<!-- 冲程 -->
|
||||
<ColumnDefinition Width="4*"/>
|
||||
<!-- 名称 -->
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 第一组标题 -->
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Text="ID" HorizontalAlignment="Center" FontWeight="Bold" Margin="5"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="2" Text="冲程" HorizontalAlignment="Center" FontWeight="Bold" Margin="5"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="3" Text="名称" HorizontalAlignment="Center" FontWeight="Bold" Margin="5"/>
|
||||
|
||||
<!-- 第一组输入 -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="传感器1:" VerticalAlignment="Center" Margin="5,0"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="2" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="3" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="传感器2:" VerticalAlignment="Center" Margin="5,0"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="3" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Text="传感器3:" VerticalAlignment="Center" Margin="5,0"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="1" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="2" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="3" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" Text="传感器4:" VerticalAlignment="Center" Margin="5,0"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="1" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="3" Height="25" Margin="5" Background="#E6F3FF"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Border>
|
||||
|
||||
|
||||
<!-- 按钮区域 -->
|
||||
<Grid Grid.Row="3" Margin="0,10,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<!-- 左侧按钮 -->
|
||||
<ColumnDefinition Width="*"/>
|
||||
<!-- 右侧按钮 -->
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 左侧:第一个按钮左对齐 -->
|
||||
<Button Name="SelectSensorButton"
|
||||
Content="读取传感器"
|
||||
Width="80" Height="25"
|
||||
FontSize="12"
|
||||
Margin="0,0,10,0"
|
||||
HorizontalAlignment="Left"
|
||||
Click="SelectSensorButton_Click"/>
|
||||
|
||||
<!-- 右侧:其余按钮右对齐 -->
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Name="SaveButton" Content="保存" Width="60" Height="25" Margin="0,0,10,0" FontSize="12" Click="SaveButton_Click"/>
|
||||
<Button Name="CancelButton" Content="取消" Width="60" Height="25" Margin="0,0,10,0" FontSize="12" Click="CancelButton_Click"/>
|
||||
<Button Name="ConfirmButton" Content="确定" Width="60" Height="25" FontSize="12" Click="ConfirmButton_Click"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<!-- 测试页面 -->
|
||||
<TabItem Header="测试" FontSize="12" Height="19" VerticalAlignment="Top">
|
||||
<Grid Background="White" Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 传感器设置表格 -->
|
||||
<GroupBox Header="传感器配置" FontWeight="Bold" FontSize="13">
|
||||
<Grid Margin="10">
|
||||
<!-- 行定义 -->
|
||||
<Grid.RowDefinitions>
|
||||
<!-- 第一组 -->
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- 第二组 -->
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 列定义(12等分逻辑) -->
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="0"/>
|
||||
<!-- 预留空列 -->
|
||||
<ColumnDefinition Width="3*"/>
|
||||
<!-- 名字:ID -->
|
||||
<ColumnDefinition Width="3*"/>
|
||||
<!-- 刻度值 -->
|
||||
<ColumnDefinition Width="6*"/>
|
||||
<!-- 实际值 -->
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 第一组标题 -->
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Text="名称:ID" HorizontalAlignment="Center" FontWeight="Bold" Margin="5"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="2" Text="刻度值" HorizontalAlignment="Center" FontWeight="Bold" Margin="5"/>
|
||||
<!--<TextBlock Grid.Row="0" Grid.Column="3" Text="实际值" HorizontalAlignment="Center" FontWeight="Bold" Margin="5"/>-->
|
||||
<!-- 刻度尺标题区域 -->
|
||||
<Canvas Grid.Row="0" Grid.Column="3" Height="40" Width="360" Background="White">
|
||||
<!-- 刻度尺顶线 -->
|
||||
<Line X1="0" Y1="10" X2="360" Y2="10" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
<!-- 刻度线(大刻度每40像素一个,小刻度每10像素一个) -->
|
||||
<Line X1="0" Y1="10" X2="0" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
<!-- 小刻度 -->
|
||||
<Line X1="10" Y1="10" X2="10" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="20" Y1="10" X2="20" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="30" Y1="10" X2="30" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<!-- 大刻度 -->
|
||||
<Line X1="40" Y1="10" X2="40" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
<!-- 重复下一个区间 -->
|
||||
<Line X1="50" Y1="10" X2="50" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="60" Y1="10" X2="60" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="70" Y1="10" X2="70" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="80" Y1="10" X2="80" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
<Line X1="90" Y1="10" X2="90" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="100" Y1="10" X2="100" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="110" Y1="10" X2="110" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="120" Y1="10" X2="120" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
<Line X1="130" Y1="10" X2="130" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="140" Y1="10" X2="140" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="150" Y1="10" X2="150" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="160" Y1="10" X2="160" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
<Line X1="170" Y1="10" X2="170" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="180" Y1="10" X2="180" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="190" Y1="10" X2="190" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="200" Y1="10" X2="200" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
<Line X1="210" Y1="10" X2="210" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="220" Y1="10" X2="220" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="230" Y1="10" X2="230" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="240" Y1="10" X2="240" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
<Line X1="250" Y1="10" X2="250" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="260" Y1="10" X2="260" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="270" Y1="10" X2="270" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="280" Y1="10" X2="280" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
<Line X1="290" Y1="10" X2="290" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="300" Y1="10" X2="300" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="310" Y1="10" X2="310" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="320" Y1="10" X2="320" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
<Line X1="330" Y1="10" X2="330" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="340" Y1="10" X2="340" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="350" Y1="10" X2="350" Y2="20" Stroke="Black" StrokeThickness="1"/>
|
||||
<Line X1="360" Y1="10" X2="360" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
<!-- 可以继续按规律扩展到整条刻度尺 -->
|
||||
|
||||
<Line X1="360" Y1="10" X2="360" Y2="25" Stroke="Black" StrokeThickness="1"/>
|
||||
|
||||
|
||||
</Canvas>
|
||||
|
||||
|
||||
<!-- 第一组输入 -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Height="25" Margin="5" Text="A1:130PC32609"
|
||||
TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="2" Height="25" Margin="5" Background="#E6F3FF" Text="0.73211"/>
|
||||
<ProgressBar Grid.Row="1" Grid.Column="3" Height="20" Margin="5"
|
||||
Minimum="0" Maximum="1" Value="0.73" Foreground="#2196F3"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="1" Height="25" Margin="5" Text="A2:130PC32610"
|
||||
TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Height="25" Margin="5" Background="#E6F3FF" Text="0.70211"/>
|
||||
<ProgressBar Grid.Row="2" Grid.Column="3" Height="20" Margin="5"
|
||||
Minimum="0" Maximum="1" Value="0.70211" Foreground="#2196F3"/>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="1" Height="25" Margin="5" Text="A3:130PC32611"
|
||||
TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="2" Height="25" Margin="5" Background="#E6F3FF" Text="0.00000"/>
|
||||
<ProgressBar Grid.Row="3" Grid.Column="3" Height="20" Margin="5"
|
||||
Minimum="0" Maximum="1" Value="0.00000" Foreground="#2196F3"/>
|
||||
|
||||
<TextBlock Grid.Row="4" Grid.Column="1" Height="25" Margin="5" Text=""
|
||||
TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Height="25" Margin="5" Background="#E6F3FF" Text="0.00000"/>
|
||||
<ProgressBar Grid.Row="4" Grid.Column="3" Height="20" Margin="5"
|
||||
Minimum="0" Maximum="1" Value="0.00000" Foreground="#2196F3"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
|
||||
</TabControl>
|
||||
</Grid>
|
||||
</Page>
|
||||
102
src/view/SysSetPage.xaml.cs
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace WpfApp.src.view
|
||||
{
|
||||
/// <summary>
|
||||
/// SysSetPage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SysSetPage : Page
|
||||
{
|
||||
public ObservableCollection<SensorSettingItem> SensorSettings { get; set; }
|
||||
public ObservableCollection<SensorConfigItem> SensorConfigs { get; set; }
|
||||
|
||||
public SysSetPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeData();
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
private void InitializeData()
|
||||
{
|
||||
// 初始化传感器设置数据
|
||||
SensorSettings = new ObservableCollection<SensorSettingItem>
|
||||
{
|
||||
new SensorSettingItem { Name = "A1:130BC32P09", ScaleValue = "0.71777", Progress = 0.71777 },
|
||||
new SensorSettingItem { Name = "A2:130BC32P10", ScaleValue = "0.00000", Progress = 0.0 },
|
||||
new SensorSettingItem { Name = "A3:130BC32P08", ScaleValue = "0.73578", Progress = 0.73578 },
|
||||
new SensorSettingItem { Name = "", ScaleValue = "0.00000", Progress = 0.0 }
|
||||
};
|
||||
|
||||
// 初始化传感器配置数据
|
||||
SensorConfigs = new ObservableCollection<SensorConfigItem>
|
||||
{
|
||||
new SensorConfigItem { Sensor1Id = "130BC32P09", Id = "5", Range = "5", Name = "A1" },
|
||||
new SensorConfigItem { Sensor1Id = "130BC32P10", Id = "5", Range = "5", Name = "A2" },
|
||||
new SensorConfigItem { Sensor1Id = "130BC32P08", Id = "6", Range = "6", Name = "A3" },
|
||||
new SensorConfigItem { Sensor1Id = "", Id = "", Range = "", Name = "" }
|
||||
};
|
||||
|
||||
// 绑定数据到DataGrid
|
||||
//SensorSettingsGrid.ItemsSource = SensorSettings;
|
||||
//SensorConfigGrid.ItemsSource = SensorConfigs;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void SelectSensorButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 选择传感器按钮点击事件
|
||||
MessageBox.Show("选择传感器功能待实现");
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 保存按钮点击事件
|
||||
MessageBox.Show("保存成功");
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 取消按钮点击事件
|
||||
MessageBox.Show("已取消");
|
||||
}
|
||||
|
||||
private void ConfirmButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 确定按钮点击事件
|
||||
MessageBox.Show("确定");
|
||||
}
|
||||
}
|
||||
|
||||
// 传感器设置数据模型
|
||||
public class SensorSettingItem
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string ScaleValue { get; set; }
|
||||
public double Progress { get; set; }
|
||||
}
|
||||
|
||||
// 传感器配置数据模型
|
||||
public class SensorConfigItem
|
||||
{
|
||||
public string Sensor1Id { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string Range { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||