using HMI.Util;
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);
}
}
private int _ngCount;
public int ngCount
{
get => _ngCount;
set
{
RaiseAndSetIfchanged(ref _ngCount, value);
}
}
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);
}
}
private double? _leftTime;
public double? leftTime
{
get => _leftTime;
set
{
RaiseAndSetIfchanged(ref _leftTime, value);
}
}
public string consumeTimeStr
{
get
{
var str1 = ConvertDurtion(consumeTime);
if (leftTime != null)
{
str1 += $"/{ConvertDurtion(leftTime.Value)}";
}
return str1;
}
}
private string ConvertDurtion(double seconds)
{
if (seconds <= 0)
{
return "0s";
}
if (seconds <= 60)
{
return $"{seconds.ToString("f2")}s";
}
else if (seconds <= 3600)
{
var min = Math.Floor(seconds / 60);
seconds = seconds % 60;
if (seconds > 0)
{
return $"{min}m{seconds.ToString("f2")}s";
}
return $"{min}m";
}
else
{
var hour = Math.Floor(seconds / 3600);
var min = Math.Floor((seconds % 3600) / 60);
seconds = seconds % 60;
if (seconds > 0)
{
return $"{hour}h{min}m{seconds.ToString("f2")}s";
}
return $"{hour}h{min}m";
}
}
private string _endTimeStr;
public string endTimeStr
{
get => _endTimeStr;
set => RaiseAndSetIfchanged(ref _endTimeStr, value);
}
public void UpdateNumber(int ok, int ng)
{
this._okCount = ok;
this._ngCount = ng;
this._allCount = this._okCount + this._ngCount;
RaisePropertyChanged("countStr");
}
public void UpdateConsumeTime(double consumeTime, double? leftTime)
{
this.consumeTime = consumeTime;
this.leftTime = leftTime;
RaisePropertyChanged("consumeTimeStr");
}
public InfoTable()
{
this.DataContext = this;
InitializeComponent();
}
}
}