From 2f2d312095a229e493e95e62ff07e0ddbf4eb474 Mon Sep 17 00:00:00 2001 From: rain Date: Fri, 15 May 2026 14:35:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E9=80=BB=E8=BE=91=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ViewModels/YdTest.cs | 108 +++++++++++++++++++++++++++++++++++++++ Views/MainWindow.xaml | 10 ++-- Views/MainWindow.xaml.cs | 47 ++++++++++++++++- 3 files changed, 159 insertions(+), 6 deletions(-) create mode 100644 ViewModels/YdTest.cs diff --git a/ViewModels/YdTest.cs b/ViewModels/YdTest.cs new file mode 100644 index 0000000..02fdc16 --- /dev/null +++ b/ViewModels/YdTest.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Text; + +namespace 片剂四用仪.ViewModels +{ + internal class YdTest + { + // 测试参数(界面可设置) + private int _testCount = 8; + public int HardnessTestCount + { + get => _testCount; + set { _testCount = value; OnPropertyChanged(); } + } + + private int _intervalSec = 9; + public int HardnessIntervalSec + { + get => _intervalSec; + set { _intervalSec = value; OnPropertyChanged(); } + } + + // 测试结果(界面显示) + private float _max; + public float HardnessMax + { + get => _max; + set { _max = value; OnPropertyChanged(); } + } + + private float _min; + public float HardnessMin + { + get => _min; + set { _min = value; OnPropertyChanged(); } + } + + private float _avg; + public float HardnessAvg + { + get => _avg; + set { _avg = value; OnPropertyChanged(); } + } + + // 状态显示 + private int _completedCount; + public int HardnessCompletedCount + { + get => _completedCount; + set { _completedCount = value; OnPropertyChanged(); } + } + + private float _currentValue; + public float HardnessCurrentValue + { + get => _currentValue; + set { _currentValue = value; OnPropertyChanged(); } + } + + // 内部存储测试结果 + private readonly List _results = new List(); + + // 添加单次结果并更新统计值 + public void AddResult(float value) + { + _results.Add(value); + HardnessCurrentValue = value; + HardnessCompletedCount = _results.Count; + UpdateStats(); + } + + // 更新最大/最小/平均值 + private void UpdateStats() + { + if (_results.Count == 0) + { + HardnessMax = 0; + HardnessMin = 0; + HardnessAvg = 0; + return; + } + HardnessMax = _results.Max(); + HardnessMin = _results.Min(); + HardnessAvg = (float)Math.Round(_results.Average(), 1); + } + + // 重置所有数据 + public void Reset() + { + _results.Clear(); + HardnessMax = 0; + HardnessMin = 0; + HardnessAvg = 0; + HardnessCompletedCount = 0; + HardnessCurrentValue = 0; + } + + // INotifyPropertyChanged 接口实现 + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged([CallerMemberName] string name = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + } +} diff --git a/Views/MainWindow.xaml b/Views/MainWindow.xaml index 4869621..25eaf83 100644 --- a/Views/MainWindow.xaml +++ b/Views/MainWindow.xaml @@ -123,11 +123,11 @@ -