using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Media; namespace BeWo.Scheduling.SchedulingUtils { public class AppointmentColorHelper { public LinearGradientBrush ResourceAndCustomerBackground { get; set; } public LinearGradientBrush EmployeeBackground { get; set; } public AppointmentColorHelper(Color employeeColor, List resourceColors, bool hasCustomers, bool isTask) { var defaultColor = isTask ? Color.FromRgb(153, 59, 59) : Color.FromRgb(192, 255, 208); EmployeeBackground = new LinearGradientBrush(new GradientStopCollection { new GradientStop(employeeColor, 1) }, new Point(0, 0), new Point(0, 1)); if(resourceColors is null) { resourceColors = new List(); } // Weder Ressourcen noch Klienten vorhanden if(!resourceColors.Any() && !hasCustomers) { ResourceAndCustomerBackground = new LinearGradientBrush(new GradientStopCollection { new GradientStop(defaultColor, 1) }, new Point(.5, 0), new Point(.5, 1)); } var colorList = new List(); var gradientStopCollection = new GradientStopCollection(); if(hasCustomers) { colorList.Add(Color.FromRgb(59, 119, 153)); } if(resourceColors.Any()) { colorList.Add(Color.FromRgb(4, 180, 208)); } switch(colorList.Count) { case 1: if(BeWoApp.AppSettings.ShowMultipleResourceColors) { AddResourceColors(gradientStopCollection, resourceColors, hasCustomers); } else { var color = resourceColors.Count >= 1 ? resourceColors[0] : Color.FromRgb(4, 180, 208); var gradientStop = new GradientStop(color, 1); gradientStopCollection.Add(gradientStop); } break; case 2: // 1. Klientenfarbe gradientStopCollection.Add(new GradientStop(colorList[0], .5)); // 2. Ressourcenfarben if(BeWoApp.AppSettings.ShowMultipleResourceColors) { AddResourceColors(gradientStopCollection, resourceColors, hasCustomers); } else { var color = resourceColors.Count >= 1 ? resourceColors[0] : Color.FromRgb(4, 180, 208); gradientStopCollection.Add(new GradientStop(color, .5)); } break; default: gradientStopCollection.Add(new GradientStop(defaultColor, 1)); break; } ResourceAndCustomerBackground = new LinearGradientBrush(gradientStopCollection, new Point(.5, 0), new Point(.5, 1)); } private static void AddResourceColors(GradientStopCollection gradientStopCollection, List resourceColors, bool hasCustomers) { var previousOffset = hasCustomers ? .5 : 0; var numberOfResources = resourceColors.Count; if(numberOfResources == 0) { return; } if(numberOfResources > 4) { numberOfResources = 4; } var iterator = hasCustomers ? previousOffset / numberOfResources : 1d / numberOfResources; for(var i = 0; i < numberOfResources; i++) { var currentOffset = previousOffset; var nextOffset = currentOffset + iterator; if(nextOffset > 1) { nextOffset = 1; } previousOffset = nextOffset; gradientStopCollection.Add(new GradientStop(resourceColors[i], currentOffset)); gradientStopCollection.Add(new GradientStop(resourceColors[i], nextOffset)); } } } }