Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WPF/CS/SchedulerDemo.Wpf/Modules/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WPF/CS/SchedulerDemo.Wpf/Modules/CustomMenu.xaml.cs

using System;
using System.Windows;
using SchedulerDemo;
using DevExpress.XtraScheduler;
using DevExpress.Xpf.Scheduler;
using System.Windows.Input;
using DevExpress.Xpf.Scheduler.UI;
using System.ComponentModel;

namespace SchedulerDemo {
    public partial class CustomMenu : SchedulerDemoModule {
        CustomMenuDemoAppointmentCommandsCollection commandsCollection;

        public CustomMenu() {
            InitializeComponent();
            InitializeScheduler();
            this.scheduler.PopupMenuShowing += new SchedulerMenuEventHandler(PopupMenuShowing);
            CustomMenuModule.DataContext = this;
            commandsCollection = new CustomMenuDemoAppointmentCommandsCollection(scheduler);
        }

        public CustomMenuDemoAppointmentCommandsCollection CommandsCollection { get { return commandsCollection; } }

        void PopupMenuShowing(object sender, SchedulerMenuEventArgs e) {
            if(e.Menu.Name == SchedulerMenuItemName.AppointmentMenu) {
                e.Customizations.Add(changeAppointment);
            }
        }
    }
    public abstract class AppointmentCommandBase : DependencyObject, ICommand {
        public static readonly DependencyProperty ControlProperty =
            DependencyProperty.Register("Control", typeof(SchedulerControl), typeof(AppointmentCommandBase), new PropertyMetadata(null));
        string subject;
        int labelId;

        public AppointmentCommandBase(SchedulerControl control, string subject, int labelId) {
            this.Control = control;
            this.subject = subject;
            this.labelId = labelId;
        }
        public AppointmentCommandBase()
            : this(null, String.Empty, 0) {
        }

        public SchedulerControl Control {
            get { return (SchedulerControl)GetValue(ControlProperty); }
            set { SetValue(ControlProperty, value); }
        }
        public string Subject { get { return subject; } set { subject = value; } }
        public int LabelId { get { return labelId; } set { labelId = value; } }

        #region ICommand Members
        public bool CanExecute(object parameter) {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        protected void FakeMethod() {
            CanExecuteChanged(this, EventArgs.Empty);
        }
        public abstract void Execute(object parameter);
        #endregion
    }
    public class CreateAppointmentCommand : AppointmentCommandBase {
        public CreateAppointmentCommand(SchedulerControl control, string subject, int labelId) : base(control, subject, labelId) {
        }
        public CreateAppointmentCommand() : this(null, String.Empty, 0) {
        }

        public override void Execute(object parameter) {
            Appointment apt = Control.Storage.CreateAppointment(AppointmentType.Normal);
            apt.Subject = Subject;
            apt.Start = Control.ActiveView.SelectedInterval.Start;
            apt.End = Control.ActiveView.SelectedInterval.End;
            apt.ResourceId = Control.ActiveView.SelectedResource.Id;
            apt.StatusId = 1;
            apt.LabelId = LabelId;
            Control.Storage.AppointmentStorage.Add(apt);
        }
    }
    public class ChangeAppointmentCommand : AppointmentCommandBase {
        public ChangeAppointmentCommand(SchedulerControl control, string subject, int labelId) : base(control, subject, labelId) {
        }
        public ChangeAppointmentCommand() : this(null, String.Empty, 0) {
        }

        public override void Execute(object parameter) {
            AppointmentBaseCollection appointments = Control.SelectedAppointments;
            for (int i = 0; i < appointments.Count; i++) {
                Appointment apt = appointments[i];
                apt.Subject = Subject;
                apt.StatusId = 1;
                apt.LabelId = LabelId;
            }
        }
    }
    public class CustomMenuDemoAppointmentCommandsCollection : INotifyPropertyChanged {
        ChangeAppointmentCommand changeCheckEngineOilCommand;
        CreateAppointmentCommand createCheckEngineOilCommand;
        ChangeAppointmentCommand changeWashTheCarCommand;
        CreateAppointmentCommand createWashTheCarCommand;
        ChangeAppointmentCommand changeWaxTheCarCommand;
        CreateAppointmentCommand createWaxTheCarCommand;
        ChangeAppointmentCommand changeCheckTransmissionFluidCommand;
        CreateAppointmentCommand createCheckTransmissionFluidCommand;
        ChangeAppointmentCommand changeInspectByMechanicCommand;
        CreateAppointmentCommand createInspectByMechanicCommand;

        public CustomMenuDemoAppointmentCommandsCollection(SchedulerControl control) {
            changeCheckEngineOilCommand = new ChangeAppointmentCommand(control, "Check engine oil", 1);
            createCheckEngineOilCommand = new CreateAppointmentCommand(control, "Check engine oil", 1);
            changeWashTheCarCommand = new ChangeAppointmentCommand(control, "Wash the car", 2);
            createWashTheCarCommand = new CreateAppointmentCommand(control, "Wash the car", 2);
            changeWaxTheCarCommand = new ChangeAppointmentCommand(control, "Wax the car", 3);
            createWaxTheCarCommand = new CreateAppointmentCommand(control, "Wax the car", 3);
            changeCheckTransmissionFluidCommand = new ChangeAppointmentCommand(control, "Check transmission fluid", 4);
            createCheckTransmissionFluidCommand = new CreateAppointmentCommand(control, "Check transmission fluid", 4);
            changeInspectByMechanicCommand = new ChangeAppointmentCommand(control, "Inspect by mechanic", 5);
            createInspectByMechanicCommand = new CreateAppointmentCommand(control, "Inspect by mechanic", 5);
        }

        public ChangeAppointmentCommand ChangeCheckEngineOilCommand { get { return changeCheckEngineOilCommand; } }
        public CreateAppointmentCommand CreateCheckEngineOilCommand { get { return createCheckEngineOilCommand; } }
        public ChangeAppointmentCommand ChangeWashTheCarCommand { get { return changeWashTheCarCommand; } }
        public CreateAppointmentCommand CreateWashTheCarCommand { get { return createWashTheCarCommand; } }
        public ChangeAppointmentCommand ChangeWaxTheCarCommand { get { return changeWaxTheCarCommand; } }
        public CreateAppointmentCommand CreateWaxTheCarCommand { get { return createWaxTheCarCommand; } }
        public ChangeAppointmentCommand ChangeCheckTransmissionFluidCommand { get { return changeCheckTransmissionFluidCommand; } }
        public CreateAppointmentCommand CreateCheckTransmissionFluidCommand { get { return createCheckTransmissionFluidCommand; } }
        public ChangeAppointmentCommand ChangeInspectByMechanicCommand { get { return changeInspectByMechanicCommand; } }
        public CreateAppointmentCommand CreateInspectByMechanicCommand { get { return createInspectByMechanicCommand; } }

        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void RaisePropertyChanged(string name) {
            if (PropertyChanged == null)
                return;
            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
        #endregion
    }
}