vb.net coding:
CODE
Imports System.Data.OleDb
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
' Generates report for current year
lblCalendar.Text = "<table width='600px'>"
Dim horizontalRepeat As Integer = 3 ' number of months in horizontal direction
Dim month As Integer
For month = 1 To 12
If (month Mod horizontalRepeat = 1) Then
lblCalendar.Text += "<tr valign='top'>"
End If
lblCalendar.Text += "<td>" + generateCalendar(month, 2007) + "</td>"
If (month Mod horizontalRepeat = 0) Then
lblCalendar.Text += "</tr>"
End If
Next
lblCalendar.Text += "</table>"
End If
End Sub
Private Function generateCalendar(ByVal month As Integer, ByVal year As Integer) As String
' generates the calendar as per the booking status
Dim wholeCalendar(5, 6) As Integer
Dim weeks As Integer = 0
Dim day As String = ""
Dim tmpDate As DateTime
Dim myDate As Integer
For myDate = 1 To 31
Try
tmpDate = New DateTime(year, month, myDate)
If (day = "Saturday") Then
weeks += 1
End If
day = tmpDate.DayOfWeek.ToString()
If (day = "Sunday") Then
'If (wholeCalendar(weeks, 0) > 0) Then weeks += 1
wholeCalendar(weeks, 0) = myDate
ElseIf (day = "Monday") Then
'If (wholeCalendar(weeks, 1) > 0) Then weeks += 1
wholeCalendar(weeks, 1) = myDate
ElseIf (day = "Tuesday") Then
'If (wholeCalendar(weeks, 2) > 0) Then weeks += 1
wholeCalendar(weeks, 2) = myDate
ElseIf (day = "Wednesday") Then
'If (wholeCalendar(weeks, 3) > 0) Then weeks += 1
wholeCalendar(weeks, 3) = myDate
ElseIf (day = "Thursday") Then
'If (wholeCalendar(weeks, 4) > 0) Then weeks += 1
wholeCalendar(weeks, 4) = myDate
ElseIf (day = "Friday") Then
'If (wholeCalendar(weeks, 5) > 0) Then weeks += 1
wholeCalendar(weeks, 5) = myDate
ElseIf (day = "Saturday") Then
'If (wholeCalendar(weeks, 6) > 0) Then weeks += 1
wholeCalendar(weeks, 6) = myDate
End If
Catch ex As Exception
Exit For
End Try
Next
' Generates the HTML calendar
Dim htmlCalendar As String = ""
Dim objEventsDAO As New EventsDAO()
Dim dt As DataTable
Dim i As Integer, j As Integer
htmlCalendar += "<table class='calendarFrame' cellspacing=0>"
htmlCalendar += "<tr class='calendarMonthYear' style='text-align: center;'><td colspan='7'>" + getMonthName(month) + " " + year.ToString() + "</td></tr>"
htmlCalendar += "<tr class='calendarDay' style='text-align: center;'> <td>Sun</td> <td>Mon</td> <td>Tue</td> <td>Wed</td> <td>Thu</td> <td>Fri</td> <td>Sat</td> </tr>"
For i = 0 To 5
htmlCalendar += "<tr>"
For j = 0 To 6
If wholeCalendar(i, j) > 0 Then
dt = objEventsDAO.GetEvent(wholeCalendar(i, j), month, year)
If (dt.Rows.Count > 0) Then
Dim toolTip As String = dt.Rows(0)("Event").ToString()
htmlCalendar += "<td class='hasEvent' title=""" + toolTip + """>" + wholeCalendar(i, j).ToString() + "</td>"
Else
htmlCalendar += "<td class='hasNoEvent'>" + wholeCalendar(i, j).ToString() + "</td>"
End If
Else
htmlCalendar += "<td class='hasNoEvent'> </td>"
End If
Next
htmlCalendar += "</tr>"
Next
htmlCalendar += "</table>"
' Close database connection
objEventsDAO.CloseConnection()
' returns the generated HTML calendar
Return htmlCalendar
End Function
Private Function getMonthName(ByVal month As Integer) As String
Dim months() As String = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
Return months(month - 1)
End Function
End Class