This is a migrated thread and some comments may be shown as answers.

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.

7 Answers 191 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Devang
Top achievements
Rank 1
Devang asked on 13 Aug 2012, 06:40 AM
Hello,
I am using radgridview to display data,in the gird i have EDIT imagebutton when i click on it  row will be edited in seprate textboxes which is  outside of the grid.
on some rows edit operations is working good and on some rows it gives me an error:

                Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException:
                         The message received from the  server could not be parsed.
Thank You
Devang Tadvi

7 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 15 Aug 2012, 12:12 PM
Hello,

Try to disable the Ajax of the page by using the EnableAjax property of the RadAjaxManager or the RadAjaxPanel control to False and check where the exception will be raised.

Additionally, share your complete page source code along with the code-behind file content. Thus all the people who want to help you will have better understanding of you project.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Allen
Top achievements
Rank 1
answered on 20 Nov 2012, 03:52 PM
After I upgrade to the latest version, I'm haveing a similar issue.   When I adjust the appointments on scheduler, it errors out.
error:  Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.

Here is my codes:

Imports System.IO
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Configuration
Imports System.Web.Security
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Telerik.Web.UI
Imports System.Drawing
Imports System.Xml
Imports MSPBusinessLogic
Imports MSPMsgMgr
Imports System
Partial Class MyAvailability
    Inherits System.Web.UI.Page

    'de-compress view state
    Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object
        Dim pageStatePersister1 As System.Web.UI.PageStatePersister = Me.PageStatePersister
        pageStatePersister1.Load()
        Dim vState As String = pageStatePersister1.ViewState.ToString
        Dim pBytes() As Byte = System.Convert.FromBase64String(vState)
        pBytes = ViewStateCompDecomp.Decompress(pBytes)
        Dim mFormat As LosFormatter = New LosFormatter
        Dim ViewState As Object = mFormat.Deserialize(System.Convert.ToBase64String(pBytes))
        Return New Pair(pageStatePersister1.ControlState, ViewState)
    End Function

    'compress view state
    Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal pViewState As Object)
        Dim pair1 As Pair
        Dim pageStatePersister1 As System.Web.UI.PageStatePersister = Me.PageStatePersister
        Dim ViewState As Object
        If (TypeOf pViewState Is Pair) Then
            pair1 = CType(pViewState, Pair)
            pageStatePersister1.ControlState = pair1.First
            ViewState = pair1.Second
        Else
            ViewState = pViewState
        End If
        Dim mFormat As LosFormatter = New LosFormatter
        Dim mWriter As StringWriter = New StringWriter
        mFormat.Serialize(mWriter, ViewState)
        Dim mViewStateStr As String = mWriter.ToString
        Dim pBytes() As Byte = System.Convert.FromBase64String(mViewStateStr)
        pBytes = ViewStateCompDecomp.Compress(pBytes)
        Dim vStateStr As String = System.Convert.ToBase64String(pBytes)
        pageStatePersister1.ViewState = vStateStr
        pageStatePersister1.Save()
    End Sub

    Private Class CustomAppointmentComparer
        Implements IComparer(Of Appointment)
        Public Function Compare(first As Appointment, second As Appointment) As Integer Implements IComparer(Of Telerik.Web.UI.Appointment).Compare
            Dim infoStart1 As String = first.Start.ToString
            Dim infoend1 As String = first.End.ToString
            Dim infoStar2 As String = second.Start.ToString
            Dim infoend2 As String = second.End.ToString
            If first Is Nothing OrElse second Is Nothing Then
                Throw New InvalidOperationException("Can't compare null Appointment object(s).")
            End If

            If [String].Compare(first.Subject.ToString, second.Subject.ToString) < 0 Then
                Return -1
            End If

            If [String].Compare(first.Subject.ToString, second.Subject.ToString) > 0 Then
                Return 1
            End If

            Return 0
        End Function
    End Class

    Protected Overrides Sub OnInit(e As EventArgs)
        MyBase.OnInit(e)
        'RadScheduler1.Provider = New XmlSchedulerProvider(Server.MapPath("~/MyAvailability/App_Data/Appointments.xml"), True)
        'RadScheduler1.Provider = New XmlSchedulerProvider(Server.MapPath("~/App_Data/Appointments_CustomTemplates.xml"), True)

    End Sub

    Protected Sub RadScheduler1_AppointmentDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.SchedulerEventArgs) Handles RadScheduler1.AppointmentDataBound
        e.Appointment.CssClass = "MyCustomAppointmentStyle"

        If e.Appointment.Subject = "available" Then
            'e.Appointment.CssClass = "•rsCategoryYellow"
            e.Appointment.BackColor = System.Drawing.Color.FromName("#FEEDA9")
        End If

        If e.Appointment.Subject = "preferred" Then
            'e.Appointment.CssClass = "•rsCategoryGreen"
            e.Appointment.BackColor = System.Drawing.Color.FromName("#D0ECBB")
        End If

        If e.Appointment.Subject = "unavailable" Then
            e.Appointment.Visible = False
        End If

        ''Cust
        Dim colorAttribute As String = e.Appointment.Attributes("AppointmentColor")
        If Not String.IsNullOrEmpty(colorAttribute) Then
            Dim colorValue As Integer
            If Integer.TryParse(colorAttribute, colorValue) Then
                Dim borderColorValue As Integer = CInt(If(colorValue < -&H7F7F7F, colorValue + &H202020, colorValue - &H202020))
                e.Appointment.BackColor = Color.FromArgb(colorValue)
                e.Appointment.BorderColor = Color.FromArgb(borderColorValue)
            End If
        End If
        'e.Appointment.ToolTip = e.Appointment.Subject + ": " + e.Appointment.Description

    End Sub

    Protected Sub RadScheduler1_AppointmentCreated(sender As Object, e As AppointmentCreatedEventArgs) Handles RadScheduler1.AppointmentCreated

        'If e.Appointment.Subject = "available" Then
        '    e.Appointment.CssClass = "•rsCategoryYellow"
        'End If

        'If e.Appointment.Subject = "preferred" Then
        '    e.Appointment.CssClass = "•rsCategoryGreen"
        'End If

        If e.Appointment.Subject = "available" Then
            e.Appointment.BackColor = System.Drawing.Color.FromName("#FEEDA9")
        End If

        If e.Appointment.Subject = "preferred" Then
            e.Appointment.BackColor = System.Drawing.Color.FromName("#D0ECBB")
        End If

        'If e.Appointment.Visible AndAlso Not IsAppointmentRegisteredForTooltip(e.Appointment) Then
        '    Dim id As String = e.Appointment.ID.ToString()

        '    For Each domElementID As String In e.Appointment.DomElements
        '        RadToolTipManager1.TargetControls.Add(domElementID, id, True)
        '    Next
        'End If
        ''Cust
        'If e.Appointment.RecurrenceState = RecurrenceState.Master OrElse e.Appointment.RecurrenceState = RecurrenceState.Occurrence Then
        '    Dim recurrenceStateDiv As New Panel()
        '    recurrenceStateDiv.CssClass = "rsAptRecurrence"
        '    e.Container.Controls.AddAt(0, recurrenceStateDiv)
        'End If
        'If e.Appointment.RecurrenceState = RecurrenceState.Exception Then
        '    Dim recurrenceStateDiv As New Panel()
        '    recurrenceStateDiv.CssClass = "rsAptRecurrenceException"
        '    e.Container.Controls.AddAt(0, recurrenceStateDiv)
        'End If

    End Sub

    'Rad Scheduler Appointments to bind to
    Private ReadOnly Property Appointments() As List(Of AppointmentInfo)
        Get
            Dim appFact As New AppointmentsFactory()
            Dim appointmentsList As List(Of AppointmentInfo)
            appointmentsList = appFact.getAppointmentsList()
            Return appointmentsList
        End Get
    End Property

    '' '' ''modal section
    '' '' ''Private Property _person As Person
    Public Shared sundayTempFlag As Boolean = False
    Public Shared mondayTempFlag As Boolean = False
    Public Shared tuesdayTempFlag As Boolean = False
    Public Shared wednesdayTempFlag As Boolean = False
    Public Shared thursdayTempFlag As Boolean = False
    Public Shared fridayTempFlag As Boolean = False
    Public Shared saturdayTempFlag As Boolean = False

    '' '' ''Private ReadOnly Property Appointments() As List(Of AppointmentInfo)
    '' '' ''    Get
    '' '' ''        Dim appFact As New AppointmentsFactory()
    '' '' ''        Dim appointmentsList As List(Of AppointmentInfo)
    '' '' ''        appointmentsList = appFact.getAppointmentsList()
    '' '' ''        Return appointmentsList
    '' '' ''    End Get
    '' '' ''End Property

    Private Property _person As Person
    Private mySessionMgr As SessionDataMgr
    Private cMymessage As MyMessages
    'TODO - get these from application settings
    Private Property _initialDispalyWeeksOut As Integer = 3
    Public newStartLabel As String = ""
    Public newEndLabel As String = ""
    Public dayOfWeek_Label As String = ""
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

        'object binding
        'get person
        Dim sessionDataManger As New SessionDataMgr()
        _person = sessionDataManger.getPerson()

        'Do not allow saving Avail Pattern if person is impersonated
        If Not IsNothing(sessionDataManger.getImpAssocNbr) Then
            Me.ButtonSaveAvailabilityChanges.Visible = False
        End If

        If Not IsPostBack Then
            InstantiateScheduleOptions()
            InstantiateScheduler()
        End If
        RadScheduler1.DataSource = Me.Appointments

        mySessionMgr = New SessionDataMgr()

        'Populate the My Messages ui for this page
        cMymessage = mySessionMgr.getMyMessages("AV")
        'cMymessage = "You have selected to be assigned 20-30 hours from December 9th - December 29th.  Please take the time now to update your availability and preference choices for these dates, and remember to expand your availability wherever possible so that you can be assigned the holiday range of hours."

        'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

        'RadToolTipManager1.OnClientRequestStart = "OnClientRequestStart"
        RadScheduler1.AppointmentComparer = New CustomAppointmentComparer()

        'If Not IsPostBack Then
        '    RulesReader()
        'End If
        'If Not IsPostBack Then
        '    'InstantiateScheduleOptions()
        '    'InstantiateScheduler()

        '    RadTextBoxScheduleOptionsDescription.Text = "- Select up to 4 mornings (shifts not assigned before 1pm) off (M-F) and" & vbCrLf & _
        '                                "- Select up to 4 evenings (shifts not assigned after 6 pm) off (M-Th) OR" & vbCrLf & _
        '                                "______________________________________________________________________________" & vbCrLf & _
        '                                "- Select up to 2 full days off (M-Th) by selecting a morning & evening on the same day and" & vbCrLf & _
        '                                "  Up to 1 additional morning & 1 additional evening off (not on same day)" & vbCrLf & _
        '                                " ______________________________________________________________________________" & vbCrLf & _
        '                                "" & vbCrLf & _
        '                                "On any Key Day, the system may override your Availability choices to support the business as needed." & vbCrLf & _
        '                                "Your preferences must follow the same work rules as your availability selections" & vbCrLf & _
        '                                "Your preferred time range must fall within the available time range."
        'End If

        formatUIMyMessages()

        '' '' ''Modal section

        Dim UserSelection As String = ""
        If Not Request.Form("EditPreference") Is Nothing Then
            ' buttonName was clicked
            UserSelection = "Preference"
        End If

        If Not IsPostBack Then
            'bind the coresponding time range to the timepickers
            Dim selecteddate As Date = Appointments.Item(1).StartDateTime.Date
            'Dim candidateDate = [Date]
            While selecteddate.DayOfWeek <> DayOfWeek.Sunday
                selecteddate = selecteddate.AddDays(-1)
            End While
            'Dim dayDiff As Integer = selecteddate.DayOfWeek - DayOfWeek.Sunday
            Dim sundayCurrent As Date = selecteddate
            Dim mondayCurrent As Date = selecteddate.AddDays(1)
            Dim tuesdayCurrent As Date = selecteddate.AddDays(2)
            Dim wednesdayCurrent As Date = selecteddate.AddDays(3)
            Dim thursdayCurrent As Date = selecteddate.AddDays(4)
            Dim fridayCurrent As Date = selecteddate.AddDays(5)
            Dim saturdayCurrent As Date = sundayCurrent.AddDays(6)
            Dim aCount As Integer = Appointments.Count
            For i = 0 To aCount - 1

                If Appointments.Item(i).StartDateTime.Date = sundayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    RadDateTimePickerSundayStart.SelectedDate = Appointments.Item(i).StartDateTime
                    RadDateTimePickerSundayEnd.SelectedDate = Appointments.Item(i).EndDateTime
                End If

                If Appointments.Item(i).StartDateTime.Date = mondayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    RadDateTimePickerMondayStart.SelectedDate = Appointments.Item(i).StartDateTime
                    RadDateTimePickerMondayEnd.SelectedDate = Appointments.Item(i).EndDateTime
                End If

                If Appointments.Item(i).StartDateTime.Date = tuesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    RadDateTimePickerTuesdayStart.SelectedDate = Appointments.Item(i).StartDateTime
                    RadDateTimePickerTuesdayEnd.SelectedDate = Appointments.Item(i).EndDateTime
                End If

                If Appointments.Item(i).StartDateTime.Date = wednesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    RadDateTimePickerWednesdayStart.SelectedDate = Appointments.Item(i).StartDateTime
                    RadDateTimePickerWednesdayEnd.SelectedDate = Appointments.Item(i).EndDateTime
                End If

                If Appointments.Item(i).StartDateTime.Date = thursdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    RadDateTimePickerThursdayStart.SelectedDate = Appointments.Item(i).StartDateTime
                    RadDateTimePickerThursdayEnd.SelectedDate = Appointments.Item(i).EndDateTime
                End If

                If Appointments.Item(i).StartDateTime.Date = fridayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    RadDateTimePickerFridayStart.SelectedDate = Appointments.Item(i).StartDateTime
                    RadDateTimePickerFridayEnd.SelectedDate = Appointments.Item(i).EndDateTime
                End If

                If Appointments.Item(i).StartDateTime.Date = saturdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    RadDateTimePickerSaturdayStart.SelectedDate = Appointments.Item(i).StartDateTime
                    RadDateTimePickerSaturdayEnd.SelectedDate = Appointments.Item(i).EndDateTime
                End If
            Next

            'add the DateTime to the dateTimePickers if there is no time range
            If RadDateTimePickerSundayStart.SelectedDate Is Nothing And RadDateTimePickerSundayEnd.SelectedDate Is Nothing Then
                RadDateTimePickerSundayStart.SelectedDate = sundayCurrent
                RadDateTimePickerSundayEnd.SelectedDate = sundayCurrent
                'RadDateTimePickerSundayStart.Visible = False
                'RadDateTimePickerSundayEnd.Visible = False
                sundayTempFlag = True
            End If
            If RadDateTimePickerMondayStart.SelectedDate Is Nothing And RadDateTimePickerMondayEnd.SelectedDate Is Nothing Then
                RadDateTimePickerMondayStart.SelectedDate = mondayCurrent
                RadDateTimePickerMondayEnd.SelectedDate = mondayCurrent
                'RadDateTimePickerMondayStart.de()
                mondayTempFlag = True
            End If
            If RadDateTimePickerTuesdayStart.SelectedDate Is Nothing And RadDateTimePickerTuesdayEnd.SelectedDate Is Nothing Then
                RadDateTimePickerTuesdayStart.SelectedDate = tuesdayCurrent
                RadDateTimePickerTuesdayEnd.SelectedDate = tuesdayCurrent
                tuesdayTempFlag = True
            End If
            If RadDateTimePickerWednesdayStart.SelectedDate Is Nothing And RadDateTimePickerWednesdayEnd.SelectedDate Is Nothing Then
                RadDateTimePickerWednesdayStart.SelectedDate = wednesdayCurrent
                RadDateTimePickerWednesdayEnd.SelectedDate = wednesdayCurrent
                wednesdayTempFlag = True
            End If
            If RadDateTimePickerThursdayStart.SelectedDate Is Nothing And RadDateTimePickerThursdayEnd.SelectedDate Is Nothing Then
                RadDateTimePickerThursdayStart.SelectedDate = thursdayCurrent
                RadDateTimePickerThursdayEnd.SelectedDate = thursdayCurrent
                thursdayTempFlag = True
            End If
            If RadDateTimePickerFridayStart.SelectedDate Is Nothing And RadDateTimePickerFridayEnd.SelectedDate Is Nothing Then
                RadDateTimePickerFridayStart.SelectedDate = fridayCurrent
                RadDateTimePickerFridayEnd.SelectedDate = fridayCurrent
                fridayTempFlag = True
            End If
            If RadDateTimePickerSaturdayStart.SelectedDate Is Nothing And RadDateTimePickerSaturdayEnd.SelectedDate Is Nothing Then
                RadDateTimePickerSaturdayStart.SelectedDate = saturdayCurrent
                RadDateTimePickerSaturdayEnd.SelectedDate = saturdayCurrent
                saturdayTempFlag = True
            End If
            'add the code to set the timepicker range
            For i = 0 To aCount - 1
                If Appointments.Item(i).StartDateTime.Date = sundayCurrent And Appointments.Item(i).Subject = "available" Then
                    Dim StartTimeAvail As DateTime
                    Dim EndTimeAvail As DateTime
                    StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                    EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                    Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                    Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                    RadDateTimePickerSundayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerSundayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                    RadDateTimePickerSundayEnd.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerSundayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                End If
                If Appointments.Item(i).StartDateTime.Date = mondayCurrent And Appointments.Item(i).Subject = "available" Then
                    Dim StartTimeAvail As DateTime
                    Dim EndTimeAvail As DateTime
                    StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                    EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                    Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                    Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                    RadDateTimePickerMondayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerMondayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                    RadDateTimePickerMondayEnd.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerMondayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                End If
                If Appointments.Item(i).StartDateTime.Date = tuesdayCurrent And Appointments.Item(i).Subject = "available" Then
                    Dim StartTimeAvail As DateTime
                    Dim EndTimeAvail As DateTime
                    StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                    EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                    Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                    Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                    RadDateTimePickerTuesdayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerTuesdayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                    RadDateTimePickerTuesdayEnd.TimeView.EndTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerTuesdayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                End If
                If Appointments.Item(i).StartDateTime.Date = wednesdayCurrent And Appointments.Item(i).Subject = "available" Then
                    Dim StartTimeAvail As DateTime
                    Dim EndTimeAvail As DateTime
                    StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                    EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                    Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                    Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                    RadDateTimePickerWednesdayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerWednesdayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                    RadDateTimePickerWednesdayEnd.TimeView.EndTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerWednesdayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                End If

                If Appointments.Item(i).StartDateTime.Date = fridayCurrent And Appointments.Item(i).Subject = "available" Then
                    Dim StartTimeAvail As DateTime
                    Dim EndTimeAvail As DateTime
                    StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                    EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                    Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                    Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                    RadDateTimePickerFridayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerFridayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                    RadDateTimePickerFridayEnd.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerFridayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                End If
                If Appointments.Item(i).StartDateTime.Date = saturdayCurrent And Appointments.Item(i).Subject = "available" Then
                    Dim StartTimeAvail As DateTime
                    Dim EndTimeAvail As DateTime
                    StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                    EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                    Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                    Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                    RadDateTimePickerSaturdayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerSaturdayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                    RadDateTimePickerSaturdayEnd.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                    RadDateTimePickerSaturdayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                End If
            Next

            'bind the coresponding time range to the radio buttons
            For i = 0 To aCount - 1
                If Appointments.Item(i).StartDateTime.Date = sundayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    Dim time As DateTime = DateTime.Now
                    Dim format As String = "t"
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                        RadioAllDaySunday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                            RadioMorningSunday.Checked = True
                        Else
                            If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                                RadioEveningSunday.Checked = True
                            Else
                                RadioOtherSunday.Checked = True
                                RadDateTimePickerSundayStart.Enabled = True
                                RadDateTimePickerSundayEnd.Enabled = True
                            End If
                        End If
                    End If
                End If
                If Appointments.Item(i).StartDateTime.Date = mondayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    Dim time As DateTime = DateTime.Now
                    Dim format As String = "t"
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                        RadioAllDayMonday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                            RadioMorningMonday.Checked = True
                        Else
                            If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                                RadioEveningMonday.Checked = True
                            Else
                                RadioOtherMonday.Checked = True
                                RadDateTimePickerMondayStart.Enabled = True
                                RadDateTimePickerMondayEnd.Enabled = True
                            End If
                        End If
                    End If
                End If
                If Appointments.Item(i).StartDateTime.Date = tuesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    Dim time As DateTime = DateTime.Now
                    Dim format As String = "t"
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                        RadioAllDayTuesday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                            RadioMorningTuesday.Checked = True
                        Else
                            If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                                RadioEveningTuesday.Checked = True
                            Else
                                RadioOtherTuesday.Checked = True
                                RadDateTimePickerTuesdayStart.Enabled = True
                                RadDateTimePickerTuesdayEnd.Enabled = True
                            End If
                        End If
                    End If
                End If
                If Appointments.Item(i).StartDateTime.Date = wednesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    Dim time As DateTime = DateTime.Now
                    Dim format As String = "t"
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                        RadioAllDayWednesday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                            RadioMorningWednesday.Checked = True
                        Else
                            If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                                RadioEveningWednesday.Checked = True
                            Else
                                RadioOtherWednesday.Checked = True
                                RadDateTimePickerWednesdayStart.Enabled = True
                                RadDateTimePickerWednesdayEnd.Enabled = True
                            End If
                        End If
                    End If
                End If
                If Appointments.Item(i).StartDateTime.Date = thursdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    Dim time As DateTime = DateTime.Now
                    Dim format As String = "t"
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                        RadioAllDayThursday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                            RadioMorningThursday.Checked = True
                        Else
                            If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                                RadioEveningThursday.Checked = True
                            Else
                                RadioOtherThursday.Checked = True
                                RadDateTimePickerThursdayStart.Enabled = True
                                RadDateTimePickerThursdayEnd.Enabled = True
                            End If
                        End If
                    End If
                End If
                If Appointments.Item(i).StartDateTime.Date = fridayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    Dim time As DateTime = DateTime.Now
                    Dim format As String = "t"
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                        RadioAllDayFriday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                            RadioMorningFriday.Checked = True
                        Else
                            If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                                RadioEveningFriday.Checked = True
                            Else
                                RadioOtherFriday.Checked = True
                                RadDateTimePickerFridayStart.Enabled = True
                                RadDateTimePickerFridayEnd.Enabled = True
                            End If
                        End If
                    End If
                End If
                If Appointments.Item(i).StartDateTime.Date = saturdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    Dim time As DateTime = DateTime.Now
                    Dim format As String = "t"
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                        RadioAllDaySaturday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                            RadioMorningSaturday.Checked = True
                        Else
                            If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                                RadioEveningSaturday.Checked = True
                            Else
                                RadioOtherSaturday.Checked = True
                                RadDateTimePickerSaturdayStart.Enabled = True
                                RadDateTimePickerSaturdayEnd.Enabled = True
                            End If
                        End If
                    End If
                End If
            Next
            'bind the coresponding Day off to the Day off radio button
            Dim appointmentSamedayCount As Integer = 0
            For i = 0 To aCount - 1
                If Appointments.Item(i).StartDateTime.Date = sundayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    appointmentSamedayCount += 1
                End If
            Next
            If appointmentSamedayCount = 0 Then
                RadioDayOffSunday.Checked = True
                RadDateTimePickerSundayStart.Enabled = False
                RadDateTimePickerSundayEnd.Enabled = False
            End If
            appointmentSamedayCount = 0
            For i = 0 To aCount - 1
                If Appointments.Item(i).StartDateTime.Date = mondayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    appointmentSamedayCount += 1
                End If
            Next
            If appointmentSamedayCount = 0 Then
                RadioDayOffMonday.Checked = True
                RadDateTimePickerMondayStart.Enabled = False
                RadDateTimePickerMondayEnd.Enabled = False
            End If
            appointmentSamedayCount = 0
            For i = 0 To aCount - 1
                If Appointments.Item(i).StartDateTime.Date = tuesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    appointmentSamedayCount += 1
                End If
            Next
            If appointmentSamedayCount = 0 Then
                RadioDayOffTuesday.Checked = True
                RadDateTimePickerTuesdayStart.Enabled = False
                RadDateTimePickerTuesdayEnd.Enabled = False
            End If
            appointmentSamedayCount = 0
            For i = 0 To aCount - 1
                If Appointments.Item(i).StartDateTime.Date = wednesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    appointmentSamedayCount += 1
                End If
            Next
            If appointmentSamedayCount = 0 Then
                RadioDayOffWednesday.Checked = True
                RadDateTimePickerWednesdayStart.Enabled = False
                RadDateTimePickerWednesdayEnd.Enabled = False
            End If
            appointmentSamedayCount = 0
            For i = 0 To aCount - 1
                If Appointments.Item(i).StartDateTime.Date = thursdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    appointmentSamedayCount += 1
                End If
            Next
            If appointmentSamedayCount = 0 Then
                RadioDayOffThursday.Checked = True
                RadDateTimePickerThursdayStart.Enabled = False
                RadDateTimePickerThursdayEnd.Enabled = False
            End If
            appointmentSamedayCount = 0
            For i = 0 To aCount - 1
                If Appointments.Item(i).StartDateTime.Date = fridayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    appointmentSamedayCount += 1
                End If
            Next
            If appointmentSamedayCount = 0 Then
                RadioDayOffFriday.Checked = True
                RadDateTimePickerFridayStart.Enabled = False
                RadDateTimePickerFridayEnd.Enabled = False
            End If
            appointmentSamedayCount = 0
            For i = 0 To aCount - 1
                If Appointments.Item(i).StartDateTime.Date = saturdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                    appointmentSamedayCount += 1
                End If
            Next
            If appointmentSamedayCount = 0 Then
                RadioDayOffSaturday.Checked = True
                RadDateTimePickerSaturdayStart.Enabled = False
                RadDateTimePickerSaturdayEnd.Enabled = False
            End If
        End If

 

        '' '' ''create Header title and time frame for modal
        Dim appointmentsCount As Integer = Appointments.Count - 1
        Header.Title = UserSelection + ":" + "&nbsp" + Appointments.Item(0).StartDateTime.Date + "&nbsp" + "-" + "&nbsp" + Appointments.Item(appointmentsCount).StartDateTime.Date

    End Sub

    Protected Sub RadScheduler1_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles RadScheduler1.DataBound
        'RadToolTipManager1.TargetControls.Clear()
        'ScriptManager.RegisterStartupScript(Me, GetType(System.Web.UI.Page), "HideToolTip", "hideActiveToolTip();", True)
        Dim monthNum As Integer = RadScheduler1.VisibleRangeStart.Month
        Dim strDate As New DateTime(1, monthNum, 1)
        RadScheduler1.Localization.AllDay = strDate.ToString("MMMMM")
        ''Cust
        ''RadScheduler1.ResourceTypes.FindByName("User").AllowMultipleValues = True
        ''RadScheduler1.ResourceTypes.FindByName("Room").AllowMultipleValues = False

    End Sub

    Protected Sub MyAvailability1_FormCreated(ByVal sender As Object, ByVal e As SchedulerFormCreatedEventArgs) Handles RadScheduler1.FormCreated
        If (e.Container.Mode = SchedulerFormMode.AdvancedEdit) OrElse (e.Container.Mode = SchedulerFormMode.AdvancedInsert) Then
            Dim allDayCheckbox As CheckBox = DirectCast(e.Container.FindControl("AllDayEvent"), CheckBox)
            allDayCheckbox.Style.Add("visibility", "hidden")
            Dim attrAnnotationsTextbox As RadTextBox = DirectCast(e.Container.FindControl("Subject"), RadTextBox)
            attrAnnotationsTextbox.Label = "Type"
            attrAnnotationsTextbox.Enabled = False
            Dim AppointmentID As Integer = e.Appointment.ID
            Dim AppointmentIDPrevious As Integer = e.Appointment.ID - 1
            Dim PreviousAppointment As New Appointment

            ''Dim startPicker As RadTimePicker = DirectCast(e.Container.FindControl("StartTime"), RadTimePicker)
            ''startPicker.TimeView.StartTime = TimeSpan.FromHours(1.5)
            ''startPicker.TimeView.EndTime = TimeSpan.FromHours(24)
            ''startPicker.TimeView.DataList.DataSource = Nothing
            ''startPicker.TimeView.DataBind()

            ''Dim endPicker As RadTimePicker = DirectCast(e.Container.FindControl("EndTime"), RadTimePicker)
            ''endPicker.TimeView.StartTime = TimeSpan.FromHours(8)
            ''endPicker.TimeView.EndTime = TimeSpan.FromHours(24)
            ''endPicker.TimeView.DataList.DataSource = Nothing
            ''endPicker.TimeView.DataBind()

            '' Dim StartTimeAppointmentIDPrevious As String = RadScheduler1.Appointments.FindByID(52).Start.ToString
            '' Catch ex As Exception
            ''ex.ToString()
            '' End Try
            Dim scheduler As RadScheduler = DirectCast(sender, RadScheduler)
            Dim StartTimeAvail As DateTime
            Dim EndTimeAvail As DateTime
            If e.Appointment.Subject = "Preference" Then

                For Each app As Appointment In scheduler.Appointments.GetAppointmentsInRange(e.Appointment.Start, e.Appointment.[End])

                    If app.Subject = "Availability" Then
                        StartTimeAvail = app.Start.ToShortTimeString
                        EndTimeAvail = app.End.ToShortTimeString
                        Exit For
                    End If

                Next

            End If
            Dim startPicker As RadTimePicker = DirectCast(e.Container.FindControl("StartTime"), RadTimePicker)
            Dim endPicker As RadTimePicker = DirectCast(e.Container.FindControl("EndTime"), RadTimePicker)
            Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
            Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
            startPicker.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
            ''startPicker.TimeView.EndTime = TimeSpan.FromHours(24)
            startPicker.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
            endPicker.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
            endPicker.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)

            startPicker.TimeView.DataList.DataSource = Nothing
            startPicker.TimeView.DataBind()
            endPicker.TimeView.DataList.DataSource = Nothing
            endPicker.TimeView.DataBind()
            ''Dim startTime As RadTimePicker = TryCast(e.Container.FindControl("StartTime"), RadTimePicker)
            ''Dim DbleTime As Double = ADate.ToOADate() * 24
            ''startPicker.TimeView.StartTime = TimeSpan.FromHours(DbleTime)
        End If
    End Sub

    'Protected Sub MyAvailability1_AppointmentInsert(sender As Object, e As AppointmentInsertEventArgs) Handles RadScheduler1.AppointmentInsert
    '    If e.Appointment.Subject = "Preference" Then
    '        Dim scheduler As RadScheduler = DirectCast(sender, RadScheduler)
    '        For Each app As Appointment In scheduler.Appointments.GetAppointmentsInRange(e.Appointment.Start, e.Appointment.[End])
    '            If app.Subject = "Availability" Then
    '                If app.Start > e.Appointment.Start OrElse app.[End] <= e.Appointment.[End] Then
    '                    e.Cancel = True
    '                End If
    '            End If

    '        Next
    '    End If

    'End Sub
    Protected Sub MyAvailability1_AppointmentUpdate(sender As Object, e As AppointmentUpdateEventArgs) Handles RadScheduler1.AppointmentUpdate
        'e.ModifiedAppointment.Description = e.ModifiedAppointment.Description + "Override"
        'Dim scheduler As RadScheduler = DirectCast(sender, RadScheduler)
        'If e.ModifiedAppointment.Subject = "preferred" Then
        '    For Each app As Appointment In scheduler.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.[End])

        '        If app.Subject = "available" Then
        '            If app.Start > e.ModifiedAppointment.Start OrElse app.[End] < e.ModifiedAppointment.[End] Then
        '                e.Cancel = True
        '            End If
        '        End If

        '    Next
        'End If

        'If e.ModifiedAppointment.Subject = "available" Then
        '    For Each app As Appointment In scheduler.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.[End])

        '        If app.Subject = "preferred" Then
        '            If app.Start < e.ModifiedAppointment.Start OrElse app.[End] > e.ModifiedAppointment.[End] Then
        '                e.Cancel = True
        '            End If
        '        End If
        '    Next
        'End If

    End Sub

    'Private Function IsAppointmentRegisteredForTooltip(ByVal apt As Appointment) As Boolean
    '    For Each targetControl As ToolTipTargetControl In RadToolTipManager1.TargetControls
    '        If (apt.DomElements.Contains(targetControl.TargetControlID)) Then
    '            Return True
    '        End If
    '    Next
    '    Return False
    'End Function

    Protected Sub RadToolTipManager1_AjaxUpdate(ByVal sender As Object, ByVal e As ToolTipUpdateEventArgs)
        Dim aptId As Integer
        Dim apt As Appointment
        If Not Integer.TryParse(e.Value, aptId) Then
            'The appoitnment is occurrence and FindByID expects a string
            apt = RadScheduler1.Appointments.FindByID(e.Value)
        Else
            'The appointment is not occurrence and FindByID expects an int
            apt = RadScheduler1.Appointments.FindByID(aptId)
        End If
    End Sub

    Protected Sub RadScheduler1_TimeSlotCreated(sender As Object, e As TimeSlotCreatedEventArgs) Handles RadScheduler1.TimeSlotCreated
        Dim scheduler As RadScheduler = DirectCast(sender, RadScheduler)
        ''If scheduler.SelectedView = SchedulerViewType.WeekView AndAlso e.TimeSlot.Duration = TimeSpan.FromDays(1) Then

        If e.TimeSlot.Duration = TimeSpan.FromDays(1) Then
            Dim startLabel As New Label()
            Dim startLabelPref As New Label()
            startLabel.ID = "startLabel" + e.TimeSlot.Start.DayOfWeek.ToString + CType(e.TimeSlot.Start.Day, String)
            startLabelPref.ID = "startLabelPref" + e.TimeSlot.Start.DayOfWeek.ToString + CType(e.TimeSlot.Start.Day, String)
            startLabel.Font.Size = 7
            startLabel.Font.Bold = True
            startLabelPref.Font.Size = 7
            startLabelPref.Font.Bold = True

            If newStartLabel <> "" AndAlso dayOfWeek_Label = e.TimeSlot.Start.DayOfWeek.ToString() Then
                startLabel.Text = newStartLabel
            Else
                For Each app As Appointment In RadScheduler1.Appointments.GetAppointmentsInRange(e.TimeSlot.Start, e.TimeSlot.[End])
                    If app.Subject = "Availability" Then
                        Dim TimeFormat As String
                        TimeFormat = Trim(app.Start.ToShortTimeString)
                        ''TimeFormat.Replace(" AM", "a")
                        If TimeFormat.Contains("AM") Then
                            startLabel.Text = "   " + TimeFormat.Replace(" AM", "a")
                        Else
                            startLabel.Text = "   " + app.Start.ToShortTimeString.Replace(" PM", "p")
                        End If
                        startLabel.BackColor = System.Drawing.Color.FromName("#FEEDA9")

                    End If

                    If app.Subject = "Preference" Then
                        Dim TimeFormat As String
                        TimeFormat = Trim(app.Start.ToShortTimeString)
                        ''TimeFormat.Replace(" AM", "a")
                        If TimeFormat.Contains("AM") Then
                            startLabelPref.Text = TimeFormat.Replace(" AM", "a")
                        Else
                            startLabelPref.Text = app.Start.ToShortTimeString.Replace(" PM", "p")
                        End If

                        startLabelPref.BackColor = System.Drawing.Color.FromName("#D0ECBB")
                    End If
                Next
            End If
            Dim endLabel As New Label()
            Dim endLabelPref As New Label()
            ''startLabel.ID = "endLabel" + e.TimeSlot.Start.DayOfWeek.ToString
            endLabel.ID = "endLabel" + e.TimeSlot.End.DayOfWeek.ToString + CType(e.TimeSlot.End.Day, String)
            ''startLabelPref.ID = "endLabelPref" + e.TimeSlot.Start.DayOfWeek.ToString
            endLabelPref.ID = "endLabelPref" + e.TimeSlot.End.DayOfWeek.ToString + CType(e.TimeSlot.End.Day, String)
            endLabel.Font.Size = 7
            endLabel.Font.Bold = True
            endLabelPref.Font.Size = 7
            endLabelPref.Font.Bold = True
            ''If newStartLabel <> "" AndAlso dayOfWeek = e.TimeSlot.Start.DayOfWeek.ToString() Then
            If newEndLabel <> "" AndAlso dayOfWeek_Label = e.TimeSlot.End.DayOfWeek.ToString() Then
                endLabel.Text = "-" + newEndLabel
            Else
                For Each app As Appointment In RadScheduler1.Appointments.GetAppointmentsInRange(e.TimeSlot.Start, e.TimeSlot.[End])
                    If app.Subject = "Availability" Then
                        Dim TimeFormat2 As String
                        TimeFormat2 = Trim("-" + app.[End].ToShortTimeString)
                        endLabel.Text = TimeFormat2.Replace(" AM", "a")
                        endLabel.Text = "-" + app.[End].ToShortTimeString.Replace(" PM", "p")
                        endLabel.BackColor = System.Drawing.Color.FromName("#FEEDA9")
                    End If

                    If app.Subject = "Preference" Then
                        Dim TimeFormat2 As String
                        TimeFormat2 = Trim("-" + app.[End].ToShortTimeString)
                        endLabelPref.Text = TimeFormat2.Replace(" AM", "a")
                        endLabelPref.Text = "-" + app.[End].ToShortTimeString.Replace(" PM", "p")
                        endLabelPref.BackColor = System.Drawing.Color.FromName("#D0ECBB")
                    End If
                Next
            End If
            Dim divisionLabel As New Label()
            divisionLabel.Text = " | "
            divisionLabel.BackColor = Color.Transparent
            e.TimeSlot.Control.Controls.Add(startLabel)
            e.TimeSlot.Control.Controls.Add(endLabel)
            e.TimeSlot.Control.Controls.Add(divisionLabel)
            e.TimeSlot.Control.Controls.Add(startLabelPref)
            e.TimeSlot.Control.Controls.Add(endLabelPref)
            ''e.Appointment.Attributes.Add("onclick", "javascript:ViewLeave('" & DataRowView.Item("LeaveID").ToString() & "');")
            startLabel.Attributes.Add("onclick", "TimeRangeOnclick")
        End If
        ''End If
        ''e.TimeSlot.Appointments.Item(2).Description = "Test"
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged

        For Each schedopt As Schedule_Option In _person.ScheduleOptionsControl.ScheduleOptions
            If schedopt.DisplayName = Me.DropDownList1.SelectedItem.Text Then
                schedopt.IsCurrent = True
                Me.RadTextBoxScheduleOptionsDescription.Text = schedopt.DisplayDescription
                'Me.LabelScheduleOptionsDescription.Text = schedopt.DisplayDescription
            Else
                schedopt.IsCurrent = False
            End If
        Next

        Dim BRE As New BusinessRulesProcessor()
        BRE.Process(_person)

    End Sub

    Sub AssignOptMsg()
        Dim ScheduleOption As String = DropDownList1.SelectedItem.ToString
        Dim OptMsg1 As String = "- Select up to 2 mornings (shifts not assigned before 1pm) off (M-F) and" & vbCrLf & _
                                                "- Select up to 2 evenings (shifts not assigned after 6 pm) off (M-Th) OR" & vbCrLf & _
                                                "______________________________________________________________________________" & vbCrLf & _
                                                "" & vbCrLf & _
                                                "- Select up to 1 full day off (M-Th)by selecting a morning & evening on the same day and" & vbCrLf & _
                                                "- Up to 1 additional morning & 1 additional evening off (not on same day)"
        Dim OptMsg2 As String = "- Select up to 2 mornings (shifts not assigned before 1pm) off (M-F) and" & vbCrLf & _
                                        "- Select up to 2 evenings (shifts not assigned after 6 pm) off (M-Th) OR" & vbCrLf & _
                                        "______________________________________________________________________________" & vbCrLf & _
                                        "" & vbCrLf & _
                                        "- Select up to 1 full day off (M-Th)by selecting a morning & evening on the same day and" & vbCrLf & _
                                        "- Up to 1 additional"
        Dim OptMsg3 As String = "- Select up to 4 mornings (shifts not assigned before 1pm) off (M-F) and" & vbCrLf & _
                                        "- Select up to 4 evenings (shifts not assigned after 6 pm) off (M-Th) OR" & vbCrLf & _
                                        "______________________________________________________________________________" & vbCrLf & _
                                        "- Select up to 2 full days off (M-Th) by selecting a morning & evening on the same day and" & vbCrLf & _
                                        "  Up to 1 additional morning & 1 additional evening off (not on same day)" & vbCrLf & _
                                        " ______________________________________________________________________________" & vbCrLf & _
                                        "" & vbCrLf & _
                                        "On any Key Day, the system may override your Availability choices to support the business as needed." & vbCrLf & _
                                        "Your preferences must follow the same work rules as your availability selections" & vbCrLf & _
                                        "Your preferred time range must fall within the available time range."
        Select Case ScheduleOption
            Case "Full-Time_35_to_40_Assigned_Hours"
                RadTextBoxScheduleOptionsDescription.Text = OptMsg1
            Case "Full-Time_28_to_32_Assigned_Hours"
                RadTextBoxScheduleOptionsDescription.Text = OptMsg2
            Case "Full-Time_20_to_30_Assigned_Hours"
                Me.RadTextBoxScheduleOptionsDescription.Text = OptMsg3
        End Select
    End Sub

    Sub RulesReader()
        Try
            Dim m_xmld As XmlDocument
            Dim m_nodelist As XmlNodeList
            Dim m_node As XmlNode
            ''Dim m_element As XmlElement
            ''Dim m_attributeCollection As XmlAttributeCollection
            ''Dim m_attribute As XmlAttribute
            'Create the XML Document
            m_xmld = New XmlDocument()
            'Load the Xml file
            ''m_xmld.Load("C:\Availability Rewrite Project\MSP_DEVProject\MSP\App_Data\Rules.xml")
            m_xmld.Load(Server.MapPath("~/App_Data/Rules.xml"))

            'Get the list of name nodes
            ''m_nodelist = m_xmld.SelectNodes("/family/name")
            m_nodelist = m_xmld.SelectNodes("/Tibco/Option")
            Dim Ocount As Integer = 0
            DropDownList1.Items.Clear()
            'BulletedList1.Items.Clear()
            For Each m_node In m_nodelist
                'Get the Gender Attribute Value
                ''Dim genderAttribute = m_node.Attributes.GetNamedItem("gender").Value
                Dim SelSchedOptAttribute = m_node.Attributes.GetNamedItem("OptionText").Value
                'add options into dropdown box
                DropDownList1.Items.Add(SelSchedOptAttribute)
                Dim Itemcount As Integer = DropDownList1.Items.Count
                ''''If SelSchedOptAttribute = "y" Then
                'Get the firstName Element Value
                ''Dim firstNameValue = m_node.ChildNodes.Item(0).InnerText
                Dim OptionSelectcount As Integer = m_node.ChildNodes.Count
                ''For m As Integer = 0 To OptionSelectcount
                ''Dim OptionSelect = m_node.ChildNodes.Item(0).InnerText
                Ocount = Ocount + 1
                Dim Description1 = m_node.ChildNodes.Item(0).InnerText
                'Get the lastName Element Value
                ''Dim lastNameValue = m_node.ChildNodes.Item(1).InnerText
                Dim Description2 = m_node.ChildNodes.Item(1).InnerText
                Dim Description3 = m_node.ChildNodes.Item(2).InnerText
                Dim Description4 = m_node.ChildNodes.Item(3).InnerText

            Next
        Catch errorVariable As Exception
            'Error trapping
            Console.Write(errorVariable.ToString())
        End Try
    End Sub

    Private Sub formatUIMyMessages()

        lblMessage.Text = "Messages as of " & DateTime.Now.ToString("MM/dd/yyyy h:mmtt")
        Dim test_tr As New TableRow()
        test_tr.CssClass = "myMessageRow"
        Dim test_td As New TableCell()
        test_td.CssClass = "myMessageCell"
        test_td.Width = New Unit("100%")
        test_td.Text = " - You have selected to be assigned 20-30 hours from December 9th - December 29th.  Please take the time now to update your availability and preference choices for these dates, and remember to expand your availability wherever possible so that you can be assigned the holiday range of hours."
        test_tr.Cells.Add(test_td)
        tblMyMsgs.Rows.Add(test_tr)

    End Sub

    'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Private Sub InstantiateScheduler()
        'set initial scheduler view and mappings
        RadScheduler1.DataKeyField = "ID"
        RadScheduler1.DataStartField = "StartDateTime"
        RadScheduler1.DataEndField = "EndDateTime"
        RadScheduler1.DataSubjectField = "Subject"
        RadScheduler1.DataDescriptionField = "Description"
        Dim StartDate As DateTime = GetStartDate()
        RadScheduler1.SelectedDate = StartDate
        Dim dateFrom As DateTime = GetWeekStart(StartDate)
        Dim dateTo As DateTime = dateFrom.AddDays(6.0)
        Dim appFact As New MSPBusinessLogic.AppointmentsFactory()
        appFact.LoadAppointmentsList(_person, dateFrom, dateTo)
    End Sub

    Private Sub InstantiateScheduleOptions()

        'TODO - get the person's current Sched Option

        Dim ScheduleOptions As New List(Of Schedule_Option)

        Dim currentSchedOption As New Schedule_Option()
        currentSchedOption.Name = "FT1"
        currentSchedOption.DisplayName = "Full-Time 35 to 40 Assigned Hours"
        currentSchedOption.DisplayDescription = "- Select up to 2 mornings (shifts not assigned before 1pm) off (M-F) and" & vbCrLf & _
                                                "- Select up to 2 evenings (shifts not assigned after 6 pm) off (M-Th) OR" & vbCrLf & _
                                                "______________________________________________________________________________" & vbCrLf & _
                                                "" & vbCrLf & _
                                                "- Select up to 1 full day off (M-Th)by selecting a morning & evening on the same day and" & vbCrLf & _
                                                "- Up to 1 additional morning & 1 additional evening off (not on same day)"

        currentSchedOption.IsCurrent = False
        ScheduleOptions.Add(currentSchedOption)
        'TODO - determine how to get the other Sched Options
        Dim schedopt1 As New Schedule_Option()
        schedopt1.Name = "FT2"
        schedopt1.DisplayName = "Full-Time 28 to 32 Assigned Hours"
        schedopt1.DisplayDescription = "- Select up to 2 mornings (shifts not assigned before 1pm) off (M-F) and" & vbCrLf & _
                                        "- Select up to 2 evenings (shifts not assigned after 6 pm) off (M-Th) OR" & vbCrLf & _
                                        "______________________________________________________________________________" & vbCrLf & _
                                        "" & vbCrLf & _
                                        "- Select up to 1 full day off (M-Th)by selecting a morning & evening on the same day and" & vbCrLf & _
                                        "- Up to 1 additional"
        schedopt1.IsCurrent = False
        ScheduleOptions.Add(schedopt1)
        Dim schedopt2 As New Schedule_Option()
        'schedopt2.Name = "FT3"
        'schedopt2.DisplayName = "Full-Time 20 to 30 Assigned Hours"
        'schedopt2.DisplayDescription = "- Select up to 4 mornings (shifts not assigned before 1pm) off (M-F) and" & vbCrLf & _
        '                                "- Select up to 4 evenings (shifts not assigned after 6 pm) off (M-Th) OR" & vbCrLf & _
        '                                "______________________________________________________________________________" & vbCrLf & _
        '                                "" & vbCrLf & _
        '                                "- Select up to 2 full day off (M-Th)by selecting a morning & evening on the same day and" & vbCrLf & _
        '                                "- Up to 1"
        schedopt2.Name = "PT1"
        schedopt2.DisplayName = "Part-Time 12 to 20 Assigned Hours"
        schedopt2.DisplayDescription = "- Select up to 4 mornings (shifts not assigned before 1pm) off (M-F) and" & vbCrLf & _
                                        "- Select up to 4 evenings (shifts not assigned after 6 pm) off (M-Th) OR" & vbCrLf & _
                                        "______________________________________________________________________________" & vbCrLf & _
                                        "- Select up to 2 full days off (M-Th) by selecting a morning & evening on the same day and" & vbCrLf & _
                                        "  Up to 1 additional morning & 1 additional evening off (not on same day)" & vbCrLf & _
                                        " ______________________________________________________________________________" & vbCrLf & _
                                        "" & vbCrLf & _
                                        "On any Key Day, the system may override your Availability choices to support the business as needed." & vbCrLf & _
                                        "Your preferences must follow the same work rules as your availability selections" & vbCrLf & _
                                        "Your preferred time range must fall within the available time range."

        schedopt2.IsCurrent = True
        ScheduleOptions.Add(schedopt2)

        _person.ScheduleOptionsControl.ScheduleOptions = ScheduleOptions

        'pass through BRE to get all the other Sched Options
        'and the current sched option rule messages
        Dim BRE As New BusinessRulesProcessor()
        BRE.Process(_person)
        For Each schedopt As Schedule_Option In _person.ScheduleOptionsControl.ScheduleOptions
            If schedopt.IsCurrent = True Then
                Me.DropDownList1.Items.Add(schedopt.DisplayName)
                Me.RadTextBoxScheduleOptionsDescription.Text = schedopt.DisplayDescription
                'LabelScheduleOptionsDescription.Text = schedopt.DisplayDescription
            End If

        Next
        For Each schedopt As Schedule_Option In _person.ScheduleOptionsControl.ScheduleOptions
            If schedopt.IsCurrent = False Then
                Me.DropDownList1.Items.Add(schedopt.DisplayName)
            End If
        Next
        'Dim OptionListValues As String() = _person.AvailabilityMessages.Split(vbCrLf)
        'BulletedList1.Items.Clear()
        'Dim message As String
        'For Each message In OptionListValues
        '    Me.BulletedList1.Items.Add(message)
        'Next

        If _person.ScheduleOptionsControl.CanChange = False Then
            Me.DropDownList1.Enabled = False
        End If

        If _person.ScheduleOptionsControl.IsVisible = False Then
            Me.DropDownList1.Visible = False
            Me.RadTextBoxScheduleOptionsDescription.Visible = False
        End If
    End Sub

    Protected Function GetStartDate() As DateTime
        Dim intWeekOffset As Double = Convert.ToDouble(_initialDispalyWeeksOut * 7)
        Return DateTime.Now.AddDays(intWeekOffset).Date
    End Function

    Protected Function GetWeekStart(ByVal day As DateTime) As DateTime
        'returns Sunday's date for the week 'day' belongs to
        Dim dayOfWeek As Integer = Convert.ToInt32(day.DayOfWeek)
        If dayOfWeek < 0 Then
            dayOfWeek = 6
        End If
        Return day.AddDays(-1 * Convert.ToDouble(dayOfWeek)).Date
    End Function

    Protected Sub RadScheduler1_AppointmentInsert(sender As Object, e As Telerik.Web.UI.AppointmentInsertEventArgs) Handles RadScheduler1.AppointmentInsert
        Dim AppointmentsFactory As New AppointmentsFactory()
        Dim NewAppointmentInfo As AppointmentInfo = AppointmentsFactory.getAppointmentInfo(e.Appointment)
        Dim AppointmentInfoList As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
        AppointmentInfoList.Add(NewAppointmentInfo)
    End Sub

    Protected Sub RadScheduler1_AppointmentUpdate(sender As Object, e As Telerik.Web.UI.AppointmentUpdateEventArgs) Handles RadScheduler1.AppointmentUpdate
        Dim AppointmentsFactory As New AppointmentsFactory()
        Dim AppointmentInfoList As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
        For Each AppointmentInfo As AppointmentInfo In AppointmentInfoList
            If String.Compare(e.Appointment.ID, AppointmentInfo.ID) = 0 Then
                AppointmentInfo.StartDateTime = e.ModifiedAppointment.Start
                AppointmentInfo.EndDateTime = e.ModifiedAppointment.End
                'TODO - this needs to be changed from user selection in the Appointment object, remove test below
                AppointmentInfo.Description = "base"
                'AppointmentInfo.Description = "override"
            End If
        Next
    End Sub

    Protected Sub RadScheduler1_AppointmentDelete(sender As Object, e As Telerik.Web.UI.AppointmentDeleteEventArgs) Handles RadScheduler1.AppointmentDelete
        Dim AppointmentsFactory As New AppointmentsFactory()
        Dim AppointmentInfoList As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
        For Each AppointmentInfo As AppointmentInfo In AppointmentInfoList
            If String.Compare(e.Appointment.ID, AppointmentInfo.ID) = 0 Then
                AppointmentInfoList.Remove(AppointmentInfo)
                Exit For
            End If
        Next
    End Sub

    Protected Sub RadScheduler1_NavigationCommand(sender As Object, e As Telerik.Web.UI.SchedulerNavigationCommandEventArgs) Handles RadScheduler1.NavigationCommand
        ''TODO - if any appointments changed and user navigates away, alert the changes will be lost if not saved first

        'Dim fromDate As DateTime = RadScheduler1.SelectedDate
        'Dim toDate As DateTime
        'Dim dateFrom As DateTime
        'Dim dateTo As DateTime
        'Dim appFact As New MSPBusinessLogic.AppointmentsFactory()

        'If e.Command = SchedulerNavigationCommand.SwitchToDayView Then
        '    'TODO
        'End If

        'If e.Command = SchedulerNavigationCommand.SwitchToWeekView Then
        '    'TODO
        'End If

        'If e.Command = SchedulerNavigationCommand.NavigateToNextPeriod Then
        '    'TODO account for month view mode: only week works
        '    If RadScheduler1.SelectedView = SchedulerViewType.DayView Then
        '        toDate = fromDate.AddDays(1.0)
        '        dateFrom = toDate
        '        dateTo = toDate
        '    End If

        '    If RadScheduler1.SelectedView = SchedulerViewType.WeekView Then
        '        toDate = fromDate.AddDays(6.0)
        '        dateFrom = GetWeekStart(toDate)
        '        dateTo = dateFrom.AddDays(6.0)
        '    End If
        'End If

        'If e.Command = SchedulerNavigationCommand.NavigateToPreviousPeriod Then
        '    'TODO account for month view mode: only week works
        '    If RadScheduler1.SelectedView = SchedulerViewType.DayView Then
        '        toDate = fromDate.AddDays(-1.0)
        '        dateFrom = toDate
        '        dateTo = toDate
        '    End If

        '    If RadScheduler1.SelectedView = SchedulerViewType.WeekView Then
        '        toDate = fromDate.AddDays(-6.0)
        '        dateFrom = GetWeekStart(toDate)
        '        dateTo = dateFrom.AddDays(6.0)
        '    End If

        'End If

        'If e.Command = SchedulerNavigationCommand.NavigateToSelectedDate Then
        '    'TODO account for month view mode: only week work
        '    toDate = e.SelectedDate
        '    If RadScheduler1.SelectedView = SchedulerViewType.DayView Then
        '        dateFrom = toDate
        '        dateTo = toDate
        '    End If

        '    If RadScheduler1.SelectedView = SchedulerViewType.WeekView Then
        '        dateFrom = GetWeekStart(toDate)
        '        dateTo = dateFrom.AddDays(6.0)
        '    End If
        'End If

        ''navigate to Today using the Today button
        'If e.Command = SchedulerNavigationCommand.SwitchToSelectedDay Then
        '    toDate = e.SelectedDate
        '    If RadScheduler1.SelectedView = SchedulerViewType.WeekView Then
        '        dateFrom = GetWeekStart(toDate)
        '        dateTo = dateFrom.AddDays(6.0)
        '    End If
        'End If

        'appFact.LoadAppointmentsList(_person, dateFrom, dateTo)
        'RadScheduler1.DataSource = Appointments
    End Sub

    Protected Sub ButtonSaveAvailabilityChanges_Click(sender As Object, e As EventArgs) Handles ButtonSaveAvailabilityChanges.Click
        Try
            Dim AvailFactory As New Availability_Factory()

            'read the appointments from session and load them into the availability objects
            AvailFactory.LoadAvailabilityFromSession(_person, RadScheduler1.SelectedDate)

            'pass person through business rule engine
            Dim BRE As New BusinessRulesProcessor()
            BRE.Process(_person)

            'save avail to WFM
            Dim AvailSaveMessage As String
            AvailSaveMessage = AvailFactory.SaveAvailability(_person)

            Dim ConfirmationMessage As String
            ConfirmationMessage = AvailSaveMessage & "<br />"
            ConfirmationMessage = ConfirmationMessage & "Results of SAVE attempt: <br />"
            ConfirmationMessage = ConfirmationMessage & "<ul>"

            Dim AvailabilityMessages As String() = _person.AvailabilityMessages.Split(vbCrLf)
            Dim AvailabilityMessage As String
            For Each AvailabilityMessage In AvailabilityMessages
                ConfirmationMessage = ConfirmationMessage & "<li>"
                ConfirmationMessage = ConfirmationMessage & AvailabilityMessage.Trim()
                ConfirmationMessage = ConfirmationMessage & "</li>"
            Next
            ConfirmationMessage = ConfirmationMessage & "</ul>"
            'ConfirmationMessage = "An <br /><b>html</b> string.<br />"

            'Me.RadWindowManager1.RadAlert(ConfirmationMessage, 400, 120, "", "RadAlertCallBackFunction")
        Catch ex As Exception
            'TODO
            'Me.RadWindowManager1.RadAlert(ex.Message, 400, 120, "", "RadAlertCallBackFunction")

        End Try
    End Sub

    'Protected Sub Button1_Click(sender As Object, e As EventArgs)
    '    Dim startTime0 As String = Appointments.Item(0).StartDateTime.ToString
    '    Dim startTime1 As String = Appointments.Item(1).StartDateTime.ToString
    '    Appointments.Item(0).StartDateTime = "10/21/2012 1:00:00 PM"
    '    Appointments.Item(1).StartDateTime = "10/21/2012 2:00:00 PM"
    'End Sub

    'Protected Sub ButtonUpdate_Click(sender As Object, e As EventArgs) Handles ButtonUpdate.Click
    '    Dim startTime0 As String = Appointments.Item(0).StartDateTime.ToString
    '    Dim startTime1 As String = Appointments.Item(1).StartDateTime.ToString
    '    Appointments.Item(0).StartDateTime = "10/21/2012 3:00:00 PM"
    '    Appointments.Item(1).StartDateTime = "10/21/2012 4:00:00 PM"
    'End Sub

    ''Protected Sub RadWindowManager1_Load(sender As Object, e As EventArgs) Handles RadWindowManager1.Load
    ''    'RadWindowManager1.Enabled = False
    ''End Sub

    'Protected Sub RadWindowManager1_Init(sender As Object, e As EventArgs) Handles RadWindowManager1.Init
    '    'RadWindowManager1.Enabled = False
    'End Sub

    '' '' ''Modal section

    '' '' ''Private Property _person As Person
    '' '' ''Public Shared sundayTempFlag As Boolean = False
    '' '' ''Public Shared mondayTempFlag As Boolean = False
    '' '' ''Public Shared tuesdayTempFlag As Boolean = False
    '' '' ''Public Shared wednesdayTempFlag As Boolean = False
    '' '' ''Public Shared thursdayTempFlag As Boolean = False
    '' '' ''Public Shared fridayTempFlag As Boolean = False
    '' '' ''Public Shared saturdayTempFlag As Boolean = False

    '' '' ''Private ReadOnly Property Appointments() As List(Of AppointmentInfo)
    '' '' ''    Get
    '' '' ''        Dim appFact As New AppointmentsFactory()
    '' '' ''        Dim appointmentsList As List(Of AppointmentInfo)
    '' '' ''        appointmentsList = appFact.getAppointmentsList()
    '' '' ''        Return appointmentsList
    '' '' ''    End Get
    '' '' ''End Property

    '' '' ''Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    '' '' ''End Sub

    Public Function datetimeTranslation(ByVal DateTimeEnd As DateTime) As DateTime
        Dim DateTimePickerEnd As DateTime = DateTimeEnd
        Dim DateTimePickerEndTranslation As DateTime = DateTimePickerEnd + New TimeSpan(0, 23, 59, 59)
        Return DateTimePickerEndTranslation
    End Function

    Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        Dim selecteddate As Date = Appointments.Item(1).StartDateTime.Date
        'Dim candidateDate = [Date]
        While selecteddate.DayOfWeek <> DayOfWeek.Sunday
            selecteddate = selecteddate.AddDays(-1)
        End While
        'Dim dayDiff As Integer = selecteddate.DayOfWeek - DayOfWeek.Sunday
        Dim sundayCurrent As Date = selecteddate
        Dim mondayCurrent As Date = selecteddate.AddDays(1)
        Dim tuesdayCurrent As Date = selecteddate.AddDays(2)
        Dim wednesdayCurrent As Date = selecteddate.AddDays(3)
        Dim thursdayCurrent As Date = selecteddate.AddDays(4)
        Dim fridayCurrent As Date = selecteddate.AddDays(5)
        Dim saturdayCurrent As Date = sundayCurrent.AddDays(6)
        Dim aCount2 As Integer = Appointments.Count

        'Edit prefreneces
        For i = 0 To aCount2 - 1
            If Appointments.Item(i).StartDateTime.Date = sundayCurrent And Appointments.Item(i).Subject <> "available" And IsNothing(RadDateTimePickerSundayStart.SelectedDate) <> True Then
                'RadDateTimePickerSundayStart.SelectedDate = #12/2/2012 10:00:00 AM#
                Appointments.Item(i).StartDateTime = RadDateTimePickerSundayStart.SelectedDate
                Dim DateTimePickerEnd As DateTime = RadDateTimePickerSundayEnd.SelectedDate.Value
                Dim DateTimePickerEndTranslation = datetimeTranslation(DateTimePickerEnd)
                If RadDateTimePickerSundayEnd.SelectedDate.Value.Hour = 0 Then
                    Appointments.Item(i).EndDateTime = DateTimePickerEndTranslation
                Else
                    Appointments.Item(i).EndDateTime = DateTimePickerEnd
                End If

            End If
            If Appointments.Item(i).StartDateTime.Date = mondayCurrent And Appointments.Item(i).Subject <> "available" And IsNothing(RadDateTimePickerMondayStart.SelectedDate) <> True Then
                Appointments.Item(i).StartDateTime = RadDateTimePickerMondayStart.SelectedDate
                'Appointments.Item(i).EndDateTime = RadDateTimePickerMondayEnd.SelectedDate
                If RadDateTimePickerMondayEnd.SelectedDate.Value.Hour = 0 Then
                    Dim DateTimePickerEnd As DateTime = RadDateTimePickerMondayEnd.SelectedDate.Value
                    Dim DateTimePickerEndTranslation = datetimeTranslation(DateTimePickerEnd)
                    'Dim DateTimePickerEndTranslation As DateTime = DateTimePickerEnd + New TimeSpan(0, 23, 59, 59)
                    Appointments.Item(i).EndDateTime = DateTimePickerEndTranslation
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = tuesdayCurrent And Appointments.Item(i).Subject <> "available" And IsNothing(RadDateTimePickerTuesdayStart.SelectedDate) <> True Then
                Appointments.Item(i).StartDateTime = RadDateTimePickerTuesdayStart.SelectedDate
                If RadDateTimePickerTuesdayEnd.SelectedDate.Value.Hour = 0 Then
                    Dim DateTimePickerEnd As DateTime = RadDateTimePickerTuesdayEnd.SelectedDate.Value
                    Dim DateTimePickerEndTranslation = datetimeTranslation(DateTimePickerEnd)
                    'Dim DateTimePickerEndTranslation As DateTime = DateTimePickerEnd + New TimeSpan(0, 23, 59, 59)
                    Appointments.Item(i).EndDateTime = DateTimePickerEndTranslation
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = wednesdayCurrent And Appointments.Item(i).Subject <> "available" And IsNothing(RadDateTimePickerWednesdayStart.SelectedDate) <> True Then
                Appointments.Item(i).StartDateTime = RadDateTimePickerWednesdayStart.SelectedDate
                If RadDateTimePickerWednesdayEnd.SelectedDate.Value.Hour = 0 Then
                    Dim DateTimePickerEnd As DateTime = RadDateTimePickerWednesdayEnd.SelectedDate.Value
                    Dim DateTimePickerEndTranslation = datetimeTranslation(DateTimePickerEnd)
                    'Dim DateTimePickerEndTranslation As DateTime = DateTimePickerEnd + New TimeSpan(0, 23, 59, 59)
                    Appointments.Item(i).EndDateTime = DateTimePickerEndTranslation
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = thursdayCurrent And Appointments.Item(i).Subject <> "available" And IsNothing(RadDateTimePickerThursdayStart.SelectedDate) <> True Then
                Appointments.Item(i).StartDateTime = RadDateTimePickerThursdayStart.SelectedDate
                If RadDateTimePickerThursdayEnd.SelectedDate.Value.Hour = 0 Then
                    Dim DateTimePickerEnd As DateTime = RadDateTimePickerThursdayEnd.SelectedDate.Value
                    Dim DateTimePickerEndTranslation = datetimeTranslation(DateTimePickerEnd)
                    'Dim DateTimePickerEndTranslation As DateTime = DateTimePickerEnd + New TimeSpan(0, 23, 59, 59)
                    Appointments.Item(i).EndDateTime = DateTimePickerEndTranslation
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = fridayCurrent And Appointments.Item(i).Subject <> "available" And IsNothing(RadDateTimePickerFridayStart.SelectedDate) <> True Then
                Appointments.Item(i).StartDateTime = RadDateTimePickerFridayStart.SelectedDate
                If RadDateTimePickerFridayEnd.SelectedDate.Value.Hour = 0 Then
                    Dim DateTimePickerEnd As DateTime = RadDateTimePickerFridayEnd.SelectedDate.Value
                    Dim DateTimePickerEndTranslation = datetimeTranslation(DateTimePickerEnd)
                    'Dim DateTimePickerEndTranslation As DateTime = DateTimePickerEnd + New TimeSpan(0, 23, 59, 59)
                    Appointments.Item(i).EndDateTime = DateTimePickerEndTranslation
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = saturdayCurrent And Appointments.Item(i).Subject <> "available" And IsNothing(RadDateTimePickerSaturdayStart.SelectedDate) <> True Then
                Appointments.Item(i).StartDateTime = RadDateTimePickerSaturdayStart.SelectedDate
                If RadDateTimePickerSaturdayEnd.SelectedDate.Value.Hour = 0 Then
                    Dim DateTimePickerEnd As DateTime = RadDateTimePickerSaturdayEnd.SelectedDate.Value
                    Dim DateTimePickerEndTranslation = datetimeTranslation(DateTimePickerEnd)
                    'Dim DateTimePickerEndTranslation As DateTime = DateTimePickerEnd + New TimeSpan(0, 23, 59, 59)
                    Appointments.Item(i).EndDateTime = DateTimePickerEndTranslation
                End If
            End If
        Next

 

        'insert new preferences

        If sundayTempFlag = True Then
            'If RadDateTimePickerSundayStart.SelectedDate <> RadDateTimePickerSundayEnd.SelectedDate Then
            Dim SelectedDateStart As DateTime = RadDateTimePickerSundayStart.SelectedDate
            Dim SelectedDateEnd As DateTime = RadDateTimePickerSundayEnd.SelectedDate
            Dim AppointmentsFactory As New AppointmentsFactory()

            Dim NewAppointmentInfo As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("preferred", SelectedDateStart, SelectedDateEnd, "")
            Dim AppointmentInfoList As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
            AppointmentInfoList.Add(NewAppointmentInfo)
            Dim appointmentCount As Integer = AppointmentInfoList.Count
            Dim k As Integer
            For k = 0 To appointmentCount - 1
                If AppointmentInfoList.Item(k).StartDateTime.DayOfYear = NewAppointmentInfo.StartDateTime.DayOfWeek Then
                    If AppointmentInfoList.Item(k).Subject <> "available" Then
                        Dim NewAppointmentInfoAvailable As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("available", SelectedDateStart, SelectedDateEnd, "")
                        Dim AppointmentInfoListAvailable As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                        AppointmentInfoList.Add(NewAppointmentInfoAvailable)
                    End If

                End If
            Next
            sundayTempFlag = False
            'End If
        End If
        If mondayTempFlag = True Then
            'If RadDateTimePickerMondayStart.SelectedDate <> RadDateTimePickerMondayEnd.SelectedDate Then
            Dim SelectedDateStart As Date = RadDateTimePickerMondayStart.SelectedDate
            Dim SelectedDateEnd As Date = RadDateTimePickerMondayEnd.SelectedDate
            Dim AppointmentsFactory As New AppointmentsFactory()

            Dim NewAppointmentInfo As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("preferred", SelectedDateStart, SelectedDateEnd, "")
            Dim AppointmentInfoList As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
            AppointmentInfoList.Add(NewAppointmentInfo)
            Dim appointmentCount As Integer = AppointmentInfoList.Count
            Dim k As Integer
            For k = 0 To appointmentCount - 1
                If AppointmentInfoList.Item(k).StartDateTime.DayOfYear = NewAppointmentInfo.StartDateTime.DayOfWeek Then
                    If AppointmentInfoList.Item(k).Subject <> "available" Then
                        Dim NewAppointmentInfoAvailable As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("available", SelectedDateStart, SelectedDateEnd, "")
                        Dim AppointmentInfoListAvailable As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                        AppointmentInfoList.Add(NewAppointmentInfoAvailable)
                    End If

                End If
            Next
            mondayTempFlag = False
            'End If
        End If
        If tuesdayTempFlag = True Then
            If RadDateTimePickerTuesdayStart.SelectedDate <> RadDateTimePickerTuesdayEnd.SelectedDate Then
                Dim SelectedDateStart As Date = RadDateTimePickerTuesdayStart.SelectedDate
                Dim SelectedDateEnd As Date = RadDateTimePickerTuesdayEnd.SelectedDate
                Dim AppointmentsFactory As New AppointmentsFactory()

                Dim NewAppointmentInfo As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("preferred", SelectedDateStart, SelectedDateEnd, "")
                Dim AppointmentInfoList As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                AppointmentInfoList.Add(NewAppointmentInfo)
                Dim appointmentCount As Integer = AppointmentInfoList.Count
                Dim k As Integer
                For k = 0 To appointmentCount - 1
                    If AppointmentInfoList.Item(k).StartDateTime.DayOfYear = NewAppointmentInfo.StartDateTime.DayOfWeek Then
                        If AppointmentInfoList.Item(k).Subject <> "available" Then
                            Dim NewAppointmentInfoAvailable As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("available", SelectedDateStart, SelectedDateEnd, "")
                            Dim AppointmentInfoListAvailable As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                            AppointmentInfoList.Add(NewAppointmentInfoAvailable)
                        End If

                    End If
                Next
                tuesdayTempFlag = False
            End If
        End If
        If wednesdayTempFlag = True Then
            If RadDateTimePickerWednesdayStart.SelectedDate <> RadDateTimePickerWednesdayEnd.SelectedDate Then
                Dim SelectedDateStart As Date = RadDateTimePickerWednesdayStart.SelectedDate
                Dim SelectedDateEnd As Date = RadDateTimePickerWednesdayEnd.SelectedDate
                Dim AppointmentsFactory As New AppointmentsFactory()

                Dim NewAppointmentInfo As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("preferred", SelectedDateStart, SelectedDateEnd, "")
                Dim AppointmentInfoList As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                AppointmentInfoList.Add(NewAppointmentInfo)
                Dim appointmentCount As Integer = AppointmentInfoList.Count
                Dim k As Integer
                For k = 0 To appointmentCount - 1
                    If AppointmentInfoList.Item(k).StartDateTime.DayOfYear = NewAppointmentInfo.StartDateTime.DayOfWeek Then
                        If AppointmentInfoList.Item(k).Subject <> "available" Then
                            Dim NewAppointmentInfoAvailable As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("available", SelectedDateStart, SelectedDateEnd, "")
                            Dim AppointmentInfoListAvailable As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                            AppointmentInfoList.Add(NewAppointmentInfoAvailable)
                        End If

                    End If
                Next
                wednesdayTempFlag = False
            End If
        End If
        If thursdayTempFlag = True Then
            If RadDateTimePickerThursdayStart.SelectedDate <> RadDateTimePickerThursdayEnd.SelectedDate Then
                Dim SelectedDateStart As Date = RadDateTimePickerThursdayStart.SelectedDate
                Dim SelectedDateEnd As Date = RadDateTimePickerThursdayEnd.SelectedDate
                Dim AppointmentsFactory As New AppointmentsFactory()

                Dim NewAppointmentInfo As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("preferred", SelectedDateStart, SelectedDateEnd, "")
                Dim AppointmentInfoList As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                AppointmentInfoList.Add(NewAppointmentInfo)
                Dim appointmentCount As Integer = AppointmentInfoList.Count
                Dim k As Integer
                For k = 0 To appointmentCount - 1
                    If AppointmentInfoList.Item(k).StartDateTime.DayOfYear = NewAppointmentInfo.StartDateTime.DayOfWeek Then
                        If AppointmentInfoList.Item(k).Subject <> "available" Then
                            Dim NewAppointmentInfoAvailable As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("available", SelectedDateStart, SelectedDateEnd, "")
                            Dim AppointmentInfoListAvailable As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                            AppointmentInfoList.Add(NewAppointmentInfoAvailable)
                        End If

                    End If
                Next
                thursdayTempFlag = False
            End If
        End If
        If fridayTempFlag = True Then
            If RadDateTimePickerFridayStart.SelectedDate <> RadDateTimePickerFridayEnd.SelectedDate Then
                Dim SelectedDateStart As Date = RadDateTimePickerFridayStart.SelectedDate
                Dim SelectedDateEnd As Date = RadDateTimePickerFridayEnd.SelectedDate
                Dim AppointmentsFactory As New AppointmentsFactory()

                Dim NewAppointmentInfo As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("preferred", SelectedDateStart, SelectedDateEnd, "")
                Dim AppointmentInfoList As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                AppointmentInfoList.Add(NewAppointmentInfo)
                Dim appointmentCount As Integer = AppointmentInfoList.Count
                Dim k As Integer
                For k = 0 To appointmentCount - 1
                    If AppointmentInfoList.Item(k).StartDateTime.DayOfYear = NewAppointmentInfo.StartDateTime.DayOfWeek Then
                        If AppointmentInfoList.Item(k).Subject <> "available" Then
                            Dim NewAppointmentInfoAvailable As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("available", SelectedDateStart, SelectedDateEnd, "")
                            Dim AppointmentInfoListAvailable As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                            AppointmentInfoList.Add(NewAppointmentInfoAvailable)
                        End If

                    End If
                Next
                fridayTempFlag = False
            End If
        End If
        If saturdayTempFlag = True Then
            If RadDateTimePickerSaturdayStart.SelectedDate <> RadDateTimePickerSaturdayEnd.SelectedDate Then
                Dim SelectedDateStart As Date = RadDateTimePickerSaturdayStart.SelectedDate
                Dim SelectedDateEnd As Date = RadDateTimePickerSaturdayEnd.SelectedDate
                Dim AppointmentsFactory As New AppointmentsFactory()

                Dim NewAppointmentInfo As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("preferred", SelectedDateStart, SelectedDateEnd, "")
                Dim AppointmentInfoList As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                AppointmentInfoList.Add(NewAppointmentInfo)
                Dim appointmentCount As Integer = AppointmentInfoList.Count
                Dim k As Integer
                For k = 0 To appointmentCount - 1
                    If AppointmentInfoList.Item(k).StartDateTime.DayOfYear = NewAppointmentInfo.StartDateTime.DayOfWeek Then
                        If AppointmentInfoList.Item(k).Subject <> "available" Then
                            Dim NewAppointmentInfoAvailable As AppointmentInfo = AppointmentsFactory.getAppointmentInfo("available", SelectedDateStart, SelectedDateEnd, "")
                            Dim AppointmentInfoListAvailable As List(Of AppointmentInfo) = AppointmentsFactory.getAppointmentsList()
                            AppointmentInfoList.Add(NewAppointmentInfoAvailable)
                        End If

                    End If
                Next
                saturdayTempFlag = False
            End If
        End If

        'delete Appointments (day off)
        Dim AppointmentsFactory_Delete As New AppointmentsFactory()
        Dim AppointmentInfoList_Delete As List(Of AppointmentInfo) = AppointmentsFactory_Delete.getAppointmentsList()
        Dim aCount_Delete As Integer = 0
        aCount_Delete = AppointmentInfoList_Delete.Count
        Dim deletedAppointment As Integer = 0
        For j = 0 To aCount2 - 1 - deletedAppointment
            If j < Appointments.Count Then

                If Appointments.Item(j).StartDateTime.Date = sundayCurrent And Appointments.Item(j).Subject <> "available" And IsNothing(RadDateTimePickerSundayStart.SelectedDate) = True Then
                    AppointmentInfoList_Delete.RemoveAt(j)
                    deletedAppointment += 1
                    j -= 1
                End If
                If Appointments.Item(j).StartDateTime.Date = mondayCurrent And Appointments.Item(j).Subject <> "available" And IsNothing(RadDateTimePickerMondayStart.SelectedDate) = True Then
                    AppointmentInfoList_Delete.RemoveAt(j)
                    deletedAppointment += 1
                    j -= 1
                End If
                If Appointments.Item(j).StartDateTime.Date = tuesdayCurrent And Appointments.Item(j).Subject <> "available" And IsNothing(RadDateTimePickerTuesdayStart.SelectedDate) = True Then
                    AppointmentInfoList_Delete.RemoveAt(j)
                    deletedAppointment += 1
                    j -= 1
                End If
                If Appointments.Item(j).StartDateTime.Date = wednesdayCurrent And Appointments.Item(j).Subject <> "available" And IsNothing(RadDateTimePickerWednesdayStart.SelectedDate) = True Then
                    AppointmentInfoList_Delete.RemoveAt(j)
                    deletedAppointment += 1
                    j -= 1
                End If
                If Appointments.Item(j).StartDateTime.Date = thursdayCurrent And Appointments.Item(j).Subject <> "available" And IsNothing(RadDateTimePickerThursdayStart.SelectedDate) = True Then
                    AppointmentInfoList_Delete.RemoveAt(j)
                    deletedAppointment += 1
                    j -= 1
                End If
                If Appointments.Item(j).StartDateTime.Date = fridayCurrent And Appointments.Item(j).Subject <> "available" And IsNothing(RadDateTimePickerFridayStart.SelectedDate) = True Then
                    AppointmentInfoList_Delete.RemoveAt(j)
                    deletedAppointment += 1
                    j -= 1
                End If
                If Appointments.Item(j).StartDateTime.Date = saturdayCurrent And Appointments.Item(j).Subject <> "available" And IsNothing(RadDateTimePickerSaturdayStart.SelectedDate) = True Then
                    AppointmentInfoList_Delete.RemoveAt(j)
                    deletedAppointment += 1
                    j -= 1
                End If

            End If
        Next

        'age.ClientScript.RegisterStartupScript([GetType](), "key", "<script type='text/javascript'>RefreshParentPage();</script>", False)

    End Sub

 

 

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        '' '' ''Modal section

        Dim UserSelection As String = ""
        If Not Request.Form("EditPreference") Is Nothing Then
            ' buttonName was clicked
            UserSelection = "Preference"
        End If

        'If Not IsPostBack Then
        'bind the coresponding time range to the timepickers
        Dim selecteddate As Date = Appointments.Item(1).StartDateTime.Date
        'Dim candidateDate = [Date]
        While selecteddate.DayOfWeek <> DayOfWeek.Sunday
            selecteddate = selecteddate.AddDays(-1)
        End While
        'Dim dayDiff As Integer = selecteddate.DayOfWeek - DayOfWeek.Sunday
        Dim sundayCurrent As Date = selecteddate
        Dim mondayCurrent As Date = selecteddate.AddDays(1)
        Dim tuesdayCurrent As Date = selecteddate.AddDays(2)
        Dim wednesdayCurrent As Date = selecteddate.AddDays(3)
        Dim thursdayCurrent As Date = selecteddate.AddDays(4)
        Dim fridayCurrent As Date = selecteddate.AddDays(5)
        Dim saturdayCurrent As Date = sundayCurrent.AddDays(6)
        Dim aCount As Integer = Appointments.Count
        For i = 0 To aCount - 1

            If Appointments.Item(i).StartDateTime.Date = sundayCurrent And Appointments.Item(i).Subject = "preferred" Then
                RadDateTimePickerSundayStart.SelectedDate = Appointments.Item(i).StartDateTime
                RadDateTimePickerSundayEnd.SelectedDate = Appointments.Item(i).EndDateTime
            End If

            If Appointments.Item(i).StartDateTime.Date = mondayCurrent And Appointments.Item(i).Subject = "preferred" Then
                RadDateTimePickerMondayStart.SelectedDate = Appointments.Item(i).StartDateTime
                RadDateTimePickerMondayEnd.SelectedDate = Appointments.Item(i).EndDateTime
            End If

            If Appointments.Item(i).StartDateTime.Date = tuesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                RadDateTimePickerTuesdayStart.SelectedDate = Appointments.Item(i).StartDateTime
                RadDateTimePickerTuesdayEnd.SelectedDate = Appointments.Item(i).EndDateTime
            End If

            If Appointments.Item(i).StartDateTime.Date = wednesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                RadDateTimePickerWednesdayStart.SelectedDate = Appointments.Item(i).StartDateTime
                RadDateTimePickerWednesdayEnd.SelectedDate = Appointments.Item(i).EndDateTime
            End If

            If Appointments.Item(i).StartDateTime.Date = thursdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                RadDateTimePickerThursdayStart.SelectedDate = Appointments.Item(i).StartDateTime
                RadDateTimePickerThursdayEnd.SelectedDate = Appointments.Item(i).EndDateTime
            End If

            If Appointments.Item(i).StartDateTime.Date = fridayCurrent And Appointments.Item(i).Subject = "preferred" Then
                RadDateTimePickerFridayStart.SelectedDate = Appointments.Item(i).StartDateTime
                RadDateTimePickerFridayEnd.SelectedDate = Appointments.Item(i).EndDateTime
            End If

            If Appointments.Item(i).StartDateTime.Date = saturdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                RadDateTimePickerSaturdayStart.SelectedDate = Appointments.Item(i).StartDateTime
                RadDateTimePickerSaturdayEnd.SelectedDate = Appointments.Item(i).EndDateTime
            End If
        Next

        'add the DateTime to the dateTimePickers if there is no time range
        If RadDateTimePickerSundayStart.SelectedDate Is Nothing And RadDateTimePickerSundayEnd.SelectedDate Is Nothing Then
            RadDateTimePickerSundayStart.SelectedDate = sundayCurrent
            RadDateTimePickerSundayEnd.SelectedDate = sundayCurrent
            'RadDateTimePickerSundayStart.Visible = False
            'RadDateTimePickerSundayEnd.Visible = False
            sundayTempFlag = True
        End If
        If RadDateTimePickerMondayStart.SelectedDate Is Nothing And RadDateTimePickerMondayEnd.SelectedDate Is Nothing Then
            RadDateTimePickerMondayStart.SelectedDate = mondayCurrent
            RadDateTimePickerMondayEnd.SelectedDate = mondayCurrent
            'RadDateTimePickerMondayStart.de()
            mondayTempFlag = True
        End If
        If RadDateTimePickerTuesdayStart.SelectedDate Is Nothing And RadDateTimePickerTuesdayEnd.SelectedDate Is Nothing Then
            RadDateTimePickerTuesdayStart.SelectedDate = tuesdayCurrent
            RadDateTimePickerTuesdayEnd.SelectedDate = tuesdayCurrent
            tuesdayTempFlag = True
        End If
        If RadDateTimePickerWednesdayStart.SelectedDate Is Nothing And RadDateTimePickerWednesdayEnd.SelectedDate Is Nothing Then
            RadDateTimePickerWednesdayStart.SelectedDate = wednesdayCurrent
            RadDateTimePickerWednesdayEnd.SelectedDate = wednesdayCurrent
            wednesdayTempFlag = True
        End If
        If RadDateTimePickerThursdayStart.SelectedDate Is Nothing And RadDateTimePickerThursdayEnd.SelectedDate Is Nothing Then
            RadDateTimePickerThursdayStart.SelectedDate = thursdayCurrent
            RadDateTimePickerThursdayEnd.SelectedDate = thursdayCurrent
            thursdayTempFlag = True
        End If
        If RadDateTimePickerFridayStart.SelectedDate Is Nothing And RadDateTimePickerFridayEnd.SelectedDate Is Nothing Then
            RadDateTimePickerFridayStart.SelectedDate = fridayCurrent
            RadDateTimePickerFridayEnd.SelectedDate = fridayCurrent
            fridayTempFlag = True
        End If
        If RadDateTimePickerSaturdayStart.SelectedDate Is Nothing And RadDateTimePickerSaturdayEnd.SelectedDate Is Nothing Then
            RadDateTimePickerSaturdayStart.SelectedDate = saturdayCurrent
            RadDateTimePickerSaturdayEnd.SelectedDate = saturdayCurrent
            saturdayTempFlag = True
        End If
        'add the code to set the timepicker range
        For i = 0 To aCount - 1
            If Appointments.Item(i).StartDateTime.Date = sundayCurrent And Appointments.Item(i).Subject = "available" Then
                Dim StartTimeAvail As DateTime
                Dim EndTimeAvail As DateTime
                StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                RadDateTimePickerSundayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerSundayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                RadDateTimePickerSundayEnd.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerSundayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
            End If
            If Appointments.Item(i).StartDateTime.Date = mondayCurrent And Appointments.Item(i).Subject = "available" Then
                Dim StartTimeAvail As DateTime
                Dim EndTimeAvail As DateTime
                StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                RadDateTimePickerMondayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerMondayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                RadDateTimePickerMondayEnd.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerMondayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
            End If
            If Appointments.Item(i).StartDateTime.Date = tuesdayCurrent And Appointments.Item(i).Subject = "available" Then
                Dim StartTimeAvail As DateTime
                Dim EndTimeAvail As DateTime
                StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                RadDateTimePickerTuesdayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerTuesdayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                RadDateTimePickerTuesdayEnd.TimeView.EndTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerTuesdayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
            End If
            If Appointments.Item(i).StartDateTime.Date = wednesdayCurrent And Appointments.Item(i).Subject = "available" Then
                Dim StartTimeAvail As DateTime
                Dim EndTimeAvail As DateTime
                StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                RadDateTimePickerWednesdayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerWednesdayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                RadDateTimePickerWednesdayEnd.TimeView.EndTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerWednesdayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
            End If

            If Appointments.Item(i).StartDateTime.Date = fridayCurrent And Appointments.Item(i).Subject = "available" Then
                Dim StartTimeAvail As DateTime
                Dim EndTimeAvail As DateTime
                StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                RadDateTimePickerFridayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerFridayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                RadDateTimePickerFridayEnd.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerFridayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
            End If
            If Appointments.Item(i).StartDateTime.Date = saturdayCurrent And Appointments.Item(i).Subject = "available" Then
                Dim StartTimeAvail As DateTime
                Dim EndTimeAvail As DateTime
                StartTimeAvail = Appointments.Item(i).StartDateTime.ToShortTimeString
                EndTimeAvail = Appointments.Item(i).EndDateTime.ToShortTimeString
                Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24
                Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5
                RadDateTimePickerSaturdayStart.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerSaturdayStart.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
                RadDateTimePickerSaturdayEnd.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)
                RadDateTimePickerSaturdayEnd.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)
            End If
        Next

        'bind the coresponding time range to the radio buttons
        For i = 0 To aCount - 1
            If Appointments.Item(i).StartDateTime.Date = sundayCurrent And Appointments.Item(i).Subject = "preferred" Then
                Dim time As DateTime = DateTime.Now
                Dim format As String = "t"
                If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                    RadioAllDaySunday.Checked = True
                Else
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                        RadioMorningSunday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                            RadioEveningSunday.Checked = True
                        Else
                            RadioOtherSunday.Checked = True
                            RadDateTimePickerSundayStart.Enabled = True
                            RadDateTimePickerSundayEnd.Enabled = True
                        End If
                    End If
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = mondayCurrent And Appointments.Item(i).Subject = "preferred" Then
                Dim time As DateTime = DateTime.Now
                Dim format As String = "t"
                If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                    RadioAllDayMonday.Checked = True
                Else
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                        RadioMorningMonday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                            RadioEveningMonday.Checked = True
                        Else
                            RadioOtherMonday.Checked = True
                            RadDateTimePickerMondayStart.Enabled = True
                            RadDateTimePickerMondayEnd.Enabled = True
                        End If
                    End If
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = tuesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                Dim time As DateTime = DateTime.Now
                Dim format As String = "t"
                If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                    RadioAllDayTuesday.Checked = True
                Else
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                        RadioMorningTuesday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                            RadioEveningTuesday.Checked = True
                        Else
                            RadioOtherTuesday.Checked = True
                            RadDateTimePickerTuesdayStart.Enabled = True
                            RadDateTimePickerTuesdayEnd.Enabled = True
                        End If
                    End If
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = wednesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                Dim time As DateTime = DateTime.Now
                Dim format As String = "t"
                If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                    RadioAllDayWednesday.Checked = True
                Else
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                        RadioMorningWednesday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                            RadioEveningWednesday.Checked = True
                        Else
                            RadioOtherWednesday.Checked = True
                            RadDateTimePickerWednesdayStart.Enabled = True
                            RadDateTimePickerWednesdayEnd.Enabled = True
                        End If
                    End If
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = thursdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                Dim time As DateTime = DateTime.Now
                Dim format As String = "t"
                If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                    RadioAllDayThursday.Checked = True
                Else
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                        RadioMorningThursday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                            RadioEveningThursday.Checked = True
                        Else
                            RadioOtherThursday.Checked = True
                            RadDateTimePickerThursdayStart.Enabled = True
                            RadDateTimePickerThursdayEnd.Enabled = True
                        End If
                    End If
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = fridayCurrent And Appointments.Item(i).Subject = "preferred" Then
                Dim time As DateTime = DateTime.Now
                Dim format As String = "t"
                If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                    RadioAllDayFriday.Checked = True
                Else
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                        RadioMorningFriday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                            RadioEveningFriday.Checked = True
                        Else
                            RadioOtherFriday.Checked = True
                            RadDateTimePickerFridayStart.Enabled = True
                            RadDateTimePickerFridayEnd.Enabled = True
                        End If
                    End If
                End If
            End If
            If Appointments.Item(i).StartDateTime.Date = saturdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                Dim time As DateTime = DateTime.Now
                Dim format As String = "t"
                If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                    RadioAllDaySaturday.Checked = True
                Else
                    If Appointments.Item(i).StartDateTime.ToString(format) = "12:00 AM" And Appointments.Item(i).EndDateTime.ToString(format) = "6:00 PM" Then
                        RadioMorningSaturday.Checked = True
                    Else
                        If Appointments.Item(i).StartDateTime.ToString(format) = "6:00 PM" And Appointments.Item(i).EndDateTime.ToString(format) = "11:59 PM" Then
                            RadioEveningSaturday.Checked = True
                        Else
                            RadioOtherSaturday.Checked = True
                            RadDateTimePickerSaturdayStart.Enabled = True
                            RadDateTimePickerSaturdayEnd.Enabled = True
                        End If
                    End If
                End If
            End If
        Next
        'bind the coresponding Day off to the Day off radio button
        Dim appointmentSamedayCount As Integer = 0
        For i = 0 To aCount - 1
            If Appointments.Item(i).StartDateTime.Date = sundayCurrent And Appointments.Item(i).Subject = "preferred" Then
                appointmentSamedayCount += 1
            End If
        Next
        If appointmentSamedayCount = 0 Then
            RadioDayOffSunday.Checked = True
            RadDateTimePickerSundayStart.Enabled = False
            RadDateTimePickerSundayEnd.Enabled = False
        End If
        appointmentSamedayCount = 0
        For i = 0 To aCount - 1
            If Appointments.Item(i).StartDateTime.Date = mondayCurrent And Appointments.Item(i).Subject = "preferred" Then
                appointmentSamedayCount += 1
            End If
        Next
        If appointmentSamedayCount = 0 Then
            RadioDayOffMonday.Checked = True
            RadDateTimePickerMondayStart.Enabled = False
            RadDateTimePickerMondayEnd.Enabled = False
        End If
        appointmentSamedayCount = 0
        For i = 0 To aCount - 1
            If Appointments.Item(i).StartDateTime.Date = tuesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                appointmentSamedayCount += 1
            End If
        Next
        If appointmentSamedayCount = 0 Then
            RadioDayOffTuesday.Checked = True
            RadDateTimePickerTuesdayStart.Enabled = False
            RadDateTimePickerTuesdayEnd.Enabled = False
        End If
        appointmentSamedayCount = 0
        For i = 0 To aCount - 1
            If Appointments.Item(i).StartDateTime.Date = wednesdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                appointmentSamedayCount += 1
            End If
        Next
        If appointmentSamedayCount = 0 Then
            RadioDayOffWednesday.Checked = True
            RadDateTimePickerWednesdayStart.Enabled = False
            RadDateTimePickerWednesdayEnd.Enabled = False
        End If
        appointmentSamedayCount = 0
        For i = 0 To aCount - 1
            If Appointments.Item(i).StartDateTime.Date = thursdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                appointmentSamedayCount += 1
            End If
        Next
        If appointmentSamedayCount = 0 Then
            RadioDayOffThursday.Checked = True
            RadDateTimePickerThursdayStart.Enabled = False
            RadDateTimePickerThursdayEnd.Enabled = False
        End If
        appointmentSamedayCount = 0
        For i = 0 To aCount - 1
            If Appointments.Item(i).StartDateTime.Date = fridayCurrent And Appointments.Item(i).Subject = "preferred" Then
                appointmentSamedayCount += 1
            End If
        Next
        If appointmentSamedayCount = 0 Then
            RadioDayOffFriday.Checked = True
            RadDateTimePickerFridayStart.Enabled = False
            RadDateTimePickerFridayEnd.Enabled = False
        End If
        appointmentSamedayCount = 0
        For i = 0 To aCount - 1
            If Appointments.Item(i).StartDateTime.Date = saturdayCurrent And Appointments.Item(i).Subject = "preferred" Then
                appointmentSamedayCount += 1
            End If
        Next
        If appointmentSamedayCount = 0 Then
            RadioDayOffSaturday.Checked = True
            RadDateTimePickerSaturdayStart.Enabled = False
            RadDateTimePickerSaturdayEnd.Enabled = False
        End If
        'End If

 

        '' '' ''create Header title and time frame for modal
        Dim appointmentsCount As Integer = Appointments.Count - 1
        Header.Title = UserSelection + ":" + "&nbsp" + Appointments.Item(0).StartDateTime.Date + "&nbsp" + "-" + "&nbsp" + Appointments.Item(appointmentsCount).StartDateTime.Date

        'business logic goes here 

 

        Dim script As String = "function f(){$find(""" + RadWindow1.ClientID + """).show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"

        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, True)

    End Sub

End Class

0
Plamen
Telerik team
answered on 26 Nov 2012, 11:31 AM
Hi Allen,

 
Such error is most probably caused by some not proper custom formatting of the DateTime objects. Please refer to this forum thread where similar issue have been explained.

Hope this will be helpful.

All the best,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Allen
Top achievements
Rank 1
answered on 26 Nov 2012, 11:26 PM
After reading the forum threat, I still have no clue.  The old version of Telerik works just fine.  It happend right after I upgrade to the new version.  It errors out when I change the appointment start time or end time.
it throw exception on this codes:

_endPostBack:

 

function PageRequestManager$_endPostBack(error, executor, data) {

 

 

 

if (this._request === executor.get_webRequest()) {

 

 

 

this._processingRequest = false;

 

 

 

this._additionalInput = null;

 

 

 

this._request = null;

 

}

 

 

var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor);

 

Sys.Observer.raiseEvent(

 

this, "endRequest", eventArgs);

 

 

 

if (error && !eventArgs.get_errorHandled()) {

 

 

 

throw error;

 

}

},

0
Plamen
Telerik team
answered on 29 Nov 2012, 01:24 PM
Hi Allen,

 
I have inspected the code that you shared but unfortunately it is full of some custom logic that is not related with RadScheduler and can not be tested at all. That is why I created a sample web page with isolated test RadScheduler(created from our Application Scenarios as explained here at the bottom).

Would you please try to share only the code that will help us reproduce the described behavior so we can be more helpful?

Regards,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Allen
Top achievements
Rank 1
answered on 10 Jan 2013, 11:57 PM
I'm still having the same error.  Is there a way to debug and find out where this error comes from:
"Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar."  Please refer to the attached file.

Note: this only happen when I resize (either from the top or buttom) the appointment.  I have even disabled my javascripts, but still give me the same error. 
0
Plamen
Telerik team
answered on 15 Jan 2013, 03:46 PM
Hello Allen,

 
The issue sounds quite unusual indeed and we are not able to reproduce it at our side. Would you please share what is the code that should be added to the sample project I attached so we will be able to inspect it and be more helpful?

All the best,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Devang
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Allen
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or