Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data.SqlClient
Imports System.Web.Script.Serialization
Imports System.Web.Script.Services
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class GetEvents
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
''''''''' TOCH DUIDELIJK RESPONSEFORMAT = JSON, NIET ???
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function GetEvents() As List(Of CalendarEvent)
'ByVal d_start As String, ByVal d_end As String, ByVal dummy As String
Dim ds As New DataSet
Dim sqlCmd As New SqlCommand
Dim strSql As String = ""
strSql = "select id,title,d_start,d_end,allday,url from tblcalendar"
sqlCmd.CommandText = strSql
ds = DAL.ExecQuery(sqlCmd)
Dim temp As String = ""
Dim strDum As String = ""
Dim ubound As Integer = ds.Tables(0).Rows.Count - 1
Dim lstCalendarEvent As New List(Of CalendarEvent)
' Create a multidimensional jagged array
Dim JaggedArray As String()() = New String(ds.Tables(0).Rows.Count - 1)() {}
Dim i As Integer = 0
For Each rs As DataRow In ds.Tables(0).Rows
Select Case True
Case rs("allday") = True
temp = "true"
Case rs("allday") = False
temp = "false"
Case Else
temp = "false"
End Select
Dim calevt As New CalendarEvent
calevt.d_start = "new Date(" & rs("d_start") & ")"
calevt.d_end = "new Date(" & rs("d_end") & ")"
calevt.allDay = CBool(temp)
calevt.title = rs("title").ToString()
lstCalendarEvent.Add(calevt)
calevt = Nothing
'strDum = lstCalendarEvent(1).id & " " & lstCalendarEvent(1).title & " " & lstCalendarEvent(1).d_start & " " & lstCalendarEvent(1).d_end
'strDum += "/// " & vbCrLf
JaggedArray(i) = New String() {rs("title").ToString(), rs("d_start").ToString(), rs("d_end").ToString(), temp}
i = i + 1
Next
'Return lstCalendarEvent()
' Return JSON data
Dim js As New JavaScriptSerializer()
Dim strJSON As String = js.Serialize(lstCalendarEvent)
'tijdelijke oplossing?
'strJSON = strJSON.Replace("""""new Date", "new Date")
'strJSON = strJSON.Replace("0)""""", "0)")
Return lstCalendarEvent
'Dim strT As String = ""
'strT = "[{'id':null,'title':'testje','allDay':false,'d_start': new Date(2010,5,30,12,0),'d_end': new Date(2010,5,30,13,0),'url':null,'className':null,'editable':false,'source':null},{'id':null,'title':'testje2','allDay':false,'d_start': new Date(2010,5,30,14,0),'d_end': new Date(2010,5,30,15,0),'url':null,'className':null,'editable':false,'source':null},{'id':null,'title':'testje3','allDay':false,'d_start': new Date(2010,6,6,12,0),'d_end': new Date(2010,6,6,15,0),'url':null,'className':null,'editable':false,'source':null}]"
'Return strT
'Return "[{ title: 'testje', start: new Date(2010,5,30,12,0), end: new Date(2010,5,30,13,0), allDay : false},{ title: 'testje2', start: new Date(2010,5,28,12,0), end: new Date(2010,5,28,12,0), allDay: false}]"
End Function
End Class