Der Überschneidungstest ist angepasst und die Bugs behoben
This commit is contained in:
@@ -146,6 +146,7 @@ namespace BeWo.Scheduler.ViewModel
|
||||
|
||||
UpdateSchedulerAppointment(item, vm);
|
||||
|
||||
// Wird ein Serientermin bearbeitet, erfolgt ein Insert und ein Update. Beim Insert erfolgt bereits die Überschneidungsprüfung und muss hier nicht wiederholt werden.
|
||||
var shouldSkipResourceAvailablityCheck = false;
|
||||
|
||||
if(_RecurrenceInfoId != null && item.RecurrenceInfo?.Id is Guid recurrenceId)
|
||||
@@ -153,51 +154,46 @@ namespace BeWo.Scheduler.ViewModel
|
||||
shouldSkipResourceAvailablityCheck = recurrenceId.Equals(_RecurrenceInfoId);
|
||||
}
|
||||
|
||||
if(vm.ResourceList.Any() && !shouldSkipResourceAvailablityCheck)
|
||||
|
||||
/*
|
||||
* EventTypes:
|
||||
* 0: Normal
|
||||
* 1: Pattern
|
||||
* 2: Occurrence
|
||||
* 3: ChangedOccurrence
|
||||
* 4: DeletedOccurrence
|
||||
*
|
||||
*
|
||||
*
|
||||
* Wozu ist das gut?
|
||||
* !ShouldLockOverlappingAppointmentCheck &&
|
||||
*/
|
||||
|
||||
if(!shouldSkipResourceAvailablityCheck && !vm.IsTask && vm.EventType != 4 && !(vm.EventType == 3 && vm.DataContract?.SchedulerAppointmentOid == null))
|
||||
{
|
||||
if(!CheckForUnavailableResources(vm))
|
||||
var start = vm.Start;
|
||||
var end = vm.End;
|
||||
var employeeOids = vm.EmployeeList.Select(emp => emp.Employee.EmployeeOid).ToList();
|
||||
var customerOids = vm.CustomerList.Select(cc => cc.CustomerOid).ToList();
|
||||
var resourceOids = vm.ResourceList.Where(r => r.ResourceOid.HasValue).Select(r => r.ResourceOid.Value).ToList();
|
||||
var originatorOid = vm.Originator.EmployeeOid;
|
||||
var schedulerAppointmentOid = vm.DataContract?.SchedulerAppointmentOid;
|
||||
var recurrenceInfoId = vm.RecurrenceId;
|
||||
var recurrenceIndex = vm.RecurrenceIndex;
|
||||
|
||||
var message = string.Empty;
|
||||
|
||||
ServiceFacade.DoResourceServiceSync( s => message = s.ValidateSchedulerAppointment(start, end, employeeOids, customerOids, resourceOids, originatorOid, schedulerAppointmentOid, recurrenceInfoId, recurrenceIndex, shouldSkipResourceAvailablityCheck));
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
return;
|
||||
var messageBoxResult = MessageBox.Show(message, "Überschneidung", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
|
||||
|
||||
if(messageBoxResult.Equals(MessageBoxResult.No))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* EventTypes:
|
||||
* 0: Normal
|
||||
* 1: Pattern
|
||||
* 2: Occurrence
|
||||
* 3: ChangedOccurrence
|
||||
* 4: DeletedOccurrence
|
||||
*
|
||||
*
|
||||
*
|
||||
* Wozu ist das gut?
|
||||
* !ShouldLockOverlappingAppointmentCheck &&
|
||||
*/
|
||||
|
||||
if(!vm.IsTask && vm.EventType != 4 && !(vm.EventType == 3 && vm.DataContract?.SchedulerAppointmentOid == null))
|
||||
{
|
||||
var isOverlapping = false;
|
||||
|
||||
ServiceFacade.DoResourceServiceSync(s => isOverlapping = s.OverlappingAppointmentsExist(
|
||||
vm.Start,
|
||||
vm.End,
|
||||
vm.EmployeeList.Select(emp => emp.Employee.EmployeeOid).ToList(),
|
||||
vm.CustomerList.Select(cc => cc.CustomerOid).ToList(),
|
||||
vm.ResourceList.Select(r => r.ResourceOid.Value).ToList(),
|
||||
vm.Originator.EmployeeOid,
|
||||
vm.DataContract.SchedulerAppointmentOid,
|
||||
item.RecurrenceInfo?.Id.ToString() ?? string.Empty, item.RecurrenceIndex));
|
||||
|
||||
if (isOverlapping)
|
||||
{
|
||||
var erg = MessageBox.Show("Dieser Termin überschneidet sich mit einem anderen bereits existierenden Termin.\nMöchten Sie ihn wirklich speichern?", "Überschneidung", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
|
||||
|
||||
if (erg.Equals(MessageBoxResult.No))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item.Type.Equals(AppointmentType.ChangedOccurrence) && _GeoeffneterTermin != null)
|
||||
@@ -226,8 +222,7 @@ namespace BeWo.Scheduler.ViewModel
|
||||
}
|
||||
|
||||
private Guid? _RecurrenceInfoId;
|
||||
|
||||
public void InsertAppointments(SchedulerControl control, IEnumerable<Appointment> list)
|
||||
public void InsertAppointments(SchedulerControl control, IEnumerable<Appointment> list)
|
||||
{
|
||||
var dcList = new List<SchedulerAppointmentDC>();
|
||||
foreach (var item in list)
|
||||
@@ -275,39 +270,35 @@ namespace BeWo.Scheduler.ViewModel
|
||||
|
||||
UpdateSchedulerAppointment(item, vm);
|
||||
|
||||
if(vm.ResourceList.Any())
|
||||
if(!vm.IsTask && vm.EventType != 4 && !ShouldLockOverlappingAppointmentCheck)
|
||||
{
|
||||
if(!CheckForUnavailableResources(vm))
|
||||
var start = vm.Start;
|
||||
var end = vm.End;
|
||||
var employeeOids = vm.EmployeeList.Select(emp => emp.Employee.EmployeeOid).ToList();
|
||||
var customerOids = vm.CustomerList.Select(cc => cc.CustomerOid).ToList();
|
||||
var resourceOids = vm.ResourceList.Where(r => r.ResourceOid.HasValue).Select(r => r.ResourceOid.Value).ToList();
|
||||
var originatorOid = vm.Originator.EmployeeOid;
|
||||
var schedulerAppointmentOid = vm.DataContract?.SchedulerAppointmentOid;
|
||||
var recurrenceInfoId = vm.RecurrenceId;
|
||||
var recurrenceIndex = vm.RecurrenceIndex;
|
||||
|
||||
var message = string.Empty;
|
||||
|
||||
ServiceFacade.DoResourceServiceSync(s => message = s.ValidateSchedulerAppointment(start, end, employeeOids, customerOids, resourceOids, originatorOid, schedulerAppointmentOid, recurrenceInfoId, recurrenceIndex, false));
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
return;
|
||||
var messageBoxResult = MessageBox.Show(message, "Überschneidung", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
|
||||
|
||||
if(messageBoxResult.Equals(MessageBoxResult.No))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ShouldLockOverlappingAppointmentCheck && !vm.IsTask && vm.EventType != 4)
|
||||
{
|
||||
var isOverlapping = false;
|
||||
ServiceFacade.DoResourceServiceSync(s => isOverlapping = s.OverlappingAppointmentsExist(
|
||||
vm.Start,
|
||||
vm.End,
|
||||
vm.EmployeeList.Select(emp => emp.Employee.EmployeeOid).ToList(),
|
||||
vm.CustomerList.Select(cc => cc.CustomerOid).ToList(),
|
||||
vm.ResourceList.Select(r => r.ResourceOid.Value).ToList(),
|
||||
vm.Originator.EmployeeOid,
|
||||
vm.DataContract.SchedulerAppointmentOid,
|
||||
item.RecurrenceInfo?.Id.ToString() ?? string.Empty, item.RecurrenceIndex));
|
||||
|
||||
if (isOverlapping)
|
||||
{
|
||||
var erg = MessageBox.Show("Dieser Termin überschneidet sich mit einem anderen bereits existierenden Termin.\nMöchten Sie ihn wirklich speichern?", "Überschneidung", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
|
||||
|
||||
if (erg.Equals(MessageBoxResult.No))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dcList.Add(vm.CommitToDataContract());
|
||||
dcList.Add(vm.CommitToDataContract());
|
||||
}
|
||||
|
||||
if (dcList.Count <= 0)
|
||||
@@ -665,39 +656,6 @@ namespace BeWo.Scheduler.ViewModel
|
||||
|
||||
return areEqual;
|
||||
}
|
||||
|
||||
private static bool CheckForUnavailableResources(SchedulerAppointmentVM vm)
|
||||
{
|
||||
var unavailableResources = new List<ResourceDC>();
|
||||
|
||||
ServiceFacade.DoResourceServiceSync(s => unavailableResources = s.CheckResourceAvailability(vm.Start, vm.End, vm.ResourceList.Select(resource => resource.ResourceOid.Value).ToList(), vm.DataContract?.SchedulerAppointmentOid));
|
||||
|
||||
if(unavailableResources.Any())
|
||||
{
|
||||
var names = string.Empty;
|
||||
|
||||
unavailableResources.DoForEach(resource => names += resource.Name + ", ");
|
||||
|
||||
names = names.TrimEnd(' ').TrimEnd(',');
|
||||
|
||||
var resourceCount = vm.ResourceList.Count;
|
||||
|
||||
var warningMessage = unavailableResources.Count > 1 ?
|
||||
$"Ein{(resourceCount > 1 ? "ige" : "e")} der ausgewählten Ressourcen ({names}) sind" :
|
||||
$"{(resourceCount > 1 ? "Eine der" : "Die")} ausgewählte{(resourceCount > 1 ? "n" : string.Empty)} Ressource{(resourceCount > 1 ? "n" : string.Empty)} ({names}) ist";
|
||||
|
||||
warningMessage += $" zum gewählten Zeitpunkt ({vm.Start.GetIntervalDescription(vm.End).TrimStart(' ')}) nicht verfügbar.\n\nMöchten Sie trotzdem speichern?";
|
||||
|
||||
var erg = MessageBox.Show(warningMessage, "Überschneidung", MessageBoxButton.YesNo);
|
||||
|
||||
if(erg.Equals(MessageBoxResult.No))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4482,6 +4482,10 @@ namespace BeWo.ServiceProxy
|
||||
[System.ServiceModel.FaultContractAttribute(typeof(BeWo.ServiceProxy.BeWoFault), Action="http://tempuri.org/IResourceService/FindRootAppointmentByRecurrenceIdBeWoFaultFau" +
|
||||
"lt", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BeWo.Service.ServiceContracts")]
|
||||
BS.Shared.DataContracts.SchedulerAppointmentDC FindRootAppointmentByRecurrenceId(string recurrenceId);
|
||||
|
||||
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IResourceService/ValidateSchedulerAppointment", ReplyAction="http://tempuri.org/IResourceService/ValidateSchedulerAppointmentResponse")]
|
||||
[System.ServiceModel.FaultContractAttribute(typeof(BeWo.ServiceProxy.BeWoFault), Action="http://tempuri.org/IResourceService/ValidateSchedulerAppointmentBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BeWo.Service.ServiceContracts")]
|
||||
string ValidateSchedulerAppointment(System.DateTime start, System.DateTime end, System.Collections.Generic.List<long> employees, System.Collections.Generic.List<long> customers, System.Collections.Generic.List<long> resources, long originator, System.Nullable<long> appointmentOid, System.Nullable<System.Guid> recurrenceId, int occurrenceIndex, bool shouldSkipResourceAvailability);
|
||||
}
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
|
||||
@@ -4767,6 +4771,11 @@ namespace BeWo.ServiceProxy
|
||||
{
|
||||
return base.Channel.FindRootAppointmentByRecurrenceId(recurrenceId);
|
||||
}
|
||||
|
||||
public string ValidateSchedulerAppointment(System.DateTime start, System.DateTime end, System.Collections.Generic.List<long> employees, System.Collections.Generic.List<long> customers, System.Collections.Generic.List<long> resources, long originator, System.Nullable<long> appointmentOid, System.Nullable<System.Guid> recurrenceId, int occurrenceIndex, bool shouldSkipResourceAvailability)
|
||||
{
|
||||
return base.Channel.ValidateSchedulerAppointment(start, end, employees, customers, resources, originator, appointmentOid, recurrenceId, occurrenceIndex, shouldSkipResourceAvailability);
|
||||
}
|
||||
}
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
|
||||
|
||||
@@ -1408,15 +1408,17 @@ namespace BeWo.Data.Access
|
||||
var pattern = StaticAppointmentFactory.CreateAppointment(AppointmentType.Pattern);
|
||||
pattern.RecurrenceInfo.FromXml(appointment.RecurrenceInfo);
|
||||
pattern.Start = pattern.RecurrenceInfo.Start;
|
||||
pattern.End = pattern.RecurrenceInfo.End;
|
||||
pattern.End = appointment.EndDate.Value;//pattern.RecurrenceInfo.End;
|
||||
|
||||
var patternId = pattern.RecurrenceInfo.Id.ToString();
|
||||
|
||||
var appointmentType = appointment.Type;
|
||||
var patternDuration = pattern.Duration;
|
||||
var appointmentDuration = new TimeSpan((appointment.EndDate.Value - appointment.StartDate.Value).Ticks);
|
||||
|
||||
// In diesem Fall die Start- und Enddaten des zu überprüfenden, neuen Termins
|
||||
var interval = new TimeInterval(start, end);
|
||||
|
||||
var subject = appointment.Subject;
|
||||
|
||||
// Die Serientermine werden berechnet (ausnahmslos, d.h. es werden auch bearbeitete und gelöschte Termine erstellt, die herausgefiltert werden müssen).
|
||||
var occurrences = occurenceCalculator.CalcOccurrences(interval, pattern);
|
||||
|
||||
@@ -4032,16 +4034,14 @@ namespace BeWo.Data.Access
|
||||
return criteria.List<SchedulerAppointment>().FirstOrDefault();
|
||||
}
|
||||
|
||||
public string ValidateSchedulerAppointment(DateTime start, DateTime end, IEnumerable<long> employees, IEnumerable<long> customers, List<long> resources, long originator, long? appointmentOid, string recurrenceId = "", int occurrenceIndex = 0)
|
||||
public string ValidateSchedulerAppointment(DateTime start, DateTime end, IEnumerable<long> employees, IEnumerable<long> customers, List<long> resources, long originator, long? appointmentOid, Guid? recurrenceId = null, int occurrenceIndex = 0, bool shouldSkipResourceAvailability = false)
|
||||
{
|
||||
var isOverlapping = OverlappingAppointmentsExist(start, end, employees, customers, resources, originator, appointmentOid, recurrenceId?.ToString() ?? "", occurrenceIndex);
|
||||
|
||||
var isOverlapping = OverlappingAppointmentsExist(start, end, employees, customers, resources, originator, appointmentOid, recurrenceId, occurrenceIndex);
|
||||
|
||||
var unavailableResources = CheckAvailabilityOfResources(resources.ToList(), start, end, appointmentOid);
|
||||
var unavailableResources = shouldSkipResourceAvailability ? new List<Resource>() : CheckAvailabilityOfResources(resources.ToList(), start, end, appointmentOid);
|
||||
|
||||
var stringBuilder = new StringBuilder();
|
||||
|
||||
|
||||
|
||||
if(unavailableResources.Any())
|
||||
{
|
||||
var names = string.Empty;
|
||||
@@ -4058,11 +4058,26 @@ namespace BeWo.Data.Access
|
||||
$"Ein{(resourceCount > 1 ? "ige" : "e")} der ausgewählten Ressourcen ({names}) sind" :
|
||||
$"{(resourceCount > 1 ? "Eine der" : "Die")} ausgewählte{suffix} Ressource{suffix} ({names}) ist";
|
||||
|
||||
ressourceWarningMessage += $" zum gewählten Zeitpunkt ({start.GetDateString(end)}) nicht verfügbar.\n\nMöchten Sie trotzdem speichern?";
|
||||
ressourceWarningMessage += $" zum gewählten Zeitpunkt ({start.GetDateString(end)}) nicht verfügbar.";
|
||||
|
||||
stringBuilder.Append(ressourceWarningMessage);
|
||||
}
|
||||
|
||||
if(isOverlapping)
|
||||
{
|
||||
if(unavailableResources.Any())
|
||||
{
|
||||
stringBuilder.Append("\n\n");
|
||||
}
|
||||
|
||||
stringBuilder.Append("Dieser Termin überschneidet sich mit einem anderen bereits existierenden Termin.");
|
||||
}
|
||||
|
||||
if(unavailableResources.Any() || isOverlapping)
|
||||
{
|
||||
stringBuilder.Append("\n\nMöchten Sie trotzdem speichern?");
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,5 +208,9 @@ namespace BeWo.Service.ServiceContracts
|
||||
[FaultContract(typeof(BeWoFault))]
|
||||
[OperationContract]
|
||||
SchedulerAppointmentDC FindRootAppointmentByRecurrenceId(string recurrenceId);
|
||||
|
||||
[FaultContract(typeof(BeWoFault))]
|
||||
[OperationContract]
|
||||
string ValidateSchedulerAppointment(DateTime start, DateTime end, IEnumerable<long> employees, IEnumerable<long> customers, List<long> resources, long originator, long? appointmentOid, Guid? recurrenceId, int occurrenceIndex = 0, bool shouldSkipResourceAvailability = false);
|
||||
}
|
||||
}
|
||||
@@ -2305,5 +2305,10 @@ namespace BeWo.Service.ServiceImplementations
|
||||
|
||||
return rootAppointment == null ? null : MapperFactory.SchedulerAppointmentDCSchedulerAppointment.MapToNewDC(rootAppointment);
|
||||
}
|
||||
|
||||
public string ValidateSchedulerAppointment(DateTime start, DateTime end, IEnumerable<long> employees, IEnumerable<long> customers, List<long> resources, long originator, long? appointmentOid, Guid? recurrenceId, int occurrenceIndex = 0, bool shouldSkipResourceAvailability = false)
|
||||
{
|
||||
return DAOFactory.SearchDAO.ValidateSchedulerAppointment(start, end, employees, customers, resources, originator, appointmentOid, recurrenceId, occurrenceIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user