Hi,
I've tried to implement a custom data provider with a database backend accessed through linq.
I've created the following base environment:
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
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
the scheduler diplays properly
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 String) As 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 Object, ByVal 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 Object, ByVal 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 |