using System; using System.Collections.Generic; using System.Linq; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.Extensions; using BeWo.ViewModel; using BeWo.ViewModel.ListViewModel; using BeWo.ServiceProxy; using System.Windows.Threading; using System.Windows.Media; using BS.Shared.DataContracts.Compact; using BeWo.Scheduler.Resources; using System.ComponentModel; using BeWo.Scheduler.View; using DevExpress.XtraScheduler; namespace BeWo.Scheduler.ViewModel { public class ResourceBookingListVM : AbstractDCListMapperVM, ISchedulerViewModel { private IList mAppointmentCategoryList = null; private IList mAppointmentResourceList = null; private Dictionary> mCategoriesToResources; private List mAllEmployees; public ResourceBookingListVM(List pDCList) : base(pDCList) { } public ResourceBookingListVM(Dictionary> lCategoriesToResources, List allemps, List bookings) : base(bookings) { this.mCategoriesToResources = lCategoriesToResources; this.mAllEmployees = allemps; InitViewModel(); } private void InitViewModel() { mAppointmentCategoryList = new List(); mAppointmentResourceList = new List(); Dictionary oid2Category = new Dictionary(); Dictionary oid2Resource = new Dictionary(); foreach (var item in mCategoriesToResources.Keys) { foreach (var res in mCategoriesToResources[item]) { BeWoAppointmentCategory cat = new BeWoAppointmentCategory(); cat.CategoryObject = res; cat.Color = ((SolidColorBrush)new BrushConverter().ConvertFrom(res.Color)).Color; cat.DisplayName = res.Name; cat.MenuCaption = res.Name; if (!oid2Category.ContainsKey(res.ResourceOid.Value)) oid2Category.Add(res.ResourceOid.Value, cat); mAppointmentCategoryList.Add(cat); } } foreach (var item in VMList) { if (item.Resource != null && oid2Category.ContainsKey(item.Resource.ResourceOid.Value)) item.AppointmentCategory = oid2Category[item.Resource.ResourceOid.Value]; } } protected override ResourceBookingVM CreateVM(BookingSequenceDC pDC) { if (pDC.SequenceOid == null) { pDC.RootBooking = new ResourceBookingDC(); pDC.RootBooking.Duration = new DateTimeSpan { StartDateTime = DateTime.Now.AddMinutes(15 - DateTime.Now.Minute % 15) }; pDC.RootBooking.Duration.EndDateTime = pDC.RootBooking.Duration.StartDateTime.AddHours(1); pDC.RootBooking.SequencePosition = 0; pDC.Frequency = ResourceBookingFrequencyType.Once; pDC.RepeatInterval = 1; pDC.SequenceEnd = pDC.RootBooking.Duration.StartDateTime.AddMonths(12).Date; } return new ResourceBookingVM(pDC); } #region ISchedulerViewModel Member public IList Categories { get { return mAppointmentCategoryList; } } public IList Resources { get { return mAppointmentResourceList; } } public BindingList Appointments { get { return new BindingList(VMList.ToList()); } } public SchedulerSettings GetDefaultSchedulerSettings() { SchedulerSettings settings = new SchedulerSettings(AppointmentKind.Employee, AppointmentViewType.Timeline); return settings; } public void SaveAppointments(DevExpress.Xpf.Scheduler.SchedulerControl control, IList list) { foreach (var item in list) { AppointmentVM vm = item.GetSourceObject(control.GetCoreStorage()) as AppointmentVM; if (vm != null) { AppointmentDC dc = vm.CommitToDataContract(); } } } public void DeleteAppointments(DevExpress.Xpf.Scheduler.SchedulerControl control, IList list) { throw new NotImplementedException(); } public void InsertNewAppointments(DevExpress.Xpf.Scheduler.SchedulerControl control, IList list) { throw new NotImplementedException(); } public AbstractAppointmentEditForm GetEditAppointmentForm(DevExpress.Xpf.Scheduler.SchedulerControl control, DevExpress.XtraScheduler.Appointment appointment) { return null; // new ResourceAppointmentEditForm(control, appointment); } public void AddCustomFieldsMapping(DevExpress.Xpf.Scheduler.SchedulerStorage schedulerStorage) { // } public void InitNewAppointment(Appointment appointment) { // } #endregion } }