This commit is contained in:
@@ -20,6 +20,43 @@
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="IconButtonStyle" TargetType="Button">
|
||||
<Setter Property="Width" Value="28"/>
|
||||
<Setter Property="Height" Value="28"/>
|
||||
<Setter Property="Background" Value="#3498DB"/>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
<Setter Property="BorderBrush" Value="#2980B9"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="#2980B9"/>
|
||||
<Setter Property="BorderBrush" Value="#1F6393"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Background" Value="#1F6393"/>
|
||||
<Setter Property="BorderBrush" Value="#154360"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Background" Value="#BDC3C7"/>
|
||||
<Setter Property="BorderBrush" Value="#95A5A6"/>
|
||||
<Setter Property="Foreground" Value="#7F8C8D"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Background" Value="#3498DB"/>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
@@ -164,7 +201,7 @@
|
||||
Foreground="White"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="14"/>
|
||||
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<!-- 启动设备按钮 -->
|
||||
@@ -496,7 +533,7 @@
|
||||
Tag="火焰持续时间备注(s)"
|
||||
Height="35" TextChanged="txtCombustionNote_TextChanged" />
|
||||
<CheckBox x:Name="chkHasSmoke" Content="有冒烟" FontSize="13" Margin="30,10,20,0" Unchecked="chkHasSmoke_Unchecked" Checked="chkHasSmoke_Checked" />
|
||||
|
||||
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -603,7 +640,7 @@
|
||||
</Button.Effect>
|
||||
</Button>
|
||||
|
||||
<Button x:Name="btnShowChart"
|
||||
<!--<Button x:Name="btnShowChart"
|
||||
Content=" 测试温度曲线图"
|
||||
Width="120"
|
||||
Height="45"
|
||||
@@ -619,7 +656,7 @@
|
||||
<Button.Effect>
|
||||
<DropShadowEffect ShadowDepth="2" Opacity="0.3" BlurRadius="4"/>
|
||||
</Button.Effect>
|
||||
</Button>
|
||||
</Button>-->
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
@@ -704,7 +741,7 @@
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
|
||||
|
||||
<StackPanel Grid.Column="1">
|
||||
<TextBlock Text="试样重量"
|
||||
FontSize="13"
|
||||
@@ -740,6 +777,53 @@
|
||||
|
||||
|
||||
<!-- 4. 新增多温度监控卡片 -->
|
||||
|
||||
<!-- ========== 新增:温度平衡状态卡片 ========== -->
|
||||
<Border Background="#E0F7FA" Style="{StaticResource CardStyle}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
|
||||
|
||||
<StackPanel Grid.Column="1">
|
||||
<TextBlock Text="温度平衡状态"
|
||||
FontSize="13"
|
||||
Foreground="#666666"/>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="计时:"
|
||||
FontSize="16"
|
||||
Foreground="#2C3E50"
|
||||
Margin="0,0,5,0"/>
|
||||
<TextBlock x:Name="txtBalanceTimeElapsed"
|
||||
Text="0秒"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Foreground="#2C3E50"
|
||||
Margin="0,0,15,0"/>
|
||||
|
||||
</StackPanel>
|
||||
<TextBlock x:Name="txtBalanceCondition"
|
||||
Text="平衡条件: 炉内温度波动正常至少10分钟 且 最大温差<10°C 且 温度漂移<2°C"
|
||||
FontSize="12"
|
||||
Foreground="#666666"
|
||||
Margin="0,5,0,0"/>
|
||||
<Border x:Name="balanceStatusBorder"
|
||||
Background="#BDC3C7"
|
||||
CornerRadius="4"
|
||||
Padding="8,4"
|
||||
Margin="0,5,0,0">
|
||||
<TextBlock x:Name="txtBalanceResult"
|
||||
Text="未判断"
|
||||
Foreground="White"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
<Border Background="#F0F7FF" Style="{StaticResource CardStyle}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -819,53 +903,6 @@
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- ========== 新增:温度平衡状态卡片 ========== -->
|
||||
<Border Background="#E0F7FA" Style="{StaticResource CardStyle}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
|
||||
|
||||
<StackPanel Grid.Column="1">
|
||||
<TextBlock Text="温度平衡状态"
|
||||
FontSize="13"
|
||||
Foreground="#666666"/>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="计时:"
|
||||
FontSize="16"
|
||||
Foreground="#2C3E50"
|
||||
Margin="0,0,5,0"/>
|
||||
<TextBlock x:Name="txtBalanceTimeElapsed"
|
||||
Text="0秒"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Foreground="#2C3E50"
|
||||
Margin="0,0,15,0"/>
|
||||
|
||||
</StackPanel>
|
||||
<TextBlock x:Name="txtBalanceCondition"
|
||||
Text="平衡条件: 炉内温度波动正常至少10分钟 且 最大温差<10°C 且 温度漂移<2°C"
|
||||
FontSize="12"
|
||||
Foreground="#666666"
|
||||
Margin="0,5,0,0"/>
|
||||
<Border x:Name="balanceStatusBorder"
|
||||
Background="#BDC3C7"
|
||||
CornerRadius="4"
|
||||
Padding="8,4"
|
||||
Margin="0,5,0,0">
|
||||
<TextBlock x:Name="txtBalanceResult"
|
||||
Text="未判断"
|
||||
Foreground="White"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 新增:最终平衡判断状态卡片 -->
|
||||
<Border Background="#FFECB3" Style="{StaticResource CardStyle}">
|
||||
<Grid>
|
||||
@@ -879,99 +916,257 @@
|
||||
|
||||
<!-- 中间:状态信息 -->
|
||||
<StackPanel Grid.Column="1">
|
||||
<TextBlock Text="最终平衡判断"
|
||||
FontSize="13"
|
||||
Foreground="#666666"
|
||||
FontWeight="SemiBold"/>
|
||||
<TextBlock Text="三通道温度平衡判断"
|
||||
FontSize="13"
|
||||
Foreground="#666666"
|
||||
FontWeight="SemiBold"/>
|
||||
|
||||
<!-- 第一行:状态和计时 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,2,0,0">
|
||||
<TextBlock x:Name="txtFinalBalanceState"
|
||||
Text="未开始"
|
||||
Text="实验未开始"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Foreground="#2C3E50"
|
||||
Margin="0,0,15,0"/>
|
||||
<TextBlock Text="计时:"
|
||||
<TextBlock Text="实验时间:"
|
||||
FontSize="14"
|
||||
Foreground="#666666"
|
||||
Margin="0,0,5,0"/>
|
||||
<TextBlock x:Name="txtFinalBalanceTimer"
|
||||
Text="00:00"
|
||||
Text="00:00 / 60:00"
|
||||
FontSize="14"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#E74C3C"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 第二行:温度数据 -->
|
||||
<!-- 第二行:温度数据和窗口信息 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
|
||||
<TextBlock Text="初始:"
|
||||
<TextBlock Text="当前窗口:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtFinalBalanceInitialTemp"
|
||||
Text="0.0°C"
|
||||
<TextBlock x:Name="txtCurrentWindow"
|
||||
Text="0-10min"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#2C3E50"
|
||||
Margin="0,0,10,0"/>
|
||||
Margin="0,0,15,0"/>
|
||||
|
||||
<TextBlock Text="最高:"
|
||||
<TextBlock Text="计算次数:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtFinalBalanceMaxTemp"
|
||||
Text="0.0°C"
|
||||
<TextBlock x:Name="txtCalculationCount"
|
||||
Text="第1次"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#E74C3C"
|
||||
Margin="0,0,10,0"/>
|
||||
|
||||
<TextBlock Text="当前:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtFinalBalanceCurrentTemp"
|
||||
Text="0.0°C"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#2C3E50"/>
|
||||
Foreground="#E74C3C"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 第三行:数据统计 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
|
||||
<TextBlock Text="数据点:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtFinalBalanceDataCount"
|
||||
Text="0"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#2C3E50"
|
||||
Margin="0,0,10,0"/>
|
||||
|
||||
<TextBlock Text="漂移:"
|
||||
<!-- 第三行:三路温度显示 -->
|
||||
<StackPanel Margin="0,3,0,0">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="炉内:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtFinalBalanceDrift"
|
||||
<TextBlock x:Name="txtFurnaceTemp"
|
||||
Text="0.0°C"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#2C3E50"/>
|
||||
Foreground="#E74C3C"
|
||||
Margin="0,0,15,0"/>
|
||||
|
||||
<TextBlock Text="样品内:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtSampleInnerTemp"
|
||||
Text="0.0°C"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#3498DB"
|
||||
Margin="0,0,15,0"/>
|
||||
|
||||
<TextBlock Text="样品表面:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtSampleOuterTemp"
|
||||
Text="0.0°C"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#9B59B6"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 三路温度斜率 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,2,0,0">
|
||||
<Border Background="#FFE5E5" CornerRadius="2" Padding="3,1" Margin="0,0,4,0">
|
||||
<TextBlock x:Name="txtFurnaceSlope"
|
||||
Text="炉内: 0.00℃/10min"
|
||||
FontSize="10"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#E74C3C"/>
|
||||
</Border>
|
||||
|
||||
<Border Background="#E5F3FF" CornerRadius="2" Padding="3,1" Margin="4,0,4,0">
|
||||
<TextBlock x:Name="txtSampleInnerSlope"
|
||||
Text="样品内: 0.00℃/10min"
|
||||
FontSize="10"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#3498DB"/>
|
||||
</Border>
|
||||
|
||||
<Border Background="#F0E5FF" CornerRadius="2" Padding="3,1" Margin="4,0,0,0">
|
||||
<TextBlock x:Name="txtSampleOuterSlope"
|
||||
Text="样品表面: 0.00℃/10min"
|
||||
FontSize="10"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#9B59B6"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 第四行:平衡状态和平衡条件 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
|
||||
<TextBlock Text="平衡状态:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtBalanceStatus2"
|
||||
Text="未平衡"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#E74C3C"
|
||||
Margin="0,0,15,0"/>
|
||||
|
||||
<TextBlock Text="平衡条件:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtBalanceCondition2"
|
||||
Text="三通道<2℃/10min"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#27AE60"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 第五行:平衡时间和窗口统计 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
|
||||
<TextBlock Text="最终平衡时间:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtFinalBalanceTime"
|
||||
Text="未达到"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#27AE60"
|
||||
Margin="0,0,15,0"/>
|
||||
|
||||
<TextBlock Text="平衡窗口:"
|
||||
FontSize="12"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtBalancedWindowsCount"
|
||||
Text="0/0"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#2C3E50"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 第六行:进度条 -->
|
||||
<StackPanel Margin="0,8,0,0">
|
||||
<Grid Margin="0,0,0,2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 进度文本 -->
|
||||
<TextBlock x:Name="txtExperimentProgress"
|
||||
Text="实验进度: 0/60分钟 (0%)"
|
||||
FontSize="10"
|
||||
Foreground="#666666"/>
|
||||
|
||||
<!-- 数据统计 -->
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||
<TextBlock Text="数据点:"
|
||||
FontSize="10"
|
||||
Foreground="#666666"/>
|
||||
<TextBlock x:Name="txtDataPointCount"
|
||||
Text="0"
|
||||
FontSize="10"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="#2C3E50"
|
||||
Margin="0,0,10,0"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- 进度条 -->
|
||||
<ProgressBar x:Name="progressExperiment"
|
||||
Height="8"
|
||||
Minimum="0"
|
||||
Maximum="60"
|
||||
Value="0"
|
||||
Foreground="#3498DB"
|
||||
Background="#ECF0F1"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 右侧:状态指示 -->
|
||||
<Border Grid.Column="2"
|
||||
x:Name="finalBalanceStatusBorder"
|
||||
Background="#BDC3C7"
|
||||
CornerRadius="4"
|
||||
Padding="8,4"
|
||||
Margin="10,0,0,0"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock x:Name="txtFinalBalanceStatusText"
|
||||
Text="等待开始"
|
||||
Foreground="White"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"/>
|
||||
</Border>
|
||||
<!-- 右侧:状态指示和控制按钮 -->
|
||||
<StackPanel Grid.Column="2"
|
||||
Margin="10,0,0,0"
|
||||
VerticalAlignment="Center">
|
||||
|
||||
<!-- 状态指示 -->
|
||||
<Border x:Name="finalBalanceStatusBorder"
|
||||
Background="#BDC3C7"
|
||||
CornerRadius="4"
|
||||
Padding="8,4"
|
||||
Margin="0,0,0,8">
|
||||
<StackPanel>
|
||||
<TextBlock x:Name="txtFinalBalanceStatusText"
|
||||
Text="等待开始"
|
||||
Foreground="White"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"/>
|
||||
<TextBlock x:Name="txtExperimentPhase"
|
||||
Text="前30分钟"
|
||||
Foreground="White"
|
||||
FontSize="10"
|
||||
Margin="0,2,0,0"
|
||||
HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 控制按钮 -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,5,0,0">
|
||||
|
||||
<!-- 暂停按钮 -->
|
||||
<Button x:Name="btnPauseExperiment"
|
||||
Style="{StaticResource IconButtonStyle}"
|
||||
ToolTip="暂停实验"
|
||||
Click="btnPauseExperiment_Click"
|
||||
Margin="2,0,2,0"
|
||||
IsEnabled="False">
|
||||
<Viewbox Width="16" Height="16">
|
||||
<Canvas Width="24" Height="24">
|
||||
<Rectangle Width="4" Height="14" Fill="White" Canvas.Left="6" Canvas.Top="5"/>
|
||||
<Rectangle Width="4" Height="14" Fill="White" Canvas.Left="14" Canvas.Top="5"/>
|
||||
</Canvas>
|
||||
</Viewbox>
|
||||
</Button>
|
||||
|
||||
<!-- 重置按钮 -->
|
||||
<Button x:Name="btnResetExperiment"
|
||||
Style="{StaticResource IconButtonStyle}"
|
||||
ToolTip="重置实验"
|
||||
Click="btnResetExperiment_Click"
|
||||
Margin="2,0,0,0">
|
||||
<Viewbox Width="16" Height="16">
|
||||
<Canvas Width="24" Height="24">
|
||||
<Path Data="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"
|
||||
Fill="White"/>
|
||||
</Canvas>
|
||||
</Viewbox>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -57,7 +57,8 @@ namespace jiancaiburanxing
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadTempDataFromFile();
|
||||
LoadDataFromTempFile();
|
||||
//LoadTempDataFromFile();
|
||||
//AddSampleData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -66,50 +67,141 @@ namespace jiancaiburanxing
|
||||
MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
// 可选:从临时文件加载数据
|
||||
private void LoadTempDataFromFile()
|
||||
|
||||
|
||||
// 在类中添加这些辅助方法
|
||||
private double ParseDouble(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return 0;
|
||||
|
||||
// 移除可能的中文单位字符
|
||||
value = value.Replace("℃", "").Replace("°C", "").Replace("g", "").Replace("%", "").Trim();
|
||||
|
||||
if (double.TryParse(value, out double result))
|
||||
return result;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int ParseInt(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return 0;
|
||||
|
||||
// 移除非数字字符
|
||||
value = new string(value.Where(char.IsDigit).ToArray());
|
||||
|
||||
if (int.TryParse(value, out int result))
|
||||
return result;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private List<TestReportData> LoadDataFromTempFile()
|
||||
{
|
||||
var reportDataList = new List<TestReportData>();
|
||||
|
||||
try
|
||||
{
|
||||
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TempReportData.txt");
|
||||
if (!File.Exists(filePath)) return;
|
||||
|
||||
var lines = File.ReadAllLines(filePath, Encoding.UTF8);
|
||||
foreach (var line in lines)
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
var parts = line.Split('|');
|
||||
if (parts.Length >= 14)
|
||||
{
|
||||
var reportData = new TestReportData
|
||||
{
|
||||
SampleCode = parts[0],
|
||||
SampleName = parts[1],
|
||||
SampleSpec = parts[2],
|
||||
InitialTemp = double.Parse(parts[3]),
|
||||
MaxTemp = double.Parse(parts[4]),
|
||||
FinalTemp = double.Parse(parts[5]),
|
||||
TempRise = double.Parse(parts[6]),
|
||||
InitialWeight = double.Parse(parts[7]),
|
||||
FinalWeight = double.Parse(parts[8]),
|
||||
LossPercent = double.Parse(parts[9]),
|
||||
FlameDuration = int.Parse(parts[10]),
|
||||
TestDate = parts[11],
|
||||
TestDuration = parts[12],
|
||||
BalanceStatus = parts[13],
|
||||
Remarks = parts.Length > 14 ? parts[14] : ""
|
||||
};
|
||||
|
||||
_testData.Add(reportData);
|
||||
}
|
||||
return reportDataList;
|
||||
}
|
||||
|
||||
Debug.WriteLine($"从临时文件加载了 {_testData.Count} 条数据");
|
||||
var lines = File.ReadAllLines(filePath, Encoding.UTF8);
|
||||
|
||||
// 跳过表头(第一行)
|
||||
for (int i = 1; i < lines.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(lines[i]))
|
||||
continue;
|
||||
|
||||
var fields = lines[i].Split('|');
|
||||
|
||||
if (fields.Length >= 19) // 确保有足够的字段
|
||||
{
|
||||
var data = new TestReportData
|
||||
{
|
||||
SampleCode = fields[0],
|
||||
SampleName = fields[1],
|
||||
SampleSpec = fields[2],
|
||||
InitialTemp = ParseDouble(fields[3]),
|
||||
MaxTemp = ParseDouble(fields[4]),
|
||||
FinalTemp = ParseDouble(fields[5]),
|
||||
TempRise = ParseDouble(fields[6]),
|
||||
CenterMaxTemp = ParseDouble(fields[7]),
|
||||
CenterFinalTemp = ParseDouble(fields[8]),
|
||||
SurfaceMaxTemp = ParseDouble(fields[9]),
|
||||
SurfaceFinalTemp = ParseDouble(fields[10]),
|
||||
InitialWeight = ParseDouble(fields[11]),
|
||||
FinalWeight = ParseDouble(fields[12]),
|
||||
LossPercent = ParseDouble(fields[13]),
|
||||
FlameDuration = ParseInt(fields[14]),
|
||||
TestDate = fields[15],
|
||||
TestDuration = fields[16],
|
||||
BalanceStatus = fields[17],
|
||||
Remarks = fields.Length > 18 ? fields[18] : ""
|
||||
};
|
||||
|
||||
reportDataList.Add(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"加载临时数据失败: {ex.Message}");
|
||||
Debug.WriteLine($"读取临时数据失败: {ex.Message}");
|
||||
}
|
||||
|
||||
return reportDataList;
|
||||
}
|
||||
|
||||
// 可选:从临时文件加载数据
|
||||
//private void LoadTempDataFromFile()
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TempReportData.txt");
|
||||
// if (!File.Exists(filePath)) return;
|
||||
|
||||
// var lines = File.ReadAllLines(filePath, Encoding.UTF8);
|
||||
// foreach (var line in lines)
|
||||
// {
|
||||
// var parts = line.Split('|');
|
||||
// if (parts.Length >= 14)
|
||||
// {
|
||||
// var reportData = new TestReportData
|
||||
// {
|
||||
// SampleCode = parts[0],
|
||||
// SampleName = parts[1],
|
||||
// SampleSpec = parts[2],
|
||||
// InitialTemp = double.Parse(parts[3]),
|
||||
// MaxTemp = double.Parse(parts[4]),
|
||||
// FinalTemp = double.Parse(parts[5]),
|
||||
// TempRise = double.Parse(parts[6]),
|
||||
// InitialWeight = double.Parse(parts[7]),
|
||||
// FinalWeight = double.Parse(parts[8]),
|
||||
// LossPercent = double.Parse(parts[9]),
|
||||
// FlameDuration = int.Parse(parts[10]),
|
||||
// TestDate = parts[11],
|
||||
// TestDuration = parts[12],
|
||||
// BalanceStatus = parts[13],
|
||||
// Remarks = parts.Length > 14 ? parts[14] : ""
|
||||
// };
|
||||
|
||||
// _testData.Add(reportData);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Debug.WriteLine($"从临时文件加载了 {_testData.Count} 条数据");
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Debug.WriteLine($"加载临时数据失败: {ex.Message}");
|
||||
// }
|
||||
//}
|
||||
//// 添加示例数据
|
||||
//private void AddSampleData()
|
||||
//{
|
||||
@@ -198,178 +290,429 @@ namespace jiancaiburanxing
|
||||
|
||||
// 添加新的试验数据(由主窗口调用)
|
||||
|
||||
//private void ExportToExcel(string filePath)
|
||||
//{
|
||||
// using (var workbook = new XLWorkbook())
|
||||
// {
|
||||
// // 创建一个工作表
|
||||
// var worksheet = workbook.Worksheets.Add("不燃性试验报告");
|
||||
|
||||
// // 设置整体样式
|
||||
// worksheet.Style.Font.FontName = "微软雅黑";
|
||||
// worksheet.Style.Font.FontSize = 10;
|
||||
|
||||
// // 1. 标题行
|
||||
// var titleRow1 = worksheet.Cell(1, 1);
|
||||
// titleRow1.Value = "建材不燃性试验数据报表";
|
||||
// titleRow1.Style.Font.FontSize = 16;
|
||||
// titleRow1.Style.Font.Bold = true;
|
||||
// titleRow1.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
// titleRow1.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
// worksheet.Range(1, 1, 1, 19).Merge(); // 合并单元格,19列(增加4个温度字段)
|
||||
|
||||
// var titleRow2 = worksheet.Cell(2, 1);
|
||||
// titleRow2.Value = $"生成时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
|
||||
// titleRow2.Style.Font.FontSize = 11;
|
||||
// titleRow2.Style.Font.Italic = true;
|
||||
// worksheet.Range(2, 1, 2, 19).Merge();
|
||||
|
||||
// var titleRow3 = worksheet.Cell(3, 1);
|
||||
// titleRow3.Value = "符合标准: GB/T 5464-2010";
|
||||
// titleRow3.Style.Font.FontSize = 11;
|
||||
// worksheet.Range(3, 1, 3, 19).Merge();
|
||||
|
||||
// // 空行
|
||||
// worksheet.Row(4).Height = 10;
|
||||
|
||||
// // 2. 表头(共19列)
|
||||
// var headers = new string[]
|
||||
// {
|
||||
// "试样编号", "试样名称", "试样规格",
|
||||
// "炉内初始温度(℃)", "炉内最高温度(℃)", "炉内最终温度(℃)", "温升(℃)",
|
||||
// "试样中心最高温(℃)", "试样中心最终温(℃)", // 新增字段
|
||||
// "试样表面最高温(℃)", "试样表面最终温(℃)", // 新增字段
|
||||
// "试样初始质量(g)", "试样结束质量(g)", "质量损失(%)",
|
||||
// "火焰持续时间(s)", "试验日期", "试验持续时间", "平衡状态", "备注"
|
||||
// };
|
||||
|
||||
// int rowIndex = 5;
|
||||
// for (int i = 0; i < headers.Length; i++)
|
||||
// {
|
||||
// var cell = worksheet.Cell(rowIndex, i + 1);
|
||||
// cell.Value = headers[i];
|
||||
// cell.Style.Font.Bold = true;
|
||||
// cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
// cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
// cell.Style.Fill.BackgroundColor = XLColor.LightGray;
|
||||
// cell.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
|
||||
// cell.Style.Border.OutsideBorderColor = XLColor.Black;
|
||||
|
||||
// // 设置列宽(根据内容调整)
|
||||
// switch (i)
|
||||
// {
|
||||
// case 0: worksheet.Column(i + 1).Width = 12; break; // 试样编号
|
||||
// case 1: worksheet.Column(i + 1).Width = 15; break; // 试样名称
|
||||
// case 2: worksheet.Column(i + 1).Width = 10; break; // 试样规格
|
||||
// case 3: worksheet.Column(i + 1).Width = 15; break; // 炉内初始温度
|
||||
// case 4: worksheet.Column(i + 1).Width = 15; break; // 炉内最高温度
|
||||
// case 5: worksheet.Column(i + 1).Width = 15; break; // 炉内最终温度
|
||||
// case 6: worksheet.Column(i + 1).Width = 12; break; // 温升
|
||||
// case 7: worksheet.Column(i + 1).Width = 15; break; // 试样中心最高温度
|
||||
// case 8: worksheet.Column(i + 1).Width = 15; break; // 试样中心最终温度
|
||||
// case 9: worksheet.Column(i + 1).Width = 15; break; // 试样表面最高温度
|
||||
// case 10: worksheet.Column(i + 1).Width = 15; break; // 试样表面最终温度
|
||||
// case 11: worksheet.Column(i + 1).Width = 15; break; // 试样初始质量
|
||||
// case 12: worksheet.Column(i + 1).Width = 15; break; // 试样结束质量
|
||||
// case 13: worksheet.Column(i + 1).Width = 12; break; // 质量损失
|
||||
// case 14: worksheet.Column(i + 1).Width = 15; break; // 火焰持续时间
|
||||
// case 15: worksheet.Column(i + 1).Width = 12; break; // 试验日期
|
||||
// case 16: worksheet.Column(i + 1).Width = 12; break; // 试验持续时间
|
||||
// case 17: worksheet.Column(i + 1).Width = 12; break; // 平衡状态
|
||||
// case 18: worksheet.Column(i + 1).Width = 20; break; // 备注
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 3. 数据行
|
||||
// rowIndex++;
|
||||
// foreach (var item in _testData)
|
||||
// {
|
||||
// worksheet.Cell(rowIndex, 1).Value = item.SampleCode;
|
||||
// worksheet.Cell(rowIndex, 2).Value = item.SampleName;
|
||||
// worksheet.Cell(rowIndex, 3).Value = item.SampleSpec;
|
||||
// worksheet.Cell(rowIndex, 4).Value = item.InitialTemp;
|
||||
// worksheet.Cell(rowIndex, 5).Value = item.MaxTemp;
|
||||
// worksheet.Cell(rowIndex, 6).Value = item.FinalTemp;
|
||||
// worksheet.Cell(rowIndex, 7).Value = item.TempRise;
|
||||
|
||||
// // 新增的4个温度字段
|
||||
// worksheet.Cell(rowIndex, 8).Value = item.CenterMaxTemp;
|
||||
// worksheet.Cell(rowIndex, 9).Value = item.CenterFinalTemp;
|
||||
// worksheet.Cell(rowIndex, 10).Value = item.SurfaceMaxTemp;
|
||||
// worksheet.Cell(rowIndex, 11).Value = item.SurfaceFinalTemp;
|
||||
|
||||
// worksheet.Cell(rowIndex, 12).Value = item.InitialWeight;
|
||||
// worksheet.Cell(rowIndex, 13).Value = item.FinalWeight;
|
||||
// worksheet.Cell(rowIndex, 14).Value = item.LossPercent;
|
||||
// worksheet.Cell(rowIndex, 15).Value = item.FlameDuration;
|
||||
// worksheet.Cell(rowIndex, 16).Value = item.TestDate;
|
||||
// worksheet.Cell(rowIndex, 17).Value = item.TestDuration;
|
||||
// worksheet.Cell(rowIndex, 18).Value = item.BalanceStatus;
|
||||
// worksheet.Cell(rowIndex, 19).Value = item.Remarks;
|
||||
|
||||
// // 设置数据行样式
|
||||
// for (int col = 1; col <= 19; col++)
|
||||
// {
|
||||
// var cell = worksheet.Cell(rowIndex, col);
|
||||
// cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
// cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
// cell.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
|
||||
// cell.Style.Border.OutsideBorderColor = XLColor.Gray;
|
||||
|
||||
// // 数值格式(温度和质量列保留一位小数)
|
||||
// if ((col >= 4 && col <= 11) || col == 14) // 所有温度列 + 质量损失
|
||||
// {
|
||||
// cell.Style.NumberFormat.Format = "0.0";
|
||||
// }
|
||||
// else if (col == 12 || col == 13) // 质量列
|
||||
// {
|
||||
// cell.Style.NumberFormat.Format = "0.00";
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 隔行变色
|
||||
// if (rowIndex % 2 == 0)
|
||||
// {
|
||||
// worksheet.Range(rowIndex, 1, rowIndex, 19).Style
|
||||
// .Fill.BackgroundColor = XLColor.White;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// worksheet.Range(rowIndex, 1, rowIndex, 19).Style
|
||||
// .Fill.BackgroundColor = XLColor.LightSkyBlue;
|
||||
// }
|
||||
|
||||
// rowIndex++;
|
||||
// }
|
||||
|
||||
// // 4. 自动调整行高
|
||||
// worksheet.Rows(5, rowIndex - 1).AdjustToContents();
|
||||
|
||||
// // 5. 添加边框
|
||||
// var dataRange = worksheet.Range(5, 1, rowIndex - 1, 19);
|
||||
// dataRange.Style.Border.InsideBorder = XLBorderStyleValues.Thin;
|
||||
// dataRange.Style.Border.InsideBorderColor = XLColor.Gray;
|
||||
// dataRange.Style.Border.OutsideBorder = XLBorderStyleValues.Medium;
|
||||
// dataRange.Style.Border.OutsideBorderColor = XLColor.Black;
|
||||
|
||||
// // 6. 添加分组标识(可选)
|
||||
// // 温度相关列设置不同背景色
|
||||
// //var tempHeaderRange = worksheet.Range(5, 4, 5, 11);
|
||||
// //tempHeaderRange.Style.Fill.BackgroundColor = XLColor.LightGreen;
|
||||
|
||||
// //var weightHeaderRange = worksheet.Range(5, 12, 5, 14);
|
||||
// //weightHeaderRange.Style.Fill.BackgroundColor = XLColor.LightYellow;
|
||||
|
||||
// // 7. 添加页脚
|
||||
// //var footerRow = worksheet.Cell(rowIndex + 2, 1);
|
||||
// //footerRow.Value = "备注:本报表自动生成,数据仅供参考";
|
||||
// //footerRow.Style.Font.FontSize = 9;
|
||||
// //footerRow.Style.Font.FontColor = XLColor.Gray;
|
||||
// //footerRow.Style.Font.Italic = true;
|
||||
// //worksheet.Range(rowIndex + 2, 1, rowIndex + 2, 19).Merge();
|
||||
|
||||
// // 8. 保存文件
|
||||
// workbook.SaveAs(filePath);
|
||||
// }
|
||||
//}
|
||||
|
||||
private void ExportToExcel(string filePath)
|
||||
{
|
||||
using (var workbook = new XLWorkbook())
|
||||
try
|
||||
{
|
||||
// 创建一个工作表
|
||||
var worksheet = workbook.Worksheets.Add("不燃性试验报告");
|
||||
// 从临时文件加载数据
|
||||
var dataList = LoadDataFromTempFile();
|
||||
|
||||
// 设置整体样式
|
||||
worksheet.Style.Font.FontName = "微软雅黑";
|
||||
worksheet.Style.Font.FontSize = 10;
|
||||
|
||||
// 1. 标题行
|
||||
var titleRow1 = worksheet.Cell(1, 1);
|
||||
titleRow1.Value = "建材不燃性试验数据报表";
|
||||
titleRow1.Style.Font.FontSize = 16;
|
||||
titleRow1.Style.Font.Bold = true;
|
||||
titleRow1.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
titleRow1.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
worksheet.Range(1, 1, 1, 19).Merge(); // 合并单元格,19列(增加4个温度字段)
|
||||
|
||||
var titleRow2 = worksheet.Cell(2, 1);
|
||||
titleRow2.Value = $"生成时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
|
||||
titleRow2.Style.Font.FontSize = 11;
|
||||
titleRow2.Style.Font.Italic = true;
|
||||
worksheet.Range(2, 1, 2, 19).Merge();
|
||||
|
||||
var titleRow3 = worksheet.Cell(3, 1);
|
||||
titleRow3.Value = "符合标准: GB/T 5464-2010";
|
||||
titleRow3.Style.Font.FontSize = 11;
|
||||
worksheet.Range(3, 1, 3, 19).Merge();
|
||||
|
||||
// 空行
|
||||
worksheet.Row(4).Height = 10;
|
||||
|
||||
// 2. 表头(共19列)
|
||||
var headers = new string[]
|
||||
if (dataList.Count == 0)
|
||||
{
|
||||
"试样编号", "试样名称", "试样规格",
|
||||
"炉内初始温度(℃)", "炉内最高温度(℃)", "炉内最终温度(℃)", "温升(℃)",
|
||||
"试样中心最高温(℃)", "试样中心最终温(℃)", // 新增字段
|
||||
"试样表面最高温(℃)", "试样表面最终温(℃)", // 新增字段
|
||||
"试样初始质量(g)", "试样结束质量(g)", "质量损失(%)",
|
||||
"火焰持续时间(s)", "试验日期", "试验持续时间", "平衡状态", "备注"
|
||||
};
|
||||
|
||||
int rowIndex = 5;
|
||||
for (int i = 0; i < headers.Length; i++)
|
||||
{
|
||||
var cell = worksheet.Cell(rowIndex, i + 1);
|
||||
cell.Value = headers[i];
|
||||
cell.Style.Font.Bold = true;
|
||||
cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
cell.Style.Fill.BackgroundColor = XLColor.LightGray;
|
||||
cell.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
|
||||
cell.Style.Border.OutsideBorderColor = XLColor.Black;
|
||||
|
||||
// 设置列宽(根据内容调整)
|
||||
switch (i)
|
||||
{
|
||||
case 0: worksheet.Column(i + 1).Width = 12; break; // 试样编号
|
||||
case 1: worksheet.Column(i + 1).Width = 15; break; // 试样名称
|
||||
case 2: worksheet.Column(i + 1).Width = 10; break; // 试样规格
|
||||
case 3: worksheet.Column(i + 1).Width = 15; break; // 炉内初始温度
|
||||
case 4: worksheet.Column(i + 1).Width = 15; break; // 炉内最高温度
|
||||
case 5: worksheet.Column(i + 1).Width = 15; break; // 炉内最终温度
|
||||
case 6: worksheet.Column(i + 1).Width = 12; break; // 温升
|
||||
case 7: worksheet.Column(i + 1).Width = 15; break; // 试样中心最高温度
|
||||
case 8: worksheet.Column(i + 1).Width = 15; break; // 试样中心最终温度
|
||||
case 9: worksheet.Column(i + 1).Width = 15; break; // 试样表面最高温度
|
||||
case 10: worksheet.Column(i + 1).Width = 15; break; // 试样表面最终温度
|
||||
case 11: worksheet.Column(i + 1).Width = 15; break; // 试样初始质量
|
||||
case 12: worksheet.Column(i + 1).Width = 15; break; // 试样结束质量
|
||||
case 13: worksheet.Column(i + 1).Width = 12; break; // 质量损失
|
||||
case 14: worksheet.Column(i + 1).Width = 15; break; // 火焰持续时间
|
||||
case 15: worksheet.Column(i + 1).Width = 12; break; // 试验日期
|
||||
case 16: worksheet.Column(i + 1).Width = 12; break; // 试验持续时间
|
||||
case 17: worksheet.Column(i + 1).Width = 12; break; // 平衡状态
|
||||
case 18: worksheet.Column(i + 1).Width = 20; break; // 备注
|
||||
}
|
||||
MessageBox.Show("没有可导出的数据", "导出提示",
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 数据行
|
||||
rowIndex++;
|
||||
foreach (var item in _testData)
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
worksheet.Cell(rowIndex, 1).Value = item.SampleCode;
|
||||
worksheet.Cell(rowIndex, 2).Value = item.SampleName;
|
||||
worksheet.Cell(rowIndex, 3).Value = item.SampleSpec;
|
||||
worksheet.Cell(rowIndex, 4).Value = item.InitialTemp;
|
||||
worksheet.Cell(rowIndex, 5).Value = item.MaxTemp;
|
||||
worksheet.Cell(rowIndex, 6).Value = item.FinalTemp;
|
||||
worksheet.Cell(rowIndex, 7).Value = item.TempRise;
|
||||
// 创建一个工作表
|
||||
var worksheet = workbook.Worksheets.Add("不燃性试验报告");
|
||||
|
||||
// 新增的4个温度字段
|
||||
worksheet.Cell(rowIndex, 8).Value = item.CenterMaxTemp;
|
||||
worksheet.Cell(rowIndex, 9).Value = item.CenterFinalTemp;
|
||||
worksheet.Cell(rowIndex, 10).Value = item.SurfaceMaxTemp;
|
||||
worksheet.Cell(rowIndex, 11).Value = item.SurfaceFinalTemp;
|
||||
// 设置整体样式
|
||||
worksheet.Style.Font.FontName = "微软雅黑";
|
||||
worksheet.Style.Font.FontSize = 10;
|
||||
|
||||
worksheet.Cell(rowIndex, 12).Value = item.InitialWeight;
|
||||
worksheet.Cell(rowIndex, 13).Value = item.FinalWeight;
|
||||
worksheet.Cell(rowIndex, 14).Value = item.LossPercent;
|
||||
worksheet.Cell(rowIndex, 15).Value = item.FlameDuration;
|
||||
worksheet.Cell(rowIndex, 16).Value = item.TestDate;
|
||||
worksheet.Cell(rowIndex, 17).Value = item.TestDuration;
|
||||
worksheet.Cell(rowIndex, 18).Value = item.BalanceStatus;
|
||||
worksheet.Cell(rowIndex, 19).Value = item.Remarks;
|
||||
// 1. 标题行
|
||||
var titleRow1 = worksheet.Cell(1, 1);
|
||||
titleRow1.Value = "建材不燃性试验数据报表";
|
||||
titleRow1.Style.Font.FontSize = 16;
|
||||
titleRow1.Style.Font.Bold = true;
|
||||
titleRow1.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
titleRow1.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
worksheet.Range(1, 1, 1, 19).Merge(); // 合并单元格,19列
|
||||
|
||||
// 设置数据行样式
|
||||
for (int col = 1; col <= 19; col++)
|
||||
var titleRow2 = worksheet.Cell(2, 1);
|
||||
titleRow2.Value = $"生成时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
|
||||
titleRow2.Style.Font.FontSize = 11;
|
||||
titleRow2.Style.Font.Italic = true;
|
||||
worksheet.Range(2, 1, 2, 19).Merge();
|
||||
|
||||
var titleRow3 = worksheet.Cell(3, 1);
|
||||
titleRow3.Value = "符合标准: GB/T 5464-2010";
|
||||
titleRow3.Style.Font.FontSize = 11;
|
||||
worksheet.Range(3, 1, 3, 19).Merge();
|
||||
|
||||
// 空行
|
||||
worksheet.Row(4).Height = 10;
|
||||
|
||||
// 2. 表头(共19列)
|
||||
var headers = new string[]
|
||||
{
|
||||
var cell = worksheet.Cell(rowIndex, col);
|
||||
"试样编号", "试样名称", "试样规格",
|
||||
"炉内初始温度(℃)", "炉内最高温度(℃)", "炉内最终温度(℃)", "温升(℃)",
|
||||
"试样中心最高温度(℃)", "试样中心最终温度(℃)", // 新增字段
|
||||
"试样表面最高温度(℃)", "试样表面最终温度(℃)", // 新增字段
|
||||
"试样初始质量(g)", "试样结束质量(g)", "质量损失(%)",
|
||||
"火焰持续时间(s)", "试验日期", "试验持续时间", "平衡状态", "备注"
|
||||
};
|
||||
|
||||
int rowIndex = 5;
|
||||
for (int i = 0; i < headers.Length; i++)
|
||||
{
|
||||
var cell = worksheet.Cell(rowIndex, i + 1);
|
||||
cell.Value = headers[i];
|
||||
cell.Style.Font.Bold = true;
|
||||
cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
cell.Style.Fill.BackgroundColor = XLColor.LightGray;
|
||||
cell.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
|
||||
cell.Style.Border.OutsideBorderColor = XLColor.Gray;
|
||||
cell.Style.Border.OutsideBorderColor = XLColor.Black;
|
||||
|
||||
// 数值格式(温度和质量列保留一位小数)
|
||||
if ((col >= 4 && col <= 11) || col == 14) // 所有温度列 + 质量损失
|
||||
// 设置列宽(根据内容调整)
|
||||
switch (i)
|
||||
{
|
||||
cell.Style.NumberFormat.Format = "0.0";
|
||||
}
|
||||
else if (col == 12 || col == 13) // 质量列
|
||||
{
|
||||
cell.Style.NumberFormat.Format = "0.00";
|
||||
case 0: worksheet.Column(i + 1).Width = 12; break; // 试样编号
|
||||
case 1: worksheet.Column(i + 1).Width = 15; break; // 试样名称
|
||||
case 2: worksheet.Column(i + 1).Width = 10; break; // 试样规格
|
||||
case 3: worksheet.Column(i + 1).Width = 15; break; // 炉内初始温度
|
||||
case 4: worksheet.Column(i + 1).Width = 15; break; // 炉内最高温度
|
||||
case 5: worksheet.Column(i + 1).Width = 15; break; // 炉内最终温度
|
||||
case 6: worksheet.Column(i + 1).Width = 12; break; // 温升
|
||||
case 7: worksheet.Column(i + 1).Width = 15; break; // 试样中心最高温度
|
||||
case 8: worksheet.Column(i + 1).Width = 15; break; // 试样中心最终温度
|
||||
case 9: worksheet.Column(i + 1).Width = 15; break; // 试样表面最高温度
|
||||
case 10: worksheet.Column(i + 1).Width = 15; break; // 试样表面最终温度
|
||||
case 11: worksheet.Column(i + 1).Width = 15; break; // 试样初始质量
|
||||
case 12: worksheet.Column(i + 1).Width = 15; break; // 试样结束质量
|
||||
case 13: worksheet.Column(i + 1).Width = 12; break; // 质量损失
|
||||
case 14: worksheet.Column(i + 1).Width = 15; break; // 火焰持续时间
|
||||
case 15: worksheet.Column(i + 1).Width = 12; break; // 试验日期
|
||||
case 16: worksheet.Column(i + 1).Width = 12; break; // 试验持续时间
|
||||
case 17: worksheet.Column(i + 1).Width = 12; break; // 平衡状态
|
||||
case 18: worksheet.Column(i + 1).Width = 20; break; // 备注
|
||||
}
|
||||
}
|
||||
|
||||
// 隔行变色
|
||||
if (rowIndex % 2 == 0)
|
||||
{
|
||||
worksheet.Range(rowIndex, 1, rowIndex, 19).Style
|
||||
.Fill.BackgroundColor = XLColor.White;
|
||||
}
|
||||
else
|
||||
{
|
||||
worksheet.Range(rowIndex, 1, rowIndex, 19).Style
|
||||
.Fill.BackgroundColor = XLColor.LightSkyBlue;
|
||||
}
|
||||
|
||||
// 3. 数据行
|
||||
rowIndex++;
|
||||
foreach (var item in dataList)
|
||||
{
|
||||
worksheet.Cell(rowIndex, 1).Value = item.SampleCode ?? "";
|
||||
worksheet.Cell(rowIndex, 2).Value = item.SampleName ?? "";
|
||||
worksheet.Cell(rowIndex, 3).Value = item.SampleSpec ?? "";
|
||||
worksheet.Cell(rowIndex, 4).Value = item.InitialTemp;
|
||||
worksheet.Cell(rowIndex, 5).Value = item.MaxTemp;
|
||||
worksheet.Cell(rowIndex, 6).Value = item.FinalTemp;
|
||||
worksheet.Cell(rowIndex, 7).Value = item.TempRise;
|
||||
|
||||
// 新增的4个温度字段
|
||||
worksheet.Cell(rowIndex, 8).Value = item.CenterMaxTemp;
|
||||
worksheet.Cell(rowIndex, 9).Value = item.CenterFinalTemp;
|
||||
worksheet.Cell(rowIndex, 10).Value = item.SurfaceMaxTemp;
|
||||
worksheet.Cell(rowIndex, 11).Value = item.SurfaceFinalTemp;
|
||||
|
||||
worksheet.Cell(rowIndex, 12).Value = item.InitialWeight;
|
||||
worksheet.Cell(rowIndex, 13).Value = item.FinalWeight;
|
||||
worksheet.Cell(rowIndex, 14).Value = item.LossPercent;
|
||||
worksheet.Cell(rowIndex, 15).Value = item.FlameDuration;
|
||||
worksheet.Cell(rowIndex, 16).Value = item.TestDate ?? "";
|
||||
worksheet.Cell(rowIndex, 17).Value = item.TestDuration ?? "";
|
||||
worksheet.Cell(rowIndex, 18).Value = item.BalanceStatus ?? "";
|
||||
worksheet.Cell(rowIndex, 19).Value = item.Remarks ?? "";
|
||||
|
||||
// 设置数据行样式
|
||||
for (int col = 1; col <= 19; col++)
|
||||
{
|
||||
var cell = worksheet.Cell(rowIndex, col);
|
||||
cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
cell.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
|
||||
cell.Style.Border.OutsideBorderColor = XLColor.Gray;
|
||||
|
||||
// 数值格式(温度和质量列保留一位小数)
|
||||
if ((col >= 4 && col <= 11) || col == 14) // 所有温度列 + 质量损失
|
||||
{
|
||||
cell.Style.NumberFormat.Format = "0.0";
|
||||
}
|
||||
else if (col == 12 || col == 13) // 质量列
|
||||
{
|
||||
cell.Style.NumberFormat.Format = "0.00";
|
||||
}
|
||||
}
|
||||
|
||||
// 隔行变色
|
||||
if (rowIndex % 2 == 0)
|
||||
{
|
||||
worksheet.Range(rowIndex, 1, rowIndex, 19).Style
|
||||
.Fill.BackgroundColor = XLColor.White;
|
||||
}
|
||||
else
|
||||
{
|
||||
worksheet.Range(rowIndex, 1, rowIndex, 19).Style
|
||||
.Fill.BackgroundColor = XLColor.FromArgb(240, 248, 255); // 淡蓝色
|
||||
}
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
// 4. 自动调整行高
|
||||
worksheet.Rows(5, rowIndex - 1).AdjustToContents();
|
||||
|
||||
// 5. 添加边框
|
||||
var dataRange = worksheet.Range(5, 1, rowIndex - 1, 19);
|
||||
dataRange.Style.Border.InsideBorder = XLBorderStyleValues.Thin;
|
||||
dataRange.Style.Border.InsideBorderColor = XLColor.Gray;
|
||||
dataRange.Style.Border.OutsideBorder = XLBorderStyleValues.Medium;
|
||||
dataRange.Style.Border.OutsideBorderColor = XLColor.Black;
|
||||
|
||||
// 6. 添加分组标识(可选)
|
||||
// 温度相关列设置不同背景色
|
||||
var tempHeaderRange = worksheet.Range(5, 4, 5, 11);
|
||||
tempHeaderRange.Style.Fill.BackgroundColor = XLColor.LightGreen;
|
||||
|
||||
var weightHeaderRange = worksheet.Range(5, 12, 5, 14);
|
||||
weightHeaderRange.Style.Fill.BackgroundColor = XLColor.LightYellow;
|
||||
|
||||
var otherHeaderRange = worksheet.Range(5, 15, 5, 19);
|
||||
otherHeaderRange.Style.Fill.BackgroundColor = XLColor.LightSteelBlue;
|
||||
|
||||
// 7. 添加统计行(可选)
|
||||
//rowIndex += 2;
|
||||
//var statRow = worksheet.Row(rowIndex);
|
||||
|
||||
//worksheet.Cell(rowIndex, 1).Value = "统计";
|
||||
//worksheet.Cell(rowIndex, 1).Style.Font.Bold = true;
|
||||
//worksheet.Cell(rowIndex, 1).Style.Fill.BackgroundColor = XLColor.LightGray;
|
||||
//worksheet.Range(rowIndex, 1, rowIndex, 3).Merge();
|
||||
|
||||
//// 平均初始温度
|
||||
//worksheet.Cell(rowIndex, 4).Value = dataList.Average(d => d.InitialTemp);
|
||||
//worksheet.Cell(rowIndex, 4).Style.NumberFormat.Format = "0.0";
|
||||
//worksheet.Cell(rowIndex, 4).Style.Fill.BackgroundColor = XLColor.LightGreen;
|
||||
|
||||
//// 平均最高温度
|
||||
//worksheet.Cell(rowIndex, 5).Value = dataList.Average(d => d.MaxTemp);
|
||||
//worksheet.Cell(rowIndex, 5).Style.NumberFormat.Format = "0.0";
|
||||
//worksheet.Cell(rowIndex, 5).Style.Fill.BackgroundColor = XLColor.LightGreen;
|
||||
|
||||
//// 平均最终温度
|
||||
//worksheet.Cell(rowIndex, 6).Value = dataList.Average(d => d.FinalTemp);
|
||||
//worksheet.Cell(rowIndex, 6).Style.NumberFormat.Format = "0.0";
|
||||
//worksheet.Cell(rowIndex, 6).Style.Fill.BackgroundColor = XLColor.LightGreen;
|
||||
|
||||
//// 平均温升
|
||||
//worksheet.Cell(rowIndex, 7).Value = dataList.Average(d => d.TempRise);
|
||||
//worksheet.Cell(rowIndex, 7).Style.NumberFormat.Format = "0.0";
|
||||
//worksheet.Cell(rowIndex, 7).Style.Fill.BackgroundColor = XLColor.LightGreen;
|
||||
|
||||
//// 其他统计信息
|
||||
//worksheet.Cell(rowIndex, 14).Value = dataList.Average(d => d.LossPercent);
|
||||
//worksheet.Cell(rowIndex, 14).Style.NumberFormat.Format = "0.0";
|
||||
//worksheet.Cell(rowIndex, 14).Style.Fill.BackgroundColor = XLColor.LightYellow;
|
||||
|
||||
//// 8. 添加页脚
|
||||
//rowIndex += 2;
|
||||
//var footerRow = worksheet.Cell(rowIndex, 1);
|
||||
//footerRow.Value = "备注:本报表自动生成,数据仅供参考";
|
||||
//footerRow.Style.Font.FontSize = 9;
|
||||
//footerRow.Style.Font.FontColor = XLColor.Gray;
|
||||
//footerRow.Style.Font.Italic = true;
|
||||
//worksheet.Range(rowIndex, 1, rowIndex, 19).Merge();
|
||||
|
||||
//// 9. 添加筛选
|
||||
//worksheet.Range(5, 1, 5, 19).SetAutoFilter();
|
||||
|
||||
//// 10. 冻结表头
|
||||
//worksheet.SheetView.FreezeRows(5);
|
||||
|
||||
// 11. 保存文件
|
||||
workbook.SaveAs(filePath);
|
||||
|
||||
Debug.WriteLine($"Excel文件已保存: {filePath}");
|
||||
|
||||
// 显示成功消息
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
MessageBox.Show($"数据已成功导出到:\n{filePath}\n\n共导出 {dataList.Count} 条记录",
|
||||
"导出成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"导出Excel失败: {ex.Message}");
|
||||
|
||||
// 4. 自动调整行高
|
||||
worksheet.Rows(5, rowIndex - 1).AdjustToContents();
|
||||
|
||||
// 5. 添加边框
|
||||
var dataRange = worksheet.Range(5, 1, rowIndex - 1, 19);
|
||||
dataRange.Style.Border.InsideBorder = XLBorderStyleValues.Thin;
|
||||
dataRange.Style.Border.InsideBorderColor = XLColor.Gray;
|
||||
dataRange.Style.Border.OutsideBorder = XLBorderStyleValues.Medium;
|
||||
dataRange.Style.Border.OutsideBorderColor = XLColor.Black;
|
||||
|
||||
// 6. 添加分组标识(可选)
|
||||
// 温度相关列设置不同背景色
|
||||
//var tempHeaderRange = worksheet.Range(5, 4, 5, 11);
|
||||
//tempHeaderRange.Style.Fill.BackgroundColor = XLColor.LightGreen;
|
||||
|
||||
//var weightHeaderRange = worksheet.Range(5, 12, 5, 14);
|
||||
//weightHeaderRange.Style.Fill.BackgroundColor = XLColor.LightYellow;
|
||||
|
||||
// 7. 添加页脚
|
||||
//var footerRow = worksheet.Cell(rowIndex + 2, 1);
|
||||
//footerRow.Value = "备注:本报表自动生成,数据仅供参考";
|
||||
//footerRow.Style.Font.FontSize = 9;
|
||||
//footerRow.Style.Font.FontColor = XLColor.Gray;
|
||||
//footerRow.Style.Font.Italic = true;
|
||||
//worksheet.Range(rowIndex + 2, 1, rowIndex + 2, 19).Merge();
|
||||
|
||||
// 8. 保存文件
|
||||
workbook.SaveAs(filePath);
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
MessageBox.Show($"导出Excel文件失败:\n{ex.Message}",
|
||||
"导出错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
});
|
||||
}
|
||||
}
|
||||
public void AddTestReportData(TestReportData data)
|
||||
|
||||
Reference in New Issue
Block a user