This commit is contained in:
wxt
2026-02-03 16:51:25 +08:00
parent 29d2821eef
commit 228f976b16
5 changed files with 125 additions and 233 deletions

View File

@@ -336,9 +336,6 @@ namespace 建材不燃性试验炉
}, TaskScheduler.FromCurrentSynchronizationContext());
}
#endregion
#region

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:建材不燃性试验炉"
mc:Ignorable="d"
Title="建材不燃性试验炉控制系统"
Height="800"
Height="760"
Width="1280"
WindowStartupLocation="CenterScreen"
Loaded="ThemedWindow_Loaded" Closing="Window_Closing">
@@ -777,7 +777,84 @@
<!-- 4. 新增多温度监控卡片 -->
<Border Background="#F0F7FF" Style="{StaticResource CardStyle}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</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="txtFurnaceWallTemp"
Text="25°C"
FontSize="18"
FontWeight="Bold"
Foreground="#2C3E50"
Margin="0,0,15,0"/>
<TextBlock Text="试样中心温度:"
FontSize="16"
Foreground="#2C3E50"
Margin="0,0,5,0"/>
<TextBlock x:Name="txtSampleCenterTemp"
Text="25°C"
FontSize="18"
FontWeight="Bold"
Foreground="#2C3E50"
Margin="0,0,15,0"/>
<TextBlock Text="试样表面温度:"
FontSize="16"
Foreground="#2C3E50"
Margin="0,0,5,0"/>
<TextBlock x:Name="txtSampleSurfaceTemp"
Text="25°C"
FontSize="18"
FontWeight="Bold"
Foreground="#2C3E50"/>
</StackPanel>
<StackPanel Orientation="Horizontal" >
<Border Background="#27AE60"
CornerRadius="4"
Padding="8,4" Margin="0,5,0,5">
<TextBlock x:Name="txtFurnaceTempStatus"
Text="炉内温度波动"
Foreground="White"
FontSize="15"
FontWeight="SemiBold"/>
</Border>
<!--<Border Background="#27AE60"
CornerRadius="4"
Padding="8,4" Margin="10,5,0,5">
<TextBlock x:Name="txtSampleInternalTempStatus"
Text="式样中心温度波动"
Foreground="White"
FontSize="12"
FontWeight="SemiBold" />
</Border>-->
<!--<Border Background="#27AE60"
CornerRadius="4"
Padding="8,4" Margin="10,5,0,5">
<TextBlock x:Name="txtSampleSurfaceTempStatus"
Text="式样表面温度波动"
Foreground="White"
FontSize="12"
FontWeight="SemiBold"/>
</Border>-->
</StackPanel>
</StackPanel>
</Grid>
</Border>
<!-- ========== 新增:温度平衡状态卡片 ========== -->
<Border Background="#E0F7FA" Style="{StaticResource CardStyle}">
<Grid>
@@ -789,7 +866,7 @@
<StackPanel Grid.Column="1">
<TextBlock Text="温度平衡状态"
<TextBlock Text="初次温度平衡判断"
FontSize="13"
Foreground="#666666"/>
<StackPanel Orientation="Horizontal">
@@ -824,84 +901,8 @@
</StackPanel>
</Grid>
</Border>
<Border Background="#F0F7FF" Style="{StaticResource CardStyle}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</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="txtFurnaceWallTemp"
Text="25°C"
FontSize="18"
FontWeight="Bold"
Foreground="#2C3E50"
Margin="0,0,15,0"/>
<TextBlock Text="试样中心温度:"
FontSize="16"
Foreground="#2C3E50"
Margin="0,0,5,0"/>
<TextBlock x:Name="txtSampleCenterTemp"
Text="25°C"
FontSize="18"
FontWeight="Bold"
Foreground="#2C3E50"
Margin="0,0,15,0"/>
<TextBlock Text="试样表面温度:"
FontSize="16"
Foreground="#2C3E50"
Margin="0,0,5,0"/>
<TextBlock x:Name="txtSampleSurfaceTemp"
Text="25°C"
FontSize="18"
FontWeight="Bold"
Foreground="#2C3E50"/>
</StackPanel>
<StackPanel Orientation="Horizontal" >
<Border Background="#27AE60"
CornerRadius="4"
Padding="8,4" Margin="0,5,0,5">
<TextBlock x:Name="txtFurnaceTempStatus"
Text="炉内温度波动"
Foreground="White"
FontSize="12"
FontWeight="SemiBold"/>
</Border>
<Border Background="#27AE60"
CornerRadius="4"
Padding="8,4" Margin="10,5,0,5">
<TextBlock x:Name="txtSampleInternalTempStatus"
Text="式样中心温度波动"
Foreground="White"
FontSize="12"
FontWeight="SemiBold" />
</Border>
<Border Background="#27AE60"
CornerRadius="4"
Padding="8,4" Margin="10,5,0,5">
<TextBlock x:Name="txtSampleSurfaceTempStatus"
Text="式样表面温度波动"
Foreground="White"
FontSize="12"
FontWeight="SemiBold"/>
</Border>
</StackPanel>
</StackPanel>
</Grid>
</Border>
<!-- 新增:最终平衡判断状态卡片 -->
<Border Background="#FFECB3" Style="{StaticResource CardStyle}">
@@ -916,7 +917,7 @@
<!-- 中间:状态信息 -->
<StackPanel Grid.Column="1">
<TextBlock Text="三通道温度平衡判断"
<TextBlock Text="最终温度平衡判断"
FontSize="13"
Foreground="#666666"
FontWeight="SemiBold"/>

View File

@@ -33,7 +33,6 @@ namespace 建材不燃性试验炉
private bool _isTestRunning = false;
private bool _isCalibrating = false;
private BackgroundWorker _calibrationWorker;
private Random _random = new Random();
//温度平衡相关
private DispatcherTimer _balanceTimer; // 平衡判断定时器1秒触发一次
@@ -100,15 +99,6 @@ namespace 建材不燃性试验炉
_statusTimer.Interval = TimeSpan.FromSeconds(1);
_statusTimer.Tick += StatusTimer_Tick;
// 试验计时器
//_testTimer = new DispatcherTimer();
//_testTimer.Interval = TimeSpan.FromSeconds(1);
//_testTimer.Tick += TestTimer_Tick;
//初始化平衡判断定时器
//_balanceTimer = new DispatcherTimer();
//_balanceTimer.Interval = TimeSpan.FromSeconds(1);
//_balanceTimer.Tick += BalanceTimer_Tick;
}
private void InitializeControls()
@@ -197,72 +187,6 @@ namespace 建材不燃性试验炉
}
//private void TestTimer_Tick(object sender, EventArgs e)
//{
//if (_isTestRunning)
//{
// _testElapsedTime = _testElapsedTime.Add(TimeSpan.FromSeconds(1));
//}
//}
//private void BalanceTimer_Tick(object sender, EventArgs e)
//{
// try
// {
// // 1. 计时递增
// _balanceElapsedSeconds++;
// txtBalanceTimeElapsed.Text = $"{_balanceElapsedSeconds}秒";
// // 2. 采集当前炉壁温度
// double currentTemp = GetCurrentFurnaceTemp();
// _tempDataList.Add(currentTemp);
// // 4. 计算最大值、最小值、平均值
// _maxTemp = double.MinValue;
// _minTemp = double.MaxValue;
// double sumTemp = 0;
// foreach (var temp in _tempDataList)
// {
// if (temp > _maxTemp) _maxTemp = temp;
// if (temp < _minTemp) _minTemp = temp;
// sumTemp += temp;
// }
// _avgTemp = sumTemp / _tempDataList.Count;
// double currentMaxDiff = _maxTemp - _avgTemp; // 最大值与平均值的温差
// double tempRange = _maxTemp - _minTemp; // 温度波动范围
// txtBalanceCondition.Text = $"平衡条件: 最大温差≤{_maxTempDiffThreshold}°C 且 温度波动≤±{_tempRangeThreshold}°C (当前: {tempRange:F1}°C)";
// // 6. 判断是否达到平衡条件(计时结束后)
// if (_balanceElapsedSeconds >= _balanceTotalSeconds)
// {
// _balanceTimer.Stop(); // 停止定时器
// _isBalanceChecking = false;
// bool isBalanced = currentMaxDiff <= _maxTempDiffThreshold && tempRange <= _tempRangeThreshold * 2;
// // 更新平衡状态显示
// if (isBalanced)
// {
// balanceStatusBorder.Background = new SolidColorBrush(Colors.Green);
// txtBalanceResult.Text = "已平衡";
// txtBalanceStatus.Text = $"温度平衡状态: 达到平衡(最大温差{currentMaxDiff:F1}°C温度波动{tempRange:F1}°C";
// UpdateStatusBar("温度平衡判断完成:炉温已稳定");
// }
// }
// }
// catch (Exception ex)
// {
// MessageBox.Show($"温度平衡判断出错:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
// _balanceTimer.Stop();
// _isBalanceChecking = false;
// }
//}
// 获取当前炉壁温度
private double GetFurnaceTemperature()
@@ -350,7 +274,7 @@ namespace 建材不燃性试验炉
StopTest();
var result = MessageBox.Show("确定要停止实验吗?",
"停止实验", MessageBoxButton.YesNo, MessageBoxImage.Question);
"停止实验", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
@@ -672,8 +596,6 @@ namespace 建材不燃性试验炉
return;
}
// 读取三个温度值
float TempSet = 0, furnaceTemp = 0, sampleInternalTemp = 0, sampleSurfaceTemp = 0;
//炉内温度设定
@@ -815,13 +737,13 @@ namespace 建材不燃性试验炉
CheckSingleTemperature("炉内", furnaceTemp, targetTemp, allowedFluctuation,
txtFurnaceTempStatus);
// 检查样品内部温度波动
CheckSingleTemperature("样品中心", sampleInternalTemp, targetTemp, allowedFluctuation,
txtSampleInternalTempStatus);
//// 检查样品内部温度波动
//CheckSingleTemperature("样品中心", sampleInternalTemp, targetTemp, allowedFluctuation,
// txtSampleInternalTempStatus);
// 检查样品表面温度波动
CheckSingleTemperature("样品表面", sampleSurfaceTemp, targetTemp, allowedFluctuation,
txtSampleSurfaceTempStatus);
//// 检查样品表面温度波动
//CheckSingleTemperature("样品表面", sampleSurfaceTemp, targetTemp, allowedFluctuation,
// txtSampleSurfaceTempStatus);
}
catch (Exception ex)
{
@@ -841,26 +763,9 @@ namespace 建材不燃性试验炉
string statusText;
string backgroundColor;
//if (Math.Abs(targetTemp) < 0.001) // 目标温度为0表示未设置
//{
// statusText = $"{tempName}温度: {currentTemp:F1}°C";
// backgroundColor = "#95A5A6"; // 灰色 - 未设置目标
//}
//else if (actualFluctuation <= allowedFluctuation)
//{
statusText = $"{tempName}温度波动 (±{actualFluctuation:F1}°C)";
backgroundColor = "#27AE60"; // 绿色 - 正常
//}
//else if (actualFluctuation <= allowedFluctuation * 2) // 在2倍范围内
//{
// statusText = $"{tempName}温度波动警告 (±{actualFluctuation:F1}°C)";
// backgroundColor = "#F39C12"; // 橙色 - 警告
//}
//else
//{
// statusText = $"{tempName}温度波动异常 (±{actualFluctuation:F1}°C)";
// backgroundColor = "#E74C3C"; // 红色 - 异常
//}
// 更新UI
Dispatcher.Invoke(() =>
@@ -1363,12 +1268,38 @@ namespace 建材不燃性试验炉
#region
private CofficientSetting _cofficientSetting;
private TestReportWindow _testReportWindow;
private DispatcherTimer _longPressTimer;
private void Button_Click(object sender, RoutedEventArgs e)
{
SwitchWindow(ref _testReportWindow, () => new TestReportWindow());
try
{
// 使用异步避免阻塞
Dispatcher.BeginInvoke(new Action(() =>
{
try
{
// 创建窗口但不立即初始化
var TestReportWindow = new TestReportWindow();
TestReportWindow.Owner = this;
TestReportWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
// 延迟显示
TestReportWindow.Show();
UpdateStatusBar("打开数据报表");
}
catch (Exception ex)
{
MessageBox.Show($"无法打开数据报表: {ex.Message}", "错误");
}
}), DispatcherPriority.Background);
}
catch (Exception ex)
{
MessageBox.Show($"打开报表窗口失败: {ex.Message}", "错误");
}
}
private void btnCoefficient_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
@@ -1400,15 +1331,6 @@ namespace 建材不燃性试验炉
{
windowInstance = createFunc();
if (windowInstance is TestReportWindow reportWindow)
{
}
// 添加窗口关闭事件处理
windowInstance.Closed += (s, args) =>
{
@@ -1430,18 +1352,15 @@ namespace 建材不燃性试验炉
windowInstance.Show();
}
#endregion
#region
// 开始平衡判断按钮点击事件
// 添加全局变量来存储温度平衡结果
private double _balanceAverageTemp = 0.0; // 存储平衡平均温度
private double _startavgTemp = 0.0; // 实验开始时的平衡温度
// 开始平衡判断按钮点击事件
private void btnStartBalanceCheck_Click(object sender, RoutedEventArgs e)
{
if (_isBalanceChecking)
@@ -2260,7 +2179,7 @@ namespace 建材不燃性试验炉
//#endregion
#region
#region
private TemperatureBalanceCalculator _calculator;
private DispatcherTimer _uiUpdateTimer;
private int _uiUpdateCounter = 0;

View File

@@ -6,7 +6,7 @@
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" x:Class="jiancaiburanxing.TestReportWindow"
mc:Ignorable="d"
Title="建材不燃性试验数据报表"
Height="800"
Height="760"
Width="1280"
WindowStartupLocation="CenterScreen"
ResizeMode="CanMinimize">

View File

@@ -778,40 +778,15 @@ namespace jiancaiburanxing
}
}
#region
private MainWindow _mainWindow;
#region
//返回
private void btnReturn_Click(object sender, RoutedEventArgs e)
{
SwitchWindow(ref _mainWindow, () => new MainWindow());
this.Close();
}
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : Window, new()
{
if (windowInstance == null)
{
windowInstance = createFunc();
// 添加窗口关闭事件处理
windowInstance.Closed += (s, args) =>
{
this.Show();
this.Activate();
};
}
else
{
windowInstance.Activate();
return;
}
this.Hide();
windowInstance.Show();
}
#endregion