using Plugin.TestResult_WPF.Constant;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Controls;
namespace Plugin.TestResult_WPF
{
///
/// InfoTable.xaml 的交互逻辑
///
public partial class InfoTable : UserControl, INotifyPropertyChanged
{
#region ...
public event PropertyChangedEventHandler PropertyChanged;
public virtual void RaisePropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public void RaiseAndSetIfchanged(ref T old, T @new, [CallerMemberName] string propertyName = null)
{
old = @new;
if (propertyName != null) RaisePropertyChanged(propertyName);
}
#endregion
private double _temperature;
public double temperature
{
get => _temperature;
set
{
RaiseAndSetIfchanged(ref _temperature, value);
RaisePropertyChanged("temperatureStr");
}
}
public string temperatureStr
{
get => $"{_temperature.ToString("f2")}℃";
}
private string _status;
public string status
{
get => _status;
set
{
RaiseAndSetIfchanged(ref _status, value);
RaisePropertyChanged("statusStr");
}
}
public string statusStr
{
get => status != null && CommonStatus.STATUS_MAP.ContainsKey(status) ? CommonStatus.STATUS_MAP[status] : "";
}
private int _okCount;
public int okCount
{
get => _okCount;
set
{
RaiseAndSetIfchanged(ref _okCount, value);
RefreshCount();
}
}
private int _ngCount;
public int ngCount
{
get => _ngCount;
set
{
RaiseAndSetIfchanged(ref _ngCount, value);
RefreshCount();
}
}
private int _allCount;
public int allCount
{
get => _allCount;
set
{
RaiseAndSetIfchanged(ref _allCount, value);
}
}
public string countStr
{
get => $"OK:{okCount},NG:{ngCount},ALL:{allCount}";
}
private string _startTimeStr;
public string startTimeStr
{
get => _startTimeStr;
set
{
RaiseAndSetIfchanged(ref _startTimeStr, value);
}
}
private double _consumeTime;
public double consumeTime
{
get => _consumeTime;
set
{
RaiseAndSetIfchanged(ref _consumeTime, value);
RaisePropertyChanged("consumeTimeStr");
}
}
public string consumeTimeStr
{
get
{
if (consumeTime < 60) return $"{consumeTime.ToString("f2")}s";
else if (consumeTime < 3600) return $"{Math.Floor(consumeTime / 60)}m{(consumeTime % 60).ToString("f2")}s";
return $"{Math.Floor(consumeTime / 3600)}h{Math.Floor((consumeTime % 3600) / 60)}m{(consumeTime % 60).ToString("f2")}s";
}
}
private string _endTimeStr;
public string endTimeStr
{
get => _endTimeStr;
set => RaiseAndSetIfchanged(ref _endTimeStr, value);
}
private void RefreshCount()
{
this.allCount = this.okCount + this.ngCount;
RaisePropertyChanged("countStr");
}
public InfoTable()
{
this.DataContext = this;
InitializeComponent();
}
}
}