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

Custom Appointment Event Handling And DataBound Resource.Color Code Snippet!

1 Answer 123 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 14 Aug 2011, 06:35 AM
Hello Telerik Members,

I have done "A Lot" of searching the net to figure out the best way to Update my datasource or database without User interaction. I was very surprised when i did not see a "AppointmentCreated" event for RadScheduler .... Not sure why this was never an event.
Anyways, I have spent some time to try to give you guys a little more flexibility in the events that happen at runtime.

Also, was unable to find answers to how to assign each resource a color with a databound Scheduler. I was able to get this working as well. I will provide the code for this while here. Hopefully Telerik admins will see this and make it in the code library or sticky this thread ?

Anyways, here you go:

Custom Event Handling:
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports Telerik.WinControls.UI
Imports Telerik.WinControls.Data

' EVENT HANDLER FOR APPOINTMENTS COLLECTION CHANGED CALLS FUNCTION
' Appointments_CollectionChanged()
' CAN ADD THIS TO THE FORM_LOAD EVENT
AddHandler RadScheduler1.Appointments.CollectionChanged,
AddressOf
Appointments_CollectionChanged
 
'Appointments_CollectionChanged()
Private Function Appointments_CollectionChanged(ByVal sender As Object,
ByVal e As NotifyCollectionChangedEventArgs) As String
' WILL PASS A ACTION TO CollectionChangedCompleted()
' DEPENDING ON THE ACTION PERFORMED AT RUNTIME
        Select Case e.Action
            Case NotifyCollectionChangedAction.Add
                CollectionChangedCompleted("Add")
            Case NotifyCollectionChangedAction.Batch
                CollectionChangedCompleted("Batch")
            Case NotifyCollectionChangedAction.ItemChanged
                CollectionChangedCompleted("ItemChanged")
            Case NotifyCollectionChangedAction.ItemChanging
                CollectionChangedCompleted("ItemChanging")
            Case NotifyCollectionChangedAction.Move
                CollectionChangedCompleted("Move")
            Case NotifyCollectionChangedAction.Remove
                CollectionChangedCompleted("Remove")
            Case NotifyCollectionChangedAction.Replace
                CollectionChangedCompleted("Replace")
            Case NotifyCollectionChangedAction.Reset
                CollectionChangedCompleted("Reset")
        End Select
 
        Return String.Empty
End Function
 
' CollectionChangedCompleted()
' THIS FUNCTION CHECKS TO MAKE SURE THE RadScheduler APPOINTMENTS
' WHERE UPDATED
Private Function CollectionChangedCompleted(ByVal action As String) As Boolean
        If RadScheduler1.Appointments.IsUpdated Then
            ' FORWARD THE ACTION TO performAction()
                 ' FOR PROCESSING CUSTOM OPERATIONS
            performAction(action)
            Return True
        Else
            Return False
        End If
 
        Return False
End Function
 
' performAction()
Private Function performAction(ByVal action As String) As Boolean
        Select Case action
            Case "Add"
                'DO CUSTOM OPERATIONS
                ' ie: updating your datasource/database
                ' WITH OUT THE NEED FOR A "SAVE/UPDATE" BUTTON
                ' AUTOMATED UPDATING :)
 
            Case "Batch"
                'DO CUSTOM OPERATIONS
 
            Case "ItemChanged"
                'DO CUSTOM OPERATIONS
 
            Case "ItemChanging"
                'DO CUSTOM OPERATIONS
 
            Case "Move"
                'DO CUSTOM OPERATIONS
 
            Case "Remove"
                'DO CUSTOM OPERATIONS
 
            Case "Replace"
                'DO CUSTOM OPERATIONS
 
            Case "Reset"
                'DO CUSTOM OPERATIONS
 
        End Select
End Function


And the Resources Color Code:
' CALL TO APPLY COLORS TO RESOURCES!!!!
Private Sub applyResourceColors()
        Dim colors() As Color = {Color.LightPink, Color.LightBlue, Color.LightCyan, Color.LightGreen, Color.LightSalmon, Color.LightYellow, Color.LightCoral}
        Dim i As Integer = 0
 
        For Each res As Resource In RadScheduler1.Resources
            res.Color = colors(i)
 
            ' TO MAKE SURE WE DON'T GO OUT OF RANGE FOR THE COLORS() ARRAY
            ' IF WE REACH OUR ZERO BASED INDEX COUNT ON COLORS ARRAY WE RESET i TO 0
            ' ALLOWING IT TO REPEAT THE COLORS
            Dim colorsCount As Integer = colors.Count
 
            If Not i = colorsCount Then
                i += 1
            Else
                i = 0
            End If
 
        Next
End Sub
[UPDATE] - I have noticed that for whatever reason that resource colors get reset after data updating ... not sure why yet but I have contacted Rob Shoemate on his blog about resource grouping to try and see if there is a better way of doing this! If I get any updates i will edit this post so that all can learn from it!

You can follow this blog for responses from Rob here

Hope this helps some of you!

Will continue to contribute when possible!

Thanks,
Mike

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 17 Aug 2011, 01:36 PM
Hello Mike,

Thank you very much for sharing your code with the community. We highly appreciate your efforts.

Do not hesitate to contact us if you have any questions.

Regards,
Martin Vasilev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
Scheduler and Reminder
Asked by
Mike
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or