This is a migrated thread and some comments may be shown as answers.

Occupied timeslots for multiple resources

1 Answer 40 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 15 Jun 2012, 08:38 AM
Hello,

How could i change the following code in order to support multiple resources (ResourceType User cannot be concurrently to more than one ResourceType Room)?

using System.Web.UI;
using Telerik.Web.UI;
 
namespace Telerik.Web.Examples.Scheduler.Default
{
    public partial class DefaultCS : System.Web.UI.Page
    {
        private const int AppointmentsLimit = 1;
 
        private bool ExceedsLimit(Appointment apt)
        {
            int appointmentsCount = 0;
            foreach (Appointment existingApt in RadScheduler1.Appointments.GetAppointmentsInRange(apt.Start, apt.End))
            {
                if (existingApt.Visible)
                    appointmentsCount++;
            }
 
            return (appointmentsCount > AppointmentsLimit - 1);
        }
 
        private bool AppointmentsOverlap(Appointment appointment)
        {
            if (ExceedsLimit(appointment))
            {
                foreach (Appointment a in RadScheduler1.Appointments.GetAppointmentsInRange(appointment.Start, appointment.End))
                {
                    if (a.ID != appointment.ID)
                    {
                        return true;
                    }
                }
            }
 
            return false;
        }
 
        private void RegisterScript()
        {
            Label1.Text = "Invalid move! There are appointments arranged for this time period.";
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "LabelUpdated",
                    "$telerik.$('.lblError').show().animate({ opacity: 0.9 }, 2000).fadeOut('slow');", true);
        }
 
        protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
        {
            if (ExceedsLimit(e.Appointment))
            {
                e.Cancel = true;
                RegisterScript();
            }
        }
 
        protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
        {
            if (AppointmentsOverlap(e.ModifiedAppointment))
            {
                e.Cancel = true;
                RegisterScript();
            }
        }
 
        protected void RadScheduler1_RecurrenceExceptionCreated(object sender, RecurrenceExceptionCreatedEventArgs e)
        {
            if(AppointmentsOverlap(e.ExceptionAppointment))
            {
                e.Cancel = true;
                RegisterScript();
            }
        }
    }
}


This is how did i try to give a solution to this problem:

protected bool ExceedsLimit(Appointment apt)
    {
        
        foreach (Appointment existingApt in RadScheduler1.Appointments.GetAppointmentsInRange(apt.Start, apt.End))
        {
            foreach (Resource existingRes in existingApt.Resources.GetResourcesByType("User"))
            {
 
                if (((apt.Resources.GetResource(existingRes.Type, existingRes.Key)) != null))
                {
                         
                        return true;
                }
            }
        }
     
        return false;
    }
 
    private bool AppointmentsOverlap(Appointment appointment)
    {
        
            foreach (Appointment a in RadScheduler1.Appointments.GetAppointmentsInRange(appointment.Start, appointment.End))
            {
                 
 
                    if (ExceedsLimit(appointment) && a.ID != appointment.ID)
                    {
                        return true;
                    }
                
            }
       
 
        return false;
    }
 
 
    protected void RadScheduler1_AppointmentInsert(object sender, Telerik.Web.UI.SchedulerCancelEventArgs e)
    {
        if (ExceedsLimit(e.Appointment))
        {
            Messages.Text = "This resource has already been scheduled for this time slot.";
            e.Cancel = true;
            
 
 
             
        }
    }
 
    protected void RadScheduler1_AppointmentUpdate(object sender, Telerik.Web.UI.AppointmentUpdateEventArgs e)
    {
        if (AppointmentsOverlap(e.ModifiedAppointment))
        {
            Messages.Text = "This resource has already been scheduled for this time slot.";
            e.Cancel = true;
 
 
 
        }
    }

  Thank you very much.

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 20 Jun 2012, 05:03 AM
Hello George,

 
You can refer to this Code Library where the Occupied time slots demo is extended to support resource grouping as well.

hope this will be helpful.

Regards,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Scheduler
Asked by
George
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or