75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using Aurora.Api.Manager;
|
|
using Aurora.View;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Data;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
|
|
namespace AuroraScale.CAS
|
|
{
|
|
// Color Converter하는 클래스만들기, Xaml에서 Usercontrol.Resource 사용
|
|
public class ScaleColorConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
bool isNormal = (bool)value;
|
|
if (isNormal)
|
|
{
|
|
return Brushes.White;
|
|
}
|
|
return Brushes.Red;
|
|
}
|
|
|
|
//ConvertBack은 Convert의 반대로 구현, 구현안해도 무방함
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
Brush brush = value as Brush;
|
|
if (brush == Brushes.White)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public class UCScaleTestViewModel : NotifyPropertyChangedBase
|
|
{
|
|
private bool _IsNormal;
|
|
private readonly CASScale _Scale;
|
|
private IDeviceManager _DeviceManager;
|
|
|
|
public bool IsNormal { get => _IsNormal; set => SetProperty(ref _IsNormal, value); }
|
|
|
|
private double _CurrentValue;
|
|
public double CurrentValue { get => _CurrentValue; set => SetProperty(ref _CurrentValue, value); }
|
|
|
|
public ICommand CMD_Click { get; set; }
|
|
public UCScaleTestViewModel(IDeviceManager devManger,CASScale scale)
|
|
{
|
|
_Scale = scale;
|
|
_DeviceManager = devManger;
|
|
|
|
CMD_Click = new DelegateCommand(Click);
|
|
}
|
|
|
|
private void Click(object obj)
|
|
{
|
|
CurrentValue = _Scale.Weight();
|
|
var config = _DeviceManager.GetDeviceConfig(_Scale.DeviceId) as CASScaleConfig;
|
|
if (CurrentValue < config.MinValue || CurrentValue > config.MaxValue)
|
|
{
|
|
IsNormal = false;
|
|
}
|
|
else
|
|
{
|
|
IsNormal = true;
|
|
}
|
|
}
|
|
}
|
|
}
|