704 lines
20 KiB
C#
704 lines
20 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
|
|
using BeWo.ViewModel;
|
|
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BeWo.Scheduler.ViewModel
|
|
{
|
|
public class SchedulerAppointmentVM : AbstractDCMapperVM<SchedulerAppointmentDC>, IMainSessionointment
|
|
{
|
|
public static string PropertyName_Type = "Type";
|
|
public static string PropertyName_Start = "Start";
|
|
public static string PropertyName_End = "End";
|
|
public static string PropertyName_AllDay = "AllDay";
|
|
public static string PropertyName_Subject = "Subject";
|
|
public static string PropertyName_Location = "Location";
|
|
public static string PropertyName_Status = "Status";
|
|
public static string PropertyName_RecurrenceInfo = "RecurrenceInfo";
|
|
public static string PropertyName_Description = "Description";
|
|
public static string PropertyName_EmployeeList = "EmployeeList";
|
|
public static string PropertyName_CustomerList = "CustomerList";
|
|
public static string PropertyName_ResourceList = "ResourceList";
|
|
public static string PropertyName_IsPrivate = "IsPrivate";
|
|
public static string PropertyName_Originator = "Originator";
|
|
public static string PropertyName_IsAbsenceTime = "IsAbsenceTime";
|
|
public static string PropertyName_IsTask = nameof(IsTask);
|
|
public static string PropertyName_DueDate = nameof(DueDate);
|
|
public static string PropertyName_CompletedDate = nameof(CompletedDate);
|
|
public static string PropertyName_CompletedNotice = nameof(CompletedNotice);
|
|
public static string PropertyName_TaskDescription = nameof(TaskDescription);
|
|
|
|
private bool _AllDay;
|
|
private string _Description;
|
|
private DateTime _End;
|
|
private string _Location;
|
|
private string _RecurrenceInfo;
|
|
private DateTime _Start;
|
|
private int _Status;
|
|
private string _Subject;
|
|
private int _Type;
|
|
private Dictionary<string, object> _CustomFields;
|
|
private bool _IsPrivate;
|
|
private ObservableCollection<Employee2SchedulerAppointmentDC> _EmployeeList;
|
|
private List<CompactCustomerDC> _CustomerList;
|
|
private List<ResourceDC> _ResourceList;
|
|
private List<CompactSupportConceptDC> _SupportConceptList;
|
|
private CompactEmployeeDC _Originator;
|
|
private bool _IsTask;
|
|
private string _TaskDescription;
|
|
private string _CompletedNotice;
|
|
private DateTime? _CompletedDate;
|
|
private DateTime? _DueDate;
|
|
private DateTime? _DueTime;
|
|
private bool _HasServiceRecordEntry;
|
|
|
|
|
|
public bool HasServiceRecordEntry
|
|
{
|
|
get => _HasServiceRecordEntry;
|
|
set
|
|
{
|
|
if(AreDifferent(_HasServiceRecordEntry, value))
|
|
{
|
|
_HasServiceRecordEntry = value;
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.HasServiceRecordEntry, value), nameof(HasServiceRecordEntry));
|
|
FirePropertyChanged(nameof(HasServiceRecordEntry));
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateTime? AbsenceTimeStart { get; set; }
|
|
public DateTime? AbsenceTimeEnd { get; set; }
|
|
|
|
public object Id { get; set; }
|
|
public int LabelId { get; set; }
|
|
public Dictionary<string, object> CustomFields
|
|
{
|
|
get => _CustomFields ?? (_CustomFields = new Dictionary<string, object>());
|
|
set
|
|
{
|
|
if (!AreDifferent(_CustomFields, value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_CustomFields = value;
|
|
|
|
var customFieldStorage = (CustomFieldStorage) value[nameof(CustomFieldStorage)];
|
|
|
|
EmployeeList = customFieldStorage.EmployeeList;
|
|
CustomerList = customFieldStorage.CustomerList;
|
|
ResourceList = customFieldStorage.ResourceList;
|
|
Originator = customFieldStorage.Originator;
|
|
IsPrivate = customFieldStorage.IsPrivate;
|
|
IsTask = customFieldStorage.IsTask;
|
|
DueDate = customFieldStorage.DueDate;
|
|
TaskDescription = customFieldStorage.TaskDescription;
|
|
CompletedDate = customFieldStorage.CompletedDate;
|
|
CompletedNotice = customFieldStorage.CompletedNotice;
|
|
SupportConceptList = customFieldStorage.SupportConceptList;
|
|
}
|
|
}
|
|
|
|
public int EventType
|
|
{
|
|
get => _Type;
|
|
set
|
|
{
|
|
if (AreDifferent(_Type, value))
|
|
{
|
|
_Type = value;
|
|
StoreDirtyInformation(AreDifferent(DataContract.Type, value), PropertyName_Type);
|
|
FirePropertyChanged(PropertyName_Type);
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateTime End
|
|
{
|
|
get => _End;
|
|
set
|
|
{
|
|
if (AreDifferent(_End, value))
|
|
{
|
|
_End = value;
|
|
|
|
if (IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.EndDate, value), PropertyName_End);
|
|
FirePropertyChanged(PropertyName_End);
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateTime Start
|
|
{
|
|
get => _Start;
|
|
set
|
|
{
|
|
if (AreDifferent(_Start, value))
|
|
{
|
|
_Start = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.StartDate, value), PropertyName_Start);
|
|
FirePropertyChanged(PropertyName_Start);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool AllDay
|
|
{
|
|
get => _AllDay;
|
|
set
|
|
{
|
|
if (AreDifferent(_AllDay, value))
|
|
{
|
|
_AllDay = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.AllDay, value), PropertyName_AllDay);
|
|
FirePropertyChanged(PropertyName_AllDay);
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Subject
|
|
{
|
|
get => _Subject;
|
|
set
|
|
{
|
|
if(AreDifferent(_Subject, value))
|
|
{
|
|
_Subject = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Subject, value), PropertyName_Subject);
|
|
FirePropertyChanged(PropertyName_Subject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Location
|
|
{
|
|
get => _Location;
|
|
set
|
|
{
|
|
if (AreDifferent(_Location, value))
|
|
{
|
|
_Location = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Location, value), PropertyName_Location);
|
|
FirePropertyChanged(PropertyName_Location);
|
|
}
|
|
}
|
|
}
|
|
|
|
public int Status
|
|
{
|
|
get => _Status;
|
|
set
|
|
{
|
|
if (AreDifferent(_Status, value))
|
|
{
|
|
_Status = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Status, value), PropertyName_Status);
|
|
FirePropertyChanged(PropertyName_Status);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsTeilnahmeBestaetigung { get; }
|
|
|
|
public string RecurrenceInfo
|
|
{
|
|
get => _RecurrenceInfo;
|
|
set
|
|
{
|
|
if (AreDifferent(_RecurrenceInfo, value))
|
|
{
|
|
_RecurrenceInfo = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.RecurrenceInfo, value), PropertyName_RecurrenceInfo);
|
|
FirePropertyChanged(PropertyName_RecurrenceInfo);
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Description
|
|
{
|
|
get => _Description;
|
|
set
|
|
{
|
|
if (AreDifferent(_Description, value))
|
|
{
|
|
_Description = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Description, value), PropertyName_Description);
|
|
FirePropertyChanged(PropertyName_Description);
|
|
}
|
|
}
|
|
}
|
|
|
|
public ObservableCollection<Employee2SchedulerAppointmentDC> EmployeeList
|
|
{
|
|
get => _EmployeeList ?? (_EmployeeList = new ObservableCollection<Employee2SchedulerAppointmentDC>());
|
|
set
|
|
{
|
|
if (AreDifferent(_EmployeeList, value))
|
|
{
|
|
_EmployeeList = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.EmployeeList, value), PropertyName_EmployeeList);
|
|
FirePropertyChanged(PropertyName_EmployeeList);
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<CompactCustomerDC> CustomerList
|
|
{
|
|
get => _CustomerList ?? (_CustomerList = new List<CompactCustomerDC>());
|
|
set
|
|
{
|
|
if (AreDifferent(_CustomerList, value))
|
|
{
|
|
_CustomerList = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.CustomerList, value), PropertyName_CustomerList);
|
|
FirePropertyChanged(PropertyName_CustomerList);
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<ResourceDC> ResourceList
|
|
{
|
|
get => _ResourceList ?? (ResourceList = new List<ResourceDC>());
|
|
set
|
|
{
|
|
if (AreDifferent(_ResourceList, value))
|
|
{
|
|
_ResourceList = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.ResourceList, value), PropertyName_ResourceList);
|
|
FirePropertyChanged(PropertyName_ResourceList);
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<CompactSupportConceptDC> SupportConceptList
|
|
{
|
|
get => _SupportConceptList ?? (SupportConceptList = new List<CompactSupportConceptDC>());
|
|
set
|
|
{
|
|
if(AreDifferent(_SupportConceptList, value))
|
|
{
|
|
_SupportConceptList = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.SupportConceptList, value), nameof(SupportConceptList));
|
|
FirePropertyChanged(nameof(SupportConceptList));
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsPrivate
|
|
{
|
|
get => _IsPrivate;
|
|
set
|
|
{
|
|
if (AreDifferent(_IsPrivate, value))
|
|
{
|
|
_IsPrivate = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.IsPrivate,value), PropertyName_IsPrivate);
|
|
FirePropertyChanged(PropertyName_IsPrivate);
|
|
}
|
|
}
|
|
}
|
|
|
|
public CompactEmployeeDC Originator
|
|
{
|
|
get => _Originator;
|
|
set
|
|
{
|
|
if (AreDifferent(_Originator, value))
|
|
{
|
|
_Originator = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Originator, value), PropertyName_Originator);
|
|
FirePropertyChanged(PropertyName_Originator);
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual TimeSpan EndTime => End.TimeOfDay;
|
|
|
|
public virtual TimeSpan StartTime => Start.TimeOfDay;
|
|
|
|
public virtual bool IsAbsenceTime { get; }
|
|
|
|
public bool IsTask
|
|
{
|
|
get => _IsTask;
|
|
|
|
set
|
|
{
|
|
if (AreDifferent(_IsTask, value))
|
|
{
|
|
_IsTask = value;
|
|
|
|
if (IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.IsTask, value), nameof(IsTask));
|
|
FirePropertyChanged(nameof(IsTask));
|
|
}
|
|
}
|
|
}
|
|
|
|
public string TaskDescription
|
|
{
|
|
get => _TaskDescription;
|
|
|
|
set
|
|
{
|
|
if(AreDifferent(_TaskDescription, value))
|
|
{
|
|
_TaskDescription = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.TaskDescription, value), nameof(TaskDescription));
|
|
FirePropertyChanged(nameof(TaskDescription));
|
|
}
|
|
}
|
|
}
|
|
|
|
public string CompletedNotice
|
|
{
|
|
get => _CompletedNotice;
|
|
|
|
set
|
|
{
|
|
if(AreDifferent(_CompletedNotice, value))
|
|
{
|
|
_CompletedNotice = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.CompletedNotice, value), nameof(CompletedNotice));
|
|
FirePropertyChanged(nameof(CompletedNotice));
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateTime? CompletedDate
|
|
{
|
|
get => _CompletedDate;
|
|
|
|
set
|
|
{
|
|
if(AreDifferent(_CompletedDate, value))
|
|
{
|
|
_CompletedDate = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.CompletedDate, value), nameof(CompletedDate));
|
|
FirePropertyChanged(nameof(CompletedDate));
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateTime? DueDate
|
|
{
|
|
get => _DueDate;
|
|
|
|
set
|
|
{
|
|
if(AreDifferent(_DueDate, value))
|
|
{
|
|
_DueDate = value;
|
|
|
|
if(IsAbsenceTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.DueDate, value), nameof(DueDate));
|
|
FirePropertyChanged(nameof(DueDate));
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateTime? DueTime
|
|
{
|
|
get => _DueTime;
|
|
|
|
set
|
|
{
|
|
if(AreDifferent(_DueTime, value))
|
|
{
|
|
_DueTime = value;
|
|
StoreDirtyInformation(AreDifferent(DataContract.DueDate, value), nameof(DueTime));
|
|
FirePropertyChanged(nameof(DueTime));
|
|
}
|
|
}
|
|
}
|
|
|
|
public SchedulerAppointmentVM(SchedulerAppointmentDC pDC) : base(pDC, pDC.SchedulerAppointmentOid == null)
|
|
{
|
|
IsTeilnahmeBestaetigung = pDC.IsTeilnahmeBestaetigung;
|
|
}
|
|
|
|
// 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;
|
|
_Start = pStart;
|
|
_End = pEnd;
|
|
_Originator = pOriginator;
|
|
|
|
AbsenceTimeStart = absenceTimeStart;
|
|
AbsenceTimeEnd = absenceTimeEnd;
|
|
|
|
IsAbsenceTime = true;
|
|
|
|
UpdateCustomFields();
|
|
}
|
|
|
|
public void UpdateCustomFields()
|
|
{
|
|
CustomFields = new Dictionary<string, object>
|
|
{
|
|
{nameof(CustomFieldStorage), new CustomFieldStorage(this)}
|
|
};
|
|
}
|
|
|
|
protected override void InitByDataContract(SchedulerAppointmentDC pDataContract)
|
|
{
|
|
_AllDay = pDataContract.AllDay;
|
|
_Description = pDataContract.Description;
|
|
_End = pDataContract.EndDate ?? DateTime.Now;
|
|
_Location = pDataContract.Location;
|
|
_RecurrenceInfo = pDataContract.RecurrenceInfo;
|
|
_Start = pDataContract.StartDate ?? DateTime.Now;
|
|
_Status = pDataContract.Status;
|
|
_Subject = pDataContract.Subject;
|
|
_Type = pDataContract.Type;
|
|
_IsPrivate = pDataContract.IsPrivate;
|
|
_Originator = pDataContract.Originator;
|
|
_CustomerList = pDataContract.CustomerList ?? new List<CompactCustomerDC>();
|
|
_EmployeeList = new ObservableCollection<Employee2SchedulerAppointmentDC>(pDataContract.EmployeeList ?? new List<Employee2SchedulerAppointmentDC>());
|
|
_ResourceList = pDataContract.ResourceList ?? new List<ResourceDC>();
|
|
_IsTask = pDataContract.IsTask;
|
|
_TaskDescription = pDataContract.TaskDescription;
|
|
_CompletedNotice = pDataContract.CompletedNotice;
|
|
_CompletedDate = pDataContract.CompletedDate;
|
|
_SupportConceptList = pDataContract.SupportConceptList ?? new List<CompactSupportConceptDC>();
|
|
_HasServiceRecordEntry = pDataContract.HasServiceRecordEntry;
|
|
|
|
|
|
if(pDataContract.DueDate.HasValue)
|
|
{
|
|
_DueDate = pDataContract.DueDate;
|
|
_DueTime = pDataContract.DueDate;
|
|
}
|
|
}
|
|
|
|
protected override SchedulerAppointmentDC MapToDataContract(SchedulerAppointmentDC pDataContract, bool doCommit)
|
|
{
|
|
pDataContract.AllDay = _AllDay;
|
|
pDataContract.Description = _Description;
|
|
pDataContract.EndDate = _End;
|
|
pDataContract.Location = _Location;
|
|
pDataContract.RecurrenceInfo = _RecurrenceInfo;
|
|
pDataContract.StartDate = _Start;
|
|
pDataContract.Status = _Status;
|
|
pDataContract.Subject = _Subject;
|
|
pDataContract.Type = _Type;
|
|
pDataContract.IsPrivate = _IsPrivate;
|
|
pDataContract.Originator = _Originator;
|
|
pDataContract.CustomerList = _CustomerList;
|
|
pDataContract.EmployeeList = _EmployeeList.ToList();
|
|
pDataContract.ResourceList = _ResourceList;
|
|
pDataContract.IsTask = _IsTask;
|
|
pDataContract.TaskDescription = _TaskDescription;
|
|
pDataContract.CompletedNotice = _CompletedNotice;
|
|
pDataContract.CompletedDate = _CompletedDate;
|
|
pDataContract.SupportConceptList = _SupportConceptList;
|
|
pDataContract.HasServiceRecordEntry = _HasServiceRecordEntry;
|
|
|
|
|
|
if(_DueDate.HasValue && _DueTime.HasValue)
|
|
{
|
|
pDataContract.DueDate = new DateTime(_DueDate.Value.Year, _DueDate.Value.Month, _DueDate.Value.Day, _DueTime.Value.Hour, _DueTime.Value.Minute, 0);
|
|
}
|
|
else
|
|
{
|
|
pDataContract.DueDate = _DueDate;
|
|
}
|
|
|
|
return pDataContract;
|
|
}
|
|
|
|
public override bool Equals(object pObj)
|
|
{
|
|
if (!(pObj is SchedulerAppointmentVM))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var obj = (SchedulerAppointmentVM) pObj;
|
|
|
|
var customFieldsAreEqual = false;
|
|
|
|
if(CustomFields.Count == 0 && obj.CustomFields.Count == 0)
|
|
{
|
|
customFieldsAreEqual = CustomFields.Equals(obj.CustomFields);
|
|
}
|
|
else if(CustomFields.Count == obj.CustomFields.Count)
|
|
{
|
|
for (var i = 0; i < CustomFields.Count; i++)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
var customFieldStorage1 = (CustomFieldStorage) CustomFields.ElementAt(i).Value;
|
|
var objCustomFieldStorage = (CustomFieldStorage) obj.CustomFields.ElementAt(i).Value;
|
|
|
|
customFieldsAreEqual = customFieldStorage1 == null && objCustomFieldStorage == null || customFieldStorage1 != null && Equals(customFieldStorage1, objCustomFieldStorage);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
var areEqual =
|
|
Equals(Subject, obj.Subject) &&
|
|
LabelId == obj.LabelId &&
|
|
AllDay == obj.AllDay &&
|
|
IsPrivate == obj.IsPrivate &&
|
|
IsDirty == obj.IsDirty &&
|
|
IsNew == obj.IsNew &&
|
|
IsTask == obj.IsTask &&
|
|
TaskDescription == obj.TaskDescription &&
|
|
Equals(CompletedDate, obj.CompletedDate) &&
|
|
Equals(DueDate, obj.DueDate) &&
|
|
Equals(CompletedNotice, obj.CompletedNotice) &&
|
|
customFieldsAreEqual &&
|
|
CustomerList.AreEqual(obj.CustomerList) &&
|
|
Equals(Description, obj.Description) &&
|
|
EmployeeList.AreEqual(obj.EmployeeList) &&
|
|
Equals(End, obj.End) &&
|
|
Equals(EndTime, obj.EndTime) &&
|
|
Equals(Location, obj.Location) &&
|
|
ResourceList.AreEqual(obj.ResourceList) &&
|
|
Equals(RecurrenceInfo, obj.RecurrenceInfo) &&
|
|
HasServiceRecordEntry == obj.HasServiceRecordEntry;
|
|
|
|
return areEqual;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return DataContract.SchedulerAppointmentOid.HasValue
|
|
? GetType().Name.GetHashCode() ^ DataContract.SchedulerAppointmentOid.Value.GetHashCode()
|
|
: base.GetHashCode();
|
|
}
|
|
|
|
public override bool IsDirty => !IsAbsenceTime && base.IsDirty;
|
|
|
|
public new bool IsNew
|
|
{
|
|
get => !IsAbsenceTime && base.IsNew;
|
|
|
|
set => base.IsNew = value;
|
|
}
|
|
}
|
|
}
|