From cb2c97026fe2c8b99402e81e74560cc4ddef3a24 Mon Sep 17 00:00:00 2001 From: Lyndon Jetten Date: Wed, 2 Dec 2020 21:46:58 +0100 Subject: [PATCH] =?UTF-8?q?Der=20=C3=9Cberschneidungstest=20ist=20angepass?= =?UTF-8?q?t=20und=20die=20Bugs=20behoben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModel/SchedulerAppointmentListVM.cs | 168 +++++++----------- BeWo/ServiceProxy/Generated.cs | 9 + Data/Access/SearchDAO.cs | 35 ++-- Service/ServiceContracts/IResourceService.cs | 4 + .../ResourceServiceImp.cs | 5 + 5 files changed, 106 insertions(+), 115 deletions(-) diff --git a/BeWo/Scheduler/ViewModel/SchedulerAppointmentListVM.cs b/BeWo/Scheduler/ViewModel/SchedulerAppointmentListVM.cs index 18cc59702..881b9756c 100644 --- a/BeWo/Scheduler/ViewModel/SchedulerAppointmentListVM.cs +++ b/BeWo/Scheduler/ViewModel/SchedulerAppointmentListVM.cs @@ -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 list) + public void InsertAppointments(SchedulerControl control, IEnumerable list) { var dcList = new List(); 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(); - - 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; - } } } diff --git a/BeWo/ServiceProxy/Generated.cs b/BeWo/ServiceProxy/Generated.cs index 521e4f7aa..9ba409a7a 100644 --- a/BeWo/ServiceProxy/Generated.cs +++ b/BeWo/ServiceProxy/Generated.cs @@ -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 employees, System.Collections.Generic.List customers, System.Collections.Generic.List resources, long originator, System.Nullable appointmentOid, System.Nullable 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 employees, System.Collections.Generic.List customers, System.Collections.Generic.List resources, long originator, System.Nullable appointmentOid, System.Nullable 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")] diff --git a/Data/Access/SearchDAO.cs b/Data/Access/SearchDAO.cs index 1e028ba2a..292bce358 100644 --- a/Data/Access/SearchDAO.cs +++ b/Data/Access/SearchDAO.cs @@ -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().FirstOrDefault(); } - public string ValidateSchedulerAppointment(DateTime start, DateTime end, IEnumerable employees, IEnumerable customers, List resources, long originator, long? appointmentOid, string recurrenceId = "", int occurrenceIndex = 0) + public string ValidateSchedulerAppointment(DateTime start, DateTime end, IEnumerable employees, IEnumerable customers, List 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() : 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(); } } diff --git a/Service/ServiceContracts/IResourceService.cs b/Service/ServiceContracts/IResourceService.cs index d9e7c3b0a..ed155db4c 100644 --- a/Service/ServiceContracts/IResourceService.cs +++ b/Service/ServiceContracts/IResourceService.cs @@ -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 employees, IEnumerable customers, List resources, long originator, long? appointmentOid, Guid? recurrenceId, int occurrenceIndex = 0, bool shouldSkipResourceAvailability = false); } } \ No newline at end of file diff --git a/Service/ServiceImplementations/ResourceServiceImp.cs b/Service/ServiceImplementations/ResourceServiceImp.cs index f6911a403..7df55d9e5 100644 --- a/Service/ServiceImplementations/ResourceServiceImp.cs +++ b/Service/ServiceImplementations/ResourceServiceImp.cs @@ -2305,5 +2305,10 @@ namespace BeWo.Service.ServiceImplementations return rootAppointment == null ? null : MapperFactory.SchedulerAppointmentDCSchedulerAppointment.MapToNewDC(rootAppointment); } + + public string ValidateSchedulerAppointment(DateTime start, DateTime end, IEnumerable employees, IEnumerable customers, List 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); + } } } \ No newline at end of file