eDosStationFull/eDosStation_Backup_2025.02.19_01.14.34/Converters.cs

110 lines
4 KiB
C#
Raw Permalink Normal View History

2026-08-18 12:15:26 +02:00
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Forms;
using System.Windows.Media;
using Telerik.Windows.Controls.ColorEditor;
namespace eDosStation
{
class Converters
{
static public readonly Color cBlack = System.Windows.Media.Colors.Black;
static public readonly Color cGreen= System.Windows.Media.Colors.LightGreen;
static public readonly Color cYellow = System.Windows.Media.Colors.Yellow;
static public readonly Color cRed = System.Windows.Media.Colors.LightCoral;
static public readonly Color cBlue = System.Windows.Media.Colors.LightBlue;
static public readonly Color cGray = System.Windows.Media.Colors.Gray;
static public readonly Brush cbBlack = new SolidColorBrush(cBlack);
static public readonly Brush cbGreen = new SolidColorBrush(cGreen);
static public readonly Brush cbYellow = new SolidColorBrush(cYellow);
static public readonly Brush cbRed = new SolidColorBrush(cRed);
static public readonly Brush cbBlue = new SolidColorBrush(cBlue);
static public readonly Brush cbGray = new SolidColorBrush(cGray);
public class BrushColorValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) value = (int)0;
int cv = (int)value;
Brush rv ;
switch (value) {
case 0: rv = cbBlack; break;
case 1: rv = cbGreen; break;
case 2: rv = cbYellow; break;
case 3: rv = cbRed; break;
case 4: rv = cbBlue; break;
default: rv = cbGray; break;
}
return rv;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class BrushColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Brush rv = cbGreen;
if (value == null || (bool?)value ==true ) rv = cbRed;
return rv;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
/// <summary>
/// Date expiry and boolean OK
/// </summary>
public class BrushExpiryConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Brush rv = cbGreen;
if (parameter != null
&& ( (parameter is bool && !(bool)parameter)
|| (parameter is int && (int)parameter==0)
)
)
rv = cbRed;
else
{
if (value != null && value is DateTime dt)
{
int weeksleft = (dt - DateTime.Today).Days / 7;
if (weeksleft > 2) rv = cbGreen;
else if (weeksleft > -1) rv = cbYellow;
else rv = cbRed;
}
else
rv = cbBlack;
}
return rv;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
}