Files
BeWoPlaner/BeWo/View/Controls/DPCtrlDay.cs

203 lines
8.2 KiB
C#

using BeWo.ServiceProxy;
using BeWo.View.Detail.Report;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
using System;
using System.Collections.Generic;
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.Border = new Thickness(0, 0, Convert.ToDouble(right), Convert.ToDouble(bottom));
if (!info.IsInContractRange)
{
c.Background = Brushes.Gray;
c.Foreground = Brushes.Red;
c.Text = string.Empty;
c.ToolTip = "Kein gültiger Arbeitsvertrag";
}
else if (info.Reason != null)
{
c.Background = Brushes.White;
c.Foreground = Brushes.Red;
c.Text = $"{info.Reason.Description[0]}";
c.ToolTip = $"{info.Reason.Description}";
}
else if (dc != null)
{
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;
c.Foreground = grey < 70 ? Brushes.White : Brushes.Black;
c.ToolTip = new DPCtrlDienstTooltip(dc, info.Bemerkung, info.Zeiten);
}
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 (!info.Bemerkung.IsNullOrEmpty())
{
bemerkungVorhanden = true;
c.Path_Notice.Visibility = Visibility.Visible;
}
else
{
c.BorderThickness = new Thickness(0, 0, 0, 0);
c.BorderBrush = Brushes.Transparent;
c.Path_Notice.Visibility = Visibility.Collapsed;
}
}
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 = ServiceFacade.DoOperationsServiceSync(se => se.GetColorForStatus(info.StatusInformation.BesetzungsStatus));
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.IsFeiertag)
{
c.Background = Brushes.LightPink;
c.ToolTip = "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 AbsenceReasonDC Reason { 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 bool IsFeiertag { 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; }
}
}