119 lines
4.7 KiB
C#
119 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BeWo.Core.Service;
|
|
using BS.Shared.Core;
|
|
|
|
using BeWo.Scheduler.View;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.ViewModel;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using DevExpress.XtraPrinting.Native;
|
|
using DevExpress.XtraScheduler;
|
|
|
|
namespace BeWo.Scheduler.ViewModel
|
|
{
|
|
public class NewSchedulerViewModel
|
|
{
|
|
public event EventHandler<EventArgs<ISchedulerViewModel>> ViewModelChanged;
|
|
|
|
private ISchedulerViewModel mActiveAppointmentViewModel;
|
|
private Dictionary<ValueListEntryDC, List<ResourceDC>> mAllCats2ResInDic;
|
|
public ISchedulerViewModel ActiveAppointmentViewModel
|
|
{
|
|
get
|
|
{
|
|
return mActiveAppointmentViewModel;
|
|
}
|
|
|
|
set
|
|
{
|
|
if ((mActiveAppointmentViewModel == null && value != null) || (mActiveAppointmentViewModel != null && !mActiveAppointmentViewModel.Equals(value)))
|
|
{
|
|
mActiveAppointmentViewModel = value;
|
|
|
|
if (ViewModelChanged != null)
|
|
{
|
|
ViewModelChanged(this, new EventArgs<ISchedulerViewModel>(value));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateAppointmentViewModel(DateTime intervalStart, DateTime intervalEnd)
|
|
{
|
|
BeWoApp.MainControl.StartWaiting();
|
|
|
|
if (!BeWoApp.LoggedOnEmployee.EmployeeOid.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
var allEmps = new List<CompactEmployeeDC>();
|
|
|
|
var appointments = new List<SchedulerAppointmentDC>();
|
|
var allCust = new List<CompactCustomerDC>();
|
|
|
|
allEmps = Cache.GetInstance().GetAllActiveEmployeesCompactSync();
|
|
|
|
if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen))
|
|
{
|
|
ServiceFacade.DoEmployeeServiceSync(es => allEmps = new List<CompactEmployeeDC> { es.LoadCompactEmployee(BeWoApp.LoggedOnEmployee.EmployeeOid.Value) });
|
|
}
|
|
|
|
if (mAllCats2ResInDic == null)
|
|
{
|
|
ServiceFacade.DoResourceServiceSync(s => mAllCats2ResInDic = s.GetAllCategories2ResourcesInDictionary());
|
|
}
|
|
|
|
var start = intervalStart - NewSchedulerView.FetchPadding;
|
|
var end = intervalEnd + NewSchedulerView.FetchPadding;
|
|
|
|
ServiceFacade.DoResourceServiceSync(rs => appointments = rs.GetAllActiveAppointmentsForEmployeeInInterval2(start, end, BeWoApp.LoggedOnEmployee.EmployeeOid.Value, BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen)));
|
|
|
|
allCust = Cache.GetInstance().GetAllActiveCustomersCompactSync();
|
|
|
|
if (BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyCustomers) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View))
|
|
{
|
|
allCust = allCust.Where(c => BeWoApp.LoggedOnEmployee.RelatedCustomers.Any(a => a.Customer.Equals(c))).ToList();
|
|
}
|
|
|
|
var prefilteredAppointments = appointments.Where(w => ((w.EmployeeList.Count == 0 && w.Originator.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid) ||
|
|
w.EmployeeList.Count > 0 && w.EmployeeList.Any(a => a.Employee.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid))) ||
|
|
BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen)) && (!w.EmployeeList.TrueForAll(e2a => e2a.ParticipationAnswer == ParticipationAnswer.Absage) || w.EmployeeList.IsEmpty()));
|
|
|
|
var vm = new SchedulerAppointmentListVM(prefilteredAppointments.ToList(), allCust, allEmps, mAllCats2ResInDic);
|
|
|
|
ActiveAppointmentViewModel = vm;
|
|
SchedulerSettings = GetActiveSettings();
|
|
SchedulerSettings.StartDate = intervalStart;
|
|
|
|
BeWoApp.MainControl.EndWaiting();
|
|
//BeWoApp.MainControl.AufOffeneTerminePruefen();
|
|
}
|
|
|
|
public AbstractAppointmentEditForm GetEditAppointmentForm(DevExpress.Xpf.Scheduler.SchedulerControl control, Appointment appointment)
|
|
{
|
|
return ActiveAppointmentViewModel != null ? ActiveAppointmentViewModel.GetEditAppointmentForm(control, appointment) : null;
|
|
}
|
|
|
|
internal void InitNewAppointment(Appointment appointment)
|
|
{
|
|
if (ActiveAppointmentViewModel != null)
|
|
{
|
|
ActiveAppointmentViewModel.InitNewAppointment(appointment);
|
|
}
|
|
}
|
|
|
|
public SchedulerSettings SchedulerSettings { get; set; }
|
|
|
|
public SchedulerSettings GetActiveSettings()
|
|
{
|
|
return ActiveAppointmentViewModel == null ? null : SchedulerSettings ?? ActiveAppointmentViewModel.GetDefaultSchedulerSettings();
|
|
}
|
|
}
|
|
}
|