Skip to content

Handles the CustomAllowAppointmentCreate and CustomAllowAppointmentConflicts events to restrict appointment creation and movement during a specified time interval in the WPF Scheduler.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/wpf-scheduler-apply-end-user-restrictions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Scheduler - Apply User Restrictions

This example applies the following user restrictions:

  • Prevents users from creating new appointments.
  • Prevents users from moving appointments to the lunch break interval (12:00–13:00).

In this example, the Ribbon UI displays Disable Creating Appointments and Disable Appointment Conflict controls that toggle these restrictions.

Apply User Restrictions - WPF Scheduler, DevExpress

Implementation Details

Define Restricted Interval

In this example, the restricted interval covers the lunch break time (12:00–13:00):

TimeInterval lunchTime = new TimeInterval(DateTime.Today.AddHours(12), TimeSpan.FromHours(1));

The IsIntervalAllowed method returns false if any part of the selected interval overlaps with the restricted time range:

private bool IsIntervalAllowed(TimeInterval interval) {
    DateTime dayStart = interval.Start.Date;
    while (dayStart < interval.End) {
        if (interval.IntersectsWithExcludingBounds(lunchTime))
            return false;
        dayStart = dayStart.AddDays(1);
    }
    return true;
}

Restrict Appointment Creation

The CustomAllowAppointmentCreate event allows you to define rules that restrict appointment creation. In this example, the event handler:

  • Blocks appointment creation if Disable Creating Appointments is turned on.
  • Prevents users from creating appointments during lunch time if Disable Creating Appointments is turned off.
private void customAllowAppointmentCreateHandler(object sender, AppointmentItemOperationEventArgs e) {
    // Cancel the operation if the "Disable Creating Appointments" bar item is checked
    if((bool)barItemDisableCreatingAppointments.IsChecked) {
        e.Allow = false;
        return;
    }
    DateTimeRange selectedIntervalRange = schedulerControl1.SelectedInterval;
    TimeInterval selectedInterval = new TimeInterval(selectedIntervalRange.Start, selectedIntervalRange.End);
    e.Allow = IsIntervalAllowed(selectedInterval);
}

The barItemDisableCreatingAppointments.IsChecked flag is bound to the Disable Creating Appointments Ribbon item and acts as a switch.

Resolve Appointment Conflicts

The CustomAllowAppointmentConflicts event allows you to control how the scheduler handles appointment conflicts. In this example, a conflict occurs when a user moves an appointment to a time interval that already contains another appointment or to the lunch break time. In the Ribbon UI, you can enable the Disable Appointment Conflicts item to ignore conflicts.

private void customAllowAppointmentConflictsHandler(object sender, AppointmentItemConflictEventArgs e) {
    if((bool)barItemDisableAppointmentConflicts.IsChecked) { 
        e.Conflicts.Clear(); // clear all restrictions
        return;
    }

    TimeInterval interval = e.Interval;

    if (!IsIntervalAllowed(interval))
        e.Conflicts.Add(e.AppointmentClone);
}

The barItemDisableAppointmentConflicts.IsChecked flag is bound to a custom Ribbon item (Disable Appointment Conflict) that toggles this behavior.

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Handles the CustomAllowAppointmentCreate and CustomAllowAppointmentConflicts events to restrict appointment creation and movement during a specified time interval in the WPF Scheduler.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 6