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

Prevent user from making duplicate entries in a given time slot

11 Answers 522 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Indranik
Top achievements
Rank 1
Indranik asked on 22 Jan 2009, 07:28 AM
How do I prevent user from making duplicate entries in a given time slot? I am in timeline and resourceview.

11 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Jan 2009, 11:39 AM
Hello Indranik,

You can go through the following online demo which explains on how to prevent users from creating concurrent appointments.
Limiting concurrent appointments - client-side

Hope you find this helpful..
Princy.
0
Josh
Top achievements
Rank 1
answered on 27 Jan 2009, 02:44 PM
This answer is somewhat right.  When you try to add or edit an entry in the calendar view it won't let you have an appointment that overlaps.  But if you click on the "Options" link and set the times within the appointment to overlap it will allow you to save the entry.

Is there functionality built into the Scheduler control that would verify that there is no concurrency issues when using the advanced entry form?

Thanks
Josh
0
Peter
Telerik team
answered on 27 Jan 2009, 03:40 PM
Hi Josh,

For this case you will need a server side solution. Please, check this demo:
http://demos.telerik.com/aspnet-ajax/Scheduler/Examples/LimitConcurrentAppointments/DefaultCS.aspx


Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Josh
Top achievements
Rank 1
answered on 27 Jan 2009, 03:47 PM
Thanks Peter!  I can't believe I didn't see that demo.

Josh

0
Josh
Top achievements
Rank 1
answered on 27 Jan 2009, 04:10 PM
Peter,

There's one issue with the server side validation solution...it only validates the date of the first event, not the recurring instances.  For example, if you go to Sunday April 1, 2007 in the demo and enter a new appointment that 8:00 am to 5:00 PM.  Then specifiy that it's a recurring task that takes place every day (Daily) for 5 days.  It won't recongize that there is a conflict on Monday April 2, 2007 (or April 3, April 4, etc.) at 9:30 am.

Is there a function in the control to look for instances that would conflict with the entire range or would I have to write that into the validation myself?

Thanks,
Josh
0
Peter
Telerik team
answered on 27 Jan 2009, 04:31 PM

That's a special case which we have omitted for now to keep things simple. Here is the code which extends the example and handles the case with recurring apointments.

C#
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;  
            }  
        }  
    }  
}  
 
 


VB.NET
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 ObjectByVal 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 ObjectByVal 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    
 




Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Karl
Top achievements
Rank 1
answered on 21 Sep 2009, 06:35 PM
Hi Peter,

I've just tried implementing the code you posted in this post and I get the following error:-

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for 'Telerik.Web.UI.RecurrenceRule.TryParse(string, out Telerik.Web.UI.RecurrenceRule)' has some invalid arguments

Source Error:

Line 232:        foreach (Appointment a in RadScheduler1.Appointments)
Line 233:        {
Line 234: if (RecurrenceRule.TryParse(a.RecurrenceRule.ToString(), parsedRule)) { Line 235:            
Line 236:                //parsedRule.SetEffectiveRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd);      


Am I missing something?

Thanks
0
Karl
Top achievements
Rank 1
answered on 24 Sep 2009, 08:59 AM
Hi,

Is there any news on this?

Thanks
0
Peter
Telerik team
answered on 25 Sep 2009, 08:20 AM
Hello Karl,

Thank you for asking this question. You are right, the TryParse needs "out" before parsedRule:

//***  
 if (RecurrenceRule.TryParse(a.RecurrenceRule.ToString(), out parsedRule))  
//***  
            

I am not sure how this error slipped through. I guess the code was converted from VB to C# and the converter didn't catch this. Anyway, I am glad you posted this.


Best wishes,
Peter
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Gavin Pollock
Top achievements
Rank 1
answered on 05 Apr 2012, 05:00 PM
Hi guys,

If you were editing a specific Occurrence of a series, how would this affect the code below. Would that fire the Updating event, and pass through the entire series appointment? How would you check just for the occurence edited?

Cheers
Gavin
0
Peter
Telerik team
answered on 05 Apr 2012, 05:24 PM
Hello Gavin,

There is a special code library project that addresses the scenario with Occupied time slots and recurring appointments.

Regards,
Peter
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
Indranik
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Josh
Top achievements
Rank 1
Peter
Telerik team
Karl
Top achievements
Rank 1
Gavin Pollock
Top achievements
Rank 1
Share this question
or