Appointment color when using webservice binding

2 posts, 0 answers
  1. Marja
    Marja avatar
    70 posts
    Member since:
    Nov 2013

    Posted 05 Jun 2015 Link to this post


    Based on appointment type, I need to display the appointments in different colors.

    My "GetAppointments" method looks like this:

    Public Overrides Function GetAppointments(ByVal p_oSchedulerInfo As ISchedulerInfo) As IEnumerable(Of Appointment)
        Dim l_oScheduleInfo = TryCast(p_oSchedulerInfo, wsScheduleInfo)
        Dim l_sScheduleIDs As String = l_oScheduleInfo.ScheduleIDs
        Dim l_aAppointments As New List(Of Appointment)()
        Using l_oDP As New wsDataProvider
            Using l_oSystem As New wsSystemGeneral(l_oDP)
                Dim l_sSql As String = "select * from `PlanningTaskBlocks` where `numScheduleID` in (" & l_sScheduleIDs & ") order by `numTaskID` asc"
                Using l_oDR As IDataReader = l_oDP.ExecuteReader(l_sSql)
                    If l_oDR IsNot Nothing Then
                        Dim l_oAppointment As Appointment = Nothing, l_iTaskID As Long = 0
                        Dim l_sTask As String = Nothing, l_sColor As String = Nothing, l_iAgeMin As Integer = 18, l_iAgeMax As Integer = 99, l_sGender As String = "X"
                        While l_oDR.Read
                            If l_iTaskID <> l_oDR("numTaskID") Then
                                Using l_oDRtask As IDataReader = l_oDP.ExecuteReader("select * from `PlanningTasks` where `ID` = " & l_oDR("numTaskID") & " limit 1")
                                    If l_oDRtask IsNot Nothing Then
                                        If l_oDRtask.Read Then
                                            l_sTask = l_oDRtask("txtName")
                                            l_sColor = l_oDRtask("txtColor")
                                            l_iAgeMin = l_oDRtask("numAgeMin")
                                            l_iAgeMax = l_oDRtask("numAgeMax")
                                            l_sGender = l_oDRtask("txtGender")
                                        End If
                                        If Not l_oDRtask.IsClosed Then l_oDRtask.Close()
                                    End If
                                End Using
                                l_iTaskID = l_oDR("numTaskID")
                            End If
                            l_oAppointment = New Appointment
                            l_oAppointment.ID = l_oDR("ID")
                            l_oAppointment.Subject = Convert.ToString(l_sTask)
                            l_oAppointment.Start = DateTime.SpecifyKind(Convert.ToDateTime(l_oDR("dateStart")), DateTimeKind.Utc)
                            l_oAppointment.[End] = DateTime.SpecifyKind(Convert.ToDateTime(l_oDR("dateEnd")), DateTimeKind.Utc)
                            l_oAppointment.BackColor = System.Drawing.ColorTranslator.FromHtml(l_sColor)
                            l_oAppointment.Attributes("TaskID") = Convert.ToString(l_oDR("numTaskID"))
                            l_oAppointment.Attributes("TaskPoints") = Convert.ToString(l_oDR("numTaskPoints"))
                            l_oAppointment.Attributes("NumberOfPlaces") = Convert.ToString(l_oDR("numNumberOfPlaces"))
                            l_oAppointment.Attributes("AgeMin") = Convert.ToString(l_iAgeMin)
                            l_oAppointment.Attributes("AgeMax") = Convert.ToString(l_iAgeMax)
                            l_oAppointment.Attributes("Gender") = Convert.ToString(l_sGender)
                        End While
                        If Not l_oDR.IsClosed Then l_oDR.Close()
                    End If
                End Using
            End Using
        End Using
        Return l_aAppointments
    End Function

    As you can see, I'm setting the BackColor property on every Appointment instance.

    However, the Appointment.BackColor property is ignored and all appointsments are displayed with the same color in the RadScheduler. 

    What do I need to do to 'push' my custom colors through the webservice to the scheduler?


  2. Marja
    Marja avatar
    70 posts
    Member since:
    Nov 2013

    Posted 05 Jun 2015 in reply to Marja Link to this post

    Found out how to do it. :-)

    When using webservice databinding, it needs to be done client-side with some jQuery templating engine, eg. like this:

    function wsOnSchedulerDataBound(scheduler) {
        $(".rsApt").each(function () {
            var l_oAppointment = scheduler.getAppointmentFromDomElement(this);
            var l_aAttr = l_oAppointment.get_attributes();
            var bgColor = l_aAttr.getAttribute('BgColor');
        $(".rsAptDelete").each(function () {
            var l_oAppointment = scheduler.getAppointmentFromDomElement(this);
            var l_aAttr = l_oAppointment.get_attributes();
            // creating an object containing the data that should be applied on the template
            var l_aValues = {
                NumberOfPlaces: l_aAttr.getAttribute('NumberOfPlaces'),
                TaskPoints: l_aAttr.getAttribute('TaskPoints'),
                AgeMin: l_aAttr.getAttribute('AgeMin'),
                AgeMax: l_aAttr.getAttribute('AgeMax'),
                Gender: l_aAttr.getAttribute('Gender')
            // instantiate the template, populate it and insert before the delete handler (".rsAptDelete")
            $('<div></div>').loadTemplate("#tmplAppointmentData", l_aValues).insertBefore(this);

Back to Top