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 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> ViewModelChanged; private ISchedulerViewModel mActiveAppointmentViewModel; private Dictionary> mAllCats2ResInDic; public ISchedulerViewModel ActiveAppointmentViewModel { get { return mActiveAppointmentViewModel; } set { if(value != null) { mActiveAppointmentViewModel = value; if (ViewModelChanged != null) { ViewModelChanged.Invoke(this, new EventArgs(value)); } } } } public void UpdateAppointmentViewModel(DateTime intervalStart, DateTime intervalEnd) { if (!BeWoApp.LoggedOnEmployee.EmployeeOid.HasValue) { return; } var allEmps = new List(); var appointments = new List(); var allCust = new List(); allEmps = Cache.GetInstance().GetAllActiveEmployeesCompactSync(); if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen)) { ServiceFacade.DoEmployeeServiceSync(es => allEmps = new List { 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 == null || w.EmployeeList.Count == 0))); //###cb testen :w.EmployeeList.IsEmpty geht nicht mehr var vm = new SchedulerAppointmentListVM(prefilteredAppointments.ToList(), allCust, allEmps, mAllCats2ResInDic); ActiveAppointmentViewModel = vm; SchedulerSettings = GetActiveSettings(); SchedulerSettings.StartDate = intervalStart; } 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(); } } }