254 lines
8.4 KiB
C#
254 lines
8.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
using System.Text.RegularExpressions;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.XtraScheduler;
|
|
|
|
namespace BS.Shared.DataContracts
|
|
{
|
|
[DataContract]
|
|
public class SchedulerAppointmentDC : IDataContract
|
|
{
|
|
[DataMember]
|
|
public ActivationTypeId ActivationType { get; set; }
|
|
|
|
[DataMember]
|
|
public long? SchedulerAppointmentOid { get; set; }
|
|
|
|
[DataMember]
|
|
public long? NewSchedulerAppointmentVersion { get; set; }
|
|
|
|
[DataMember]
|
|
public bool IsPrivate { get; set; }
|
|
|
|
[DataMember]
|
|
public string Subject { get; set; }
|
|
|
|
[DataMember]
|
|
public string Description { get; set; }
|
|
|
|
[DataMember]
|
|
public DateTime? StartDate { get; set; }
|
|
|
|
[DataMember]
|
|
public DateTime? EndDate { get; set; }
|
|
|
|
[DataMember]
|
|
public CompactEmployeeDC Originator { get; set; }
|
|
|
|
[DataMember]
|
|
public bool AllDay { get; set; }
|
|
|
|
[DataMember]
|
|
public int Status { get; set; }
|
|
|
|
[DataMember]
|
|
public int Type { get; set; }
|
|
|
|
[DataMember]
|
|
public string Location { get; set; }
|
|
|
|
[DataMember]
|
|
public string RecurrenceInfo { get; set; }
|
|
|
|
[DataMember]
|
|
public string ReminderInfo { get; set; }
|
|
|
|
[DataMember]
|
|
public List<CompactCustomerDC> CustomerList { get; set; }// = new List<CompactCustomerDC>();
|
|
|
|
[DataMember]
|
|
public List<Employee2SchedulerAppointmentDC> EmployeeList { get; set; }// = new List<Employee2SchedulerAppointmentDC>();
|
|
|
|
[DataMember]
|
|
public List<ResourceDC> ResourceList { get; set; }// = new List<ResourceDC>();
|
|
|
|
[DataMember]
|
|
public long? FormerBookingSequenceOid { get; set; }
|
|
|
|
[DataMember]
|
|
public bool IsTeilnahmeBestaetigung { get; set; }
|
|
|
|
[DataMember]
|
|
public bool IsTask { get; set; }
|
|
|
|
[DataMember]
|
|
public string CompletedNotice { get; set; }
|
|
|
|
[DataMember]
|
|
public string CompletedUser { get; set; }
|
|
|
|
[DataMember]
|
|
public string TaskDescription { get; set; }
|
|
|
|
[DataMember]
|
|
public DateTime? CompletedDate { get; set; }
|
|
|
|
[DataMember]
|
|
public DateTime? DueDate { get; set; }
|
|
|
|
[DataMember]
|
|
public List<CompactSupportConceptDC> SupportConceptList { get; set; }
|
|
|
|
[DataMember]
|
|
public long? LabelKey { get; set; }
|
|
|
|
public int RecurrenceIndex { get; set; }
|
|
|
|
public string RecurrenceId { get; set; }
|
|
|
|
private static readonly Regex RecurrenceIdRegex = new Regex("(Id=\\\"[a-z0-9-]+\\\")");
|
|
public string RecurrenceIdReference
|
|
{
|
|
get
|
|
{
|
|
if(RecurrenceInfo is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var match = RecurrenceIdRegex.Match(RecurrenceInfo);
|
|
|
|
if(!match.Success)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var matchValue = match.Value;
|
|
var idValue = matchValue.Split("\"");
|
|
|
|
return idValue[1];
|
|
|
|
}
|
|
}
|
|
|
|
private static readonly Regex RecurrenceIndexRegex = new Regex("(Index=\\\"[0-9]+\\\")");
|
|
|
|
public int? RecurrenceIndexReference
|
|
{
|
|
get
|
|
{
|
|
if(RecurrenceInfo is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var match = RecurrenceIndexRegex.Match(RecurrenceInfo);
|
|
|
|
if(!match.Success)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var matchValue = match.Value;
|
|
var indexValue = matchValue.Split("\"");
|
|
|
|
return int.TryParse(indexValue[1], out var indexInt) ? (int?)indexInt : null;
|
|
}
|
|
}
|
|
|
|
[DataMember]
|
|
public long? FormerTaskOid { get; set; }
|
|
|
|
[DataMember]
|
|
public bool HasServiceRecordEntry { get; set; }
|
|
|
|
[DataMember]
|
|
public bool CanBeEdited { get; set; } = true;
|
|
|
|
[DataMember]
|
|
public List<ServiceRecordDC> ServiceRecordList { get; set; }
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (!(obj is SchedulerAppointmentDC schedulerAppointmentDC))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var oidEqualsValue = false;
|
|
|
|
if(SchedulerAppointmentOid is null && schedulerAppointmentDC.SchedulerAppointmentOid is null)
|
|
{
|
|
// Prüfen, ob es sich um einen Serientermin handelt und index und id vergleichen
|
|
|
|
var appointmentType1 = (AppointmentType)Type;
|
|
var appointmentType2 = (AppointmentType)schedulerAppointmentDC.Type;
|
|
|
|
if(appointmentType1.Equals(AppointmentType.Occurrence) && appointmentType2.Equals(AppointmentType.Occurrence))
|
|
{
|
|
var recurrenceId1 = RecurrenceIdReference;
|
|
var recurrenceIndex1 = RecurrenceIndex;
|
|
|
|
var recurrenceId2 = schedulerAppointmentDC.RecurrenceIdReference;
|
|
var recurrenceIndex2 = schedulerAppointmentDC.RecurrenceIndex;
|
|
|
|
if(!(recurrenceId1 is null || recurrenceId2 is null))
|
|
{
|
|
oidEqualsValue = recurrenceId1.Equals(recurrenceId2) && recurrenceIndex1.Equals(recurrenceIndex2);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
oidEqualsValue = GetHashCode() == schedulerAppointmentDC.GetHashCode();
|
|
}
|
|
}
|
|
|
|
if(SchedulerAppointmentOid != null && schedulerAppointmentDC.SchedulerAppointmentOid != null)
|
|
{
|
|
oidEqualsValue = SchedulerAppointmentOid == schedulerAppointmentDC.SchedulerAppointmentOid;
|
|
}
|
|
|
|
var value = StartDate == schedulerAppointmentDC.StartDate && EndDate == schedulerAppointmentDC.EndDate && Type == schedulerAppointmentDC.Type && Description == schedulerAppointmentDC.Description &&
|
|
EmployeeList.SequenceEqual(schedulerAppointmentDC.EmployeeList) &&
|
|
ResourceList.SequenceEqual(schedulerAppointmentDC.ResourceList) &&
|
|
CustomerList.SequenceEqual(schedulerAppointmentDC.CustomerList) &&
|
|
ServiceRecordList.SequenceEqual(schedulerAppointmentDC.ServiceRecordList) &&
|
|
SupportConceptList.SequenceEqual(schedulerAppointmentDC.SupportConceptList) &&
|
|
oidEqualsValue;
|
|
|
|
return value;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return SchedulerAppointmentOid.HasValue
|
|
? GetType().Name.GetHashCode() ^ SchedulerAppointmentOid.GetHashCode()
|
|
: base.GetHashCode();
|
|
}
|
|
|
|
public override string ToString() => $"{SchedulerAppointmentOid} {StartDate:dd.MM.yyyy HH:mm}-{EndDate:dd.MM.yyyy HH:mm}: {Subject}";
|
|
|
|
public static SchedulerAppointmentDC RecurringExceptionFromDevExpressAppointment(Appointment appointment, SchedulerAppointmentDC baseAppointment)
|
|
{
|
|
return new SchedulerAppointmentDC
|
|
{
|
|
ActivationType = ActivationTypeId.Active,
|
|
Subject = baseAppointment.Subject,
|
|
Description = baseAppointment.Description,
|
|
CustomerList = baseAppointment.CustomerList,
|
|
Originator = baseAppointment.Originator,
|
|
EmployeeList = baseAppointment.EmployeeList,
|
|
ResourceList = baseAppointment.ResourceList,
|
|
AllDay = baseAppointment.AllDay,
|
|
CanBeEdited = baseAppointment.CanBeEdited,
|
|
FormerBookingSequenceOid = baseAppointment.FormerBookingSequenceOid,
|
|
IsPrivate = baseAppointment.IsPrivate,
|
|
Location = baseAppointment.Location,
|
|
StartDate = appointment.Start,
|
|
EndDate = appointment.End,
|
|
RecurrenceId = appointment.RecurrenceInfo.Id.ToString(),
|
|
LabelKey = (long?) appointment.LabelKey,
|
|
RecurrenceIndex = appointment.RecurrenceIndex,
|
|
RecurrenceInfo = appointment.RecurrenceInfo.ToXml(),
|
|
Type = (int) appointment.Type,
|
|
SupportConceptList = baseAppointment.SupportConceptList,
|
|
ServiceRecordList = baseAppointment.ServiceRecordList
|
|
};
|
|
}
|
|
}
|
|
}
|