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

114 lines
4.5 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;
using BeWo.Core.Service;
2016-06-27 01:45:38 +02:00
using BS.Shared.Core;
using BeWo.Scheduler.View;
2017-02-01 13:53:59 +01:00
using BeWo.ServiceProxy;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using DevExpress.XtraPrinting.Native;
2016-06-27 01:45:38 +02:00
using DevExpress.XtraScheduler;
namespace BeWo.Scheduler.ViewModel
{
public class NewSchedulerViewModel
{
public event EventHandler<EventArgs<ISchedulerViewModel>> ViewModelChanged;
private ISchedulerViewModel mActiveAppointmentViewModel;
2017-02-01 13:53:59 +01:00
private Dictionary<ValueListEntryDC, List<ResourceDC>> mAllCats2ResInDic;
public ISchedulerViewModel ActiveAppointmentViewModel
2016-06-27 01:45:38 +02:00
{
get
{
return mActiveAppointmentViewModel;
}
set
{
2017-04-18 15:11:45 +02:00
if(value != null)
{
2016-06-27 01:45:38 +02:00
mActiveAppointmentViewModel = value;
if (ViewModelChanged != null)
{
2017-04-20 13:31:32 +02:00
ViewModelChanged.Invoke(this, new EventArgs<ISchedulerViewModel>(value));
}
2017-04-12 10:55:32 +02:00
}
2016-06-27 01:45:38 +02:00
}
}
public void UpdateAppointmentViewModel(DateTime intervalStart, DateTime intervalEnd)
{
2017-02-01 13:53:59 +01:00
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) });
}
2017-04-03 13:07:06 +02:00
//if (mAllCats2ResInDic == null)
//{
2017-02-01 13:53:59 +01:00
ServiceFacade.DoResourceServiceSync(s => mAllCats2ResInDic = s.GetAllCategories2ResourcesInDictionary());
2017-04-03 13:07:06 +02:00
//}
2017-02-01 13:53:59 +01:00
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();
}
2017-04-12 10:55:32 +02:00
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 == null || w.EmployeeList.Count == 0)));
//###cb testen :w.EmployeeList.IsEmpty geht nicht mehr
2017-02-01 13:53:59 +01:00
var vm = new SchedulerAppointmentListVM(prefilteredAppointments.ToList(), allCust, allEmps, mAllCats2ResInDic);
ActiveAppointmentViewModel = vm;
2017-04-18 15:11:45 +02:00
2017-02-01 13:53:59 +01:00
SchedulerSettings = GetActiveSettings();
SchedulerSettings.StartDate = intervalStart;
}
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 != null ? ActiveAppointmentViewModel.GetEditAppointmentForm(control, appointment) : null;
}
internal void InitNewAppointment(Appointment appointment)
{
2017-04-20 13:31:32 +02:00
if(ActiveAppointmentViewModel != null)
ActiveAppointmentViewModel.InitNewAppointment(appointment);
2016-06-27 01:45:38 +02:00
}
public SchedulerSettings SchedulerSettings { get; set; }
public SchedulerSettings GetActiveSettings()
{
return ActiveAppointmentViewModel == null ? null : SchedulerSettings ?? ActiveAppointmentViewModel.GetDefaultSchedulerSettings();
}
}
}