Files
BeWoPlaner/BeWo/View/Controls/DPCtrlEmployee.cs
2020-09-30 10:00:31 +02:00

128 lines
4.2 KiB
C#

using BS.Shared.DataContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace BeWo.View.Controls
{
public class DPCtrlEmployee : DienstplanerControl
{
public static readonly DependencyProperty EmployeeInformationProperty = DependencyProperty.Register(
"EmployeeInformation",
typeof(DPCtrlEmployeeInformation),
typeof(DPCtrlEmployee),
new UIPropertyMetadata(
(s, e) =>
{
var information = (DPCtrlEmployeeInformation)e.NewValue;
var ctrl = (DPCtrlEmployee)s;
if (ctrl != null)
{
if (information != null)
{
switch (information.Row)
{
case 0:
case 1:
ctrl.BorderBlack.BorderThickness = new Thickness(0, 0, 1, 0);
ctrl.BorderLight.BorderThickness = new Thickness(0, 0, 0, 1);
break;
case 2:
ctrl.BorderBlack.BorderThickness = new Thickness(0, 0, 1, 1);
ctrl.BorderLight.BorderThickness = new Thickness(0, 0, 0, 1);
break;
}
ctrl.Text = ctrl.DisplayMember;
ctrl.ToolTip = new DPCtrlEmployeeTooltip(information.Employee, information.Contracts);
}
else
{
ctrl.ToolTip = null;
}
}
}));
public DPCtrlEmployee()
{
InitializeComponent();
FontSize = 12;
txt.HorizontalAlignment = HorizontalAlignment.Left;
}
public DPCtrlEmployeeInformation EmployeeInformation
{
get { return (DPCtrlEmployeeInformation)GetValue(EmployeeInformationProperty); }
set { SetValue(EmployeeInformationProperty, value); }
}
public string DisplayMember
{
get
{
var sb = new StringBuilder();
switch (EmployeeInformation.Row)
{
case 0: return EmployeeInformation.Employee.LastNameFirstName;
case 1:
foreach (var contract in EmployeeInformation.Contracts)
{
sb.Append(contract.EmploymentType?.Name);
sb.Append('/');
}
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
case 2:
foreach (var contract in EmployeeInformation.Contracts)
{
sb.Append('(');
if (contract.EntryDate.HasValue)
sb.Append(contract.EntryDate.Value.ToString("dd.MM"));
else
sb.Append("k.A.");
sb.Append('-');
if (contract.ContractEndDate.HasValue)
sb.Append(contract.ContractEndDate.Value.ToString("dd.MM"));
else
sb.Append("unbefr.");
sb.Append(')');
sb.Append('/');
}
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}
return null;
}
}
}
public class DPCtrlEmployeeInformation
{
public EmployeeDC Employee { get; set; }
public List<ContractDC> Contracts { get; set; }
public int Row { get; set; }
}
}