Hi,
How can i make my scheduler to accept only 1 appointment per Time Slot?
And if possible, how can make it on clientside only.
For example :
I schedule an appointment on Jan 5, 2009 8:00am to Jan 5, 2009 10:00am
Between 8am and 10am timeslot i will not be able to insert a new appointment.
Thanks,
Bermo
6 Answers, 1 is accepted
0
Accepted
Hello Bermo,
Please, see this demo:
http://demos.telerik.com/aspnet-ajax-beta/scheduler/examples/resourceavailability/defaultcs.aspx
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Please, see this demo:
http://demos.telerik.com/aspnet-ajax-beta/scheduler/examples/resourceavailability/defaultcs.aspx
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Bermo
Top achievements
Rank 1
answered on 06 Mar 2009, 10:23 AM
Thanks!
0
andrea
Top achievements
Rank 1
answered on 06 Mar 2009, 06:43 PM
How could it be done regarding recurrent appointments?
I mean, if I'm creating a serie and one or more appointments of the series will be setted in a occupied time slot, how cold I been noticed about it and cancel the event?
Thanks in advance,
Andrea
I mean, if I'm creating a serie and one or more appointments of the series will be setted in a occupied time slot, how cold I been noticed about it and cancel the event?
Thanks in advance,
Andrea
0
Hello andrea,
This can be achieved with the server side API. Here is an example:
ASPX:
C#
VB.NET
Greetings,
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
This can be achieved with the server side API. Here is an example:
ASPX:
<asp:Label ForeColor="Red" ID="Label1" runat="server" ></asp:Label> |
<telerik:RadScheduler |
ID="RadScheduler1" |
runat="server" |
DataEndField="End" |
DataKeyField="ID" |
DataRecurrenceField="RecurrenceRule" |
DataRecurrenceParentKeyField="RecurrenceParentID" |
DataSourceID="AccessDataSource1" |
DataStartField="Start" |
DataSubjectField="Subject" |
OnAppointmentInsert="RadScheduler1_AppointmentInsert" |
OnAppointmentUpdate="RadScheduler1_AppointmentUpdate" |
OnAppointmentCancelingEdit="RadScheduler1_AppointmentCancelingEdit"> |
</telerik:RadScheduler> |
C#
private const int AppointmentsLimit = 1; |
private void Page_Load(object sender, EventArgs e) |
{ |
} |
protected bool ExceedsLimit(Appointment apt) |
{ |
// Check if the new appointment overlaps with the existing appointments |
int appointmentsCount = RadScheduler1.Appointments.GetAppointmentsInRange(apt.Start, apt.End).Count; |
if ((appointmentsCount > (AppointmentsLimit - 1))) { |
return true; |
} |
// If this is a recurring appointment, we will also check if it's occurrences |
// overlap with other appointments in the current view |
RecurrenceRule parsedRule; |
if (RecurrenceRule.TryParse(apt.RecurrenceRule.ToString(), parsedRule)) { |
parsedRule.SetEffectiveRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd); |
foreach (DateTime occurrence in parsedRule.Occurrences) { |
appointmentsCount = RadScheduler1.Appointments.GetAppointmentsInRange(occurrence, occurrence.Add(apt.Duration)).Count; |
if ((appointmentsCount > (AppointmentsLimit - 1))) { |
return true; |
} |
} |
} |
return false; |
} |
protected bool ConflictsWithOccurrences(Appointment apt) |
{ |
RecurrenceRule parsedRule; |
foreach (Appointment a in RadScheduler1.Appointments) { |
if (RecurrenceRule.TryParse(a.RecurrenceRule.ToString(), parsedRule)) { |
//parsedRule.SetEffectiveRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd); |
foreach (DateTime occurrence in parsedRule.Occurrences) { |
//check if the start time of the occurrence is within the range of the appointment: |
if ((occurrence.CompareTo(apt.Start) > 0) & (occurrence.CompareTo(apt.End) < 0)) { |
return true; |
} |
//check if the end time of the occurrence is within the range of the appointment: |
if ((occurrence.Add(a.Duration).CompareTo(apt.Start) > 0) & (occurrence.Add(a.Duration).CompareTo(apt.End) < 0)) { |
return true; |
} |
//check if the start time of the appointment is within the range of the occurrence: |
if ((apt.Start.CompareTo(occurrence) > 0) & (apt.Start.CompareTo(occurrence.Add(a.Duration)) < 0)) { |
return true; |
} |
//check if the end time of the appointment is within the range of the occurrence: |
if ((apt.End.CompareTo(occurrence) > 0) & (apt.End.CompareTo(occurrence.Add(a.Duration)) < 0)) { |
return true; |
} |
//check if start or end the appoitnment coincide with start or end of the occurrence |
if ((apt.Start.CompareTo(occurrence) == 0) || (apt.Start.CompareTo(occurrence.Add(a.Duration)) == 0) || (apt.End.CompareTo(occurrence) == 0) || (apt.End.CompareTo(occurrence.Add(a.Duration)) == 0)) { |
return true; |
} |
} |
} |
} |
return false; |
} |
protected void RadScheduler1_AppointmentInsert(object sender, Telerik.Web.UI.SchedulerCancelEventArgs e) |
{ |
if (ExceedsLimit(e.Appointment) || ConflictsWithOccurrences(e.Appointment)) { |
Label1.Text = "Another appointment exists in this time slot."; |
e.Cancel = true; |
} |
} |
protected void RadScheduler1_AppointmentUpdate(object sender, Telerik.Web.UI.AppointmentUpdateEventArgs e) |
{ |
if (ExceedsLimit(e.ModifiedAppointment) || ConflictsWithOccurrences(e.ModifiedAppointment)) { |
Label1.Text = "Another appointment exists in this time slot."; |
foreach (Appointment a in RadScheduler1.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.End)) { |
if (a.ID.ToString() != e.Appointment.ID.ToString()) { |
e.Cancel = true; |
} |
} |
} |
} |
protected void RadScheduler1_AppointmentCancelingEdit(object sender, AppointmentCancelingEditEventArgs e) |
{ |
Label1.Text = ""; |
} |
VB.NET
Private Const AppointmentsLimit As Integer = 1 |
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) |
End Sub |
Protected Function ExceedsLimit(ByVal apt As Appointment) As Boolean |
' Check if the new appointment overlaps with the existing appointments |
Dim appointmentsCount As Integer = RadScheduler1.Appointments.GetAppointmentsInRange(apt.Start, apt.End).Count |
If (appointmentsCount > (AppointmentsLimit - 1)) Then |
Return True |
End If |
' If this is a recurring appointment, we will also check if it's occurrences |
' overlap with other appointments in the current view |
Dim parsedRule As RecurrenceRule |
If RecurrenceRule.TryParse(apt.RecurrenceRule.ToString(), parsedRule) Then |
parsedRule.SetEffectiveRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd) |
For Each occurrence As DateTime In parsedRule.Occurrences |
appointmentsCount = RadScheduler1.Appointments.GetAppointmentsInRange(occurrence, occurrence.Add(apt.Duration)).Count |
If (appointmentsCount > (AppointmentsLimit - 1)) Then |
Return True |
End If |
Next |
End If |
Return False |
End Function |
Protected Function ConflictsWithOccurrences(ByVal apt As Appointment) As Boolean |
Dim parsedRule As RecurrenceRule |
For Each a As Appointment In RadScheduler1.Appointments |
If RecurrenceRule.TryParse(a.RecurrenceRule.ToString(), parsedRule) Then |
'parsedRule.SetEffectiveRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd); |
For Each occurrence As DateTime In parsedRule.Occurrences |
'check if the start time of the occurrence is within the range of the appointment: |
If (occurrence.CompareTo(apt.Start) > 0) And (occurrence.CompareTo(apt.[End]) < 0) Then |
Return True |
End If |
'check if the end time of the occurrence is within the range of the appointment: |
If (occurrence.Add(a.Duration).CompareTo(apt.Start) > 0) And (occurrence.Add(a.Duration).CompareTo(apt.[End]) < 0) Then |
Return True |
End If |
'check if the start time of the appointment is within the range of the occurrence: |
If (apt.Start.CompareTo(occurrence) > 0) And (apt.Start.CompareTo(occurrence.Add(a.Duration)) < 0) Then |
Return True |
End If |
'check if the end time of the appointment is within the range of the occurrence: |
If (apt.[End].CompareTo(occurrence) > 0) And (apt.[End].CompareTo(occurrence.Add(a.Duration)) < 0) Then |
Return True |
End If |
'check if start or end the appoitnment coincide with start or end of the occurrence |
If (apt.Start.CompareTo(occurrence) = 0) OrElse (apt.Start.CompareTo(occurrence.Add(a.Duration)) = 0) OrElse (apt.[End].CompareTo(occurrence) = 0) OrElse (apt.[End].CompareTo(occurrence.Add(a.Duration)) = 0) Then |
Return True |
End If |
Next |
End If |
Next |
Return False |
End Function |
Protected Sub RadScheduler1_AppointmentInsert(ByVal sender As Object, ByVal e As Telerik.Web.UI.SchedulerCancelEventArgs) |
If ExceedsLimit(e.Appointment) OrElse ConflictsWithOccurrences(e.Appointment) Then |
Label1.Text = "Another appointment exists in this time slot." |
e.Cancel = True |
End If |
End Sub |
Protected Sub RadScheduler1_AppointmentUpdate(ByVal sender As Object, ByVal e As Telerik.Web.UI.AppointmentUpdateEventArgs) |
If ExceedsLimit(e.ModifiedAppointment) OrElse ConflictsWithOccurrences(e.ModifiedAppointment) Then |
Label1.Text = "Another appointment exists in this time slot." |
For Each a As Appointment In RadScheduler1.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.[End]) |
If a.ID.ToString() <> e.Appointment.ID.ToString() Then |
e.Cancel = True |
End If |
Next |
End If |
End Sub |
Protected Sub RadScheduler1_AppointmentCancelingEdit(ByVal sender As Object, ByVal e As AppointmentCancelingEditEventArgs) |
Label1.Text = "" |
End Sub |
Greetings,
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
andrea
Top achievements
Rank 1
answered on 10 Mar 2009, 11:20 AM
I'm doing some test with your code, and here is my problem.
I noticed that updating an appointment of a serie the first method called is RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e).
e.Appointment and e.ModifiedAppointment refer to the Parent in order to update the Parent RecurrenceRule.
Then RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e) is called and I have to check if the new appointment (Exception) "exceed the limit". So, if i need to cancel insert event the Exception disappear cause the parent has already updated. I think it would be better first to try the insert of the exception and then to perform the update of the parent. Is there a way to accomplish that, maybe looking at the problem from another side?
Thanks again for your help
I noticed that updating an appointment of a serie the first method called is RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e).
e.Appointment and e.ModifiedAppointment refer to the Parent in order to update the Parent RecurrenceRule.
Then RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e) is called and I have to check if the new appointment (Exception) "exceed the limit". So, if i need to cancel insert event the Exception disappear cause the parent has already updated. I think it would be better first to try the insert of the exception and then to perform the update of the parent. Is there a way to accomplish that, maybe looking at the problem from another side?
Thanks again for your help
0
andrea
Top achievements
Rank 1
answered on 10 Mar 2009, 05:15 PM
Well, I got it.
I have to use RecurrenceExceptionCreated event.
Sorry for my previous question.
Andrea
I have to use RecurrenceExceptionCreated event.
Sorry for my previous question.
Andrea