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

Custom appointment: TryCast return nothing

9 Answers 90 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
manuele
Top achievements
Rank 1
manuele asked on 24 Feb 2015, 04:16 PM
hi, i have created a Custom Appointment Class inherit Telerik.Appointment Class

Public Class CustomAppointment
    Inherits Telerik.WinControls.UI.Appointment
    Public Sub New()
        MyBase.New()
    End Sub

    Private _Visitato As Boolean = False
    Private _Ordine As Boolean = False



    Public Property Visitato() As Boolean
        Get
            Return Me._Visitato
        End Get
        Set(ByVal value As Boolean)
            If Me._Visitato <> value Then
                Me._Visitato = value
                Me.OnPropertyChanged("Visitato")
            End If
        End Set
    End Property


    Public Property Ordine() As Boolean
        Get
            Return Me._Ordine
        End Get
        Set(ByVal value As Boolean)
            If Me._Ordine <> value Then
                Me._Ordine = value
                Me.OnPropertyChanged("Ordine")
            End If
        End Set
    End Property
End Class

But when i try to modify an appointment the TryCast between my object and telerik appointment return always nothing

Protected Overrides Sub LoadSettingsFromEvent(ByVal ev As IEvent)
        MyBase.LoadSettingsFromEvent(ev)

        Dim CustomAppointment As CustomAppointment = TryCast(ev, CustomAppointment)
        If CustomAppointment IsNot Nothing Then
            Me.Visitato_chk.Checked = CustomAppointment.Visitato
            Me.Ordine_chk.Checked = CustomAppointment.Ordine
        End If
    End Sub









9 Answers, 1 is accepted

Sort by
0
manuele
Top achievements
Rank 1
answered on 26 Feb 2015, 09:36 AM
Now the try cast works correctly, but i can retrieve data before save data to my sql database.

The custom fields added on my custuomappointment class are always DBNULL

The code that i use to update my DB is:

  Dim newAppointmentRecords As DATADataSet.PlanningDataTable = TryCast(Me.DATADataSet.Planning.GetChanges(DataRowState.Added), DATADataSet.PlanningDataTable)
        Dim deletedAppointmentRecords As DATADataSet.PlanningDataTable = TryCast(Me.DATADataSet.Planning.GetChanges(DataRowState.Deleted), DATADataSet.PlanningDataTable)
        Dim modifiedAppointmentRecords As DATADataSet.PlanningDataTable = TryCast(Me.DATADataSet.Planning.GetChanges(DataRowState.Modified), DATADataSet.PlanningDataTable)

        Try
            If newAppointmentRecords IsNot Nothing Then
                Dim newAppointmentIds As New Dictionary(Of Integer, Integer)()
                Dim oldAppointmentIds As New Dictionary(Of Object, Integer)()

                For i As Integer = 0 To newAppointmentRecords.Count - 1
                    oldAppointmentIds.Add(newAppointmentRecords(i), newAppointmentRecords(i).ID)
                Next

                PlanningTableAdapter.Update(newAppointmentRecords)

                For i As Integer = 0 To newAppointmentRecords.Count - 1
                    ' PlanningTableAdapter.Insert(newAppointmentRecords(i).Item, newAppointmentRecords(i).Data.Date, newAppointmentRecords(i).CodiceCliente, _
                    '                             newAppointmentRecords(i).RagioneSociale, newAppointmentRecords(i).Visita, newAppointmentRecords(i).Ordine, _
                    '                            newAppointmentRecords(i).Note, False)
                    newAppointmentIds.Add(oldAppointmentIds(newAppointmentRecords(i)), newAppointmentRecords(i).ID)
                Next

                'For i As Integer = 0 To newRelationRecords.Count - 1
                '    newRelationRecords(i).AppointmentID = newAppointmentIds(newRelationRecords(i).AppointmentID)
                'Next
            End If

           

            If deletedAppointmentRecords IsNot Nothing Then


                For i As Integer = 0 To deletedAppointmentRecords.Count - 1
                    PlanningTableAdapter.Update(deletedAppointmentRecords)
                    '    PlanningTableAdapter.UpdateDeletedQuery(deletedAppointmentRecords(i).Item)
                Next

            End If

            If modifiedAppointmentRecords IsNot Nothing Then
                PlanningTableAdapter.Update(modifiedAppointmentRecords)
            End If

            'If newRelationRecords IsNot Nothing Then
            '    AppointmentsResourcesTableAdapter.Update(newRelationRecords)
            'End If
            'If modifiedRelationRecords IsNot Nothing Then
            '    AppointmentsResourcesTableAdapter.Update(modifiedRelationRecords)
            'End If

            Me.DATADataSet.AcceptChanges()
        Catch ex As Exception
            MessageBox.Show(String.Format("An error occurred during the update process:" & vbLf & "{0}", ex.Message))
        Finally
            'If deletedRelationRecords IsNot Nothing Then
            '    deletedRelationRecords.Dispose()
            'End If
            'If newRelationRecords IsNot Nothing Then
            '    newRelationRecords.Dispose()
            'End If
            'If modifiedRelationRecords IsNot Nothing Then
            '    modifiedRelationRecords.Dispose()
            'End If
        End Try

        'lblStatus.Text = "Updated scheduler at " + DateTime.Now.ToString()

    End Sub
