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

duplicate resource appointment

13 Answers 136 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Rubihno
Top achievements
Rank 1
Rubihno asked on 10 Oct 2008, 06:53 AM
Hi, i have implement a function that  check if a resourcetype("ClassRoom") exist in radscheduler, for example can not insert two appointment at the same day,start and end time for the same resource, the limitings appointment runs, but if i insert the same resource at the same day,start and end time, the function is not correct...

My code:   Where is the error of my function?is not easy to implement this..but is more important for keep the overlop.
 
Private Const AppointmentsLimit As Integer = 1 
 
Protected Function ExceedsLimit(ByVal apt As Appointment) As Boolean 
        Dim appointmentsCount As Integer = RadScheduler1.Appointments.GetAppointmentsInRange(apt.Start, apt.End).Count 
        Return (appointmentsCount > (AppointmentsLimit - 1)) 
 
    End Function 
 
 Protected Function OccupazioneAule(ByVal apt As Appointment, ByVal scheduler As RadScheduler) As Boolean 
        For Each ResourceAule As Appointment In RadScheduler1.Appointments.GetAppointmentsInRange(apt.Start, apt.[End]) 
            For Each ResourceAuleApt As Resource In ResourceAule.Resources.GetResourcesByType("Aule") 
                For Each res As Resource In apt.Resources.GetResourcesByType("Aule") 
                    If ResourceAuleApt.Key.Equals(res.Key) Then 
                        Return True 
                    End If 
                Next 
            Next 
        Next 
        Return False 
    End Function 
 
 
 Protected Sub RadScheduler1_AppointmentInsert(ByVal sender As Object, ByVal e As Telerik.Web.UI.SchedulerCancelEventArgs) Handles RadScheduler1.AppointmentInsert 
 
        If ExceedsLimit(e.Appointment) And OccupazioneAule(e.Appointment, RadScheduler1) Then 
            RadAjaxManager1.ResponseScripts.Add("radalert('Aula già prenotata, riprovare!!', 300, 180);") 
            e.Cancel = True 
        Else 
            If ExceedsLimit(e.Appointment) Then 
                RadAjaxManager1.ResponseScripts.Add("radalert('Aula già prenotata, riprovare!!', 300, 180);") 
                e.Cancel = True 
            End If 
        End If 
    End Sub 
 
 
 Protected Sub RadScheduler1_AppointmentUpdate(ByVal sender As Object, ByVal e As Telerik.Web.UI.AppointmentUpdateEventArgs) Handles RadScheduler1.AppointmentUpdate 
 
        If ExceedsLimit(e.ModifiedAppointment) Then 
            For Each a As Appointment In RadScheduler1.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.[End]) 
                If a.ID <> e.Appointment.ID Then 
                    e.Cancel = True 
                End If 
            Next 
        End If 
 
    End Sub 
 
 




13 Answers, 1 is accepted

Sort by
0
Rubihno
Top achievements
Rank 1
answered on 11 Oct 2008, 03:38 PM
I try to explain more clearly the problem of my function..for insert reservation..

My function works if i insert all resourcestype into a  radscheduler, but my radscheduler is filtered by classroom, when I select the classroom on treeview and  in mode advancedinsert i insert only the classroom that I selected, the function works correctly.

Problem:
For example if i filter scheduler with classrom "CC20" and in mode schedulerdefaultform choose another classroom, the function does not check if  in that classroom is already  exist....why?because the radscheduler is filter by another classroom and not for the classroom that i choose in mode schedulerformode.advancedinsert....




0
T. Tsonev
Telerik team
answered on 11 Oct 2008, 03:47 PM
Hello Rubihno,

It looks like you are not always testing for the OccupazionaAule condition. Try changing the AppointmentInsert/AppointmentUpdate condition to this:

