using BeWo.ServiceProxy; using BeWo.View.Detail.Report; using BS.Shared.DataContracts; using BS.Shared.Extensions; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using Brush = System.Windows.Media.Brush; using SolidColorBrush = System.Windows.Media.SolidColorBrush; namespace BeWo.View.Controls { public class DPCtrlDay : DienstplanerControl { public static bool bemerkungVorhanden = false; public static readonly DependencyProperty DPCtrlDayInformationProperty = DependencyProperty.Register( "DPCtrlDayInformation", typeof(DPCtrlDayInformation), typeof(DPCtrlDay), new UIPropertyMetadata( (s, e) => { var info = (DPCtrlDayInformation)e.NewValue; var c = (DPCtrlDay)s; if (c != null && info != null) { if (info.StatusInformation == null) { var dc = info.DienstInfoDC; var right = info.DayOfWeek == DayOfWeek.Sunday || info.IsLastColumn; var bottom = info.IsLastRow; c.Path_Notice.Visibility = info.MarkierungBenoetigt ? Visibility.Visible : Visibility.Collapsed; var bottomBorder = bottom ? 1.5 : 0; c.Border = new Thickness(0, 0, Convert.ToDouble(right), bottomBorder); if (!info.IsInContractRange) { c.Background = Brushes.Gray; c.Foreground = Brushes.Red; c.Text = string.Empty; c.ToolTip = "Kein gültiger Arbeitsvertrag"; } else if (info.AbsenceTime != null && info.EnableDiensteAnFeiertagen == true) { string additionToTooltip = ""; var start = info.AbsenceTime.Start.Value; var end = info.AbsenceTime.End.Value; var startArray = start.ToString().Split(' '); var endArray = end.ToString().Split(' '); if (start.Date == end.Date) { if (start.TimeOfDay == end.TimeOfDay) additionToTooltip = " (ganzer Tag)"; else additionToTooltip = " (halber Tag)"; } else additionToTooltip = string.Format(" ({0} - {1})", startArray[0], endArray[0]); c.Foreground = Brushes.Red; c.Text = $"{info.AbsenceTime.Reason.Description[0]}"; c.ToolTip = $"{info.AbsenceTime.Reason.Description}" + additionToTooltip; if (info.DayOfWeek == DayOfWeek.Saturday || info.DayOfWeek == DayOfWeek.Sunday) c.Background = new SolidColorBrush(ColorExtensions.FromHexString("EFEFEF")); else c.Background = Brushes.White; } else if (info.OverTime != null) { c.Foreground = Brushes.Red; c.Text = "ÜS"; c.ToolTip = (dc == null) ? string.Format("Überstunden:\t{0:0.00}\nAuszahlung:\t{1}\nBemerkung:\t{2}", info.OverTime.Betrag, info.OverTime.Auszahlungsart.Name, info.OverTime.Notice) : null; if (info.DayOfWeek == DayOfWeek.Saturday || info.DayOfWeek == DayOfWeek.Sunday) c.Background = new SolidColorBrush(ColorExtensions.FromHexString("EFEFEF")); else if (dc != null) c.Background = (SolidColorBrush)new BrushConverter().ConvertFrom(dc.Farbe); else c.Background = Brushes.White; } else { c.Background = ((int)info.DayOfWeek % 6 == 0) ? new SolidColorBrush(ColorExtensions.FromHexString("EFEFEF")) : Brushes.White; c.Text = string.Empty; c.ToolTip = null; } if (dc != null) { c.Text = $"{dc.Kurz}"; if (c.Path_Notice.Visibility == Visibility.Collapsed) { c.BorderThickness = new Thickness(0, 0, 0, 0); c.BorderBrush = Brushes.Transparent; } var bg = string.IsNullOrEmpty(dc.Farbe) ? Brushes.White : (SolidColorBrush)new BrushConverter().ConvertFrom(dc.Farbe); var grey = 0.2989 * bg.Color.R + 0.5870 * bg.Color.G + 0.1140 * bg.Color.B; c.Background = bg; if (info.OverTime == null && info.AbsenceTime == null) c.Foreground = grey < 70 ? Brushes.White : Brushes.Black; else c.Foreground = Brushes.Red; c.ToolTip = new DPCtrlDienstTooltip(dc, info.Dauer, info.Bemerkung, info.Zeiten, info.OverTime, info.AbsenceTime); } else { c.Path_Notice.Visibility = Visibility.Collapsed; c.BorderThickness = new Thickness(0, 0, 0, 0); c.BorderBrush = Brushes.Transparent; } } else { var right = info.DayOfWeek == DayOfWeek.Sunday || info.IsLastColumn; c.Border = new Thickness(0, 0, Convert.ToDouble(right), 2); if (info.StatusInformation != null) { var converter = new BrushConverter(); var color = (info.StatusInformation.BesetzungsStatus) ? info.StatusInformation.ColorTrue : info.StatusInformation.ColorFalse; c.Background = (Brush)converter.ConvertFromString(color); if (info.StatusInformation.BesetzungsStatus) { c.ToolTip = "Dienste decken 24 Stunden ab"; } else { c.ToolTip = "Achtung: Dienste decken nicht 24 Stunden ab"; } if (!info.StatusInformation.StatusInfoString.IsNullOrEmpty()) { c.ToolTip += c.ToolTip.ToString().IsNullOrEmpty() ? info.StatusInformation.StatusInfoString : "\n" + info.StatusInformation.StatusInfoString; c.Path_Notice.Visibility = Visibility.Visible; } else c.Path_Notice.Visibility = Visibility.Collapsed; } } if (info.Feiertag != null) { c.Background = Brushes.LightPink; c.ToolTip += "\n" + info.Feiertag.Name + " (gesetzl. Feiertag)"; } } })); public DPCtrlDay() { InitializeComponent(); MouseDown += DienstplanerControl_MouseDown; } public new Brush Background { get => BorderLight.Background; set => BorderLight.Background = value; } public Thickness Border { get => BorderBlack.BorderThickness; set => BorderBlack.BorderThickness = value; } public DPCtrlDayInformation DPCtrlDayInformation { get { return (DPCtrlDayInformation)GetValue(DPCtrlDayInformationProperty); } set { SetValue(DPCtrlDayInformationProperty, value); } } private void DienstplanerControl_MouseDown(object sender, MouseButtonEventArgs e) { DienstplanerView entryView = null; System.Windows.DependencyObject parent = VisualTreeHelper.GetParent(this); while (parent != null && entryView == null) { entryView = parent as DienstplanerView; var fe = parent as FrameworkElement; parent = fe != null ? VisualTreeHelper.GetParent(fe) : null; } if (entryView != null) { entryView.DienstplanerControl_MouseDown(sender, e); } } } public class DPCtrlDayInformation { public DienstInfoDC DienstInfoDC { get; set; } public AbsenceTimeDC AbsenceTime { get; set; } public OvertimeDC OverTime { get; set; } public bool IsInContractRange { get; set; } public bool IsLastRow { get; set; } public bool IsLastColumn { get; set; } public DayOfWeek DayOfWeek { get; set; } public StatusInformation StatusInformation { get; set; } public string Bemerkung { get; set; } public string[] Zeiten { get; set; } public double Dauer { get; set; } public FeiertagDC Feiertag { get; set; } public bool MarkierungBenoetigt { get; set; } public bool EnableDiensteAnFeiertagen { get; set; } } public class StatusInformation { public bool BesetzungsStatus { get; set; } public string StatusInfoString { get; set; } public DayOfWeek DayOfWeek { get; set; } public bool IsLastColumn { get; set; } public string ColorTrue { get; set; } public string ColorFalse { get; set; } } }