Posted
on Feb 20, 2012
(permalink)
Hi Plamen Zdravkov,
I am using that code. but the appointment not display into scheduler. but the select query got record and return appointment but not display into scheduler. please check and let me know,
Please check the code,
aspx
------
<telerik:RadScriptBlock ID="rsbScript" runat="server">
<script type="text/javascript">
//<![CDATA[
var categoryNames = new Array();
function OnClientAppointmentsPopulating(sender, eventArgs) {
//addSelectedCategoriesToArray(categoryNames);
eventArgs.get_schedulerInfo().CategoryNames = categoryNames;
categoryNames = new Array(); //clear the array
}
function OnClientAppointmentWebServiceInserting(sender, args) {
//set a default Calendar resource
if (args.get_appointment().get_resources().get_count() == 0) {
var defaultCalendarResource = sender.get_resources().getResourceByTypeAndKey("Calendar", 1);
args.get_appointment().get_resources().add(defaultCalendarResource);
}
}
function rebindScheduler() {
var scheduler = $find('<%=RadScheduler1.ClientID %>');
scheduler.rebind();
}
function onSchedulerDataBound(scheduler) {
var $ = jQuery;
$(".rsAptDelete").each(function () {
var apt = scheduler.getAppointmentFromDomElement(this);
// creating an object containing the data that should be applied on the template
var tmplValue = { Description: apt.get_description() };
// instantiate the template, populate it and insert before the delete handler (".rsAptDelete")
$("#tmplAppDescription").tmpl(tmplValue).insertBefore(this);
});
}
//]]>
</script>
</telerik:RadScriptBlock>
<form id="form1" runat="server">
<telerik:RadScriptManager runat="server" ID="RadScriptManager1">
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
<%--<asp:ScriptReference Path="Scripts/jquery.tmpl.js" />--%>
</Scripts>
</telerik:RadScriptManager>
<div>
<telerik:RadScheduler runat="server" ID="RadScheduler1" Skin="Windows7" Height="551px"
OnClientAppointmentWebServiceInserting="OnClientAppointmentWebServiceInserting"
OnClientAppointmentsPopulating="OnClientAppointmentsPopulating"
SelectedView="MonthView" ShowFooter="false" SelectedDate="2012-02-15" TimeZoneOffset="03:00:00"
DayStartTime="08:00:00" DayEndTime="21:00:00" FirstDayOfWeek="Monday" LastDayOfWeek="Friday"
EnableDescriptionField="true" AppointmentStyleMode="Default">
<WebServiceSettings Path="WebServiceScheduler.asmx" ResourcePopulationMode="ServerSide" />
<AdvancedForm Modal="true" />
<TimelineView UserSelectable="false" />
<TimeSlotContextMenuSettings EnableDefault="true" />
<AppointmentContextMenuSettings EnableDefault="true" />
</telerik:RadScheduler>
</div>
<telerik:RadAjaxLoadingPanel ID="ralpScheduler" Style="position: absolute" runat="server">
</telerik:RadAjaxLoadingPanel>
</form>
webServiceScheduler.vb(webservice)
Imports System.Collections.Generic
Imports System.Web.Script.Services
Imports System.Web.Services
Imports Telerik.Web.UI
Imports System.Data.Common
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService()> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ScriptService()> _
Public Class WebServiceScheduler
Inherits System.Web.Services.WebService
Private _controller As WebServiceAppointmentController
''' <summary>
''' The WebServiceAppointmentController class is used as a facade to the SchedulerProvider.
''' </summary>
'''
Private _provider As MyDbSchedulerProvider
Private ReadOnly Property Provider() As MyDbSchedulerProvider
Get
If _provider Is Nothing Then
Dim connString = ConfigurationManager.ConnectionStrings("TelerikVSXConnectionString").ConnectionString
Dim factory = DbProviderFactories.GetFactory("System.Data.SqlClient")
_provider = New MyDbSchedulerProvider() With { _
.ConnectionString = connString, _
.DbFactory = factory, _
.PersistChanges = True _
}
End If
Return _provider
End Get
End Property
Private ReadOnly Property Controller() As WebServiceAppointmentController
Get
If _controller Is Nothing Then
_controller = New WebServiceAppointmentController(Provider)
End If
Return _controller
End Get
End Property
<WebMethod()> _
Public Function GetAppointments(ByVal schedulerInfo As SchedulerInfo) As IEnumerable(Of AppointmentData)
Return Controller.GetAppointments(schedulerInfo)
End Function
Class File - App_code/MyDbSchedulerProvider.vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data.Common
Imports System.Data.SqlClient
Imports Telerik.Web.UI
Public Class MyDbSchedulerProvider
Public Overrides Function GetAppointments(ByVal shedulerInfo As ISchedulerInfo) As IEnumerable(Of Appointment)
Dim appointments As New List(Of Appointment)()
Using conn As DbConnection = OpenConnection()
Dim cmd As DbCommand = DbFactory.CreateCommand()
cmd.Connection = conn
cmd.CommandText = "SELECT [ClassID], [Subject], [Start], [End], [RecurrenceRule], [RecurrenceParentId], [Reminder], [Description], [AppointmentColor] FROM [DbProvider_Classes]"
Using reader As DbDataReader = cmd.ExecuteReader()
While reader.Read()
Dim apt As New Appointment()
'apt.Owner = owner;
apt.ID = reader("ClassID")
apt.Subject = Convert.ToString(reader("Subject"))
apt.Description = Convert.ToString(reader("Description"))
apt.Attributes("AppointmentColor") = Convert.ToString(reader("AppointmentColor"))
apt.Start = DateTime.SpecifyKind(Convert.ToDateTime(reader("Start")), DateTimeKind.Utc)
apt.[End] = DateTime.SpecifyKind(Convert.ToDateTime(reader("End")), DateTimeKind.Utc)
apt.RecurrenceRule = Convert.ToString(reader("RecurrenceRule"))
apt.RecurrenceParentID = If(reader("RecurrenceParentId") Is DBNull.Value, Nothing, reader("RecurrenceParentId"))
If Not reader("Reminder") Is DBNull.Value Then
Dim reminders As IList(Of Reminder) = Reminder.TryParse(Convert.ToString(reader("Reminder")))
If reminders IsNot Nothing Then
apt.Reminders.AddRange(reminders)
End If
End If
If apt.RecurrenceParentID IsNot Nothing Then
apt.RecurrenceState = RecurrenceState.Exception
ElseIf apt.RecurrenceRule <> String.Empty Then
apt.RecurrenceState = RecurrenceState.Master
End If
'LoadResources(apt)
appointments.Add(apt)
End While
End Using
End Using
Return appointments
End Function
End Class
Thanks,
Dhamu.