The SchedulerMapping class is responsible for mapping a single property from the data source to a scheduler property, which allows you to specify convert callback methods in order to convert values to and from the data source if needed.
Overview
To associate a field with a different type then the scheduler type, for example, a Background ID that is written as a string in the database:
- Create two methods with the following signatures:
Copy[C#]
object ConvertBackgrounIdToScheduler(object obj)
{
if (!(obj is DBNull))
{
string appointmentBackground = (string)obj;
switch (appointmentBackground)
{
case "Business":
return AppointmentBackground.Business;
case "Important":
return AppointmentBackground.Important;
case "MustAttend":
return AppointmentBackground.MustAttend;
case "PhoneCall":
return AppointmentBackground.PhoneCall;
}
}
return AppointmentBackground.None;
}
object ConvertBackgrounIdToDataSource(object obj)
{
AppointmentBackground appointmentBackground = (AppointmentBackground)obj;
switch (appointmentBackground)
{
case AppointmentBackground.Business:
return "Business";
case AppointmentBackground.Important:
return "Important";
case AppointmentBackground.MustAttend:
return "MustAttend";
case AppointmentBackground.PhoneCall:
return "PhoneCall";
}
return "None";
}
Copy[VB.NET]
Private Function ConvertBackgrounIdToScheduler(ByVal obj As Object) As Object
If Not (TypeOf obj Is DBNull) Then
Dim appointmentBackground As String = CStr(obj)
Select Case appointmentBackground
Case "Business"
Return Telerik.WinControls.UI.AppointmentBackground.Business
Case "Important"
Return Telerik.WinControls.UI.AppointmentBackground.Important
Case "MustAttend"
Return Telerik.WinControls.UI.AppointmentBackground.MustAttend
Case "PhoneCall"
Return Telerik.WinControls.UI.AppointmentBackground.PhoneCall
End Select
End If
Return AppointmentBackground.None
End Function
Private Function ConvertBackgrounIdToDataSource(ByVal obj As Object) As Object
Dim appointmentBackground As AppointmentBackground = CType(obj, AppointmentBackground)
Select Case appointmentBackground
Case appointmentBackground.Business
Return "Business"
Case appointmentBackground.Important
Return "Important"
Case appointmentBackground.MustAttend
Return "MustAttend"
Case appointmentBackground.PhoneCall
Return "PhoneCall"
End Select
Return "None"
End Function - Apply settings of the BackgroundId mapping in the AppointmentMappingInfo:
Copy[C#]
SchedulerMapping backgroundIdSchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("BackgroundId");
backgroundIdSchedulerMapping.ConvertToScheduler = new ConvertCallback(this.ConvertBackgrounIdToScheduler);
backgroundIdSchedulerMapping.ConvertToDataSource = new ConvertCallback(this.ConvertBackgrounIdToDataSource);
Copy[VB.NET]
Dim backgroundIdSchedulerMapping As SchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("BackgroundId")
backgroundIdSchedulerMapping.ConvertToScheduler = New ConvertCallback(AddressOf Me.ConvertBackgrounIdToScheduler)
backgroundIdSchedulerMapping.ConvertToDataSource = New ConvertCallback(AddressOf Me.ConvertBackgrounIdToDataSource)
Null Fields in the Data Base
If the database has fields that can be Null then you need to add converters for those fields. For example, let's suppose that the database has a field "Location", which is a string and you wish to check whether its value is DBNull. If it is DBNull you would want to convert it to null. Here are the steps:
- Create a conversion method with the following signature:
Copy[C#]
object ConvertLocationToScheduler(object obj)
{
if (obj is DBNull)
{
return null;
}
return obj;
}
Copy[VB.NET]
Private Function ConvertLocationToScheduler(ByVal obj As Object) As Object
If TypeOf obj Is DBNull Then
Return Nothing
End If
Return obj
End Function - Apply the Location mapping settings in the AppointmentMappingInfo:
Copy[C#]
AppointmentMappingInfo appointmentMappingInfo = new AppointmentMappingInfo();
appointmentMappingInfo.Location = "Location";
SchedulerMapping locationSchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("Location");
locationSchedulerMapping.ConvertToScheduler = new ConvertCallback(this.ConvertLocationToScheduler);
Copy[VB.NET]
Dim appointmentMappingInfo As New AppointmentMappingInfo()
appointmentMappingInfo.Location = "Location"
Dim locationSchedulerMapping As SchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("Location")
locationSchedulerMapping.ConvertToScheduler = New ConvertCallback(AddressOf Me.ConvertLocationToScheduler)
The ID field is not a Guid, or is not read only in the Data base
If the Id field type is different than a Guid, and/or it is not read only in the data table, then you will need to add a converter to convert the type to a Guid. This case holds true for Resources and Appointments.
If Id is read only in the data set, then the Scheduler will rely on the way the data set handles read only Id's.
- Create a methods with the following signatures
CopyXML
object ConvertUniqueIdToScheduler(object obj)
{
return new EventId(obj);
}
object ConvertUniqueIdToDataSource(object obj)
{
EventId eventId = obj as EventId;
//if the appointment is added from the scheduler the eventId.KeyValue is Guid
if (eventId.KeyValue is Guid)
{
//return the value that is in your object/dataset
}
//if the appointment is loaded from an object/dataset the eventId.KeyValue is its representation in the object/datase
return eventId.KeyValue;
}
CopyXML
Function ConvertUniqueIdToScheduler(obj As Object) As Object
Return New EventId(obj)
End Function
Function ConvertUniqueIdToDataSource(obj As Object) As Object
Dim eventId As EventId = TryCast(obj, EventId)
'if the appointment is added from the scheduler the eventId.KeyValue is Guid
'return the value that is in your object/dataset
If TypeOf eventId.KeyValue Is Guid Then
End If
'if the appointment is loaded from an object/dataset the eventId.KeyValue is its representation in the object/datase
Return eventId.KeyValue
End Function
- Apply the settings of the UniqueId mapping in the AppointmentMappingInfo:
CopyXML
SchedulerMapping uniqueIdSchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("UniqueId");
uniqueIdSchedulerMapping.ConvertToScheduler = new ConvertCallback(this.ConvertUniqueIdToScheduler);
uniqueIdSchedulerMapping.ConvertToDataSource = new ConvertCallback(this.ConvertUniqueIdToDataSource);
CopyXML
Dim uniqueIdSchedulerMapping As SchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("UniqueId")
uniqueIdSchedulerMapping.ConvertToScheduler = New ConvertCallback(Me.ConvertUniqueIdToScheduler)
uniqueIdSchedulerMapping.ConvertToDataSource = New ConvertCallback(Me.ConvertUniqueIdToDataSource)