Completed
Last Updated: 30 May 2017 08:21 by ADMIN
ADMIN
Hristo
Created on: 29 Nov 2016 08:08
Category: Scheduler/Reminder
Type: Bug Report
1
FIX. RadScheduler - SchedulerDailyPrintStyle and SchedulerWeeklyCalendarPrintStyle assign incorrect date to all of the print cell elements which are being created
How to reproduce:

Public Class Form1
    Sub New()

        InitializeComponent()

    End Sub

    Protected Overrides Sub OnLoad(e As EventArgs)
        MyBase.OnLoad(e)

        Me.SetUpScheduler()

        For i As Integer = 0 To 0
            Dim app As New Appointment(DateTime.Now.AddHours(1), TimeSpan.FromMinutes(60), "Summary" & i, "Description1")
            app.ResourceId = Me.RadScheduler1.Resources(i).Id
            Me.RadScheduler1.Appointments.Add(app)

            Dim app2 As New Appointment(DateTime.Now.AddHours(3), TimeSpan.FromMinutes(60), "Summary" & i, "Description2")
            app2.BackgroundId = 2
            app2.ResourceId = Me.RadScheduler1.Resources(i).Id
            Me.RadScheduler1.Appointments.Add(app2)

            Dim recurringAppointment As New Appointment(DateTime.Now, TimeSpan.FromMinutes(60), "Recurring" & i, "Recurring Appointment")
            recurringAppointment.BackgroundId = 4
            recurringAppointment.ResourceId = Me.RadScheduler1.Resources(i).Id
            recurringAppointment.RecurrenceRule = New DailyRecurrenceRule(DateTime.Now, 1, 10)

            Me.RadScheduler1.Appointments.Add(recurringAppointment)
        Next

        'AddHandler Me.RadScheduler1.CellPrintElementFormatting, AddressOf RadScheduler1_CellPrintElementFormatting

    End Sub

    Private Sub SetUpScheduler()
        Dim colors As Color() = New Color() {Color.LightBlue, Color.LightGreen, Color.LightYellow, Color.Red, Color.Orange, Color.Pink, _
            Color.Purple, Color.Peru, Color.PowderBlue}

        'Dim names As String() = New String() {"Alan Smith", "Anne Dodsworth", "Boyan Mastoni", "Richard Duncan", "Maria Schneider"}
        Dim names As String() = New String() {"Rick Astley"}

        For i As Integer = 0 To names.Length - 1
            Dim resource As New Resource()
            resource.Id = New EventId(i)
            resource.Name = names(i)
            resource.Color = colors(i)
            Me.RadScheduler1.Resources.Add(resource)
        Next

        Me.RadScheduler1.ActiveView.ResourcesPerView = 1
        Me.RadScheduler1.GroupType = GroupType.Resource

        Me.RadSchedulerNavigator1.SchedulerNavigatorElement.TimeZonesElementLayout.Visibility = ElementVisibility.Collapsed
        Me.RadSchedulerNavigator1.ShowWeekendCheckBox.Visibility = ElementVisibility.Collapsed
        Me.RadSchedulerNavigator1.SchedulerNavigatorElement.MonthViewButton.Visibility = ElementVisibility.Collapsed
        Me.RadSchedulerNavigator1.SchedulerNavigatorElement.TimelineViewButtonVisible = False
    End Sub

    Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
        Me.PrintScheduler(Me.RadScheduler1)
    End Sub

    Private Sub PrintScheduler(radScheduler As RadScheduler)
        Dim doc As RadPrintDocument = New RadPrintDocument
        doc.AssociatedObject = radScheduler

        Dim schedulerPrintStyle As Telerik.WinControls.UI.SchedulerPrintStyle = Nothing
        Select Case Me.RadScheduler1.ActiveViewType
            Case SchedulerViewType.Day
                schedulerPrintStyle = New SchedulerDailyPrintStyle()
                'schedulerPrintStyle = New CustomRadSchedulerDailyPrintStyle()
            Case SchedulerViewType.Week, SchedulerViewType.WorkWeek
                schedulerPrintStyle = New SchedulerWeeklyCalendarPrintStyle()
                'schedulerPrintStyle = New CustomSchedulerWeeklyCalendarPrintStyle()
        End Select

        schedulerPrintStyle.DateStartRange = radScheduler.ActiveView.StartDate
        schedulerPrintStyle.DateEndRange = radScheduler.ActiveView.EndDate
        schedulerPrintStyle.TimeStartRange = TimeSpan.FromMinutes(5)
        schedulerPrintStyle.TimeEndRange = TimeSpan.FromHours(23).Add(TimeSpan.FromMinutes(59))
        schedulerPrintStyle.AppointmentFont = New Font("Consolas", 8.5)
        schedulerPrintStyle.GroupType = SchedulerPrintGroupType.Resource



        AddHandler schedulerPrintStyle.CellElementFormatting, AddressOf radSchedWork_PrintSchedulerCellElementFormatting

        radScheduler.PrintStyle = schedulerPrintStyle
        radScheduler.PrintPreview()
    End Sub

    Private Sub radSchedWork_PrintSchedulerCellElementFormatting(sender As Object, e As PrintSchedulerCellEventArgs)
        e.CellElement.BackColor = Color.White
        e.CellElement.DrawFill = False

        Dim cell As SchedulerPrintCellElement = TryCast(e.CellElement, SchedulerPrintCellElement)
        If cell IsNot Nothing Then
            Dim msg As String = "PrintSchedulerCellElementFormatting for Date {0}"
            Debug.Print(String.Format(msg, e.CellElement.Date))

            'If cell.DateFormat = "hh:mm" Then
            '    cell.DateFormat = "hh:mm tt"
            'ElseIf cell.DateFormat = "dd MMM" Then
            '    cell.DateFormat = "dd ddd"
            'Else


            e.CellElement.DrawFill = True
            If e.CellElement.[Date].Hour Mod 2 = 0 Then
                If e.CellElement.[Date].Day Mod 2 = 0 Then
                    e.CellElement.BackColor = Color.LightSalmon
                Else
                    e.CellElement.BackColor = Color.LightBlue
                End If

            Else
                e.CellElement.BackColor = Color.LightGreen
            End If
            'End If
        End If
    End Sub

    Private Sub RadScheduler1_CellFormatting(sender As Object, e As SchedulerCellEventArgs) Handles RadScheduler1.CellFormatting
        'reset all properties for cells that may be changed here
        e.CellElement.BackColor = Color.White
        e.CellElement.DrawFill = False

        If e.CellElement.[Date].Hour Mod 2 = 0 Then
            e.CellElement.DrawFill = True

            If e.CellElement.[Date].Day Mod 2 = 0 Then
                e.CellElement.BackColor = Color.LightSalmon
            Else
                e.CellElement.BackColor = Color.LightBlue
            End If

        Else
            e.CellElement.BackColor = Color.LightGreen
        End If
    End Sub