Protected Sub RadScheduler1_AppointmentInsert(ByVal sender As ObjectByVal e As Telerik.Web.UI.SchedulerCancelEventArgs) Handles RadScheduler1.AppointmentInsert 
    If ExceedsLimit(e.Appointment) Or OccupazioneAule(e.Appointment, RadScheduler1) Then 
        RadAjaxManager1.ResponseScripts.Add("radalert('Aula già prenotata, riprovare!!', 300, 180);"
        e.Cancel = True 
    End If 
End Sub 
 

This way either of the conditions will stop the operation.

Best wishes,
Tsvetomir Tsonev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rubihno
Top achievements
Rank 1
answered on 11 Oct 2008, 04:12 PM
I tried but I don'check if is already exist..

The problem is that the scheduler display only the classroom that I selected(i have all reservation view of classroom selected) .. and i insert only the classroom that I have filtered ..but if I insert another classroom not check if exist...
0
Rubihno
Top achievements
Rank 1
answered on 13 Oct 2008, 06:00 PM
Is better that open a support ticket for solve the problem of this function, is not easy to explain the malfunction...maybe so can corret the problem..

I attach the projectfile into a support ticket...

Hi


0
T. Tsonev
Telerik team
answered on 14 Oct 2008, 09:16 AM
Hello Rubihno,

I have replied to your support ticket and I am posting the same response here, for reference:

I see what you mean. The problem is that the appointments from the other classrooms are currently not loaded. They are filtered by the SELECT query ("...WHERE (Prenotazioni.ID_Aula = @ID_Aula)") and the function OccupazioneAule cannot find them, as they are not part of the Appointments collection.

You can execute an SQL query in OccupazioneAule to check if there are any conflicting appointments. The query should look like this

SELECT COUNT(*) FROM [Prenotazioni] WHERE 
[Start] < @NewApptEnd AND 
[End] > @NewApptStart AND 
[ID_Aula] = @NewApptAula 

This way you will also be sure that no other user has inserted a conflicting appointment in the meantime.


Best wishes,
Tsvetomir Tsonev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rubihno
Top achievements
Rank 1
answered on 14 Oct 2008, 09:34 AM
thanks, i undestand the problem but this sql query where i must insert?to sqldatasource SQLDSScheduler or in a function occupazioneaule, is not clear where i must insert this sqlquery...
0
T. Tsonev
Telerik team
answered on 14 Oct 2008, 11:14 AM
Hi Rubihno,

Not a problem, I am attaching you the sample implementation:

Protected Function OccupazioneAule(ByVal apt As Appointment, ByVal scheduler As RadScheduler) As Boolean 
    Dim aule As Resource = apt.Resources.GetResourceByType("Aule"
    If aule Is Nothing Then 
        Return False 
    End If 
 
    Dim connectionString As String = ConfigurationManager.ConnectionStrings("connessione_gestioneAule").ConnectionString 
    Dim conn As SqlConnection = New SqlConnection(connectionString) 
    Dim cmd As SqlCommand = conn.CreateCommand() 
 
    cmd.Parameters.Add(New SqlParameter("@NewApptStart", apt.Start)) 
    cmd.Parameters.Add(New SqlParameter("@NewApptEnd", apt.[End])) 
    cmd.Parameters.Add(New SqlParameter("@NewApptAula", aule.Key)) 
    cmd.CommandText = "SELECT COUNT(*) FROM [Prenotazioni] WHERE [Start] < @NewApptEnd AND [End] > @NewApptStart AND [ID_Aula] = @NewApptAula" 
 
    Dim conflictingAppointmentsCount As Integer = 0 
 
    Try 
        conn.Open() 
        conflictingAppointmentsCount = cmd.ExecuteScalar() 
    Finally 
        If conn.State = ConnectionState.Open Then 
            conn.Close() 
        End If 
 
        conn.Dispose() 
        cmd.Dispose() 
    End Try 
 
    Return conflictingAppointmentsCount > 0 
End Function 
 


Greetings,
Tsvetomir Tsonev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rubihno
Top achievements
Rank 1
answered on 23 Oct 2008, 07:01 PM
Hi, this function is perfect for check the duplicate resource in mode insert, but for update mode?is the same?i have problem in update mode...

my code in update mode is:

 Protected Sub RadSchedulerPrenotazioni_AppointmentUpdate(ByVal sender As Object, ByVal e As Telerik.Web.UI.AppointmentUpdateEventArgs) Handles RadSchedulerPrenotazioni.AppointmentUpdate

        If e.ModifiedAppointment.RecurrenceRule <> "" Then
            Dim parsedRule As RecurrenceRule
            RecurrenceRule.TryParse(e.ModifiedAppointment.RecurrenceRule.ToString(), parsedRule)


            For Each occurrence As DateTime In parsedRule.Occurrences
                If ExceedsLimit(e.ModifiedAppointment, occurrence) Then
                    RadAjaxManager1.ResponseScripts.Add("radalert('Aula già prenotata, riprovare!!', 300, 180);")
                    e.Cancel = True
                End If
            Next

        Else
            If OccupazioneAule(e.ModifiedAppointment, RadSchedulerPrenotazioni) Then
                RadAjaxManager1.ResponseScripts.Add("radalert('Aula già prenotata, riprovare!!', 300, 180);")
                e.Cancel = True
            End If
        End If

in insert mode any problem, but in update mode can not change the appointment, every time show the message error..why?
0
Rubihno
Top achievements
Rank 1
answered on 24 Oct 2008, 01:30 PM
Someone can help me  to understand where is the error?


0
Peter
Telerik team
answered on 24 Oct 2008, 04:03 PM

Hi Marco,

We have received your support ticket witht the sample project and we are currently working on your case. However, we might not be able to resolve the problem today, but we will follow up early next week.



Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rubihno
Top achievements
Rank 1
answered on 27 Oct 2008, 07:45 AM
okay..thanks a lot
0
Rubihno
Top achievements
Rank 1
answered on 29 Oct 2008, 03:47 PM
Hi, there are problems to find the solution of my thread open?Eventually I describe more in details the problem...
0
Rubihno
Top achievements
Rank 1
answered on 31 Oct 2008, 01:28 PM
Someone can help me ?are blocked, I don't understand how to check in update mode if the resourcetype classroom if already exist....

In insert mode it is clear, with the function described up..but in update mode there are problem..



Tags
Scheduler
Asked by
Rubihno
Top achievements
Rank 1
Answers by
Rubihno
Top achievements
Rank 1
T. Tsonev
Telerik team
Peter
Telerik team
Share this question
or