diff --git a/建材不燃性试验炉/CofficientSetting.xaml.cs b/建材不燃性试验炉/CofficientSetting.xaml.cs index 2264d26..38012b8 100644 --- a/建材不燃性试验炉/CofficientSetting.xaml.cs +++ b/建材不燃性试验炉/CofficientSetting.xaml.cs @@ -336,9 +336,6 @@ namespace 建材不燃性试验炉 }, TaskScheduler.FromCurrentSynchronizationContext()); } - - - #endregion #region 按钮控件 diff --git a/建材不燃性试验炉/MainWindow.xaml b/建材不燃性试验炉/MainWindow.xaml index e26f122..c51c066 100644 --- a/建材不燃性试验炉/MainWindow.xaml +++ b/建材不燃性试验炉/MainWindow.xaml @@ -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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -789,7 +866,7 @@ - @@ -824,84 +901,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -916,7 +917,7 @@ - diff --git a/建材不燃性试验炉/MainWindow.xaml.cs b/建材不燃性试验炉/MainWindow.xaml.cs index 5514b80..09b7dd5 100644 --- a/建材不燃性试验炉/MainWindow.xaml.cs +++ b/建材不燃性试验炉/MainWindow.xaml.cs @@ -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; diff --git a/建材不燃性试验炉/TestReportWindow.xaml b/建材不燃性试验炉/TestReportWindow.xaml index b4ae745..b52cccf 100644 --- a/建材不燃性试验炉/TestReportWindow.xaml +++ b/建材不燃性试验炉/TestReportWindow.xaml @@ -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"> diff --git a/建材不燃性试验炉/TestReportWindow.xaml.cs b/建材不燃性试验炉/TestReportWindow.xaml.cs index c0f95c3..5d75a87 100644 --- a/建材不燃性试验炉/TestReportWindow.xaml.cs +++ b/建材不燃性试验炉/TestReportWindow.xaml.cs @@ -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(ref T windowInstance, Func 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