End Class

Workaround: Private Sub PrintScheduler(radScheduler As RadScheduler)
    Dim doc As RadPrintDocument = New RadPrintDocument
    doc.AssociatedObject = radScheduler

    Dim schedulerPrintStyle As Telerik.WinControls.UI.SchedulerPrintStyle = Nothing
    Select Case Me.RadScheduler1.ActiveViewType
        Case SchedulerViewType.Day
            'schedulerPrintStyle = New SchedulerDailyPrintStyle()
            schedulerPrintStyle = New CustomRadSchedulerDailyPrintStyle()
        Case SchedulerViewType.Week, SchedulerViewType.WorkWeek
            'schedulerPrintStyle = New SchedulerWeeklyCalendarPrintStyle()
            schedulerPrintStyle = New CustomSchedulerWeeklyCalendarPrintStyle()
    End Select

    schedulerPrintStyle.DateStartRange = radScheduler.ActiveView.StartDate
    schedulerPrintStyle.DateEndRange = radScheduler.ActiveView.EndDate
    schedulerPrintStyle.TimeStartRange = TimeSpan.FromMinutes(5)
    schedulerPrintStyle.TimeEndRange = TimeSpan.FromHours(23).Add(TimeSpan.FromMinutes(59))
    schedulerPrintStyle.AppointmentFont = New Font("Consolas", 8.5)
    schedulerPrintStyle.GroupType = SchedulerPrintGroupType.Resource



    AddHandler schedulerPrintStyle.CellElementFormatting, AddressOf radSchedWork_PrintSchedulerCellElementFormatting

    radScheduler.PrintStyle = schedulerPrintStyle
    radScheduler.PrintPreview()
End Sub

