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

[Solved] Custom provider not working

2 Answers 151 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
CrazyBernie
Top achievements
Rank 1
CrazyBernie asked on 17 Jun 2009, 09:46 PM
Hi,

I've tried to implement a custom data provider with a database backend accessed through linq.

I've created the following base environment:

 


Imports System  
Imports System.Collections.Generic  
Imports System.Collections.Specialized  
Imports System.Configuration.Provider  
Imports System.IO  
Imports System.Xml  
Imports Telerik.Web.UI  
 
 
 
Public Class MyDbSchedulerProvider  
    Inherits Telerik.Web.UI.SchedulerProviderBase  
 
 
 
 
    Dim _tasks As Dictionary(Of Integer, Resource)  
 
 
    Public Overrides Sub Delete(ByVal owner As Telerik.Web.UI.RadScheduler, ByVal appointmentToDelete As Telerik.Web.UI.Appointment)  
        Dim db As New hoursDataContext  
        Dim h = (From x In db.demo_hours Where x.id = appointmentToDelete.ID).First  
 
        db.demo_hours.DeleteOnSubmit(h)  
        db.SubmitChanges()  
 
 
    End Sub 
 
    Public Overrides Function GetAppointments(ByVal owner As Telerik.Web.UI.RadScheduler) As System.Collections.Generic.IEnumerable(Of Telerik.Web.UI.Appointment)  
        Dim db As New hoursDataContext  
        Dim appointments As New List(Of Appointment)  
        Dim hours = From x In db.demo_hours  
 
        For Each h In hours  
            Dim apt As New Appointment  
            apt.Subject = h.name  
            apt.ID = h.id  
            apt.Start = h.datestart  
            apt.End = h.enddate  
            appointments.Add(apt)  
        Next 
        Return appointments  
 
    End Function 
 
    Public Overloads Overrides Function GetResourcesByType(ByVal owner As RadScheduler, ByVal resourceType As StringAs IEnumerable(Of Resource)  
        Select Case resourceType  
            Case "Task" 
                Return tasks.Values  
            Case Else 
                Throw New InvalidOperationException("Unknown resource type: " + resourceType)  
        End Select 
    End Function 
 
    Private ReadOnly Property tasks() As IDictionary(Of Integer, Resource)  
 
        Get 
            _tasks = New Dictionary(Of Integer, Resource)()  
            For Each student As Resource In Loadtasks()  
                _tasks.Add(DirectCast(student.Key, Integer), student)  
            Next 
            Return _tasks  
        End Get 
    End Property 
 
    Public Overrides Function GetResourceTypes(ByVal owner As Telerik.Web.UI.RadScheduler) As System.Collections.Generic.IEnumerable(Of Telerik.Web.UI.ResourceType)  
        Dim resourceTypes As ResourceType() = New ResourceType(2) {}  
        resourceTypes(0) = New ResourceType("Teacher"False)  
        resourceTypes(1) = New ResourceType("Student"True)  
        Return resourceTypes  
    End Function 
 
    Public Overrides Sub Insert(ByVal owner As Telerik.Web.UI.RadScheduler, ByVal appointmentToInsert As Telerik.Web.UI.Appointment)  
        Dim h As New demo_hour  
        Dim a As Appointment = appointmentToInsert  
        h.datestart = a.Start  
        h.enddate = a.End 
        h.name = a.Subject  
        Dim db As New hoursDataContext  
        db.demo_hours.InsertOnSubmit(h)  
        db.SubmitChanges()  
 
    End Sub 
 
    Public Overrides Sub Update(ByVal owner As Telerik.Web.UI.RadScheduler, ByVal appointmentToUpdate As Telerik.Web.UI.Appointment)  
        Dim db As New hoursDataContext  
        Dim a As Appointment = appointmentToUpdate  
        Dim h = (From x In db.demo_hours Where x.id = a.ID).First  
 
        h.name = a.Subject  
        h.datestart = a.Start  
        h.enddate = a.End 
        db.SubmitChanges()  
 
    End Sub 
 
    Private Function Loadtasks() As IEnumerable(Of Resource)  
        Dim resources As New List(Of Resource)()  
        Dim db As New hoursDataContext  
        Dim tasks = From x In db.Tasks  
 
        For Each T In tasks  
            Dim r As New Resource  
            r.Key = T.taskid  
            r.Type = "Task" 
            r.Text = T.name  
            resources.Add(r)  
        Next 
        Return resources  
 
 
    End Function 
 
 
End Class 
 
 

Then I created a new rad scheduler in a web page in the same project and wrote the following code in the loading event of the page

Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
        If Not IsPostBack Then 
 
            RadScheduler1.DataKeyField = "ID" 
            RadScheduler1.DataStartField = "Start" 
            RadScheduler1.DataEndField = "End" 
            RadScheduler1.DataSubjectField = "Subject" 
            RadScheduler1.DataRecurrenceField = "RecurrenceRule" 
            RadScheduler1.DataRecurrenceParentKeyField = "RecurrenceParentID" 
 
        End If 
 
        Dim s As New MyDbSchedulerProvider  
 
        RadScheduler1.DataSource = s  
 
 
 
 
 
 
 
 
 
 
 
 
    End Sub 

When starting the apps throws an exception:
Data source is an invalid type.  It must be either an IListSource, IEnumerable, or IDataSource.

I've been playing around with this for the last couple of hours but can't find a solution. I also tried to inherit from dbschedulerprovider but that didn't work as well.

When i change the loading event to
  Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
        If Not IsPostBack Then 
 
            RadScheduler1.DataKeyField = "ID" 
            RadScheduler1.DataStartField = "Start" 
            RadScheduler1.DataEndField = "End" 
            RadScheduler1.DataSubjectField = "Subject" 
            RadScheduler1.DataRecurrenceField = "RecurrenceRule" 
            RadScheduler1.DataRecurrenceParentKeyField = "RecurrenceParentID" 
 
        End If 
 
        Dim s As New MyDbSchedulerProvider  
 
        RadScheduler1.DataSource = s.GetAppointments(RadScheduler1)  
 
 
 
 
 
    End Sub 
the scheduler diplays properly

2 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 18 Jun 2009, 06:41 AM
Hello,

You should use the Provider property to assign your provider to the RadScheduler instance:

Dim s As New MyDbSchedulerProvider
RadScheduler1.Provider = s


You can also configure the provider through the web.config. More info here:
http://www.telerik.com/help/aspnet-ajax/schedule_databindingusingadataprovider.html

Regards,
Tsvetomir Tsonev
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
CrazyBernie
Top achievements
Rank 1
answered on 19 Jun 2009, 11:22 AM
Thanks,

It worked after i changed the setting. maybe a good idea to add a sample to the help files that shows a custom provider based on schedulerprovider because that wasn't that clear . At least for me. I am happy to provide my complete code as a base for such a purpose.

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