ownChat: Neues TimeStamp-Objekt wird unterstützt und der Chat funktioniert wieder.
194 lines
7.8 KiB
C#
194 lines
7.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using BeWo.Scheduling.ViewModel;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.Xpf.Scheduling;
|
|
using DevExpress.XtraScheduler;
|
|
|
|
namespace BeWo.Scheduling.SchedulingUtils
|
|
{
|
|
public static class Utils
|
|
{
|
|
private static readonly Regex HexColorRegex = new Regex("^#([a-fA-F0-9]{8}|[a-fA-F0-9]{6}|[a-fA-F0-9]{3})$");
|
|
|
|
public static bool Categories2ResourcesEquals(ObservableDictionary<CategoryDependencyObject, List<ResourceDependencyObject>> dictionary1, ObservableDictionary<CategoryDependencyObject, List<ResourceDependencyObject>> dictionary2)
|
|
{
|
|
if(dictionary1 is null && dictionary2 != null || dictionary2 is null && dictionary1 != null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return dictionary1 is null && dictionary2 is null || dictionary1 != null && dictionary2 != null && dictionary1.Count == dictionary2.Count && dictionary1.Except(dictionary2).Any();
|
|
}
|
|
|
|
public static List<SchedulingAppointmentVM> ConvertAbsenceTimesToAppointments(List<AbsenceTimeDC> absenceTimes, DateTime end, List<CompactEmployeeDC> allEmployees)
|
|
{
|
|
var result = new List<SchedulingAppointmentVM>();
|
|
|
|
foreach(var absenceTime in absenceTimes)
|
|
{
|
|
if(absenceTime.AbsenceTimeOid == null || absenceTime.Start == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var subject = absenceTime.Reason.Description;
|
|
var employee = absenceTime.EmployeeOid != null ? allEmployees.FirstOrDefault(f => f.EmployeeOid == absenceTime.EmployeeOid.Value) : null;
|
|
|
|
if(employee != null)
|
|
{
|
|
subject += $" ({employee.SimpleDescription})";
|
|
}
|
|
|
|
var absenceTimeEnd = absenceTime.End?.AddTicks(1);
|
|
|
|
result.AddIfNotIn(new SchedulingAppointmentVM(true, subject, absenceTime.Start.Value, absenceTime.End ?? end, employee, absenceTime.Start, absenceTimeEnd));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static string GetDeleteMessageForAppointment(AppointmentItem appointment)
|
|
{
|
|
if(appointment is null)
|
|
{
|
|
return "Möchten Sie den gewählten Termin wirklich löschen?";
|
|
}
|
|
|
|
var subject = appointment.Subject;
|
|
|
|
var interval = GetAppointmentTimeString(appointment);
|
|
|
|
return $"Möchten Sie den gewählten Termin \"{subject}\" vom {interval} wirklich löschen?";
|
|
}
|
|
|
|
public static string GetAppointmentTimeString(AppointmentItem appointment)
|
|
{
|
|
if(appointment is null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
var start = appointment.Start;
|
|
var end = appointment.End;
|
|
|
|
// 1. 17. August 2021 09:00 Uhr bis 10:00 Uhr
|
|
// 2. 17. August 2021
|
|
// 3. 17. August 2021 09:00 Uhr bis 19. August 2021 10 Uhr
|
|
// 4. 17. August 2021 bis 19. August 2021
|
|
|
|
return start.Date == end.Date ?
|
|
appointment.AllDay ? $"{start:dd. MMMM yyyy}" : $"{start:dd. MMMM yyyy HH:mm} Uhr bis {end:HH:mm} Uhr" :
|
|
appointment.AllDay ? $"{start:dd. MMMM yyyy} bis zum {end:dd. MMMM yyyy}" : $"{start: dd. MMMM yyyy HH:mm} Uhr bis zum {end:dd. MMMM yyyy HH:mm} Uhr";
|
|
}
|
|
|
|
public static string GetDeactivationMessageForAppointments(IReadOnlyList<AppointmentItem> appointments2Deactivate)
|
|
{
|
|
var message = string.Empty;
|
|
|
|
if(appointments2Deactivate.Count > 1)
|
|
{
|
|
message = "Möchten Sie folgende Termine wirklich löschen?\n\n";
|
|
|
|
foreach(var appointment2Deactivate in appointments2Deactivate.OrderBy(o => o.Start))
|
|
{
|
|
var interval = GetAppointmentTimeString(appointment2Deactivate);
|
|
var subject = appointment2Deactivate.Subject;
|
|
|
|
message += $"{interval} \"{subject}\"\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var first = appointments2Deactivate.FirstOrDefault();
|
|
|
|
if(first is null)
|
|
{
|
|
return message;
|
|
}
|
|
|
|
var interval = GetAppointmentTimeString(first);
|
|
var subject = first.Subject;
|
|
|
|
message = $"Möchten Sie den gewählten Termin \"{subject}\" vom {interval} wirklich löschen?";
|
|
}
|
|
|
|
return message;
|
|
}
|
|
|
|
public static AppointmentType GetAppointmentTypeFromViewModel(int eventType)
|
|
{
|
|
switch(eventType)
|
|
{
|
|
case 0:
|
|
return AppointmentType.Normal;
|
|
case 1:
|
|
return AppointmentType.Pattern;
|
|
case 2:
|
|
return AppointmentType.Occurrence;
|
|
case 3:
|
|
return AppointmentType.ChangedOccurrence;
|
|
case 4:
|
|
return AppointmentType.DeletedOccurrence;
|
|
default:
|
|
return AppointmentType.Normal;
|
|
}
|
|
}
|
|
|
|
public static bool IsValidColorHexString(string hexString)
|
|
{
|
|
return !(hexString is null) && HexColorRegex.IsMatch(hexString);
|
|
}
|
|
|
|
public static StatusUpdatesAndAppointments SeperateStatusUpdatesAndAppointments(List<SchedulerAppointmentDC> statusUpdatesAndAppointments)
|
|
{
|
|
var result = new StatusUpdatesAndAppointments();
|
|
|
|
foreach(var appointment in statusUpdatesAndAppointments)
|
|
{
|
|
if(!(appointment.Originator?.Equals(BeWoApp.CompactLoggedOnEmployee) ?? false) && (appointment.EmployeeList?.Any(e2a => e2a.Employee.Equals(BeWoApp.CompactLoggedOnEmployee) && e2a.ParticipationAnswer == ParticipationAnswer.Offen) ?? false))
|
|
{
|
|
result.Appointments.AddIfNotIn(new SchedulingAppointmentVM(appointment));
|
|
}
|
|
else if((appointment.Originator?.Equals(BeWoApp.CompactLoggedOnEmployee) ?? false) && (appointment.EmployeeList?.Any(e2a => e2a.IsPChanged && e2a.ParticipationAnswer != ParticipationAnswer.Offen && e2a.ParticipationAnswer != ParticipationAnswer.Verstrichen && !e2a.Employee.Equals(BeWoApp.CompactLoggedOnEmployee)) ?? false))
|
|
{
|
|
var vm = new SchedulingAppointmentVM(appointment);
|
|
|
|
foreach(var employee2Appointment in appointment.EmployeeList.Where(e2a => e2a.IsPChanged && e2a.ParticipationAnswer != ParticipationAnswer.Offen && e2a.ParticipationAnswer != ParticipationAnswer.Verstrichen && !e2a.Employee.Equals(BeWoApp.CompactLoggedOnEmployee)))
|
|
{
|
|
if(result.StatusUpdates.All(a => a.LabelKey != employee2Appointment.Employee2SchedulerAppointmentOid))
|
|
{
|
|
if(employee2Appointment.Employee2SchedulerAppointmentOid.HasValue)
|
|
{
|
|
vm.LabelKey = employee2Appointment.Employee2SchedulerAppointmentOid;
|
|
}
|
|
}
|
|
}
|
|
|
|
result.StatusUpdates.AddIfNotIn(vm);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public class StatusUpdatesAndAppointments
|
|
{
|
|
public List<SchedulingAppointmentVM> StatusUpdates { get; }
|
|
public List<SchedulingAppointmentVM> Appointments { get; }
|
|
|
|
public StatusUpdatesAndAppointments()
|
|
{
|
|
StatusUpdates = new List<SchedulingAppointmentVM>();
|
|
Appointments = new List<SchedulingAppointmentVM>();
|
|
}
|
|
}
|
|
}
|