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)?
This is how did i try to give a solution to this problem:
Thank you very much.
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.
