Files
BeWoPlaner/BeWo/Scheduler/ViewModel/NewSchedulerViewModel.cs

133 lines
5.0 KiB
C#
Raw Normal View History

2016-06-27 01:45:38 +02:00
using System;
2017-02-01 13:53:59 +01:00
using System.Collections.Generic;
using System.Linq;
2017-12-14 18:33:17 -04:00
2016-06-27 01:45:38 +02:00
using BeWo.Scheduler.View;
using BeWo.ServiceProxy;
using BS.Shared.Core;
2017-02-01 13:53:59 +01:00
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
2017-12-14 18:33:17 -04:00
2016-06-27 01:45:38 +02:00
using DevExpress.XtraScheduler;
namespace BeWo.Scheduler.ViewModel
{
public class NewSchedulerViewModel
{
2016-06-27 01:45:38 +02:00
public event EventHandler<EventArgs<ISchedulerViewModel>> ViewModelChanged;
private ISchedulerViewModel _ActiveAppointmentViewModel;
2017-02-01 13:53:59 +01:00
public ISchedulerViewModel ActiveAppointmentViewModel
2016-06-27 01:45:38 +02:00
{
get => _ActiveAppointmentViewModel;
2016-06-27 01:45:38 +02:00
set
{
if(value is null)
{
return;
2017-04-12 10:55:32 +02:00
}
_ActiveAppointmentViewModel = value;
ViewModelChanged?.Invoke(this, new EventArgs<ISchedulerViewModel>(value));
}
2016-06-27 01:45:38 +02:00
}
2017-02-01 13:53:59 +01:00
public AbstractAppointmentEditForm GetEditAppointmentForm(DevExpress.Xpf.Scheduler.SchedulerControl control, Appointment appointment)
2016-06-27 01:45:38 +02:00
{
return ActiveAppointmentViewModel?.GetEditAppointmentForm(control, appointment);
2016-06-27 01:45:38 +02:00
}
internal void InitNewAppointment(Appointment appointment)
{
ActiveAppointmentViewModel?.InitNewAppointment(appointment);
2016-06-27 01:45:38 +02:00
}
internal void InitNewTask(Appointment pAppointment, DateTime? pDueDate, IEnumerable<Employee2SchedulerAppointmentDC> pSelectedEmployees, List<CompactCustomerDC> pSelectedCustomers, List<ResourceDC> pSelectedResources, List<CompactSupportConceptDC> pSelectedSupportConcepts)
{
ActiveAppointmentViewModel?.InitNewTask(pAppointment, pDueDate, pSelectedEmployees, pSelectedCustomers, pSelectedResources, pSelectedSupportConcepts);
}
2016-06-27 01:45:38 +02:00
public SchedulerSettings SchedulerSettings { get; set; }
public SchedulerSettings GetActiveSettings()
{
return ActiveAppointmentViewModel is null ? null : SchedulerSettings ?? ActiveAppointmentViewModel.GetDefaultSchedulerSettings();
2016-06-27 01:45:38 +02:00
}
2017-08-28 16:41:19 +02:00
public IEnumerable<SchedulerAppointmentVM> ConvertAbsenceTimesToAppointments(IEnumerable<AbsenceTimeDC> pAbsenceTimes, DateTime pIntervalEnd, List<CompactEmployeeDC> allEmployees, List<CompactCustomerDC> allCustomers)
2017-08-28 16:41:19 +02:00
{
2019-12-20 12:37:08 +01:00
return pAbsenceTimes.Where(w => w.AbsenceTimeOid.HasValue && w.Start.HasValue).Select(abwesenheit =>
{
var isEmployeeAbsenceTime = abwesenheit.EmployeeOid.HasValue;
var subject = $"{abwesenheit.Reason.Description}";
var employee = abwesenheit.EmployeeOid.HasValue ? allEmployees.FirstOrDefault(f => f.EmployeeOid == abwesenheit.EmployeeOid.Value) : null;
var customer = abwesenheit.CustomerOid.HasValue ? allCustomers.FirstOrDefault(f => f.CustomerOid == abwesenheit.CustomerOid.Value) : null;
IFilterableDC dc = employee;
var originator = employee;
if(!isEmployeeAbsenceTime)
{
dc = customer;
ServiceFacade.DoEmployeeServiceSync(s => originator = s.FindCompactEmployeeByFullname(abwesenheit.InsUser));
}
if(!(dc is null))
{
subject += $" ({dc.SimpleDescription})";
}
var absenceTimeEnd = abwesenheit.End;
// Ist nicht genau
if(abwesenheit.End.HasValue)
{
var allDay = abwesenheit.Start.Value.Hour == 0 && abwesenheit.Start.Value.Minute == 0 && abwesenheit.Start.Value.Second == 0 &&
abwesenheit.End.Value.Hour == 0 && abwesenheit.End.Value.Minute == 0 && abwesenheit.End.Value.Second == 0;
var end = abwesenheit.End.Value;
var isMultipleDayAbsenceTime = abwesenheit.End is null || abwesenheit.Start.Value.Date != abwesenheit.End.Value.Date;
if(isMultipleDayAbsenceTime && allDay)
{
absenceTimeEnd = end.AddDays(1);
}
// Wenn die Abwesenheit über mehrere Tage geht, muss ein Tag draufaddiert werden
//if(end.Hour == 0 && end.Minute == 0 && end.Second == 0)
//{
// absenceTimeEnd = end.AddSeconds(1);
//}
//else
//{
// absenceTimeEnd = end.AddTicks(1);
//}
}
if(originator is null)
{
originator = BeWoApp.CompactLoggedOnEmployee;
}
2019-12-20 12:37:08 +01:00
return new SchedulerAppointmentVM(
true,
subject,
abwesenheit.Start.Value,
absenceTimeEnd ?? pIntervalEnd,
originator,
abwesenheit.Start,
absenceTimeEnd,
abwesenheit.AbsenceTimeOid.Value,
!isEmployeeAbsenceTime);
}).ToList();
2017-08-28 16:41:19 +02:00
}
2016-06-27 01:45:38 +02:00
}
}