using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using BeWo.Scheduling.SchedulingUtils; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using DevExpress.Xpf.Scheduling; using DevExpress.XtraScheduler; using SchedulerControl = DevExpress.Xpf.Scheduling.SchedulerControl; using Utils = BS.Shared.Core.Utils; namespace BeWo.Scheduling.ViewModel { public class AppointmentWindowVM : AppointmentWindowViewModel { #region Verfügbage Mitarbeiter, Klienten und Ressourcen private ObservableCollection _AllEmployees; public ObservableCollection AllEmployees { get => _AllEmployees; set { if(!ICollectionExtensions.ListEquals(_AllEmployees, value)) { _AllEmployees = value; RaisePropertyChanged(nameof(AllEmployees)); } } } private ObservableCollection _AllCustomers; public ObservableCollection AllCustomers { get => _AllCustomers; set { if(!ICollectionExtensions.ListEquals(_AllCustomers, value)) { _AllCustomers = value; RaisePropertyChanged(nameof(AllCustomers)); } } } private ObservableDictionary> _AllCategories2Resources; public ObservableDictionary> AllCategories2Resources { get => _AllCategories2Resources; set { if(!SchedulingUtils.Utils.Categories2ResourcesEquals(_AllCategories2Resources, value)) { _AllCategories2Resources = value; RaisePropertiesChanged(nameof(AllCategories2Resources)); } } } #endregion public string OriginalRecurrenceInfo { get; } public SchedulingAppointmentVM ActualViewModel { get; } public ObservableCollection EmployeeList { get => ActualViewModel.EmployeeList; //Appointment.CustomFields["EmployeeList"] as ObservableCollection; set => ActualViewModel.EmployeeList = value; //Appointment.CustomFields["EmployeeList"] = value; } public List CustomerList { get => ActualViewModel.CustomerList; //Appointment.CustomFields["CustomerList"] as List; set => ActualViewModel.CustomerList = value; //Appointment.CustomFields["CustomerList"] = value; } public List ResourceList { get => ActualViewModel.ResourceList; //Appointment.CustomFields["ResourceList"] as List; set => ActualViewModel.ResourceList = value; //Appointment.CustomFields["ResourceList"] = value; } public ObservableCollection SupportConceptList { get => ActualViewModel.SupportConceptList; //Appointment.CustomFields["SupportConceptList"] as List; set => ActualViewModel.SupportConceptList = value; //Appointment.CustomFields["SupportConceptList"] = value; } public bool IsTask { get => ActualViewModel.IsTask; //Appointment.CustomFields["IsTask"] is bool isTask && isTask; set => ActualViewModel.IsTask = value; //Appointment.CustomFields["IsTask"] = value; } public bool IsPrivate { get => ActualViewModel.IsPrivate; //Appointment.CustomFields["IsPrivate"] is bool isPrivate && isPrivate; set => ActualViewModel.IsPrivate = value; //Appointment.CustomFields["IsPrivate"] = value; } public bool IsReadyOnly { get; } public bool IsNew => ActualViewModel?.IsNew ?? false; public CompactEmployeeDC Originator { get => ActualViewModel.Originator; //Appointment.CustomFields["Originator"] as CompactEmployeeDC; set => ActualViewModel.Originator = value; //Appointment.CustomFields["Originator"] = value; } public bool IsAbsenceTime => ActualViewModel.IsAbsenceTime; //Appointment.CustomFields["IsAbsenceTime"] is bool isAbsenceTime && isAbsenceTime; public string TaskDescription { get => ActualViewModel.TaskDescription; //Appointment.CustomFields["TaskDescription"] as string; set => ActualViewModel.TaskDescription = value; //Appointment.CustomFields["TaskDescription"] = value; } public string CompletedNotice { get => ActualViewModel.CompletedNotice; //Appointment.CustomFields["CompletedNotice"] as string; set => ActualViewModel.CompletedNotice = value; //Appointment.CustomFields["CompletedNotice"] = value; } public DateTime? CompletedDate { get => ActualViewModel.CompletedDate; //Appointment.CustomFields["CompletedDate"] as DateTime?; set => ActualViewModel.CompletedDate = value; //Appointment.CustomFields["CompletedDate"] = value; } public DateTime? DueDate { get => ActualViewModel.DueDate; //Appointment.CustomFields["DueDate"] as DateTime?; set => ActualViewModel.DueDate = value; //Appointment.CustomFields["DueDate"] = value; } public DateTime? DueTime { get => ActualViewModel.DueTime; //Appointment.CustomFields["DueTime"] as DateTime?; set => ActualViewModel.DueTime = value; //Appointment.CustomFields["DueTime"] = value; } public long? Oid => Appointment.Id as long?; public string RecurrenceTypeName => TranslateRecurrenceInfoType(); public ObservableCollection AvailableAppointmentRecurrenceTypes { get; } public Visibility RecurrenceButtonVisibility => (Appointment.Type == AppointmentType.Pattern || Appointment.Type == AppointmentType.Normal) && !IsTask ? Visibility.Visible : Visibility.Collapsed; public AppointmentWindowVM( AppointmentItem appointmentItem, SchedulerControl scheduler, ObservableCollection allEmployees, ObservableCollection allCustomers, ObservableDictionary> allCategories2Resources, CompactEmployeeDC originator, List teamMemberCustomerOids, SchedulingAppointmentVM viewModel) : base(appointmentItem, scheduler) { ActualViewModel = viewModel; OriginalRecurrenceInfo = viewModel.RecurrenceInfo; AllEmployees = allEmployees; AllCustomers = allCustomers; AllCategories2Resources = allCategories2Resources; ActualViewModel.Originator = originator; ActualViewModel.SetDirty(false); var userRightsCheckType = IsNew ? SchedulerRightsCheckType.Create : SchedulerRightsCheckType.Edit; IsReadyOnly = !Utils.CheckSchedulerRights(CustomerList.ToList(), ResourceList.ToList(), EmployeeList.ToList(), Originator, IsNew, userRightsCheckType, BeWoApp.LoggedOnUser, teamMemberCustomerOids); AvailableAppointmentRecurrenceTypes = new ObservableCollection { "(keine)", "täglich", "wöchentlich", "monatlich", "jährlich" }; } private string TranslateRecurrenceInfoType() { if(RecurrenceInfo is null) { return "(keine)"; } switch(RecurrenceInfo.Type) { case RecurrenceType.Daily: return "täglich"; case RecurrenceType.Weekly: return "wöchentlich"; case RecurrenceType.Monthly: return "monatlich"; case RecurrenceType.Yearly: return "jährlich"; default: return "(keine)"; } } } }