Provider problems

5 posts, 0 answers
  1. Andy
    Andy avatar
    3 posts
    Member since:
    Aug 2014

    Posted 15 Nov 2015 Link to this post

    Hi there,
     have set up a Provider for the Scheduler to enable multiple resources…
    This part is working well – but am getting lots of error with my recurring appointments (normal ones are fine).  Have modelled my code from the example in the DbScheduleProvider in the Demo project.
    If I try to delete a recurring (either series/individual) I get:

    Cannot locate the parent of appointment with ID = '15'. Ensure that the parent appointment with ID = '' exists and is loaded.
    [InvalidOperationException: Cannot locate the parent of appointment with ID = '15'. Ensure that the parent appointment with ID = '' exists and is loaded.]
      Telerik.Web.UI.Scheduling.AppointmentController.DeleteAppointment(ISchedulerInfo schedulerInfo, Appointment appointmentToDelete, Boolean deleteSeries) +1254
       Telerik.Web.UI.RadScheduler.DeleteAppointment(Appointment appointmentToDelete) +88
       Telerik.Web.UI.RadScheduler.ProcessPostBackCommand(SchedulerPostBackEvent postBack) +1440
       Telerik.Web.UI.RadScheduler.RaisePostBackEvent(String eventArgument) +62
       Telerik.Web.UI.RadScheduler.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9672166
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724


    If I move a recurring appointment I get:

    Object reference not set to an instance of an object.
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

    Stack Trace:



    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Web.UI.Scheduling.AppointmentController.PrepareToEdit(Appointment appointmentToEdit, Boolean editSeries) +110
       Telerik.Web.UI.RadScheduler.Telerik.Web.UI.IScheduler.HandleMove(Appointment appointmentToMove, DateTime start, DateTime end, Boolean editSeries, ResourceUpdateInfo resourceUpdateInfo) +46
       Telerik.Web.UI.Scheduler.Views.Week.Model.HandleMove(Appointment appointment, ISchedulerTimeSlot sourceSlot, ISchedulerTimeSlot targetSlot, Boolean editSeries) +438
       Telerik.Web.UI.Scheduler.Views.SchedulerModel.ProcessPostBackCommand(SchedulerPostBackEvent postBack) +279
       Telerik.Web.UI.RadScheduler.ProcessPostBackCommand(SchedulerPostBackEvent postBack) +3412
       Telerik.Web.UI.RadScheduler.RaisePostBackEvent(String eventArgument) +62
       Telerik.Web.UI.RadScheduler.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9672166
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724



    Really appreciate any help I can get!

    thanks, Andy



  2. Andy
    Andy avatar
    3 posts
    Member since:
    Aug 2014

    Posted 15 Nov 2015 in reply to Andy Link to this post

    Here is the code from the Provider:

    Imports System.Collections.Generic
    Imports System.Data.Common
    Imports System.Data.SqlClient
    Imports System.Data
    Imports Telerik.Web.UI

    Namespace Telerik.Web.Examples.Scheduler
        Public Class MyDbSchedulerProvider
            Inherits DbSchedulerProviderBase

            Private _organisationusers As IDictionary(Of Integer, Resource)

            Private ReadOnly Property OrganisationUsers() As IDictionary(Of Integer, Resource)
                Get
                    If _organisationusers Is Nothing Then
                        _organisationusers = New Dictionary(Of Integer, Resource)()
                        For Each OrganisationUser As Resource In LoadOrganisationUsers()
    _organisationusers.Add(CInt(OrganisationUser.Key), OrganisationUser)
                        Next
                    End If

                    Return _organisationusers
                End Get
            End Property

            Public Overrides Function GetAppointments(owner As RadScheduler) As IEnumerable(Of Appointment)
                Dim appointments As New List(Of Appointment)()

                Dim sqlSelectCommand As String = "SELECT * FROM tbl_Calendar_Appointment" ' WHERE " & _
                '"Organisation_ID = (select Organisation_ID from tbl_Organisation_User WHERE UserName = '" & HttpContext.Current.User.Identity.Name.ToString & "'"

                Dim adapter As New SqlDataAdapter(sqlSelectCommand, ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)
                Dim dataTable As New DataTable()
                adapter.Fill(dataTable)

                For Each dataRow As DataRow In dataTable.Rows
                    Dim apt As New Appointment()
                    apt.Owner = owner
                    apt.ID = dataRow("Calendar_Appointment_ID")
                    apt.Subject = Convert.ToString(dataRow("Subject"))
                    apt.Start = DateTime.SpecifyKind(Convert.ToDateTime(dataRow("Start")), DateTimeKind.Utc)
                    apt.[End] = DateTime.SpecifyKind(Convert.ToDateTime(dataRow("End")), DateTimeKind.Utc)
                    apt.RecurrenceRule = Convert.ToString(dataRow("Recurrence_Rule"))
                    apt.RecurrenceParentID = If(dataRow("Recurrence_Parent_Id") Is DBNull.Value, DBNull.Value, dataRow("Recurrence_Parent_Id"))

                    If Not IsNothing(dataRow("Reminder")) Then
                        Dim reminders As IList(Of Reminder) = Reminder.TryParse(Convert.ToString(dataRow("Reminder")))
                        If reminders IsNot Nothing Then
                            apt.Reminders.AddRange(reminders)
                        End If
                    End If

                    If Not apt.RecurrenceParentID Is DBNull.Value Then
                        apt.RecurrenceState = RecurrenceState.Exception
                    Else
                        If apt.RecurrenceRule <> String.Empty Then
                            apt.RecurrenceState = RecurrenceState.Master
                        End If
                    End If

                    LoadResources(apt)
                    appointments.Add(apt)
                Next

                Return appointments
            End Function

            Public Overrides Sub Insert(owner As RadScheduler, appointmentToInsert As Appointment)

                Dim sqlInsertCommand As String = "INSERT INTO tbl_Calendar_Appointment ([Subject], [Description], [Organisation_User_ID], [Start], [End], [Recurrence_Rule], [Recurrence_Parent_ID], [Reminder]) " & _
                    " VALUES (@Subject, @Description, @OrganisationUserID, @Start, @End, @RecurrenceRule, @RecurrenceParentID, @Reminder)"

                sqlInsertCommand += " SELECT SCOPE_IDENTITY()"

                Dim conMain As New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)
                conMain.Open()

                Dim cmd As New SqlCommand

                PopulateAppointmentParameters(cmd, appointmentToInsert)

                cmd.Connection = conMain
                cmd.CommandText = sqlInsertCommand

                Dim identity As Integer

                identity = cmd.ExecuteScalar()
                FillAppointmentUsers(appointmentToInsert, cmd, identity)

                cmd.Dispose()
                conMain.Close()

            End Sub

            Public Overrides Sub Update(owner As RadScheduler, appointmentToUpdate As Appointment)

                Dim sqlUpdateCommand As String = "UPDATE tbl_Calendar_Appointment SET [Subject] = @Subject, [Description] = @Description, [Start] = @Start, [End] = @End, " & _
                    "[Recurrence_Rule] = @RecurrenceRule, [Recurrence_Parent_ID] = @RecurrenceParentID WHERE Calendar_Appointment_ID = @ID"


                Dim conMain As New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)
                conMain.Open()

                Dim cmd As New SqlCommand

                PopulateAppointmentParameters(cmd, appointmentToUpdate)

                cmd.Parameters.AddWithValue("ID", appointmentToUpdate.ID)

                cmd.Connection = conMain
                cmd.CommandText = sqlUpdateCommand
                cmd.ExecuteNonQuery()


                ClearAppointmentUsers(appointmentToUpdate.ID, cmd)

                FillAppointmentUsers(appointmentToUpdate, cmd, appointmentToUpdate.ID)

                cmd.Dispose()
                conMain.Close()

            End Sub

            Public Overrides Sub Delete(owner As RadScheduler, appointmentToDelete As Appointment)

                Dim strSQL As String = "DELETE FROM tbl_Calendar_Appointment WHERE Calendar_Appointment_ID = @ID"


    Dim conMain As New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)
                conMain.Open()

                Dim cmd As New SqlCommand

                cmd.Connection = conMain
                ClearAppointmentUsers(appointmentToDelete.ID, cmd)

                cmd.Parameters.Clear()
                cmd.CommandText = strSQL
                cmd.Parameters.AddWithValue("ID", appointmentToDelete.ID)

                cmd.ExecuteNonQuery()

                cmd.Dispose()
                conMain.Close()


            End Sub

            Public Overrides Function GetResources(schedulerInfo As ISchedulerInfo) As IDictionary(Of ResourceType, IEnumerable(Of Resource))


                Dim resCollection As New Dictionary(Of ResourceType, IEnumerable(Of Resource))()

                resCollection.Add(New ResourceType("OrganisationUser", False), OrganisationUsers.Values)

                Return resCollection

            End Function

            Public Overrides Function GetResourceTypes(owner As RadScheduler) As IEnumerable(Of ResourceType)
                Dim resourceTypes As ResourceType() = New ResourceType(1) {}
                resourceTypes(0) = New ResourceType("OrganisationUser", False)
                'resourceTypes(1) = New ResourceType("Student", True)

                Return resourceTypes
            End Function

            Public Overrides Function GetResourcesByType(owner As RadScheduler, resourceType As String) As IEnumerable(Of Resource)
                Select Case resourceType
                    Case "OrganisationUser"
                        Return OrganisationUsers.Values

                        'Case "Student"
                        'Return Students.Values
                    Case Else

                        Throw New InvalidOperationException(Convert.ToString("Unknown resource type: ") & resourceType)
                End Select
            End Function

            Private Sub LoadResources(apt As Appointment)

                Dim sqlSelectCommand As String = "SELECT Organisation_User_ID FROM tbl_Calendar_Appointment_Users WHERE Calendar_Appointment_ID = @CalendarAppointmentID AND [Organisation_User_ID] IS NOT NULL"

                Dim adapter As New SqlDataAdapter(sqlSelectCommand, ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)

                adapter.SelectCommand.Parameters.Add(New SqlParameter("CalendarAppointmentID", apt.ID))

                Dim dataTable As New DataTable()
                adapter.Fill(dataTable)

                For Each dataRow As DataRow In dataTable.Rows

                    Dim organisationuser As Resource = OrganisationUsers(Convert.ToInt32(dataRow("Organisation_User_ID")))
                    apt.Resources.Add(organisationuser)
                Next

                adapter.Dispose()

            End Sub

            Private Sub FillAppointmentUsers(appointment As Appointment, cmd As SqlCommand, Id As Integer)
                For Each organisationuser As Resource In appointment.Resources.GetResourcesByType("OrganisationUser")
                    cmd.Parameters.Clear()
                    cmd.Parameters.AddWithValue("@CalendarAppointmentID", Id)
                    cmd.Parameters.AddWithValue("@OrganisationUserID", organisationuser.Key)

                    cmd.CommandText = "INSERT INTO tbl_Calendar_Appointment_Users (Calendar_Appointment_ID, Organisation_User_ID) VALUES (@CalendarAppointmentID, @OrganisationUserID)"
                    cmd.ExecuteNonQuery()
                Next
            End Sub

            Private Sub ClearAppointmentUsers(AppointmentId As Integer, cmd As SqlCommand)
                cmd.Parameters.Clear()
                cmd.Parameters.AddWithValue("@CalendarAppointmentID", AppointmentId)
                cmd.CommandText = "DELETE FROM tbl_Calendar_Appointment_Users WHERE Calendar_Appointment_ID = @CalendarAppointmentID"
                cmd.ExecuteNonQuery()
            End Sub

            Private Function LoadOrganisationUsers() As IEnumerable(Of Resource)
                Dim resources As New List(Of Resource)()

                Dim sqlSelectCommand As String = "SELECT * FROM [tbl_Organisation_User] " & _
                        "WHERE Organisation_ID = (select Organisation_ID from tbl_Organisation_User WHERE UserName = 'WCAdministrator')" ' & HttpContext.Current.User.Identity.Name.ToString & "')"

                Dim adapter As New SqlDataAdapter(sqlSelectCommand, ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)
                Dim dataTable As New DataTable()
                adapter.Fill(dataTable)

                For Each dataRow As DataRow In dataTable.Rows
                    Dim res As New Resource()
                    res.Type = "OrganisationUser"
                    res.Key = dataRow("Organisation_User_ID")
                    res.Text = Convert.ToString(dataRow("UserNameTag"))
                    'res.Attributes("Phone") = Convert.ToString(reader("Phone"))
                    resources.Add(res)
                Next

                adapter.Dispose()

                Return resources
            End Function


            Private Sub PopulateAppointmentParameters(cmd As SqlCommand, apt As Appointment)

                cmd.Parameters.AddWithValue("@Subject", apt.Subject)
                cmd.Parameters.AddWithValue("@Description", apt.Description)
                cmd.Parameters.AddWithValue("@Start", apt.Start)
                cmd.Parameters.AddWithValue("@End", apt.[End])

                Dim uc As New UserCredentials

                uc.UserName = HttpContext.Current.User.Identity.Name
                uc.GetUserDetails()

                cmd.Parameters.AddWithValue("@OrganisationUserID", uc.Organisation_User_ID)

                Dim rrule As Object
                If apt.RecurrenceRule <> String.Empty Then
                    rrule = apt.RecurrenceRule
                Else
                    rrule = DBNull.Value
                End If
                cmd.Parameters.AddWithValue("@RecurrenceRule", rrule)

                Dim parentId As Object = Nothing
                If apt.RecurrenceParentID IsNot Nothing Then
                    parentId = apt.RecurrenceParentID
                Else
                    parentId = DBNull.Value
                End If
                cmd.Parameters.AddWithValue("@RecurrenceParentId", parentId)

                If apt.Reminders IsNot Nothing Then
                    cmd.Parameters.AddWithValue("@Reminder", apt.Reminders.ToString())
                Else
                    cmd.Parameters.AddWithValue("@Reminder", DBNull.Value)
                End If
            End Sub
        End Class
    End Namespace

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 18 Nov 2015 Link to this post

    Hello,

    Is the same issue reproduced when using the demo project, or is it specific to your own implementation?

    Regards,
    Bozhidar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Andy
    Andy avatar
    3 posts
    Member since:
    Aug 2014

    Posted 18 Nov 2015 in reply to Bozhidar Link to this post

    Hi there - is working in the demo.....not in my implementation,

    thanks,

    Andy

  6. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 19 Nov 2015 Link to this post

    Hello,

    Since your implementation is using another Database and different queries, we can't troubleshoot it locally. Can you modify the demo project without changing the database and reproduce the issue? If you can, please send the modifications you've made so that we can apply them locally and investigate. If the database is crutial to the issue, please open a support ticket and attach a working sample project complete with the database.

    Regards,
    Bozhidar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017