72 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 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;
 | ||
|         }
 | ||
|     }
 | ||
| }
 |