Files
CheckDevice/Check.Main/Common/StatisticsData.cs
17860779768 2e46747ba9 视觉修改
2025-08-25 16:33:58 +08:00

72 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Check.Main.Common
{
/// <summary>
/// 封装了所有生产统计数据的模型。
/// 实现了INotifyPropertyChanged未来可用于数据绑定。
/// </summary>
public class StatisticsData : INotifyPropertyChanged
{
private int _goodCount;
private int _ngCount;
public int GoodCount
{
get => _goodCount;
private set { _goodCount = value; OnPropertyChanged(nameof(GoodCount)); OnPropertyChanged(nameof(TotalCount)); OnPropertyChanged(nameof(YieldRate)); }
}
public int NgCount
{
get => _ngCount;
private set { _ngCount = value; OnPropertyChanged(nameof(NgCount)); OnPropertyChanged(nameof(TotalCount)); OnPropertyChanged(nameof(YieldRate)); }
}
public int TotalCount => GoodCount + NgCount;
public double YieldRate => TotalCount == 0 ? 0 : (double)GoodCount / TotalCount;
/// <summary>
/// 根据检测结果更新统计数据。
/// </summary>
public void UpdateWithResult(bool isOk)
{
if (isOk) GoodCount++;
else NgCount++;
}
/// <summary>
/// 重置所有统计数据。
/// </summary>
public void Reset()
{
GoodCount = 0;
NgCount = 0;
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
/// <summary>
/// 用于在检测完成事件中传递结果的事件参数。
/// </summary>
public class DetectionResultEventArgs : EventArgs
{
public bool IsOK { get; }
public DetectionResultEventArgs(bool isOk)
{
IsOK = isOk;
}
}
}