Files
BeWoPlaner/BeWo/Scheduler/View/EmployeeBrushConverter.cs

62 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using DevExpress.XtraScheduler;
namespace BeWo.Scheduler.View
{
public class EmployeeBrushConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var farbe = Color.FromRgb(192, 255, 208);
var gradientCollection = new GradientStopCollection { new GradientStop(farbe, 1) };
if(values[2] is bool b && b == false)
{
return gradientCollection;
}
try
{
if(!(values[1] is CustomFieldCollection customViewInfo))
{
return new LinearGradientBrush(new GradientStopCollection { new GradientStop(farbe, 1) }, new Point(.5, 0), new Point(.5, 1));
}
var aptEmployees = (List<Employee2SchedulerAppointmentDC>) customViewInfo["EmployeeList"];
var ersteller = (CompactEmployeeDC) customViewInfo["Originator"];
if(aptEmployees.Count > 0)
{
var firstEmployeeInList = aptEmployees.First(f => f.Employee.EmployeeColor != null);
gradientCollection = new GradientStopCollection { new GradientStop(firstEmployeeInList.Employee.FilterableBrush.Color, 1) };
}
else if(!string.IsNullOrEmpty(ersteller.EmployeeColor))
{
gradientCollection = new GradientStopCollection {new GradientStop(ersteller.FilterableBrush.Color, 1)};
}
return new LinearGradientBrush(gradientCollection, new Point(.5, 0), new Point(.5, 1));
}
catch (Exception)
{
return new LinearGradientBrush(new GradientStopCollection { new GradientStop(farbe, 1) }, new Point(.5, 0), new Point(.5, 1));
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}