This commit is contained in:
Lyndon Jetten
2019-12-20 12:37:08 +01:00
parent c5c1ba59c2
commit 6d4352bed8
4 changed files with 74 additions and 35 deletions

View File

@@ -6,6 +6,7 @@ using System.Windows.Media;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
namespace BeWo.Scheduler.ViewModel
{
@@ -29,7 +30,12 @@ namespace BeWo.Scheduler.ViewModel
result += " bis " + DueDate.Value.ToString("dd.MM.yyyy HH:mm");
}
}
if (IsAbsenceTime && _AbsenceTimeStart.HasValue)
{
result += _AbsenceTimeStart.Value.GetIntervalDescription(_AbsenceTimeEnd);
}
return result;
}
}
@@ -61,6 +67,10 @@ namespace BeWo.Scheduler.ViewModel
public CompactEmployeeDC Originator { get; set; }
private DateTime? _AbsenceTimeStart;
private DateTime? _AbsenceTimeEnd;
public CustomFieldStorage()
{
@@ -90,6 +100,9 @@ namespace BeWo.Scheduler.ViewModel
RecurrenceId = pAppointment.DataContract?.RecurrenceId;
RecurrenceIndex = pAppointment.DataContract?.RecurrenceIndex ?? 0;
_AbsenceTimeStart = pAppointment.AbsenceTimeStart;
_AbsenceTimeEnd = pAppointment.AbsenceTimeEnd;
}
public CustomFieldStorage(SchedulerAppointmentDC pAppointment)

View File

@@ -17,7 +17,6 @@ namespace BeWo.Scheduler.ViewModel
public event EventHandler<EventArgs<ISchedulerViewModel>> ViewModelChanged;
private ISchedulerViewModel _ActiveAppointmentViewModel;
private Dictionary<ValueListEntryDC, List<ResourceDC>> _AllCats2ResInDic;
public ISchedulerViewModel ActiveAppointmentViewModel
{
@@ -58,17 +57,19 @@ namespace BeWo.Scheduler.ViewModel
public IEnumerable<SchedulerAppointmentVM> ConvertAbsenceTimesToAppointments(IEnumerable<AbsenceTimeDC> pAbsenceTimes, DateTime pIntervalEnd, List<CompactEmployeeDC> allEmployees)
{
return pAbsenceTimes.Select(abwesenheit =>
return pAbsenceTimes.Where(w => w.AbsenceTimeOid.HasValue && w.Start.HasValue).Select(abwesenheit =>
{
var subject = $"{abwesenheit.Reason.Description}";
var employee = allEmployees.FirstOrDefault(f => f.EmployeeOid == abwesenheit.EmployeeOid.Value);
var employee = abwesenheit.EmployeeOid != null ? allEmployees.FirstOrDefault(f => f.EmployeeOid == abwesenheit.EmployeeOid.Value) : null;
if(employee != null)
{
subject += $" ({employee.SimpleDescription})";
}
return new SchedulerAppointmentVM(true, subject, abwesenheit.Start.Value, abwesenheit.End ?? pIntervalEnd, employee);
var absenceTimeEnd = abwesenheit.End?.AddTicks(1);
return new SchedulerAppointmentVM(true, subject, abwesenheit.Start.Value, abwesenheit.End ?? pIntervalEnd, employee, abwesenheit.Start, absenceTimeEnd);
}).ToList();
}
}

View File

@@ -58,8 +58,10 @@ namespace BeWo.Scheduler.ViewModel
private DateTime? _CompletedDate;
private DateTime? _DueDate;
private DateTime? _DueTime;
public DateTime? AbsenceTimeStart { get; set; }
public DateTime? AbsenceTimeEnd { get; set; }
public object Id { get; set; }
public object Id { get; set; }
public int LabelId { get; set; }
public Dictionary<string, object> CustomFields
{
@@ -516,7 +518,8 @@ namespace BeWo.Scheduler.ViewModel
IsTeilnahmeBestaetigung = pDC.IsTeilnahmeBestaetigung;
}
public SchedulerAppointmentVM(bool pAllDay, string pSubject, DateTime pStart, DateTime pEnd, CompactEmployeeDC pOriginator)
// Wird für Abwesenheiten genutzt
public SchedulerAppointmentVM(bool pAllDay, string pSubject, DateTime pStart, DateTime pEnd, CompactEmployeeDC pOriginator, DateTime? absenceTimeStart, DateTime? absenceTimeEnd)
{
_AllDay = pAllDay;
_Subject = pSubject;
@@ -524,6 +527,9 @@ namespace BeWo.Scheduler.ViewModel
_End = pEnd;
_Originator = pOriginator;
AbsenceTimeStart = absenceTimeStart;
AbsenceTimeEnd = absenceTimeEnd;
IsAbsenceTime = true;
UpdateCustomFields();

View File

@@ -494,37 +494,56 @@ namespace BS.Shared.Extensions
return !(start >= start2 && start >= end2 || end <= start2 && end <= end2);
}
/// <summary>
/// Prüft, ob das Datum in einem Zeitraum liegt. Wurde für Betreuungszeiten geschrieben.
/// Achtung: Sind beide Daten des Zeitraums null, wird true zurückgegeben!
/// </summary>
/// <param name="dateTime">Das Datum bei dem zu prüfen ist, ob es im angegebenen Zeitraum liegt</param>
/// <param name="spanStart">Der Beginn des Zeitintervalls</param>
/// <param name="spanEnd">Das Ende des Zeitintervalls</param>
/// <returns>Ob das Datum im angegebenen Zeitraum liegt</returns>
public static bool InBetween(this DateTime dateTime, DateTime? spanStart, DateTime? spanEnd)
{
if(spanStart == null && spanEnd == null)
{
return true;
}
if(spanStart.HasValue && spanEnd.HasValue)
{
return InBetween(dateTime, spanStart.Value, spanEnd.Value, false);
}
if(spanStart == null)
{
return dateTime < spanEnd.Value;
}
return true;
}
public static bool IsTimeZero(this DateTime dateTime)
{
return dateTime.Hour == 0 && dateTime.Minute == 0 && dateTime.Second == 0;
}
public static string GetIntervalDescription(this DateTime start, DateTime? end)
{
var result = string.Empty;
var isAllDay = start.IsTimeZero() && (end == null || end.Value.IsTimeZero());
var endTimeHasValue = end.HasValue;
if (isAllDay)
{
if (endTimeHasValue)
{
if (start.Date.Equals(end.Value.Date))
{
result += $" {start.ToShortDateString()}";
}
else
{
result += $" {start.ToShortDateString()} - {end.Value.ToShortDateString()}";
}
}
else
{
result += $" Ab dem {start.ToShortDateString()}";
}
}
else
{
if (endTimeHasValue)
{
if (start.Date.Equals(end.Value.Date))
{
result += $" {start:dd.MM.yyyy HH:mm} - {end.Value:HH:mm}";
}
else
{
result += $" {start:dd.MM.yyyy HH:mm} - {(end.Value.IsTimeZero() ? end.Value.ToString("dd.MM.yyyy") : end.Value.ToString("dd.MM.yyyy HH:mm"))}";
}
}
else
{
result += $" Ab dem {start:dd.MM.yyyy HH:mm}";
}
}
return result;
}
}
}