diff --git a/Data/Access/SearchDAO.cs b/Data/Access/SearchDAO.cs
index 11a834cc2..5b6bcad3a 100644
--- a/Data/Access/SearchDAO.cs
+++ b/Data/Access/SearchDAO.cs
@@ -1134,7 +1134,7 @@ namespace BeWo.Data.Access
.Add(Restrictions.Eq("c2s.CustomerOid", customerOid))
.List
();
}
-
+
public AssessmentSheetCategory GetAddServiceAssessmentSheetCategoryWithName(string name)
{
return CreateCriteriaIsActive()
@@ -2860,5 +2860,93 @@ namespace BeWo.Data.Access
return c.List();
}
+
+ public IList GetInvoiceBasesBySupportConceptOids(List pSupprortConceptOids)
+ {
+ var c = CreateCriteria();
+
+ c.Add(Restrictions.In(nameof(InvoiceBase.SupportConceptOid), pSupprortConceptOids));
+
+ return c.List();
+ }
+
+ public IEnumerable GetSettlementInvoiceBySupportConceptOids(List pSupportConceptOids)
+ {
+ return CreateCriteria()
+ .CreateAlias(SettlementInvoice.PropertyName_InvoiceBase, "ib", JoinType.InnerJoin)
+ .Add(Restrictions.In("ib." + InvoiceBase.PropertyName_SupportConceptOid, pSupportConceptOids))
+ .List();
+ }
+
+ public IList GetServiceInvoicesByInvoiceBaseOids(List pIinvoiceBaseOids)
+ {
+ var res = CreateCriteria()
+ .CreateAlias(ServiceInvoice.PropertyName_InvoiceBase, "ib", JoinType.InnerJoin)
+ .Add(Restrictions.In("ib." + BeWoEntityBase.PropertyName_Oid, pIinvoiceBaseOids))
+ .List();
+
+ return res;
+ }
+
+ public IList GetAllAdditionalServiceBookingsForCustomer(long pCustomerOid)
+ {
+ return CreateCriteria()
+ .CreateAlias(AdditionalServiceBooking.PropertyName_Customer2AddServiceBookings, "c2s", JoinType.InnerJoin)
+ .Add(Restrictions.Eq("c2s.CustomerOid", pCustomerOid))
+ .List();
+ }
+
+ public IList GetAdditionalServiceGroupOfPeopleForCustomer(long pCustomerOid)
+ {
+ var c = CreateCriteria();
+
+ c.CreateCriteria(nameof(AdditionalServiceGroupOfPeople.CustomerList), JoinType.InnerJoin)
+ .Add(Restrictions.Eq(nameof(BeWoEntityBase.Oid), pCustomerOid));
+
+ return c.List();
+ }
+
+ public IList GetTasksAndAppointmentsBySupportConceptOids(List pSupportConceptOids)
+ {
+ var c = CreateCriteria();
+
+ var list = "";
+ for (var i = 0; i < pSupportConceptOids.Count; i++)
+ {
+ if (i != pSupportConceptOids.Count - 1)
+ {
+ list += "" + pSupportConceptOids[i] + ",";
+ }
+ else
+ {
+ list += "" + pSupportConceptOids[i];
+ }
+ }
+
+ var blah = $"{nameof(BeWoEntityBase.Oid)} IN (SELECT newschappoid FROM supportconcept2newschapp WHERE supportconceptoid IN ({list}))";
+ var supportConceptCriterion = Expression.Sql(blah);
+
+ c.Add(supportConceptCriterion);
+
+ return c.List();
+ }
+
+ public IList GetCustomer2TokensByCustomerOid(long pCustomerOid)
+ {
+ var c = CreateCriteria();
+
+ c.Add(Restrictions.Eq(nameof(Customer2Token.Customer) + "." + nameof(BeWoEntityBase.Oid), pCustomerOid));
+
+ return c.List();
+ }
+
+ public IList GetTestAppointments()
+ {
+ var c = CreateCriteria();
+
+ c.Add(Restrictions.Eq(nameof(BeWoEntityBase.Notice), Utils.TestAppointmentNotice));
+
+ return c.List();
+ }
}
}
diff --git a/Data/Data.csproj b/Data/Data.csproj
index 565b54864..93f274607 100644
--- a/Data/Data.csproj
+++ b/Data/Data.csproj
@@ -124,6 +124,7 @@
+
@@ -574,6 +575,7 @@
PreserveNewest
+
Designer
diff --git a/Data/DefaultHibernateSessionManager.cs b/Data/DefaultHibernateSessionManager.cs
index 176dc2709..6d5ba9d4f 100644
--- a/Data/DefaultHibernateSessionManager.cs
+++ b/Data/DefaultHibernateSessionManager.cs
@@ -53,10 +53,11 @@ namespace BeWo.Data
if (!_SessionFactories.ContainsKey(CurrentTenant))
{
#if DEBUG
- var hierarchy = (Hierarchy)LogManager.GetRepository();
- var logger = (Logger)hierarchy.GetLogger("NHibernate.SQL");
- logger.AddAppender(new TraceAppender { Layout = new SimpleLayout() });
- hierarchy.Configured = true;
+ //TODO: wieder einkommentieren!
+ //var hierarchy = (Hierarchy)LogManager.GetRepository();
+ //var logger = (Logger)hierarchy.GetLogger("NHibernate.SQL");
+ //logger.AddAppender(new TraceAppender { Layout = new SimpleLayout() });
+ //hierarchy.Configured = true;
#endif
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
diff --git a/Data/Entities/Employee2SchedulerAppointment.cs b/Data/Entities/Employee2SchedulerAppointment.cs
index 43dc72dfc..d57d89b45 100644
--- a/Data/Entities/Employee2SchedulerAppointment.cs
+++ b/Data/Entities/Employee2SchedulerAppointment.cs
@@ -22,57 +22,70 @@ namespace BeWo.Data.Entities
_Tid = TableID.Employee2SchedulerAppointment;
}
+ public Employee2SchedulerAppointment(Employee pEmployee)
+ {
+ _Tid = TableID.Employee2SchedulerAppointment;
+ Employee = pEmployee;
+ }
+
public virtual ParticipationAnswer ParticipationAnswer
{
- get { return _ParticipationAnswer; }
- set
+ get => _ParticipationAnswer;
+ set
{
if (AreDifferent(_ParticipationAnswer, value))
- _ParticipationAnswer = value;
+ {
+ _ParticipationAnswer = value;
+ }
}
}
public virtual long? SchedulerAppointmentOid
{
- get { return _SchedulerAppointmentOid; }
- set
+ get => _SchedulerAppointmentOid;
+ set
{
if (AreDifferent(_SchedulerAppointmentOid, value))
- _SchedulerAppointmentOid = value;
+ {
+ _SchedulerAppointmentOid = value;
+ }
}
}
public virtual bool IsPChanged
{
- get { return _IsPChanged; }
- set
+ get => _IsPChanged;
+ set
{
if (AreDifferent(_IsPChanged, value))
- _IsPChanged = value;
+ {
+ _IsPChanged = value;
+ }
}
}
public virtual DateTime? IsPC_CheckedTs
{
- get { return _IsPC_CheckedTs; }
- set
+ get => _IsPC_CheckedTs;
+ set
{
if (AreDifferent(_IsPC_CheckedTs, value))
- _IsPC_CheckedTs = value;
+ {
+ _IsPC_CheckedTs = value;
+ }
}
}
public virtual Employee Employee
{
- get
- {
- return _Employee;
- }
+ get => _Employee;
- set
+ set
{
if (AreDifferent(_Employee, value))
- _Employee = value;
+ {
+ _Employee = value;
+ }
}
}
}
diff --git a/Data/Entities/SchedulerAppointment.cs b/Data/Entities/SchedulerAppointment.cs
index 1c349b588..1130fe2ae 100644
--- a/Data/Entities/SchedulerAppointment.cs
+++ b/Data/Entities/SchedulerAppointment.cs
@@ -124,9 +124,9 @@ namespace BeWo.Data.Entities
public virtual string Subject { get; set; }
- //Normal = 0,
- //Pattern = 1,
- //Occurrence = 2,
+ //Normal = 0,
+ //Pattern = 1,
+ //Occurrence = 2,
//ChangedOccurrence = 3,
//DeletedOccurrence = 4
public virtual int Type { get; set; }
@@ -226,5 +226,10 @@ namespace BeWo.Data.Entities
}
}
}
+
+ public override string ToString()
+ {
+ return $"{StartDate?.ToString("dd.MM.yyyy HH:mm:ss")} - {EndDate?.ToString("dd.MM.yyyy HH:mm:ss")}: {Subject}";
+ }
}
}
\ No newline at end of file
diff --git a/Data/WCFHibernateSessionManager.cs b/Data/WCFHibernateSessionManager.cs
index 362981b73..7ffaaec53 100644
--- a/Data/WCFHibernateSessionManager.cs
+++ b/Data/WCFHibernateSessionManager.cs
@@ -46,10 +46,11 @@ namespace BeWo.Data
if (!_SessionFactories.ContainsKey(MultitenancyOperationContextExt.Current.Tenant))
{
#if DEBUG
- var hierarchy = (Hierarchy)LogManager.GetRepository();
- var logger = (Logger)hierarchy.GetLogger("NHibernate.SQL");
- logger.AddAppender(new TraceAppender { Layout = new SimpleLayout() });
- hierarchy.Configured = true;
+ //TODO: wieder einkommentieren!
+ //var hierarchy = (Hierarchy)LogManager.GetRepository();
+ //var logger = (Logger)hierarchy.GetLogger("NHibernate.SQL");
+ //logger.AddAppender(new TraceAppender { Layout = new SimpleLayout() });
+ //hierarchy.Configured = true;
#endif
_SessionFactories[MultitenancyOperationContextExt.Current.Tenant] = new Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Multitenancy\" + MultitenancyOperationContextExt.Current.Tenant + ".config")).BuildSessionFactory();
}
diff --git a/Host/Multitenancy/demo.config b/Host/Multitenancy/demo.config
index 32769335f..f15f97573 100644
--- a/Host/Multitenancy/demo.config
+++ b/Host/Multitenancy/demo.config
@@ -38,8 +38,8 @@
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
none
- true
- true
+ false
+ false
diff --git a/Service/Core/Utils.cs b/Service/Core/Utils.cs
index 10c87febf..8b8ce18f3 100644
--- a/Service/Core/Utils.cs
+++ b/Service/Core/Utils.cs
@@ -24,6 +24,9 @@ namespace BeWo.Service.Core
{
public class Utils
{
+ private static readonly Regex indexRegex = new Regex("(?:Index=\"){1}([0-9]+)\"{1}");
+ private static readonly Regex idRegex = new Regex("(?:Id=\")(([a-z0-9]{8})-{1}([a-z0-9]{4})-{1}([a-z0-9]{4})-{1}([a-z0-9]{4})-{1}([a-z0-9]{12}))(?=\"{1})");
+
public static FaultException CreateBeWoFaultException(Exception ex)
{
try
@@ -288,5 +291,24 @@ namespace BeWo.Service.Core
return result;
}
+
+ public static string ExtractIdFromRecurrenceInfo(string pRecurrenceInfo)
+ {
+ return pRecurrenceInfo != null ? idRegex.Match(pRecurrenceInfo).Groups[1].Value : null;
+ }
+
+ public static int ExtractIndexFromRecurrenceInfo(string pRecurrenceInfo)
+ {
+ if (pRecurrenceInfo != null)
+ {
+ var indexString = indexRegex.Match(pRecurrenceInfo).Groups[1].Value;
+
+ var index = !string.IsNullOrEmpty(indexString) ? int.Parse(indexString) : 0;
+
+ return index;
+ }
+
+ return -1;
+ }
}
}
\ No newline at end of file
diff --git a/Service/ServiceContracts/IResourceService.cs b/Service/ServiceContracts/IResourceService.cs
index d27dc3f80..c3757d7ea 100644
--- a/Service/ServiceContracts/IResourceService.cs
+++ b/Service/ServiceContracts/IResourceService.cs
@@ -188,5 +188,17 @@ namespace BeWo.Service.ServiceContracts
[FaultContract(typeof(BeWoFault))]
[OperationContract]
List GetSchedulerAppointmentTasksForEmployeeBySupportConecpt(long pEmployeeOid, long pSupportConceptOid);
+
+ [FaultContract(typeof(BeWoFault))]
+ [OperationContract]
+ List LoadTasksAndAppointmentsForEmployee(long pEmployeeOid, DateTime pInvertalStart, int pBufferSize, long? pEmployeeAppointmentsOid);
+
+ [FaultContract(typeof(BeWoFault))]
+ [OperationContract]
+ void InsertTestAppointments(long pEmployeeOid);
+
+ [FaultContract(typeof(BeWoFault))]
+ [OperationContract]
+ void DeleteTestAppointments();
}
}
\ No newline at end of file
diff --git a/Service/ServiceImplementations/EmployeeServiceImp.cs b/Service/ServiceImplementations/EmployeeServiceImp.cs
index 0d36e1aec..857010e0f 100644
--- a/Service/ServiceImplementations/EmployeeServiceImp.cs
+++ b/Service/ServiceImplementations/EmployeeServiceImp.cs
@@ -30,9 +30,8 @@ namespace BeWo.Service.ServiceImplementations
{
var e = DAOFactory.GenericDAO.LoadByID(pOid);
e.Person.IsActive = ActivationTypeId.Archived;
-
+
ServiceLogic.SetActivationType(pOid, pVersion, ActivationTypeId.Archived);
-
}
catch (Exception e)
{
diff --git a/Service/ServiceImplementations/OperationsServiceImp.cs b/Service/ServiceImplementations/OperationsServiceImp.cs
index aaf0eead6..75b554199 100644
--- a/Service/ServiceImplementations/OperationsServiceImp.cs
+++ b/Service/ServiceImplementations/OperationsServiceImp.cs
@@ -5293,12 +5293,52 @@ namespace BeWo.Service.ServiceImplementations
}
}
+ // TODO: Den ersten Buchstaben des Klienten und den Namen des Mitarbeiters speichern, der ihn gelöscht hat. -> Neue Tabelle
public void DeleteCustomerForGood(long pCustomerOid)
{
try
{
+ var deletionHistoryEntry = new DeletionHistory();
+
var appointments = DAOFactory.SearchDAO.FindAppointmentsForCustomer(pCustomerOid);
var customer = DAOFactory.GenericDAO.LoadByID(pCustomerOid);
+ var supportConceptOids = customer.SupportConcepts.Select(sc => sc.Oid.Value).ToList();
+
+ UserDC user;
+ if (LoggedInUserOperationContextExt.Current != null && LoggedInUserOperationContextExt.Current.User != null)
+ {
+ user = MapperFactory.UserDC_User.MapToNewDC(LoggedInUserOperationContextExt.Current.User);
+ }
+ else
+ {
+ user = MapperFactory.UserDC_User.MapToNewDC(SessionFacade.LoggedInUser);
+ }
+
+ if(user != null)
+ {
+ string initial;
+
+ if(customer.Person.FirstName.Length > 0)
+ {
+ initial = customer.Person.FirstName[0].ToString();
+ }
+ else if(customer.Person.LastName.Length > 0)
+ {
+ initial = customer.Person.LastName[0].ToString();
+ }
+ else if(customer.CustomerAlias?.Length > 0)
+ {
+ initial = customer.CustomerAlias[0].ToString();
+ }
+ else
+ {
+ initial = "unbekannt";
+ }
+
+ deletionHistoryEntry.DeletingEmployeeName = $"{user.Employee.FirstName} {user.Employee.LastName}";
+ deletionHistoryEntry.DeletedEntityName = initial;
+ deletionHistoryEntry.DeletedEntityTableId = TableID.Customer;
+ }
appointments.DoForEach(app => app.CustomerList.Remove(customer));
@@ -5324,6 +5364,23 @@ namespace BeWo.Service.ServiceImplementations
DAOFactory.GenericDAO.Update(customer.SupportConcepts);
+ var additionalServiceGroups = DAOFactory.SearchDAO.GetAdditionalServiceGroupOfPeopleForCustomer(customer.Oid.Value);
+ foreach(var additionalServiceGroup in additionalServiceGroups)
+ {
+ additionalServiceGroup.CustomerList.Remove(customer);
+ }
+
+ DAOFactory.GenericDAO.Update(additionalServiceGroups);
+
+ var additionalServiceBookings = DAOFactory.SearchDAO.GetAllAdditionalServiceBookingsForCustomer(customer.Oid.Value);
+ DAOFactory.GenericDAO.Delete(additionalServiceBookings);
+
+ var images2delete = customer.Person.Images;
+ customer.Person.Images.Clear();
+
+ DAOFactory.GenericDAO.Delete(images2delete);
+ DAOFactory.GenericDAO.Update(customer);
+
customer.SupportConcepts.DoForEach(s => s.CostBearer2SupportConceptList?.Clear());
foreach(var assessmentSheetCategory in customer.AssessmentSheetCategoryList)
{
@@ -5331,7 +5388,33 @@ namespace BeWo.Service.ServiceImplementations
}
var assessmentSheetEntries = DAOFactory.SearchDAO.GetAssessmentSheetEntriesForCustomer(customer.Oid.Value, DateTime.MinValue, DateTime.MaxValue);
-
+
+ var invoiceBases2Delete = DAOFactory.SearchDAO.GetInvoiceBasesBySupportConceptOids(supportConceptOids);
+ invoiceBases2Delete.DoForEach(ib => ib.InvoiceItems.Clear());
+
+ var settlementInvoices = DAOFactory.SearchDAO.GetSettlementInvoiceBySupportConceptOids(supportConceptOids);
+ var serviceInvoices = DAOFactory.SearchDAO.GetServiceInvoicesByInvoiceBaseOids(invoiceBases2Delete.Select(s => s.Oid.Value).ToList());
+
+ var invoiceItems = new List();
+ invoiceBases2Delete.DoForEach(ib => invoiceItems.AddRange(ib.InvoiceItems));
+ DAOFactory.GenericDAO.Update(invoiceBases2Delete);
+
+ if(supportConceptOids.Any())
+ {
+ var tasksAndAppointments2Delete = DAOFactory.SearchDAO.GetTasksAndAppointmentsBySupportConceptOids(supportConceptOids);
+ DAOFactory.GenericDAO.Delete(tasksAndAppointments2Delete);
+ }
+
+ DAOFactory.GenericDAO.Delete(invoiceItems);
+ DAOFactory.GenericDAO.Delete(settlementInvoices);
+ DAOFactory.GenericDAO.Delete(serviceInvoices);
+
+ invoiceBases2Delete = DAOFactory.SearchDAO.GetInvoiceBasesBySupportConceptOids(supportConceptOids);
+ DAOFactory.GenericDAO.Delete(invoiceBases2Delete);
+
+ var customer2Tokens2Delete = DAOFactory.SearchDAO.GetCustomer2TokensByCustomerOid(customer.Oid.Value);
+ DAOFactory.GenericDAO.Delete(customer2Tokens2Delete);
+
DAOFactory.GenericDAO.Delete(assessmentSheetEntries);
DAOFactory.GenericDAO.Update(customer);
@@ -5339,6 +5422,11 @@ namespace BeWo.Service.ServiceImplementations
DAOFactory.GenericDAO.Delete(customer.SupportConcepts);
DAOFactory.GenericDAO.Delete(DAOFactory.GenericDAO.LoadByID(customer.Oid.Value));
+
+ if(deletionHistoryEntry.DeletingEmployeeName != null)
+ {
+ DAOFactory.GenericDAO.Insert(deletionHistoryEntry);
+ }
}
catch(Exception e)
{
diff --git a/Service/ServiceImplementations/ResourceServiceImp.cs b/Service/ServiceImplementations/ResourceServiceImp.cs
index 30ae2a1a3..706a25903 100644
--- a/Service/ServiceImplementations/ResourceServiceImp.cs
+++ b/Service/ServiceImplementations/ResourceServiceImp.cs
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.ServiceModel;
@@ -13,13 +15,18 @@ using BeWo.Service.DCEntityMapper;
using BeWo.Service.ServiceContracts;
using BS.Shared;
+using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
+using DevExpress.ReportServer.ServiceModel.DataContracts;
using DevExpress.XtraScheduler;
+using DevExpress.XtraScheduler.Xml;
using static System.String;
+using Appointment = BeWo.Data.Entities.Appointment;
using Resource = BeWo.Data.Entities.Resource;
using Utils = BeWo.Service.Core.Utils;
+using SUtils = BS.Shared.Core.Utils;
namespace BeWo.Service.ServiceImplementations
{
@@ -1265,7 +1272,7 @@ namespace BeWo.Service.ServiceImplementations
var result = FilterAppointments(all, pEmployeeOid, filteredEmployeeOids, pSelectedCustomer, pSelectedResources, pCustomersOnly, pResourcesOnly);
- //Check fehlerhaftes RecurrenceInfos
+ //Check fehlerhafte RecurrenceInfos
foreach (var app in result)
{
if (!IsNullOrEmpty(app.RecurrenceInfo))
@@ -1457,5 +1464,716 @@ namespace BeWo.Service.ServiceImplementations
throw Utils.CreateBeWoFaultException(e);
}
}
+
+ public List LoadTasksAndAppointmentsForEmployee(long pEmployeeOid, DateTime pInvertalStart, int pBufferSize, long? pEmployeeAppointmentsOid)
+ {
+ try
+ {
+ var oldTasks = DAOFactory.SearchDAO.LoadTasksForConversion(pEmployeeOid);
+ var taskAppointments = new List();
+
+ foreach (var task in oldTasks)
+ {
+ var taskAsAppointment = new SchedulerAppointment
+ {
+ SupportConceptList = new List { task.SupportConcept },
+ EmployeeList = new List(),
+ FormerTaskOid = task.Oid,
+ Subject = task.Title,
+ CompletedNotice = task.CompletedNotice,
+ TaskDescription = task.Description,
+ IsActive = task.IsActive,
+ IsTask = true,
+ DueDate = task.DueDate,
+ StartDate = task.CompletedDate.HasValue ? task.DueDate?.GetShortDateTime() : task.InsTs?.GetShortDateTime(),
+ EndDate = task.DueDate?.GetShortDateTime().AddDays(1) ?? DateTime.MaxValue.Date
+ };
+
+ foreach (var employee in task.EmployeeList)
+ {
+ var rel = new Employee2SchedulerAppointment
+ {
+ Employee = DAOFactory.GenericDAO.LoadByID(employee.Oid.Value),
+ ParticipationAnswer = ParticipationAnswer.Offen
+ };
+
+ taskAsAppointment.EmployeeList.AddIfNotIn(rel);
+ }
+
+ taskAppointments.Add(taskAsAppointment);
+ }
+
+ InsertSchedulerAppointments(MapperFactory.SchedulerAppointmentDCSchedulerAppointment.MapToNewDCs(taskAppointments));
+
+ var taskAppointmentDCs = DAOFactory.SearchDAO.LoadTaskAppointmentsForEmployee(pEmployeeOid);
+
+ var monday = DateTime.Today.FirstDateOfWeek(pInvertalStart.AddDays(-1 * pBufferSize).GetIso8601WeekOfYear());
+
+ if(!pEmployeeAppointmentsOid.HasValue)
+ {
+ pEmployeeAppointmentsOid = pEmployeeOid;
+ }
+
+ var appointments = DAOFactory.SearchDAO.LoadFilteredAppointmentsForEmployee(false, pEmployeeAppointmentsOid.Value, monday, monday.AddDays(3 * pBufferSize), new List(), new List(), new List(), false, false, false, false, true, false).ToList();
+
+
+ UserDC user;
+ if (LoggedInUserOperationContextExt.Current != null && LoggedInUserOperationContextExt.Current.User != null)
+ {
+ user = MapperFactory.UserDC_User.MapToNewDC(LoggedInUserOperationContextExt.Current.User);
+ }
+ else
+ {
+ user = MapperFactory.UserDC_User.MapToNewDC(SessionFacade.LoggedInUser);
+ }
+
+ var loggedInEmployee = DAOFactory.GenericDAO.LoadByID(pEmployeeOid);
+
+ if(!user.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen))
+ {
+ var appointments2remove = appointments.Where(appointment => appointment.EmployeeList.Count > 0 && appointment.EmployeeList.Any(a => !a.Employee.Equals(loggedInEmployee))).ToList();
+ appointments = appointments.Except(appointments2remove).ToList();
+ }
+
+ // TODO: Testen!
+ if(!user.HasRight(UserRightType.KalenderKliententermineAlleAnsehen))
+ {
+ var ownCustomers = loggedInEmployee.Employee2CustomerList.Select(s => s.Customer).ToList();
+ var appointmentsWithOtherCustomers = appointments.Where(w => w.CustomerList.Any(a => !ownCustomers.Contains(a))).ToList();
+
+ appointments = appointments.Except(appointmentsWithOtherCustomers).ToList();
+ }
+
+ if(!user.HasRight(UserRightType.KalenderRessourcentermineAnsehen))
+ {
+ var appsToRemove = appointments.Where(appointment => appointment.ResourceList.Any()).ToList();
+ appointments = appointments.Except(appsToRemove).ToList();
+ }
+
+
+ var nullerIndex = new List();
+
+ var recurringAppointments = appointments.Where(app => app.RecurrenceInfo != null);
+ recurringAppointments.DoForEach(app =>
+ {
+ var index = Utils.ExtractIndexFromRecurrenceInfo(app.RecurrenceInfo);
+
+ if(index == 0)
+ {
+ nullerIndex.Add(app);
+ }
+ });
+
+ nullerIndex.DoForEach(app =>
+ {
+ var id = Utils.ExtractIdFromRecurrenceInfo(app.RecurrenceInfo);
+
+ if(app.Type == (int) AppointmentType.ChangedOccurrence)
+ {
+ var toRemove = appointments.Find(f => f.RecurrenceInfo != null && f.RecurrenceInfo.Contains(id) && !f.RecurrenceInfo.Contains("Index") && f.Type == (int) AppointmentType.Pattern);
+ appointments.Remove(toRemove);
+ }
+ });
+
+ taskAppointmentDCs.AddRangeIfElementsNotIn(appointments);
+
+ return MapperFactory.SchedulerAppointmentDCSchedulerAppointment.MapToNewDCs(taskAppointmentDCs);
+ }
+ catch (Exception e)
+ {
+ throw Utils.CreateBeWoFaultException(e);
+ }
+ }
+
+ public void InsertTestAppointments(long pEmployeeOid)
+ {
+ try
+ {
+ // Appointments speichern, dann die Mitarbeiterlisten...
+ CreateTestAppointmentsForEmployee(pEmployeeOid);
+ }
+ catch(Exception e)
+ {
+ throw Utils.CreateBeWoFaultException(e);
+ }
+ }
+
+ private static void CreateTestAppointmentsForEmployee(long pEmployeeOid)
+ {
+ #if DEBUG
+ var employee = DAOFactory.GenericDAO.LoadByID(pEmployeeOid);
+ var employeesWithoutEmployee = DAOFactory.GenericDAO.GetAllActive().Where(emp => !emp.Equals(employee)).ToList();
+ var customers = DAOFactory.GenericDAO.GetAllActive();
+ var ownCustomers = employee.Employee2CustomerList.Select(e2c => e2c.Customer).ToList();
+ var resources = DAOFactory.GenericDAO.GetAllActive();
+
+ var secondEmployee = employeesWithoutEmployee.FirstOrDefault() ?? employee;
+ var fiveOfSecondEmployeesCustomers = secondEmployee.Employee2CustomerList.Select(e2c => e2c.Customer).TakeWhile((t, j) => j != 5).ToList();
+
+ var fiveOfMyOwnCustomers = ownCustomers.TakeWhile((t, i) => i != 5).ToList();
+ var fiveCustomers = customers.TakeWhile((t, i) => i != 5).ToList();
+ var fiveResources = resources.TakeWhile((t, i) => i != 3).ToList();
+
+ var employeeList = employeesWithoutEmployee.TakeWhile((t, i) => i != 5).Select(t => new Employee2SchedulerAppointment(t)).ToList();
+
+ var employeeListIncludingLoggedInEmployee = employeesWithoutEmployee.TakeWhile((t, i) => i != 4).Select(t => new Employee2SchedulerAppointment(t)).ToList();//new List();
+ employeeListIncludingLoggedInEmployee.Add(new Employee2SchedulerAppointment(employee));
+
+ var monday = DateTime.Today.FirstDateOfWeek(DateTime.Today.GetIso8601WeekOfYear());
+ var tuesday = monday.AddDays(1);
+ var wednesday = monday.AddDays(2);
+ var thursday = monday.AddDays(3);
+ var friday = monday.AddDays(4);
+ var saturday = monday.AddDays(5);
+ var sunday = monday.AddDays(6);
+
+
+ //Originator ist angemeldeten Mitarbeiter
+ GenerateAppointments(monday, false, employee, fiveCustomers, fiveOfMyOwnCustomers, fiveResources, employeeList, null);
+
+ //Termin von anderem Mitarbeiter
+ GenerateAppointments(tuesday, false, secondEmployee, fiveCustomers, fiveOfMyOwnCustomers, fiveResources, employeeListIncludingLoggedInEmployee, null);
+
+ //Originator ist angemeldeter Mitarbeiter und in Liste
+ GenerateAppointments(wednesday, false, employee, fiveCustomers, fiveOfMyOwnCustomers, fiveResources, employeeListIncludingLoggedInEmployee, null);
+
+ //Originator ist nicht angemeldeter Mitarbeiter und der ist auch nicht in der Liste
+ GenerateAppointments(thursday, false, secondEmployee, fiveCustomers, fiveOfSecondEmployeesCustomers, fiveResources, employeeList, null);
+
+
+ //Private Termine
+ GenerateAppointments(friday, true, employee, fiveCustomers, fiveOfMyOwnCustomers, fiveResources, employeeList, null);
+ GenerateAppointments(saturday, true, secondEmployee, fiveCustomers, fiveOfSecondEmployeesCustomers, fiveResources, employeeList, null);
+ GenerateAppointments(sunday, true, secondEmployee, fiveCustomers, fiveOfSecondEmployeesCustomers, fiveResources, employeeListIncludingLoggedInEmployee, null);
+ GenerateAppointments(friday.AddHours(12), true, employee, fiveCustomers, fiveOfMyOwnCustomers, fiveResources, employeeListIncludingLoggedInEmployee, null);
+
+
+ //AllDay-Termine ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ var mon = monday.AddDays(7);
+ var tue = tuesday.AddDays(7);
+ var wed = wednesday.AddDays(7);
+ var thu = thursday.AddDays(7);
+ var fri = friday.AddDays(7);
+ var sat = saturday.AddDays(7);
+ var sun = sunday.AddDays(7);
+
+ //Originator ist angemeldeten Mitarbeiter
+ GenerateAppointments(mon, false, employee, fiveCustomers, fiveOfMyOwnCustomers, fiveResources, employeeList, null, true);
+
+ //Termin von anderem Mitarbeiter
+ GenerateAppointments(tue, false, secondEmployee, fiveCustomers, fiveOfMyOwnCustomers, fiveResources, employeeListIncludingLoggedInEmployee, null, true);
+
+ //Originator ist angemeldeter Mitarbeiter und in Liste
+ GenerateAppointments(wed, false, employee, fiveCustomers, fiveOfMyOwnCustomers, fiveResources, employeeListIncludingLoggedInEmployee, null, true);
+
+ //Originator ist nicht angemeldeter Mitarbeiter und der ist auch nicht in der Liste
+ GenerateAppointments(thu, false, secondEmployee, fiveCustomers, fiveOfSecondEmployeesCustomers, fiveResources, employeeList, null, true);
+
+
+ //Private Termine
+ GenerateAppointments(fri, true, employee, fiveCustomers, fiveOfMyOwnCustomers, fiveResources, employeeList, null, true);
+ GenerateAppointments(sat, true, secondEmployee, fiveCustomers, fiveOfSecondEmployeesCustomers, fiveResources, employeeList, null, true);
+ GenerateAppointments(sun, true, secondEmployee, fiveCustomers, fiveOfSecondEmployeesCustomers, fiveResources, employeeListIncludingLoggedInEmployee, null, true);
+ GenerateAppointments(fri.AddHours(12), true, employee, fiveCustomers, fiveOfMyOwnCustomers, fiveResources, employeeListIncludingLoggedInEmployee, null, true);
+ // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
+ var mo = mon.AddDays(7);
+ var tu = tue.AddDays(7);
+
+ // Tägliche Termine
+ var everyThirdMondayNoEnd = GenerateTestAppointment(false, false, mo.AddHours(9), mo.AddHours(10), AppointmentType.Pattern, "Täglich, alle 3 Tage. Endlos", employee);
+ everyThirdMondayNoEnd.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Daily, 0, 0, mo.AddHours(9), null, 1);
+ DAOFactory.GenericDAO.Insert(everyThirdMondayNoEnd);
+
+ var everyWeekdayNoEnd = GenerateTestAppointment(false, false, mo.AddHours(10), mo.AddHours(11), AppointmentType.Pattern, "Wochentäglich. Endlos", employee);
+ everyWeekdayNoEnd.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Daily, 0, 1, mo.AddHours(10), null, 1);
+ DAOFactory.GenericDAO.Insert(everyWeekdayNoEnd);
+
+ var everyThirdMondayEndsAfter12Times = GenerateTestAppointment(false, false, mo.AddHours(11), mo.AddHours(12), AppointmentType.Pattern, "Täglich, alle 3 Tage. Endet nach 12 Terminen", employee);
+ everyThirdMondayEndsAfter12Times.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Daily, 1, 0, mo.AddHours(11), null, 1);
+ DAOFactory.GenericDAO.Insert(everyThirdMondayEndsAfter12Times);
+
+ var everyWorkdayEndsAfter12Times = GenerateTestAppointment(false, false, mo.AddHours(12), mo.AddHours(13), AppointmentType.Pattern, "Wochentäglich. Endet nach 12 Terminen", employee);
+ everyWorkdayEndsAfter12Times.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Daily, 1, 1, mo.AddHours(12), null, 1);
+ DAOFactory.GenericDAO.Insert(everyWorkdayEndsAfter12Times);
+
+ var everyWorkdayEndsOnSpecificDate = GenerateTestAppointment(false, false, mo.AddHours(13), mo.AddHours(14), AppointmentType.Pattern, $"Wochentäglich. Endet am {mo.AddHours(13).AddDays(11):dd.MM.yyyy}", employee);
+ everyWorkdayEndsOnSpecificDate.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Daily, 2, 1, mo.AddHours(13), everyWorkdayEndsOnSpecificDate.StartDate.Value.AddDays(11), 0);
+ DAOFactory.GenericDAO.Insert(everyWorkdayEndsOnSpecificDate);
+
+ var everyThreeDaysEndsOnSpecificDate = GenerateTestAppointment(false, false, mo.AddHours(15), mo.AddHours(16), AppointmentType.Pattern, "Jeden dritten Tag. Endet 11 Tage nach Beginn", employee);
+ everyThreeDaysEndsOnSpecificDate.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Daily, 2, 0, mo.AddHours(15), mo.AddHours(15).AddDays(11), 0);
+ DAOFactory.GenericDAO.Insert(everyThreeDaysEndsOnSpecificDate);
+
+ // Wöchentliche Termine
+ var everyThirdWeekMondayAndTuesday = GenerateTestAppointment(false, false, mo.AddHours(16), mo.AddHours(17), AppointmentType.Pattern, "Jede dritte Woche Montags und Dienstags. Endlos", employee);
+ everyThirdWeekMondayAndTuesday.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Weekly, 0, 0, mo.AddHours(16), null, 1);
+ DAOFactory.GenericDAO.Insert(everyThirdWeekMondayAndTuesday);
+
+ var everySecondWeekMondaysAndTuesdays = GenerateTestAppointment(false, false, mo.AddHours(18), mo.AddHours(19), AppointmentType.Pattern, "Jede zweite Woche am Montag und Dienstag. Endet nach 17 Terminen", employee);
+ everySecondWeekMondaysAndTuesdays.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Weekly, 0, 1, mo.AddHours(18), null, 17);
+ DAOFactory.GenericDAO.Insert(everySecondWeekMondaysAndTuesdays);
+
+ var everyWeekMondaysAndTuesdays = GenerateTestAppointment(false, false, mo.AddHours(19), mo.AddHours(20), AppointmentType.Pattern, $"Jede Woche am Montag und Dienstag. Endet am {mo.AddHours(19).AddDays(20):dd.MM.yyyy}", employee);
+ everyWeekMondaysAndTuesdays.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Weekly, 1, 1, mo.AddHours(19), mo.AddHours(19).AddDays(20), 1);
+ DAOFactory.GenericDAO.Insert(everyWeekMondaysAndTuesdays);
+
+ // Monatliche Termine
+ var m1 = GenerateTestAppointment(false, false, tu.AddHours(8), tu.AddHours(9), AppointmentType.Pattern, $"Am {tu.FirstDateOfWeek(tu.GetIso8601WeekOfYear())} jedes 2. Monats. Endlos", employee);
+ m1.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Monthly, 0, 0, tu.AddHours(8), null, 1);
+ DAOFactory.GenericDAO.Insert(m1);
+
+ var m2 = GenerateTestAppointment(false, false, tu.AddHours(9), tu.AddHours(10), AppointmentType.Pattern, "Jeden dritten Mittwoch jedes 2. Monats. Endlos", employee);
+ m2.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Monthly, 0, 1, tu.AddHours(9), null, 1);
+ DAOFactory.GenericDAO.Insert(m2);
+
+ var m3 = GenerateTestAppointment(false, false, tu.AddHours(10), tu.AddHours(11), AppointmentType.Pattern, "Jeden 3. jedes 3. Monats. Endet nach 3 Terminen", employee);
+ m3.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Monthly, 1, 0, tu.AddHours(10), null, 3);
+ DAOFactory.GenericDAO.Insert(m3);
+
+ var m4 = GenerateTestAppointment(false, false, tu.AddHours(11), tu.AddHours(12), AppointmentType.Pattern, "Jeden 3. Montag jedes 3. Monats. Endet nach 3 Terminen", employee);
+ m4.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Monthly, 1, 1, tu.AddHours(11), null, 3);
+ DAOFactory.GenericDAO.Insert(m4);
+
+ var m5 = GenerateTestAppointment(false, false, tu.AddHours(12), tu.AddHours(13), AppointmentType.Pattern, $"Am 17. jedes 3. Monats. Endet am {tu.AddMonths(6):dd.MM.yyyy}", employee);
+ m5.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Monthly, 2, 0, tu.AddHours(12), tu.AddHours(12).AddMonths(6), 1);
+ DAOFactory.GenericDAO.Insert(m5);
+
+ var m6 = GenerateTestAppointment(false, false, tu.AddHours(13), tu.AddHours(14), AppointmentType.Pattern, $"Jeden 3. Montag jedes Monats. Endet am {tu.AddMonths(4):dd.MM.yyyy}", employee);
+ m6.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Monthly, 2, 1, tu.AddHours(13), tu.AddHours(13).AddMonths(4), 1);
+ DAOFactory.GenericDAO.Insert(m6);
+
+ // Jährliche Termine
+
+ var y1 = GenerateTestAppointment(false, false, tu.AddHours(14), tu.AddHours(16), AppointmentType.Pattern, $"Jährlich am {tu:dd.MM.}. Endlos", employee);
+ y1.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Yearly, 0, 0, tu.AddHours(14), null, 1);
+ DAOFactory.GenericDAO.Insert(y1);
+
+
+ var y2 = GenerateTestAppointment(false, false, tu.AddHours(16), tu.AddHours(17), AppointmentType.Pattern, $"Jährlich am 3. Montag im {tu:MMMM}. Endlos", employee);
+ y2.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Yearly, 0, 1, tu.AddHours(16), null, 1);
+ DAOFactory.GenericDAO.Insert(y2);
+
+ var y3 = GenerateTestAppointment(false, false, tu.AddHours(17), tu.AddHours(18), AppointmentType.Pattern, $"Jährlich jeden {tu.Day}. im {mo.Month:MMMM}. Endet nach 3 Terminen", employee);
+ y3.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Yearly, 1, 0, tu.AddHours(17), null, 3);
+ DAOFactory.GenericDAO.Insert(y3);
+
+ var y4 = GenerateTestAppointment(false, false, tu.AddHours(18), tu.AddHours(19), AppointmentType.Pattern, $"Jährlich jeden 3. Montag im {mo.Month:MMMM}. Endet nach 3 Terminen", employee);
+ y4.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Yearly, 1, 1, tu.AddHours(18), null, 3);
+ DAOFactory.GenericDAO.Insert(y4);
+
+ var y5 = GenerateTestAppointment(false, false, tu.AddHours(19), tu.AddHours(20), AppointmentType.Pattern, $"Jährlich am x. [Monat]. Endet am xx.xx.xxxx (1 Jahr später)", employee);
+ y5.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Yearly, 2, 0, tu.AddHours(19), tu.AddHours(19).AddYears(1), 3);
+ DAOFactory.GenericDAO.Insert(y5);
+
+ var y6 = GenerateTestAppointment(false, false, tu.AddHours(20), tu.AddHours(21), AppointmentType.Pattern, $"Jährlich jeden 3. Mittwoch im {tu:MMMM}. Endet am {tu.AddHours(20).AddYears(1):dd.MM.yyyy}", employee);
+ y6.RecurrenceInfo = GenerateRecurrenceInfo(RecurrenceType.Yearly, 2, 1, tu.AddHours(20), tu.AddHours(20).AddYears(1), 3);
+ DAOFactory.GenericDAO.Insert(y6);
+ // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+#endif
+ }
+
+ private static string CreateRandomLocationName()
+ {
+ var random = new Random(Convert.ToInt32(DateTime.Now.Ticks.ToString().Substring(0, 9))).Next();
+ var location = "";
+
+ if(random % 2 == 0)
+ {
+ location = "Duisburg";
+ }
+ else if(random % 3 == 0)
+ {
+ location = "Düsseldorf";
+ }
+ else if (random % 5 == 0)
+ {
+ location = "Köln";
+ }
+
+ return location;
+ }
+
+ private static void GenerateAppointments(DateTime pFirstDate, bool pIsPrivate, Employee pEmployee, IList pCustomerList, IList pOwnCustomers, IList pResourceList, IList pEmployees, string pRecurrenceInfo, bool pIsAllDay = false)
+ {
+ const int startHours = 6;
+
+ for(var i = 0; i < 12; i++)
+ {
+ var appointment = GenerateTestAppointment(
+ pIsPrivate,
+ new List(),
+ new List(),
+ new List(),
+ pIsAllDay,
+ pIsAllDay ? pFirstDate.GetShortDateTime() : pFirstDate.AddHours(startHours + i),
+ pIsAllDay ? pFirstDate.GetShortDateTime().AddDays(1) : pFirstDate.AddHours(startHours + i + 1),
+ AppointmentType.Normal,
+ $"Testtermin von {pEmployee.Person.FirstNameLastName}",
+ pEmployee);
+
+ switch (i)
+ {
+ case 1:
+ appointment.CustomerList = pCustomerList;
+ appointment.Subject += " mit Klienten";
+ break;
+ case 2:
+ appointment.EmployeeList = pEmployees;
+ appointment.Subject += " mit Mitarbeitern";
+ break;
+ case 3:
+ appointment.ResourceList = pResourceList;
+ appointment.Subject += " mit Ressourcen";
+ break;
+ case 4:
+ appointment.CustomerList = pCustomerList;
+ appointment.EmployeeList = pEmployees;
+ appointment.Subject += " mit Klienten und Mitarbeitern";
+ break;
+ case 5:
+ appointment.CustomerList = pCustomerList;
+ appointment.ResourceList = pResourceList;
+ appointment.Subject += " mit Klienten und Ressourcen";
+ break;
+ case 6:
+ appointment.CustomerList = pCustomerList;
+ appointment.EmployeeList = pEmployees;
+ appointment.ResourceList = pResourceList;
+ appointment.Subject += " mit Klienten, Mitarbeitern und Ressourcen";
+ break;
+ case 7:
+ appointment.EmployeeList = pEmployees;
+ appointment.ResourceList = pResourceList;
+ appointment.Subject += " mit Mitarbeitern und Ressourcen";
+ break;
+ case 8:
+ appointment.CustomerList = pOwnCustomers;
+ appointment.Subject += " mit eigenen Klienten";
+ break;
+ case 9:
+ appointment.CustomerList = pOwnCustomers;
+ appointment.EmployeeList = pEmployees;
+ appointment.Subject += " mit eigenen Klienten und Mitarbeitern";
+ break;
+ case 10:
+ appointment.CustomerList = pOwnCustomers;
+ appointment.ResourceList = pResourceList;
+ appointment.Subject += " mit eigenen Klienten und Ressourcen";
+ break;
+ case 11:
+ appointment.CustomerList = pOwnCustomers;
+ appointment.EmployeeList = pEmployees;
+ appointment.ResourceList = pResourceList;
+ appointment.Subject += " mit eigenen Klienten, Mitarbeitern und Ressourcen";
+ break;
+ }
+
+ if (pEmployees != null)
+ {
+ DAOFactory.GenericDAO.Insert(pEmployees);
+ }
+
+ appointment.Subject = (pIsPrivate ? "Privat: " : "") + appointment.Subject;
+
+ DAOFactory.GenericDAO.Insert(appointment);
+ }
+ }
+
+ private static string GenerateRecurrenceInfo(RecurrenceType pType, int pRecurrenceMode, int pRecurrenceOption, DateTime pStartDate, DateTime? pRecurrenceEndDate, int pOccurrenceCount)
+ {
+ // pRecurrenceOption ist z.B. bei täglich "Alle x Tage" oder "Jeden Arbeitstag"
+ var monday = pStartDate.FirstDateOfWeek(pStartDate.GetIso8601WeekOfYear());
+
+ // XML für die RecurrenceInfo bauen
+ var ri = new RecurrenceInfo
+ {
+ Start = pStartDate,
+ Type = pType
+ };
+
+ switch(pRecurrenceMode)
+ {
+ case 0: // Ohne Enddatum
+ ri.Range = RecurrenceRange.NoEndDate;
+ ri.Periodicity = 3;
+
+ switch (pType)
+ {
+ case RecurrenceType.Daily:
+ ri.Start = monday;
+
+ if(pRecurrenceOption == 1) // Jeden Arbeitstag
+ {
+ ri.WeekDays = WeekDays.WorkDays;
+ }
+ break;
+ case RecurrenceType.Weekly:
+ ri.WeekDays = WeekDays.Monday | WeekDays.Tuesday;
+ break;
+ case RecurrenceType.Monthly:
+ ri.WeekDays = ri.Start.GetSchedulerWeekDays();
+ ri.Periodicity = 2;
+ ri.WeekOfMonth = pRecurrenceOption == 0 ? 0 : WeekOfMonth.Third;
+
+ if(pRecurrenceOption == 1) // Am x. Wochentag jedes y.
+ {
+ var date = DateTimeUtils.GetNthDayOfWeekInMonth(ri.Start, 3, DayOfWeek.Monday);
+ ri.Start = date;
+ ri.WeekDays = date.GetSchedulerWeekDays();
+ }
+ else // Am x. jedes y. Monats
+ {
+ ri.DayNumber = monday.Day;
+ }
+
+ break;
+ case RecurrenceType.Yearly:
+ if(pRecurrenceOption == 0)
+ {
+ ri.DayNumber = monday.Day;
+ }
+
+ ri.Periodicity = 1;
+ ri.WeekOfMonth = pRecurrenceOption == 0 ? 0 : WeekOfMonth.Third;
+ ri.WeekDays = monday.GetSchedulerWeekDays();
+ ri.Month = monday.Month;
+ break;
+ }
+
+ break;
+ case 1: // Endet nach y Terminen
+ ri.Range = RecurrenceRange.OccurrenceCount;
+
+ var day = pStartDate;
+
+ switch (pType)
+ {
+ case RecurrenceType.Daily:
+ if(pRecurrenceOption == 1) // Jeden Arbeitstag endet nach y Terminen
+ {
+ ri.WeekDays = WeekDays.WorkDays;
+ var counter1 = 0;
+
+ do
+ {
+ if(day.DayOfWeek != DayOfWeek.Saturday && day.DayOfWeek != DayOfWeek.Sunday)
+ {
+ counter1++;
+ }
+
+ day = day.AddDays(1);
+ } while(counter1 < pOccurrenceCount - 1);
+ }
+ else
+ {
+ ri.Periodicity = 3;
+ ri.OccurrenceCount = pOccurrenceCount;
+
+ for (var i = 0; i < pOccurrenceCount - 1; i++)
+ {
+ day = day.AddDays(ri.Periodicity);
+ }
+ }
+
+ ri.End = day;
+
+ break;
+ case RecurrenceType.Weekly:
+ // Jeden Montag und Dienstag alle 2 Wochen
+ ri.WeekDays = WeekDays.Monday | WeekDays.Tuesday;
+ ri.OccurrenceCount = pOccurrenceCount;
+ ri.Periodicity = 2;
+
+ var weekDays = SUtils.GetWeekDaysFromNumber((int) ri.WeekDays);
+
+ var counter = 1;
+ var position = weekDays.IndexOf(day.DayOfWeek);
+
+ do
+ {
+ for(var i = position; i < weekDays.Count; i++)
+ {
+ day = SUtils.GetNextDateTime(day, weekDays.ElementAt(i), ri.Periodicity, RecurrenceType.Weekly);
+ counter++;
+ }
+
+ position = (weekDays.Count - 1) % (position == 0 ? position + 1 : position);
+ } while(counter < pOccurrenceCount);
+
+ ri.End = day;
+ break;
+ case RecurrenceType.Monthly:
+ ri.WeekDays = pStartDate.GetSchedulerWeekDays();
+ ri.WeekOfMonth = pRecurrenceOption == 0 ? 0 : pStartDate.GetWeekOfMonthForRecurrenceInfo();
+
+ if (pRecurrenceOption == 0) // Am 3. jedes 3. Monats. Endet nach 3 Terminen
+ {
+ ri.DayNumber = pStartDate.Day;
+ ri.Periodicity = 3;
+ ri.OccurrenceCount = pOccurrenceCount;
+ }
+ else // Jeden 3. Montag jedes 3. Monats. Endet nach 3 Terminen
+ {
+ ri.End = pStartDate.AddMonths(3 * pOccurrenceCount);
+ }
+ break;
+ case RecurrenceType.Yearly:
+ ri.Month = pStartDate.Month;
+ ri.WeekDays = pStartDate.GetSchedulerWeekDays();
+ ri.OccurrenceCount = pOccurrenceCount;
+
+ if (pRecurrenceOption == 0) // Am x. des Monats
+ {
+ ri.DayNumber = pStartDate.Day;
+ }
+ else // Jeden 3. Montag im Juni
+ {
+ ri.WeekOfMonth = pStartDate.GetWeekOfMonthForRecurrenceInfo();
+ }
+ break;
+ }
+
+ break;
+ case 2: // Endet am xx.xx.xxxx
+ if(!pRecurrenceEndDate.HasValue)
+ {
+ return null;
+ }
+
+ ri.Range = RecurrenceRange.EndByDate;
+ ri.End = pRecurrenceEndDate.Value;
+
+ switch (pType)
+ {
+ // Start, End
+ case RecurrenceType.Daily:
+ if(pRecurrenceOption == 0) // Alle x Tage. Endet am xx.xx.xxxx
+ {
+ day = ri.Start;
+ while(day < ri.End && ri.OccurrenceCount < 3)
+ {
+ day = day.AddDays(3);
+ ri.OccurrenceCount++;
+ }
+ }
+ else // Jeden Arbeitstag. Endet am xx.xx.xxxx
+ {
+ ri.WeekDays = WeekDays.WorkDays;
+ ri.OccurrenceCount = (ri.End - ri.Start).Days + 1 - DateTimeUtils.GetNumberOfWeekEndDaysInBetween(ri.Start, ri.End);
+ }
+ break;
+ case RecurrenceType.Weekly:
+ ri.WeekDays = WeekDays.Monday | WeekDays.Wednesday | WeekDays.Friday;
+
+ var weekDays = SUtils.GetWeekDaysFromNumber((int)ri.WeekDays);
+
+ day = ri.Start;
+ var position = weekDays.IndexOf(day.DayOfWeek) + (weekDays.Count > 1 ? 1 : 0);
+
+ do
+ {
+ for (var i = position; i < weekDays.Count; i++)
+ {
+ day = SUtils.GetNextDateTime(day, weekDays.ElementAt(i), 1, RecurrenceType.Weekly).Date;
+ ri.OccurrenceCount++;
+ }
+
+ position = (weekDays.Count - 1) % (position == 0 ? position + 1 : position);
+ } while (day < ri.End.Date);
+
+ break;
+ case RecurrenceType.Monthly:
+ ri.WeekOfMonth = pRecurrenceOption == 0 ? 0 : pStartDate.GetWeekOfMonthForRecurrenceInfo();
+
+ if (pRecurrenceOption == 0) // Am 17. jedes 3. Monats. Endet am xx.xx.xxxx (17. diesen Monats + 6 Monate)
+ {
+ ri.End = new DateTime(ri.Start.AddMonths(7).Year, ri.Start.AddMonths(7).Month, 1, ri.Start.Hour, ri.Start.Minute, ri.Start.Second);
+ ri.DayNumber = 17;
+ ri.Periodicity = 3;
+ ri.WeekDays = new DateTime(ri.Start.Year, ri.Start.Month, 17).GetSchedulerWeekDays();
+ ri.OccurrenceCount = 3;
+ }
+ else // Am x. [Wochentag] jedes y. Monats. Endet am xx.xx.xxxx
+ {
+ // 5 mal
+ var abc = DateTimeUtils.GetNthDayOfWeekInMonth(ri.Start.AddMonths(4), 3, DayOfWeek.Wednesday);
+ ri.End = abc < pRecurrenceEndDate.Value ? pRecurrenceEndDate.Value : abc;
+ ri.WeekOfMonth = WeekOfMonth.Third;
+ ri.OccurrenceCount = 5;
+ ri.WeekDays = WeekDays.Monday;
+ }
+ break;
+ case RecurrenceType.Yearly:
+ ri.WeekOfMonth = pRecurrenceOption == 0 ? 0 : pStartDate.GetWeekOfMonthForRecurrenceInfo();
+
+ if (pRecurrenceOption == 0) // Am x. [Monat]. Endet am xx.xx.xxxx (1 Jahr später)
+ {
+ ri.End = ri.Start.AddYears(1);
+ ri.DayNumber = ri.Start.Day;
+ ri.WeekDays = ri.Start.GetSchedulerWeekDays();
+ ri.Month = ri.Start.Month;
+ ri.OccurrenceCount = ri.Start.AddYears(1).Year - ri.Start.Year + 1;
+ }
+ else // Jeden 3. Mittwoch im [Aktueller Monat]. Endet am xx.xx.xxxx (1 Jahr vom Startdatum entfernt)
+ {
+ var wednesday = ri.Start.FirstDateOfWeek(ri.Start.GetIso8601WeekOfYear()).AddDays(2);
+
+ ri.WeekDays = WeekDays.Wednesday;
+ ri.Start = DateTimeUtils.GetNthDayOfWeekInMonth(wednesday, 3, wednesday.DayOfWeek);
+ ri.DayNumber = ri.Start.Day;
+ ri.Month = ri.Start.Month;
+ ri.End = DateTimeUtils.GetNthDayOfWeekInMonth(ri.Start.AddYears(1), 3, ri.Start.DayOfWeek);
+ ri.OccurrenceCount = ri.End.Year - ri.Start.Year + 1;
+ }
+ break;
+ }
+
+ break;
+ }
+
+ return ri.ToXml();
+ }
+
+ private static SchedulerAppointment GenerateTestAppointment(bool pIsPrivate, bool pIsAllDay, DateTime pStart, DateTime pEnd, AppointmentType pType, string pSubject, Employee pOriginator)
+ {
+ return GenerateTestAppointment(pIsPrivate, new List(), new List(), new List(), pIsAllDay, pStart, pEnd, pType, pSubject, pOriginator);
+ }
+
+ private static SchedulerAppointment GenerateTestAppointment(bool pIsPrivate, IList pCustomerList, IList pResourceList, IList pEmployeeList, bool pIsAllDay, DateTime pStart, DateTime pEnd, AppointmentType pType, string pSubject, Employee pOriginator)
+ {
+ var appointment = new SchedulerAppointment
+ {
+ AllDay = pIsAllDay,
+ CustomerList = pCustomerList,
+ EmployeeList = pEmployeeList,
+ ResourceList = pResourceList,
+ StartDate = pStart,
+ EndDate = pEnd,
+ Type = (int) pType,
+ Location = CreateRandomLocationName(),
+ IsPrivate = pIsPrivate,
+ Subject = pSubject,
+ Originator = pOriginator,
+ Notice = SUtils.TestAppointmentNotice
+ };
+
+
+ return appointment;
+ }
+
+ public void DeleteTestAppointments()
+ {
+ try
+ {
+ var testAppointments = DAOFactory.SearchDAO.GetTestAppointments();
+
+ DAOFactory.GenericDAO.Delete(testAppointments);
+ }
+ catch(Exception e)
+ {
+ throw Utils.CreateBeWoFaultException(e);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Shared/BeWoEntityEnums.cs b/Shared/BeWoEntityEnums.cs
index e1e21e8ea..413ccecd3 100644
--- a/Shared/BeWoEntityEnums.cs
+++ b/Shared/BeWoEntityEnums.cs
@@ -133,7 +133,8 @@ namespace BS.Shared
Feiertag = 126,
NotizenKategorie = 127,
NotizenEintrag = 128,
- BuchungsExport = 129
+ BuchungsExport = 129,
+ DeletionHistory = 130
}
public enum SystemEntryID
diff --git a/Shared/Core/DateTimeUtils.cs b/Shared/Core/DateTimeUtils.cs
index 5d224ab1b..a94f9e72a 100644
--- a/Shared/Core/DateTimeUtils.cs
+++ b/Shared/Core/DateTimeUtils.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using DevExpress.XtraScheduler;
namespace BS.Shared.Core
{
@@ -64,7 +62,107 @@ namespace BS.Shared.Core
return am;
}
-
+
+ public static WeekDays GetWeekDays(int number)
+ {
+ switch (number)
+ {
+ case 1:
+ return WeekDays.Sunday;
+ case 2:
+ return WeekDays.Monday;
+ case 4:
+ return WeekDays.Tuesday;
+ case 8:
+ return WeekDays.Wednesday;
+ case 16:
+ return WeekDays.Thursday;
+ case 32:
+ return WeekDays.Friday;
+ case 62:
+ return WeekDays.WorkDays;
+ case 64:
+ return WeekDays.Saturday;
+ case 65:
+ return WeekDays.WeekendDays;
+ case 127:
+ return WeekDays.EveryDay;
+ default:
+ return WeekDays.Monday;
+ }
+ }
+
+ public static DayOfWeek ConvertWeekDaysToDayOfWeek(WeekDays weekDays)
+ {
+ try
+ {
+ if((int) weekDays <= 64)
+ {
+ return (DayOfWeek) Convert.ToString((int) weekDays, 2).Length - 1;
+ }
+ }
+ catch(Exception)
+ {
+ return DayOfWeek.Sunday;
+ }
+
+ return DayOfWeek.Sunday;
+ }
+
+ public static int GetNumberOfWeekEndDaysInBetween(DateTime pStart, DateTime pEnd)
+ {
+ var numberOfWeekEndDays = 0;
+ var currentDate = pStart.Date;
+
+ var b = pEnd.Date;
+
+ while (currentDate <= b)
+ {
+ if (currentDate.DayOfWeek == DayOfWeek.Saturday || currentDate.DayOfWeek == DayOfWeek.Sunday)
+ {
+ numberOfWeekEndDays++;
+ }
+
+ currentDate = currentDate.AddDays(1);
+ }
+
+ return numberOfWeekEndDays;
+ }
+
+ public static DateTime GetNthDayOfWeekInMonth(DateTime date, int number, DayOfWeek dayOfWeek)
+ {
+ if (number <= 0)
+ {
+ throw new ArgumentOutOfRangeException();
+ }
+
+ // Letzter Wochentag im Monat
+ if (number > 3)
+ {
+ return GetNthDayOfWeekInMonth(date.AddMonths(1), 1, dayOfWeek).AddDays(-7);
+ }
+
+ var firstDayOfMonth = new DateTime(date.Year, date.Month, 1);
+
+ var counter = 1;
+
+ do
+ {
+ if (firstDayOfMonth.DayOfWeek == dayOfWeek)
+ {
+ if (counter == number)
+ {
+ return firstDayOfMonth;
+ }
+
+ counter++;
+ }
+
+ firstDayOfMonth = firstDayOfMonth.AddDays(1);
+ } while (counter <= number);
+
+ return firstDayOfMonth;
+ }
}
public class AnzahlMonate
diff --git a/Shared/Core/Utils.cs b/Shared/Core/Utils.cs
index 57862b03f..5ecc4bd91 100644
--- a/Shared/Core/Utils.cs
+++ b/Shared/Core/Utils.cs
@@ -12,13 +12,14 @@ using System.Xml.Serialization;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
+using DevExpress.XtraScheduler;
namespace BS.Shared.Core
{
public class Utils
{
private static readonly Dictionary criticals = new Dictionary
- {
+ {
{ '"', """ },
{ '€', "€" },
{ '¡', "¡" },
@@ -144,7 +145,7 @@ namespace BS.Shared.Core
{
if (iObject is string)
{
- if (!string.IsNullOrEmpty(iObject as string))
+ if (!String.IsNullOrEmpty(iObject as string))
{
return false;
}
@@ -279,7 +280,7 @@ namespace BS.Shared.Core
{
foreach (string iString in pStrings)
{
- if (string.IsNullOrEmpty(iString))
+ if (String.IsNullOrEmpty(iString))
{
return true;
}
@@ -522,8 +523,8 @@ namespace BS.Shared.Core
{
Bitmap originalBitmap = new Bitmap(image);
- Point min = new Point(int.MaxValue, int.MaxValue);
- Point max = new Point(int.MinValue, int.MinValue);
+ Point min = new Point(Int32.MaxValue, Int32.MaxValue);
+ Point max = new Point(Int32.MinValue, Int32.MinValue);
for (int x = 0; x < originalBitmap.Width; ++x)
{
@@ -543,7 +544,7 @@ namespace BS.Shared.Core
}
// Create a new bitmap from the crop rectangleig
- if (min.X < int.MaxValue && min.Y < int.MaxValue && max.X > int.MinValue && max.Y > int.MinValue)
+ if (min.X < Int32.MaxValue && min.Y < Int32.MaxValue && max.X > Int32.MinValue && max.Y > Int32.MinValue)
{
Rectangle cropRectangle = new Rectangle(min.X, min.Y, max.X - min.X, max.Y - min.Y);
if (cropRectangle.Width > 0 && cropRectangle.Height > 0)
@@ -634,7 +635,7 @@ namespace BS.Shared.Core
return null;
}
- var wasSuccessful = long.TryParse(object2Parse.ToString(), out var output);
+ var wasSuccessful = Int64.TryParse(object2Parse.ToString(), out var output);
if(wasSuccessful)
{
@@ -820,6 +821,91 @@ namespace BS.Shared.Core
{
return CheckSchedulerRights(pAppointment.CustomerList, pAppointment.ResourceList, pAppointment.EmployeeList, pAppointment.Originator, !pAppointment.SchedulerAppointmentOid.HasValue, pCheckType, pLoggedOnUser);
}
+
+ public static bool IsPowerOfTwo(int number)
+ {
+ return ((number - 1) & number) == 0;
+ }
+
+ public static int FindClosestPowerOfTwo(int number)
+ {
+ if (IsPowerOfTwo(number))
+ {
+ return number;
+ }
+
+ while (!IsPowerOfTwo(number))
+ {
+ number--;
+ }
+
+ return number;
+ }
+
+ public static List GetWeekDaysFromNumber(int number)
+ {
+ var weekDays = new List();
+
+ if (number % 2 != 0)
+ {
+ number--;
+ weekDays.Add(DayOfWeek.Sunday);
+ }
+
+ var closestPowerOfTwo = FindClosestPowerOfTwo(number);
+ var rest = number - closestPowerOfTwo;
+ weekDays.Add(DateTimeUtils.ConvertWeekDaysToDayOfWeek(DateTimeUtils.GetWeekDays(closestPowerOfTwo)));
+
+ if (rest > 0)
+ {
+ do
+ {
+ closestPowerOfTwo = FindClosestPowerOfTwo(rest);
+ rest -= closestPowerOfTwo;
+ weekDays.Add(DateTimeUtils.ConvertWeekDaysToDayOfWeek(DateTimeUtils.GetWeekDays(closestPowerOfTwo)));
+ } while (!IsPowerOfTwo(rest) || rest > 0);
+ }
+
+ return weekDays.OrderBy(day => (int)day).ToList();
+ }
+
+ public static DateTime GetNextDateTime(DateTime pDate, DayOfWeek pDayOfWeek, int pPeriodicity, RecurrenceType pType)
+ {
+ var dow = pDate.DayOfWeek;
+
+ if (dow > pDayOfWeek)
+ {
+ var date = pDate;
+
+ do
+ {
+ date = date.AddDays(1);
+ } while (date.DayOfWeek != pDayOfWeek);
+
+ return CalculateNextDateTime(pType, date, pType == RecurrenceType.Weekly ? 7 * pPeriodicity - 1 : pPeriodicity - 1);
+ }
+
+ return CalculateNextDateTime(pType, pDate, pDayOfWeek - dow);
+ }
+
+ private static DateTime CalculateNextDateTime(RecurrenceType recurrenceType, DateTime date, int timeToAdd)
+ {
+ switch(recurrenceType)
+ {
+ case RecurrenceType.Daily:
+ return date.AddDays(timeToAdd);
+ case RecurrenceType.Weekly:
+ return date.AddDays(timeToAdd);
+ case RecurrenceType.Monthly:
+ return date.AddMonths(timeToAdd);
+ default:
+ return date.AddYears(timeToAdd);
+ }
+
+
+ }
+
+ public static readonly string TestAppointmentNotice = "k9Rx2mU4y";
}
public struct NullCompareResult
diff --git a/Shared/DataContracts/SchedulerAppointmentDC.cs b/Shared/DataContracts/SchedulerAppointmentDC.cs
index 8b5851a9b..762967811 100644
--- a/Shared/DataContracts/SchedulerAppointmentDC.cs
+++ b/Shared/DataContracts/SchedulerAppointmentDC.cs
@@ -88,6 +88,10 @@ namespace BS.Shared.DataContracts
[DataMember]
public List SupportConceptList { get; set; }
+ public int RecurrenceIndex { get; set; }
+
+ public string RecurrenceId { get; set; }
+
[DataMember]
public long? FormerTaskOid { get; set; }
@@ -125,5 +129,7 @@ namespace BS.Shared.DataContracts
? 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}";
+ }
}
diff --git a/Shared/Extensions/DateTimeExtensions.cs b/Shared/Extensions/DateTimeExtensions.cs
index adb55af79..1b0b5c68c 100644
--- a/Shared/Extensions/DateTimeExtensions.cs
+++ b/Shared/Extensions/DateTimeExtensions.cs
@@ -433,5 +433,39 @@ namespace BS.Shared.Extensions
{
return new DateTime(pDate.Year, pDate.Month, pDate.Day, pTimeSpan.Hours, pTimeSpan.Minutes, pTimeSpan.Seconds);
}
+
+ public static WeekDays GetSchedulerWeekDays(this DateTime pDateTime)
+ {
+ return (WeekDays) (int) Math.Pow(2, (double) pDateTime.DayOfWeek);
+ }
+
+ public static WeekOfMonth GetWeekOfMonthForRecurrenceInfo(this DateTime pDate)
+ {
+ pDate = pDate.Date;
+ var firstMonthDay = new DateTime(pDate.Year, pDate.Month, 1);
+ var firstMonthMonday = firstMonthDay.AddDays((DayOfWeek.Monday + 7 - firstMonthDay.DayOfWeek) % 7);
+
+ if (firstMonthMonday > pDate)
+ {
+ firstMonthDay = firstMonthDay.AddMonths(-1);
+ firstMonthMonday = firstMonthDay.AddDays((DayOfWeek.Monday + 7 - firstMonthDay.DayOfWeek) % 7);
+ }
+
+ var weekNumber = (pDate - firstMonthMonday).Days / 7 + 1;
+
+ switch (weekNumber)
+ {
+ case 1:
+ return WeekOfMonth.First;
+ case 2:
+ return WeekOfMonth.Second;
+ case 3:
+ return WeekOfMonth.Third;
+ case 4:
+ return WeekOfMonth.Fourth;
+ default:
+ return WeekOfMonth.None;
+ }
+ }
}
}
\ No newline at end of file