Imports System.Data |
Imports Telerik.Web.UI |
Imports System.Data.SqlClient |
|
Partial Class UserControls_EventsCalendar |
Inherits System.Web.UI.UserControl |
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load |
|
BindCalData() |
|
End Sub |
Protected Sub BindCalData() |
Dim strResult As String = "" |
If Not IsPostBack Then |
Dim eventManager As New Telerik.Events.EventsManager("Events") |
Dim fromDate As New DateTime |
fromDate = Today.AddDays(-1).Date |
Dim toDate As New DateTime |
toDAte = Today.AddYears(100).Date |
' get all events starting yesterday and sorted by startDate |
Dim listOfEvents As IList = eventManager.GetEvents(fromDate, toDate, "[Start] ASC") |
|
If (listOfEvents.Count > 0) Then |
Dim calDate As DateTime = Nothing |
Dim evTitle As String = "" |
|
' read data and assign to cells |
Dim int As Integer = 1 |
For Each eventItem As Telerik.Events.IEvent In listOfEvents |
If IsDBNull(eventItem.Start) = False Then |
calDate = CDate(eventItem.Start) |
evTitle = eventItem.EventTitle |
Dim NewDay As New RadCalendarDay(RadCalendar1) |
NewDay.[Date] = New DateTime(calDate.Year, calDate.Month, calDate.Day) |
NewDay.Repeatable = Calendar.RecurringEvents.None |
|
NewDay.TemplateID = "dayTemplate1" |
NewDay.ToolTip = evTitle |
NewDay.ItemStyle.BackColor = Drawing.Color.AliceBlue |
NewDay.ItemStyle.BorderStyle = BorderStyle.Solid |
NewDay.ItemStyle.BorderWidth = 1 |
NewDay.ItemStyle.BorderColor = Drawing.Color.Blue |
RadCalendar1.SpecialDays.Add(NewDay) |
int = int + 1 |
End If |
|
Next |
|
End If |
RadCalendar1.SelectedDate = Today |
|
End If |
|
End Sub |
Protected Sub cmdSelectionChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.SelectedDatesEventArgs) Handles RadCalendar1.SelectionChanged |
' BindCalData() |
|
End Sub |
|
Protected Sub cmdDayRender(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.DayRenderEventArgs) Handles RadCalendar1.DayRender |
Dim renderedDay As String = e.Day.Date.AddDays(1).Day.ToString |
Dim myTemplate As DayTemplate |
myTemplate = RadCalendar1.CalendarDayTemplates.Item("dayTemplate1") |
Dim pubDate As String = "" |
Dim titleUrl As String = "" |
|
If Not myTemplate Is Nothing Then |
Dim eventManager As New Telerik.Events.EventsManager("Events") |
Dim fromDate As New DateTime |
fromDate = Today.AddDays(-1).Date |
Dim toDate As New DateTime |
toDate = Today.AddYears(100).Date |
' get all events starting yesterday and sorted by startDate |
Dim listOfEvents As IList = eventManager.GetEvents(fromDate, toDate, "[Start] ASC") |
|
Dim myLink As HyperLink = Nothing |
For Each ctr As Control In RadCalendar1.Controls |
myLink = DirectCast(ctr.FindControl("lnkEvent"), HyperLink) |
If Not myLink Is Nothing Then |
If (listOfEvents.Count > 0) Then |
For Each eventItem As Telerik.Events.IEvent In listOfEvents |
If CDate(eventItem.Start).Date.ToShortDateString = e.Day.Date.AddDays(1).ToShortDateString Then |
pubDate = CDate(eventItem.ContentItem.DateCreated).Date.Year.ToString & "-" & CDate(eventItem.ContentItem.DateCreated).Date.Month.ToString("D2") & "-" & CDate(eventItem.ContentItem.DateCreated).Date.Day.ToString("D2") |
If pubDate.Length > 0 Then |
pubDate = Mid(pubDate, 3) |
End If |
|
titleUrl = eventItem.EventTitle |
|
titleUrl = Replace(Replace(titleUrl, "'", "_"), "’", "_") |
titleUrl = Replace(titleUrl, " ", "_") |
titleUrl = Replace(titleUrl, "__", "_") |
titleUrl = System.Text.RegularExpressions.Regex.Replace(titleUrl, "[^\w\.-]", "") |
Exit For |
End If |
Next |
End If |
|
|
myLink.Text = renderedDay |
myLink.NavigateUrl = "~/it/eventi/" & pubDate & "/" & titleUrl & ".aspx?Events=EventItem" |
End If |
Next |
|
End If |
End Sub |
End Class |
|