This commit is contained in:
xyy
2026-06-17 20:54:24 +08:00
parent 742ce6f292
commit e16e6f5a13
4 changed files with 279 additions and 199 deletions

View File

@@ -38,7 +38,7 @@ namespace AciTester.Models
public ushort PumpCoil { get; set; } = 6; // 高压超限 M180 public ushort PumpCoil { get; set; } = 6; // 高压超限 M180
public ushort FlowRegister { get; set; } // 高压超限 M180 public ushort FlowRegister { get; set; } = 1330; // 高压超限 M180

View File

@@ -4,18 +4,19 @@
xmlns:local="clr-namespace:AciTester.ViewModels" xmlns:local="clr-namespace:AciTester.ViewModels"
Title="ACI测试系统 - 中国药典2025装置3" Title="ACI测试系统 - 中国药典2025装置3"
Height="768" Width="1024" Height="768" Width="1024"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen" WindowState="Maximized"
Background="#F0F2F5"> Background="#F0F2F5">
<Window.DataContext> <Window.DataContext>
<local:MainViewModel/> <local:MainViewModel/>
</Window.DataContext> </Window.DataContext>
<Window.Resources> <Window.Resources>
<!-- 按钮样式 --> <!-- 全局样式:紧凑版 -->
<Style TargetType="Button"> <Style TargetType="Button">
<Setter Property="Height" Value="40"/> <Setter Property="Height" Value="30"/>
<Setter Property="Margin" Value="5"/> <Setter Property="MinWidth" Value="60"/>
<Setter Property="FontSize" Value="14"/> <Setter Property="Margin" Value="3"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/> <Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Background" Value="#2C7DA0"/> <Setter Property="Background" Value="#2C7DA0"/>
<Setter Property="Foreground" Value="White"/> <Setter Property="Foreground" Value="White"/>
@@ -33,21 +34,19 @@
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<!-- 文本框样式 -->
<Style TargetType="TextBox"> <Style TargetType="TextBox">
<Setter Property="Height" Value="35"/> <Setter Property="Height" Value="28"/>
<Setter Property="FontSize" Value="14"/> <Setter Property="FontSize" Value="12"/>
<Setter Property="BorderBrush" Value="#CCCCCC"/> <Setter Property="BorderBrush" Value="#CCCCCC"/>
<Setter Property="BorderThickness" Value="1"/> <Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="5"/> <Setter Property="Padding" Value="3"/>
<Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/>
</Style> </Style>
<!-- 切换按钮样式 -->
<Style TargetType="ToggleButton"> <Style TargetType="ToggleButton">
<Setter Property="Height" Value="40"/> <Setter Property="Height" Value="28"/>
<Setter Property="Width" Value="80"/> <Setter Property="Width" Value="60"/>
<Setter Property="FontSize" Value="14"/> <Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/> <Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Background" Value="#E74C3C"/> <Setter Property="Background" Value="#E74C3C"/>
<Setter Property="Foreground" Value="White"/> <Setter Property="Foreground" Value="White"/>
@@ -60,27 +59,29 @@
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<!-- DataGrid 样式 -->
<Style TargetType="DataGrid"> <Style TargetType="DataGrid">
<Setter Property="FontSize" Value="13"/> <Setter Property="FontSize" Value="12"/>
<Setter Property="RowHeight" Value="30"/> <Setter Property="RowHeight" Value="26"/>
<Setter Property="HeadersVisibility" Value="Column"/> <Setter Property="HeadersVisibility" Value="Column"/>
<Setter Property="GridLinesVisibility" Value="Horizontal"/> <Setter Property="GridLinesVisibility" Value="Horizontal"/>
<Setter Property="AlternatingRowBackground" Value="#F9F9F9"/> <Setter Property="AlternatingRowBackground" Value="#F9F9F9"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
</Style> </Style>
<Style TargetType="DataGridColumnHeader"> <Style TargetType="DataGridColumnHeader">
<Setter Property="Height" Value="35"/> <Setter Property="Height" Value="28"/>
<Setter Property="Background" Value="#E9F0F5"/> <Setter Property="Background" Value="#E9F0F5"/>
<Setter Property="FontWeight" Value="Bold"/> <Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style> </Style>
<Style TargetType="DataGridCell"> <Style TargetType="DataGridCell">
<Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="FontSize" Value="12"/>
</Style> </Style>
</Window.Resources> </Window.Resources>
<Grid Margin="15"> <Grid Margin="8">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
@@ -90,231 +91,296 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- 状态栏 (Row 0) --> <!-- 状态栏 (Row 0) -->
<Border Grid.Row="0" Background="#2C3E50" CornerRadius="5" Padding="10" Margin="0,0,0,10"> <Border Grid.Row="0" Background="#2C3E50" CornerRadius="4" Padding="6" Margin="0,0,0,6">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="状态:" Foreground="White" FontSize="14" VerticalAlignment="Center"/> <TextBlock Text="状态:" Foreground="White" FontSize="12" VerticalAlignment="Center"/>
<TextBlock Text="{Binding ConnectionStatus}" Foreground="{Binding IsConnected, Converter={StaticResource BoolToColorConverter}}" FontSize="14" FontWeight="Bold" Margin="5,0,20,0"/> <TextBlock Text="{Binding ConnectionStatus}" Foreground="{Binding IsConnected, Converter={StaticResource BoolToColorConverter}}" FontSize="12" FontWeight="Bold" Margin="3,0,15,0"/>
<Separator Background="White" Width="1" Margin="5,0"/> <Separator Background="White" Width="1" Margin="3,0"/>
<TextBlock Text="流量:" Foreground="White" FontSize="14" Margin="15,0,0,0"/> <TextBlock Text="流量:" Foreground="White" FontSize="12" Margin="10,0,0,0"/>
<TextBlock Text="{Binding CurrentFlow, StringFormat='{}{0:F2} L/min'}" Foreground="White" FontSize="14" FontWeight="Bold" Margin="5,0,20,0"/> <TextBlock Text="{Binding CurrentFlow, StringFormat='{}{0:F2} L/min'}" Foreground="White" FontSize="12" FontWeight="Bold" Margin="3,0,15,0"/>
<Separator Background="White" Width="1" Margin="5,0"/> <Separator Background="White" Width="1" Margin="3,0"/>
<TextBlock Text="泵状态:" Foreground="White" FontSize="14" Margin="15,0,0,0"/> <TextBlock Text="泵状态:" Foreground="White" FontSize="12" Margin="10,0,0,0"/>
<TextBlock Text="{Binding IsPumpRunning, Converter={StaticResource BoolToStringConverter}}" Foreground="White" FontSize="14" FontWeight="Bold" Margin="5,0,20,0"/> <TextBlock Text="{Binding IsPumpRunning, Converter={StaticResource BoolToStringConverter}}" Foreground="White" FontSize="12" FontWeight="Bold" Margin="3,0,15,0"/>
<Separator Background="White" Width="1" Margin="5,0"/> <Separator Background="White" Width="1" Margin="3,0"/>
<TextBlock Text="倒计时:" Foreground="White" FontSize="14" Margin="15,0,0,0" Visibility="{Binding IsTesting, Converter={StaticResource BoolToVisibilityConverter}}"/> <TextBlock Text="倒计时:" Foreground="White" FontSize="12" Margin="10,0,0,0" Visibility="{Binding IsTesting, Converter={StaticResource BoolToVisibilityConverter}}"/>
<TextBlock Text="{Binding RemainingSeconds, StringFormat='{}{0} s'}" Foreground="Orange" FontSize="14" FontWeight="Bold" Margin="5,0,0,0" Visibility="{Binding IsTesting, Converter={StaticResource BoolToVisibilityConverter}}"/> <TextBlock Text="{Binding RemainingSeconds, StringFormat='{}{0} s'}" Foreground="Orange" FontSize="12" FontWeight="Bold" Margin="3,0,0,0" Visibility="{Binding IsTesting, Converter={StaticResource BoolToVisibilityConverter}}"/>
</StackPanel> </StackPanel>
</Border> </Border>
<!-- 实时监测参数 (Row 1) --> <!-- 实时监测参数 (Row 1) -->
<GroupBox Header="实时监测参数" Grid.Row="1" Margin="0,5" FontWeight="Bold" FontSize="14"> <GroupBox Header="实时监测参数" Grid.Row="1" Margin="0,3" FontWeight="Bold" FontSize="12" Padding="2">
<StackPanel Margin="10"> <StackPanel Margin="4">
<Grid Margin="0,5"> <Grid Margin="0,2">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="#E3F2FD" CornerRadius="8" Padding="10" Margin="5"> <Border Grid.Column="0" Background="#E3F2FD" CornerRadius="6" Padding="6" Margin="3">
<StackPanel> <StackPanel>
<TextBlock Text="流量 (L/min)" FontWeight="Bold" FontSize="14" TextAlignment="Center"/> <TextBlock Text="流量 (L/min)" FontWeight="Bold" FontSize="11" TextAlignment="Center"/>
<TextBlock Text="{Binding RealTime.CalibratedFlow, StringFormat='{}{0:F2}'}" FontSize="28" Foreground="#1565C0" TextAlignment="Center"/> <TextBlock Text="{Binding RealTime.CalibratedFlow, StringFormat='{}{0:F2}'}" FontSize="20" Foreground="#1565C0" TextAlignment="Center"/>
<TextBlock Text="(目标: 28.3)" FontSize="12" Foreground="Gray" TextAlignment="Center"/> <TextBlock Text="(目标: 30)" FontSize="10" Foreground="Gray" TextAlignment="Center"/>
</StackPanel> </StackPanel>
</Border> </Border>
<Border Grid.Column="1" Background="#FFF3E0" CornerRadius="8" Padding="10" Margin="5"> <Border Grid.Column="1" Background="#FFF3E0" CornerRadius="6" Padding="6" Margin="3">
<StackPanel> <StackPanel>
<TextBlock Text="温度 (℃)" FontWeight="Bold" FontSize="14" TextAlignment="Center"/> <TextBlock Text="温度 (℃)" FontWeight="Bold" FontSize="11" TextAlignment="Center"/>
<TextBlock Text="{Binding RealTime.Temperature, StringFormat='{}{0:F1}'}" FontSize="28" Foreground="#E65100" TextAlignment="Center"/> <TextBlock Text="{Binding RealTime.Temperature, StringFormat='{}{0:F1}'}" FontSize="20" Foreground="#E65100" TextAlignment="Center"/>
</StackPanel> </StackPanel>
</Border> </Border>
<Border Grid.Column="2" Background="#E8F5E9" CornerRadius="8" Padding="10" Margin="5"> <Border Grid.Column="2" Background="#E8F5E9" CornerRadius="6" Padding="6" Margin="3">
<StackPanel> <StackPanel>
<TextBlock Text="泵端压力 (kPa)" FontWeight="Bold" FontSize="14" TextAlignment="Center"/> <TextBlock Text="泵端压力 (kPa)" FontWeight="Bold" FontSize="11" TextAlignment="Center"/>
<TextBlock Text="{Binding RealTime.PumpPressure, StringFormat='{}{0:F2}'}" FontSize="28" Foreground="#2E7D32" TextAlignment="Center"/> <TextBlock Text="{Binding RealTime.PumpPressure, StringFormat='{}{0:F2}'}" FontSize="20" Foreground="#2E7D32" TextAlignment="Center"/>
</StackPanel> </StackPanel>
</Border> </Border>
<Border Grid.Column="3" Background="#FCE4EC" CornerRadius="8" Padding="10" Margin="5"> <Border Grid.Column="3" Background="#FCE4EC" CornerRadius="6" Padding="6" Margin="3">
<StackPanel> <StackPanel>
<TextBlock Text="撞击器端压力 (kPa)" FontWeight="Bold" FontSize="14" TextAlignment="Center"/> <TextBlock Text="撞击器端压力 (kPa)" FontWeight="Bold" FontSize="11" TextAlignment="Center"/>
<TextBlock Text="{Binding RealTime.ImpactorPressure, StringFormat='{}{0:F2}'}" FontSize="28" Foreground="#C2185B" TextAlignment="Center"/> <TextBlock Text="{Binding RealTime.ImpactorPressure, StringFormat='{}{0:F2}'}" FontSize="20" Foreground="#C2185B" TextAlignment="Center"/>
</StackPanel> </StackPanel>
</Border> </Border>
</Grid> </Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,2">
<TextBlock Text="压差: " FontWeight="Bold" FontSize="16"/> <TextBlock Text="压差: " FontWeight="Bold" FontSize="12"/>
<TextBlock Text="{Binding RealTime.DifferentialPressure, StringFormat='{}{0:F2} kPa'}" FontSize="16" FontWeight="Bold" Foreground="#D32F2F"/> <TextBlock Text="{Binding RealTime.DifferentialPressure, StringFormat='{}{0:F2} kPa'}" FontSize="12" FontWeight="Bold" Foreground="#D32F2F"/>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</GroupBox> </GroupBox>
<!-- 空调与除霜控制 (Row 2) --> <!-- 空调与除霜控制 (Row 2) 缩小为单行 -->
<GroupBox Header="空调与除霜控制" Grid.Row="2" Margin="0,5" FontWeight="Bold" FontSize="14"> <Border Grid.Row="2" Background="#F5F5F5" CornerRadius="4" Padding="4" Margin="0,2" BorderBrush="#DDD" BorderThickness="1">
<Grid Margin="10"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Grid.ColumnDefinitions> <TextBlock Text="空调倒计时:" FontSize="11" VerticalAlignment="Center" Margin="0,0,2,0"/>
<ColumnDefinition Width="*"/> <TextBlock Text="{Binding RealTime.AcStartupCountdown, StringFormat='{}{0}s'}" FontSize="12" FontWeight="Bold" Foreground="#F57C00" Margin="0,5,15,0"/>
<ColumnDefinition Width="*"/> <TextBlock Text="恒温启动" FontSize="11" VerticalAlignment="Center" Margin="0,0,2,0"/>
</Grid.ColumnDefinitions> <ToggleButton IsChecked="{Binding RealTime.ConstantTempStart, Mode=TwoWay}"
<Border Grid.Column="0" Background="#FFF9C4" CornerRadius="8" Padding="10" Margin="5"> Command="{Binding WriteConstantTempStartCommand}"
<StackPanel> CommandParameter="{Binding IsChecked, RelativeSource={RelativeSource Self}}"
<StackPanel Orientation="Horizontal" Margin="0,5"> IsEnabled="{Binding ConstantTempStartEnabled}"
<TextBlock Text="空调启动倒计时:" FontSize="14" Width="140" VerticalAlignment="Center"/> Width="50" Height="22" FontSize="10"/>
<TextBlock Text="{Binding RealTime.AcStartupCountdown, StringFormat='{}{0} 秒'}" FontSize="24" FontWeight="Bold" Foreground="#F57C00"/> <TextBlock Text="除霜启动" FontSize="11" VerticalAlignment="Center" Margin="10,0,2,0"/>
</StackPanel> <ToggleButton IsChecked="{Binding RealTime.DefrostStart, Mode=TwoWay}"
<Separator Margin="0,10"/> Command="{Binding WriteDefrostStartCommand}"
<StackPanel Orientation="Horizontal" Margin="0,5"> CommandParameter="{Binding IsChecked, RelativeSource={RelativeSource Self}}"
<TextBlock Text="恒温启动" Width="80" FontSize="14" VerticalAlignment="Center"/> Width="50" Height="22" FontSize="10"/>
<ToggleButton IsChecked="{Binding RealTime.ConstantTempStart, Mode=TwoWay}" <TextBlock Text="{Binding RealTime.DefrostStart, Converter={StaticResource BoolToYesNoConverter}}" FontSize="10" Foreground="Red" Margin="3,0,10,0"/>
Command="{Binding WriteConstantTempStartCommand}" <TextBlock Text="除霜温度" FontSize="11" VerticalAlignment="Center"/>
CommandParameter="{Binding IsChecked, RelativeSource={RelativeSource Self}}" <TextBox Text="{Binding RealTime.DefrostTempSet, UpdateSourceTrigger=LostFocus, Mode=TwoWay}" Width="50" Height="22" FontSize="10" Margin="2,0"/>
IsEnabled="{Binding ConstantTempStartEnabled}"/> <TextBlock Text="时间" FontSize="11" VerticalAlignment="Center" Margin="5,0,0,0"/>
<TextBlock Text="(除霜时禁用)" FontSize="11" Foreground="Gray" Margin="10,0,0,0" VerticalAlignment="Center"/> <TextBox Text="{Binding RealTime.DefrostTimeSet, UpdateSourceTrigger=LostFocus, Mode=TwoWay}" Width="50" Height="22" FontSize="10" Margin="2,0"/>
</StackPanel> <TextBlock Text="计时" FontSize="11" VerticalAlignment="Center" Margin="5,0,0,0"/>
<StackPanel Orientation="Horizontal" Margin="0,5"> <TextBlock Text="{Binding RealTime.DefrostMinute, StringFormat='{}{0}分'}" FontSize="11" Margin="2,5"/>
<TextBlock Text="除霜启动" Width="80" FontSize="14" VerticalAlignment="Center"/> <TextBlock Text="{Binding RealTime.DefrostSecond, StringFormat='{}{0}秒'}" FontSize="11" Margin="2,5"/>
<ToggleButton IsChecked="{Binding RealTime.DefrostStart, Mode=TwoWay}" </StackPanel>
Command="{Binding WriteDefrostStartCommand}" </Border>
CommandParameter="{Binding IsChecked, RelativeSource={RelativeSource Self}}"/>
<TextBlock Text="{Binding RealTime.DefrostStart, Converter={StaticResource BoolToYesNoConverter}}" Foreground="Red" FontWeight="Bold" Margin="10,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</Border>
<Border Grid.Column="1" Background="#E0F2F1" CornerRadius="8" Padding="10" Margin="5">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,8">
<TextBlock Text="除霜温度设置(℃)" Width="130" FontSize="14" VerticalAlignment="Center"/>
<TextBox Text="{Binding RealTime.DefrostTempSet, UpdateSourceTrigger=LostFocus, Mode=TwoWay}" Width="100"/>
<TextBlock Text="(≤30)" FontSize="11" Foreground="Gray" Margin="5,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,8">
<TextBlock Text="除霜时间设置(秒)" Width="130" FontSize="14" VerticalAlignment="Center"/>
<TextBox Text="{Binding RealTime.DefrostTimeSet, UpdateSourceTrigger=LostFocus, Mode=TwoWay}" Width="100"/>
<TextBlock Text="(≤180)" FontSize="11" Foreground="Gray" Margin="5,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,8">
<TextBlock Text="除霜计时" Width="130" FontSize="14" VerticalAlignment="Center"/>
<TextBlock Text="{Binding RealTime.DefrostMinute, StringFormat='{}{0}分'}" FontSize="18" FontWeight="Bold" Foreground="#00796B" Margin="0,0,10,0"/>
<TextBlock Text="{Binding RealTime.DefrostSecond, StringFormat='{}{0}秒'}" FontSize="18" FontWeight="Bold" Foreground="#00796B"/>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</GroupBox>
<!-- 主内容 (Row 3) --> <!-- 主内容 (Row 3) -->
<Grid Grid.Row="3" Margin="0,10"> <Grid Grid.Row="3" Margin="0,4">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="380"/> <ColumnDefinition Width="320"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<!-- 左侧控制区 --> <!-- 左侧控制区 -->
<Border Grid.Column="0" Background="White" CornerRadius="8" Padding="10" Margin="0,0,10,0" BorderBrush="#DDDDDD" BorderThickness="1"> <Border Grid.Column="0" Background="White" CornerRadius="6" Padding="6" Margin="0,0,6,0" BorderBrush="#DDDDDD" BorderThickness="1">
<ScrollViewer VerticalScrollBarVisibility="Auto" MaxHeight="450"> <StackPanel>
<StackPanel> <GroupBox Header="通讯控制" Margin="0,0,0,6" Padding="2" FontSize="12">
<GroupBox Header="通讯控制" Margin="0,0,0,10"> <StackPanel>
<StackPanel> <Button Command="{Binding ConnectCommand}" Content="连接PLC" Height="28"/>
<Button Command="{Binding ConnectCommand}" Content="连接PLC" Height="45"/> <Button Command="{Binding DisconnectCommand}" Content="断开连接" Height="28"/>
<Button Command="{Binding DisconnectCommand}" Content="断开连接" Height="45"/> </StackPanel>
</GroupBox>
<GroupBox Header="采样参数" Margin="0,0,0,6" Padding="2" FontSize="12">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,2">
<TextBlock Text="采样时间(秒):" Width="90" VerticalAlignment="Center" FontSize="12"/>
<TextBox Text="{Binding SampleTimeSeconds}" Width="60" IsEnabled="{Binding IsTesting, Converter={StaticResource InverseBoolConverter}}"/>
</StackPanel> </StackPanel>
</GroupBox>
<GroupBox Header="采样参数" Margin="0,0,0,10">
<StackPanel>
<!-- 采样时间设置 -->
<StackPanel Orientation="Horizontal" Margin="0,5">
<TextBlock Text="采样时间(秒):" Width="100" VerticalAlignment="Center" FontSize="14"/>
<TextBox Text="{Binding SampleTimeSeconds}" Width="80" IsEnabled="{Binding IsTesting, Converter={StaticResource InverseBoolConverter}}"/>
</StackPanel>
<!-- 阀门与泵独立控制(手动调试用) -->
<Border BorderBrush="#CCCCCC" BorderThickness="1" CornerRadius="5" Padding="5" Margin="0,5">
<StackPanel>
<TextBlock Text="手动控制" FontWeight="Bold" FontSize="12" Foreground="Gray" Margin="0,0,0,5"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Command="{Binding OpenValveCommand}" Content="开阀" Width="70" Height="30" Margin="2" Background="#3498DB" Foreground="White"/>
<Button Command="{Binding CloseValveCommand}" Content="关阀" Width="70" Height="30" Margin="2" Background="#E74C3C" Foreground="White"/>
<Button Command="{Binding StartPumpCommand}" Content="启泵" Width="70" Height="30" Margin="2" Background="#2ECC71" Foreground="White"/>
<Button Command="{Binding StopPumpCommand}" Content="停泵" Width="70" Height="30" Margin="2" Background="#E67E22" Foreground="White"/>
</StackPanel>
<!-- 手动控制 (泵/阀) 突出显示 -->
<Border BorderBrush="#2C7DA0" BorderThickness="2" CornerRadius="4" Padding="4" Margin="0,4" Background="#F0F8FF">
<StackPanel>
<TextBlock Text="手动控制 (泵/阀)" FontWeight="Bold" FontSize="11" Foreground="#1F5E7A" Margin="0,0,0,2"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Command="{Binding OpenValveCommand}" Content="开阀" Width="55" Height="28" Margin="2" Background="#3498DB"/>
<Button Command="{Binding CloseValveCommand}" Content="关阀" Width="55" Height="28" Margin="2" Background="#E74C3C"/>
<Button Command="{Binding StartPumpCommand}" Content="启泵" Width="55" Height="28" Margin="2" Background="#2ECC71"/>
<Button Command="{Binding StopPumpCommand}" Content="停泵" Width="55" Height="28" Margin="2" Background="#E67E22"/>
</StackPanel> </StackPanel>
</Border> </StackPanel>
</Border>
<!-- 自动测试按钮 --> <Button Command="{Binding StartTestCommand}" Content="开始测试" Height="30" Margin="0,6,0,0" IsEnabled="{Binding IsTesting, Converter={StaticResource InverseBoolConverter}}"/>
<Button Command="{Binding StartTestCommand}" Content="开始测试" Height="45" Margin="0,10,0,0" IsEnabled="{Binding IsTesting, Converter={StaticResource InverseBoolConverter}}"/> <TextBlock Text="测试进行中..." Visibility="{Binding IsTesting, Converter={StaticResource BoolToVisibilityConverter}}" Foreground="Orange" FontWeight="Bold" FontSize="12" Margin="0,2,0,0" HorizontalAlignment="Center"/>
<TextBlock Text="测试进行中..." Visibility="{Binding IsTesting, Converter={StaticResource BoolToVisibilityConverter}}" Foreground="Orange" FontWeight="Bold" FontSize="14" Margin="0,5,0,0" HorizontalAlignment="Center"/> <Button Command="{Binding StopTestCommand}" Content="停止测试" Height="30" Margin="0,4,0,0" Background="#E74C3C" IsEnabled="{Binding IsTesting}"/>
<Button Visibility="Visible" IsEnabled="True" Command="{Binding StopTestCommand}" Content="停止测试" Height="45" Margin="0,10,0,0" Background="#E74C3C" /> </StackPanel>
</StackPanel> </GroupBox>
</GroupBox> <GroupBox Header="数据分析" Padding="2" FontSize="12">
<GroupBox Header="数据分析"> <StackPanel>
<StackPanel> <Button Command="{Binding CalculateCommand}" Content="计算结果" Height="28"/>
<Button Command="{Binding CalculateCommand}" Content="计算结果" Height="45"/> <Button Command="{Binding ExportReportCommand}" Content="导出报告" Height="28"/>
<Button Command="{Binding ExportReportCommand}" Content="导出报告" Height="45"/> </StackPanel>
</StackPanel> </GroupBox>
</GroupBox> </StackPanel>
</StackPanel>
</ScrollViewer>
</Border> </Border>
<!-- 右侧称重数据表格 --> <Border Grid.Column="1" Background="White" CornerRadius="6" Padding="4" BorderBrush="#DDDDDD" BorderThickness="1"
<Border Grid.Column="1" Background="White" CornerRadius="8" Padding="10" BorderBrush="#DDDDDD" BorderThickness="1"> VerticalAlignment="Stretch">
<ScrollViewer VerticalScrollBarVisibility="Auto"> <DataGrid x:Name="StagesDataGrid"
<DataGrid ItemsSource="{Binding Stages}" AutoGenerateColumns="False" CanUserAddRows="False" IsReadOnly="False"> VerticalAlignment="Stretch"
<DataGrid.Columns> HorizontalAlignment="Stretch"
<DataGridTextColumn Header="层级" Binding="{Binding StageName}" Width="80" IsReadOnly="True"/> ItemsSource="{Binding Stages}"
<DataGridTextColumn Header="截止直径(μm)" Binding="{Binding CutoffDiameter, StringFormat='{}{0:F1}'}" Width="100" IsReadOnly="True"/> AutoGenerateColumns="False"
<DataGridTextColumn Header="测前质量(g)" CanUserAddRows="False"
Binding="{Binding InitialWeight, UpdateSourceTrigger=LostFocus, Delay=300, StringFormat='{}{0:F4}'}" IsReadOnly="False"
Width="120"/> Loaded="StagesDataGrid_Loaded"
<DataGridTextColumn Header="测后质量(g)" FontSize="13"
Binding="{Binding FinalWeight, UpdateSourceTrigger=LostFocus, Delay=300, StringFormat='{}{0:F4}'}" RowHeight="34"
Width="120"/> FocusVisualStyle="{x:Null}"
<DataGridTextColumn Header="净重(g)" Binding="{Binding NetWeight, StringFormat='{}{0:F6}'}" Width="120" IsReadOnly="True"> GridLinesVisibility="None"
<DataGridTextColumn.ElementStyle> SelectionMode="Single"
<Style TargetType="TextBlock"> SelectionUnit="FullRow">
<Setter Property="TextAlignment" Value="Center"/>
</Style> <DataGrid.Resources>
</DataGridTextColumn.ElementStyle> <!-- 统一单元格样式 -->
</DataGridTextColumn> <Style TargetType="DataGridCell">
</DataGrid.Columns> <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</DataGrid> <Setter Property="Padding" Value="8,4"/>
</ScrollViewer> <Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="#1E2A3A"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridCell">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="True">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#D0E4F5"/>
<Setter Property="Foreground" Value="#1E2A3A"/>
</Trigger>
</Style.Triggers>
</Style>
<!-- 选中行样式 -->
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="#1E2A3A"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#D0E4F5"/>
<Setter Property="Foreground" Value="#1E2A3A"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#E5F0FA"/>
</Trigger>
</Style.Triggers>
</Style>
<!-- 编辑状态文本框样式 -->
<Style TargetType="TextBox" x:Key="EditingTextBoxStyle">
<Setter Property="Padding" Value="6,4"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="White"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="Foreground" Value="#1E2A3A"/>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Header="层级" Binding="{Binding StageName}" Width="75" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Padding" Value="8,4"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="Foreground" Value="#1E2A3A"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="截止直径(μm)" Binding="{Binding CutoffDiameter, StringFormat='{}{0:F1}'}" Width="85" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Padding" Value="8,4"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="Foreground" Value="#1E2A3A"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="测前(g)" Binding="{Binding InitialWeight, UpdateSourceTrigger=LostFocus, Delay=300, StringFormat='{}{0:F4}'}" Width="95">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Padding" Value="8,4"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="Foreground" Value="#1E2A3A"/>
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="TextBox" BasedOn="{StaticResource EditingTextBoxStyle}"/>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="测后(g)" Binding="{Binding FinalWeight, UpdateSourceTrigger=LostFocus, Delay=300, StringFormat='{}{0:F4}'}" Width="95">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Padding" Value="8,4"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="Foreground" Value="#1E2A3A"/>
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="TextBox" BasedOn="{StaticResource EditingTextBoxStyle}"/>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="净重(g)" Binding="{Binding NetWeight, StringFormat='{}{0:F6}'}" Width="95" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Padding" Value="8,4"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="Foreground" Value="#1E2A3A"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Border> </Border>
</Grid> </Grid>
<!-- 结果显示 (Row 4) --> <!-- 结果显示 (Row 4) -->
<Border Grid.Row="4" Background="#E8F5E9" CornerRadius="8" Padding="12" Margin="0,10,0,0" BorderBrush="#A5D6A7" BorderThickness="1"> <Border Grid.Row="4" Background="#E8F5E9" CornerRadius="6" Padding="6" Margin="0,4,0,0" BorderBrush="#A5D6A7" BorderThickness="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> <WrapPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="微细粒子剂量(FPD): " FontWeight="Bold" FontSize="16"/> <TextBlock Text="FPD: " FontWeight="Bold" FontSize="12"/>
<TextBlock Text="{Binding CurrentResult.FineParticleDose, StringFormat='{}{0:F2} mg'}" FontSize="16" FontWeight="Bold" Foreground="#1565C0" Margin="5,0,30,0"/> <TextBlock Text="{Binding CurrentResult.FineParticleDose, StringFormat='{}{0:F2} mg'}" FontSize="12" Margin="0,0,15,0"/>
<TextBlock Text="微细粒子分数(FPF): " FontWeight="Bold" FontSize="16"/> <TextBlock Text="FPF: " FontWeight="Bold" FontSize="12"/>
<TextBlock Text="{Binding CurrentResult.FineParticleFraction, StringFormat='{}{0:F2} %'}" FontSize="16" FontWeight="Bold" Foreground="#1565C0"/> <TextBlock Text="{Binding CurrentResult.FineParticleFraction, StringFormat='{}{0:F2} %'}" FontSize="12" Margin="0,0,15,0"/>
<TextBlock Text="D10: " FontWeight="Bold" FontSize="12"/>
<TextBlock Text="{Binding CurrentResult.D10, StringFormat='{}{0:F2} μm'}" FontSize="12" Margin="0,0,15,0"/>
<TextBlock Text="D50: " FontWeight="Bold" FontSize="12"/>
<TextBlock Text="FPD: " FontWeight="Bold" FontSize="14"/> <TextBlock Text="{Binding CurrentResult.D50, StringFormat='{}{0:F2} μm'}" FontSize="12" Margin="0,0,15,0"/>
<TextBlock Text="{Binding CurrentResult.FineParticleDose, StringFormat='{}{0:F2} mg'}" FontSize="14" Margin="0,0,20,0"/> <TextBlock Text="D90: " FontWeight="Bold" FontSize="12"/>
<TextBlock Text="FPF: " FontWeight="Bold" FontSize="14"/> <TextBlock Text="{Binding CurrentResult.D90, StringFormat='{}{0:F2} μm'}" FontSize="12" Margin="0,0,15,0"/>
<TextBlock Text="{Binding CurrentResult.FineParticleFraction, StringFormat='{}{0:F2} %'}" FontSize="14" Margin="0,0,20,0"/> <TextBlock Text="GSD: " FontWeight="Bold" FontSize="12"/>
<TextBlock Text="D10: " FontWeight="Bold" FontSize="14"/> <TextBlock Text="{Binding CurrentResult.GSD, StringFormat='{}{0:F3}'}" FontSize="12"/>
<TextBlock Text="{Binding CurrentResult.D10, StringFormat='{}{0:F2} μm'}" FontSize="14" Margin="0,0,20,0"/> </WrapPanel>
<TextBlock Text="D50: " FontWeight="Bold" FontSize="14"/>
<TextBlock Text="{Binding CurrentResult.D50, StringFormat='{}{0:F2} μm'}" FontSize="14" Margin="0,0,20,0"/>
<TextBlock Text="D90: " FontWeight="Bold" FontSize="14"/>
<TextBlock Text="{Binding CurrentResult.D90, StringFormat='{}{0:F2} μm'}" FontSize="14" Margin="0,0,20,0"/>
<TextBlock Text="GSD: " FontWeight="Bold" FontSize="14"/>
<TextBlock Text="{Binding CurrentResult.GSD, StringFormat='{}{0:F3}'}" FontSize="14"/>
</StackPanel>
</Border> </Border>
</Grid> </Grid>
</Window> </Window>

View File

@@ -41,7 +41,21 @@ namespace AciTester.Views
} }
private void StagesDataGrid_Loaded(object sender, RoutedEventArgs e)
{
var dataGrid = sender as DataGrid;
if (dataGrid == null) return;
this.Dispatcher.BeginInvoke(new Action(() =>
{
double availableHeight = dataGrid.ActualHeight - 25 - 8; // 表头约28px边框约8px
if (dataGrid.Items.Count > 0)
{
double rowHeight = availableHeight / dataGrid.Items.Count;
dataGrid.RowHeight = Math.Max(rowHeight, 25); // 最小行高设为28px
}
}), System.Windows.Threading.DispatcherPriority.Loaded);
}
} }
} }