Public Class CustomRadSchedulerDailyPrintStyle
    Inherits SchedulerDailyPrintStyle

    Private currentPage As Integer

    Public Overrides Sub DrawPage(graphics As Graphics, drawingArea As Rectangle, pageNumber As Integer)
        Me.currentPage = pageNumber
        MyBase.DrawPage(graphics, drawingArea, pageNumber)

    End Sub

    Protected Overrides Sub DrawCells(appArea As Rectangle, graphics As Graphics)

        Dim currentDate = Me.GetPageDate(Me.currentPage)
        Dim rowCount As Single = Math.Max(1, CInt(Math.Ceiling((TimeEndRange - TimeSpan.FromHours(TimeStartRange.Hours)).TotalHours)))
        Dim rowHeight As Single = CSng(appArea.Height) / rowCount

        For row As Integer = 0 To rowCount - 1
            Dim headerCellRect As New RectangleF(appArea.X, appArea.Y + row * rowHeight, Me.HoursColumnWidth, rowHeight)

            Dim element As New SchedulerPrintCellElement()
            element.DrawBorder = True
            element.Font = Me.DateHeadingFont
            element.[Date] = currentDate.AddHours(CInt(TimeStartRange.Add(TimeSpan.FromHours(row)).TotalHours))
            element.DateFormat = "hh:mm"
            element.TextAlignment = ContentAlignment.TopRight

            Me.DrawCell(element, graphics, headerCellRect)

            element.DrawText = False

            Dim numberOfSubRows As Integer = 1

            If Me.Scheduler.ActiveViewType = SchedulerViewType.Day OrElse Me.Scheduler.ActiveViewType = SchedulerViewType.MultiDay OrElse Me.Scheduler.ActiveViewType = SchedulerViewType.Week OrElse Me.Scheduler.ActiveViewType = SchedulerViewType.WorkWeek Then
                numberOfSubRows = 60 / CInt(DirectCast(Me.Scheduler.ActiveView, SchedulerDayViewBase).RangeFactor)
            End If

            For i As Integer = 0 To numberOfSubRows - 1
                Dim rect As New RectangleF(appArea.X + HoursColumnWidth, appArea.Y + row * rowHeight + rowHeight / numberOfSubRows * i, appArea.Width - HoursColumnWidth, rowHeight / numberOfSubRows)

                If i = numberOfSubRows - 1 Then
                    rect.Height += (appArea.Y + (row + 1) * rowHeight) - (rect.Y + rect.Height)
                End If

                Me.DrawCell(element, graphics, rect)
            Next
        Next
    End Sub

End Class

Public Class CustomSchedulerWeeklyCalendarPrintStyle
    Inherits SchedulerWeeklyCalendarPrintStyle

    Protected Overrides Sub DrawCells(appArea As RectangleF, graphics As Graphics, pageNumber As Integer)
        Dim days As Integer = Me.GetNumberOfDays(pageNumber)
        Dim currentDate As DateTime = Me.GetPageDate(pageNumber)
        If Me.TwoPagesPerWeek AndAlso pageNumber Mod 2 = 0 Then
            'page numbers are 1-based
            currentDate = currentDate.AddDays(Me.GetNumberOfDays(pageNumber - 1))
        End If

        Dim rowCount As Single = Math.Max(1, CInt(Math.Ceiling((TimeEndRange - TimeSpan.FromHours(TimeStartRange.Hours)).TotalHours)))
        Dim rowHeight As Single = CSng(appArea.Height) / rowCount
        Dim columnWidth As Single = (appArea.Width - Me.HoursColumnWidth) / CSng(days)

        For row As Integer = 0 To rowCount - 1
            Dim headerCellRect As New RectangleF(appArea.X, appArea.Y + row * rowHeight, Me.HoursColumnWidth, rowHeight)

            Dim element As New SchedulerPrintCellElement()
            element.DrawBorder = True
            element.Font = Me.DateHeadingFont
            element.[Date] = DateTime.Today.AddHours(CInt(TimeStartRange.Add(TimeSpan.FromHours(row)).TotalHours))
            element.[Date] = currentDate.AddHours(CInt(TimeStartRange.Add(TimeSpan.FromHours(row)).TotalHours))
            element.DateFormat = "hh:mm"
            element.TextAlignment = ContentAlignment.TopRight

            Me.DrawCell(element, graphics, headerCellRect)

            element.DrawText = False

            Dim numberOfSubRows As Integer = 60 / CInt(DirectCast(Me.Scheduler.ActiveView, SchedulerDayViewBase).RangeFactor)

            For i As Integer = 0 To numberOfSubRows - 1
                Dim rect As New RectangleF(appArea.X + HoursColumnWidth, appArea.Y + row * rowHeight + rowHeight / numberOfSubRows * i, appArea.Width - HoursColumnWidth, rowHeight / numberOfSubRows)

                If i = numberOfSubRows - 1 Then
                    rect.Height += (appArea.Y + (row + 1) * rowHeight) - (rect.Y + rect.Height)
                End If

                Me.DrawCell(element, graphics, rect)
            Next

            For j As Integer = 0 To days - 1
                element = New SchedulerPrintCellElement()
                element.DrawBorder = True
                element.DrawText = False
                element.[Date] = currentDate.AddDays(j).AddHours(CInt(TimeStartRange.Add(TimeSpan.FromHours(row)).TotalHours))
                Dim rect As New RectangleF(appArea.X + HoursColumnWidth + j * columnWidth, appArea.Y + row * rowHeight, columnWidth, rowHeight)

                Me.DrawCell(element, graphics, rect)
            Next
        Next
    End Sub

End Class
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments