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

@@ -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;