0
manuele
Top achievements
Rank 1
answered on 26 Feb 2015, 09:38 AM
Now the trycast works
But i can retrieve data from my customappointment
All custom fields are always DBNULL
The code that i use to update my SQL database is:

 
Dim newAppointmentRecords As DATADataSet.PlanningDataTable = TryCast(Me.DATADataSet.Planning.GetChanges(DataRowState.Added), DATADataSet.PlanningDataTable)
     Dim deletedAppointmentRecords As DATADataSet.PlanningDataTable = TryCast(Me.DATADataSet.Planning.GetChanges(DataRowState.Deleted), DATADataSet.PlanningDataTable)
     Dim modifiedAppointmentRecords As DATADataSet.PlanningDataTable = TryCast(Me.DATADataSet.Planning.GetChanges(DataRowState.Modified), DATADataSet.PlanningDataTable)
 
     Try
         If newAppointmentRecords IsNot Nothing Then
             Dim newAppointmentIds As New Dictionary(Of Integer, Integer)()
             Dim oldAppointmentIds As New Dictionary(Of Object, Integer)()
 
             For i As Integer = 0 To newAppointmentRecords.Count - 1
                 oldAppointmentIds.Add(newAppointmentRecords(i), newAppointmentRecords(i).ID)
             Next
 
             PlanningTableAdapter.Update(newAppointmentRecords)
 
             For i As Integer = 0 To newAppointmentRecords.Count - 1
                 ' PlanningTableAdapter.Insert(newAppointmentRecords(i).Item, newAppointmentRecords(i).Data.Date, newAppointmentRecords(i).CodiceCliente, _
                 '                             newAppointmentRecords(i).RagioneSociale, newAppointmentRecords(i).Visita, newAppointmentRecords(i).Ordine, _
                 '                            newAppointmentRecords(i).Note, False)
                 newAppointmentIds.Add(oldAppointmentIds(newAppointmentRecords(i)), newAppointmentRecords(i).ID)
             Next
 
             'For i As Integer = 0 To newRelationRecords.Count - 1
             '    newRelationRecords(i).AppointmentID = newAppointmentIds(newRelationRecords(i).AppointmentID)
             'Next
         End If
 
         
 
         If deletedAppointmentRecords IsNot Nothing Then
 
 
             For i As Integer = 0 To deletedAppointmentRecords.Count - 1
                 PlanningTableAdapter.Update(deletedAppointmentRecords)
                 '    PlanningTableAdapter.UpdateDeletedQuery(deletedAppointmentRecords(i).Item)
             Next
 
         End If
 
         If modifiedAppointmentRecords IsNot Nothing Then
             PlanningTableAdapter.Update(modifiedAppointmentRecords)
         End If
 
         'If newRelationRecords IsNot Nothing Then
         '    AppointmentsResourcesTableAdapter.Update(newRelationRecords)
         'End If
         'If modifiedRelationRecords IsNot Nothing Then
         '    AppointmentsResourcesTableAdapter.Update(modifiedRelationRecords)
         'End If
 
         Me.DATADataSet.AcceptChanges()
     Catch ex As Exception
         MessageBox.Show(String.Format("An error occurred during the update process:" & vbLf & "{0}", ex.Message))
     Finally
         'If deletedRelationRecords IsNot Nothing Then
         '    deletedRelationRecords.Dispose()
         'End If
         'If newRelationRecords IsNot Nothing Then
         '    newRelationRecords.Dispose()
         'End If
         'If modifiedRelationRecords IsNot Nothing Then
         '    modifiedRelationRecords.Dispose()
         'End If
     End Try
 
     'lblStatus.Text = "Updated scheduler at " + DateTime.Now.ToString()
 
 End Sub
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Feb 2015, 08:51 AM
Hello Manuele,

Thank you for writing.

I have prepared a sample project demonstrating how to create a custom Appointment with email property and save the changes to database. Please refer to our Adding a custom field to the EditAppointment dialog, Data Binding Walkthrough and Binding to Custom Fields help articles which are quite useful on this topic.

Note that it is important to add SchedulerMapping to the AppointmentMappingInfo.Mappings collection for the custom fields. Additionally, you need to replace the RadScheduler.AppointmentFactory and SchedulerBindingDataSource.EventProvider.AppointmentFactory with your custom one.

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Dess
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
manuele
Top achievements
Rank 1
answered on 27 Feb 2015, 04:42 PM
i have tried to bind my custom fields:

Protected Overrides Sub OnLoad(ByVal e As EventArgs)
       MyBase.OnLoad(e)
       Me.RadScheduler1.AppointmentFactory = New CustomAppointmentFactory()
       AddHandler RadScheduler1.AppointmentEditDialogShowing, AddressOf radScheduler1_AppointmentEditDialogShowing
 
       Dim dataSource As New SchedulerBindingDataSource()
       dataSource.EventProvider.AppointmentFactory = Me.RadScheduler1.AppointmentFactory
       Dim appointmentMappingInfo As AppointmentMappingInfo = DirectCast(dataSource.EventProvider.Mapping, AppointmentMappingInfo)
       appointmentMappingInfo.Mappings.Add(New SchedulerMapping("Ordine", "Ordine"))
       appointmentMappingInfo.Mappings.Add(New SchedulerMapping("Visitato", "Visita"))
       appointmentMappingInfo.Start = "Start"
       appointmentMappingInfo.Summary = "RagioneSociale"
       appointmentMappingInfo.Description = "Note"
       appointmentMappingInfo.Location = "CodiceCliente"
       appointmentMappingInfo.UniqueId = "Item"
 
       SchedulerBindingDataSource1.EventProvider.Mapping = appointmentMappingInfo
       SchedulerBindingDataSource1.EventProvider.DataSource = DATADataSet.Planning
 
 
   End Sub


"Ordine" and "Visita" are bit fields in my SQL database.
"Ordine" and "Visitato" are custom fields in my CustomAppointment object
"Ordine" and "Visitato" are two check boxes on my CustomAppointmentEditForm

This code does not retrieve data from database for custom fields, standard fields values are retrieved correctly



0
manuele
Top achievements
Rank 1
answered on 03 Mar 2015, 09:59 AM
I have debugged my code:
it seems that my customappointment does not update my dataset
Then when i try to update my database from my dataset custom fields are DBNULL

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Mar 2015, 11:14 AM
Hello Manuele,

Thank you for writing back.

If the AppointmentMappingInfo has SchedulerMapping for the custom fields, it is not supposed to encounter any problems with loading the respective data. One possible reason would be if the column type in the database differs from the corresponding property's type in your custom appointment class. In this situation you need to make the conversion between the two types manually. You can refer to our Setting Appointment and Resource relations help article where it is demonstrated how to use the AppointmentMapping.FindBySchedulerProperty("your custom field").ConvertToDataSource and AppointmentMapping.FindBySchedulerProperty("your custom field").ConvertToScheduler callbacks. Similar approach should be followed for the custom fields as well.

If you are still experiencing any difficulties, I would kindly ask you to modify the provided sample project from my previous post on a way to reproduce the experienced issue and get back to me with it so we can investigate the precise case and assist you further. Thank you in advance.

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Dess
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
manuele
Top achievements
Rank 1
answered on 04 Mar 2015, 05:04 PM
I have found the error! (i don't have used dataSource.EventProvider correctly)

I post here my code, maybe can be useful for other users:

Protected Overrides Sub OnLoad(ByVal e As EventArgs)
      
        MyBase.OnLoad(e)
        Me.RadScheduler1.AppointmentFactory = New CustomAppointmentFactory()
        AddHandler RadScheduler1.AppointmentEditDialogShowing, AddressOf radScheduler1_AppointmentEditDialogShowing
 
        Me.RadScheduler1.ActiveViewType = Telerik.WinControls.UI.SchedulerViewType.Month
 
        BindToDataSource()
 
    End Sub
 
 Private Sub BindToDataSource()
 
 
        Me.PlanningTableAdapter.Fill(Me.DATADataSet.Planning)
 
 
 
        ' create and assign appointment mapping
        Dim appointmentMappingInfo As New AppointmentMappingInfo()
 
        Dim dataSource As New SchedulerBindingDataSource()
        dataSource.EventProvider.AppointmentFactory = Me.RadScheduler1.AppointmentFactory
        appointmentMappingInfo.Mappings.Add(New SchedulerMapping("Ordine", "Ordine"))
        appointmentMappingInfo.Mappings.Add(New SchedulerMapping("Visita", "Visita"))
 
        appointmentMappingInfo.Start = "Data"
        appointmentMappingInfo.[End] = "Data"
        appointmentMappingInfo.Summary = "RagioneSociale"
        appointmentMappingInfo.Description = "Note"
        appointmentMappingInfo.Location = "CodiceCliente"
 
        dataSource.EventProvider.Mapping = appointmentMappingInfo
        dataSource.EventProvider.DataSource = DATADataSet.Planning
 
        RadScheduler1.DataSource = dataSource
 
 
 
    End Sub

Thanks


0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Mar 2015, 02:43 PM
Hello Manuele,

Thank you for writing back.

I am glad that the issue you were facing is now resolved. Our Scheduler >> Data Binding Walkthrough help article is quite useful on this topic and demonstrates what steps should be performed in order to set up the binding correctly.

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Dess
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Deo
Top achievements
Rank 2
answered on 13 Aug 2015, 09:28 AM

Thank you... so the problem was the data type doesn't match the data type on the database table

 i was wondering my string columns was properly fetch while the int columns which was unassigned returns 0 

 

so because on my table it was unassigned Int while on my project it was integer 

:) Thank you.. very much it was a 2 day of debugging damn hahaha

Tags
Scheduler and Reminder
Asked by
manuele
Top achievements
Rank 1
Answers by
manuele
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Deo
Top achievements
Rank 2
Share this question
or