automatically save changes to the schedule

4 posts, 0 answers
  1. Klayton
    Klayton avatar
    1 posts
    Member since:
    Sep 2011

    Posted 10 Oct 2013 Link to this post

    Hello friends,

    I need any change in the schedule is saved automatically. I am building the project in vb.net. In my code below that the problem happens when I save a new appointment, the appointment is saved twice. Appear when two close and open again the agenda. Can you help me? Below is the code:

     Private Sub FrmPortal_Load(sender As Object, e As EventArgs) Handles Me.Load
            AddHandler Me.RadScheduler1.Appointments.CollectionChanged, AddressOf Appointments_CollectionChanged
            Me.RadScheduler1.ActiveView.StartDate = Date.Now
    End Sub

     Private Function Appointments_CollectionChanged(ByVal sender As Object, ByVal e As NotifyCollectionChangedEventArgs) As String
            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

        Private Function CollectionChangedCompleted(ByVal action As String) As Boolean
            If RadScheduler1.Appointments.IsUpdated Then
                performAction(action)
                Return True
            Else
                Return False
            End If
            Return False
        End Function

        Private Function performAction(ByVal action As String) As Boolean
            Select Case action
                Case "Add"
                    Call SalvarAgenda()
                Case "Batch"
                    Call SalvarAgenda()
                Case "ItemChanged"
                    Call SalvarAgenda()
                Case "ItemChanging"
                    'Call SalvarAgenda()
                Case "Move"
                    Call SalvarAgenda()
                Case "Remove"
                    Call SalvarAgenda()
                Case "Replace"
                    Call SalvarAgenda()
                Case "Reset"
                    Call SalvarAgenda()
            End Select
        End Function

     Sub SalvarAgenda()
            AppointmentsTableAdapter.Adapter.AcceptChangesDuringUpdate = False
            Dim deletedChildRecords As ERPDataSet.AppointmentsResourcesDataTable = TryCast(Me.ERPDataSet.AppointmentsResources.GetChanges(DataRowState.Deleted), ERPDataSet.AppointmentsResourcesDataTable)
            Dim newChildRecords As ERPDataSet.AppointmentsResourcesDataTable = TryCast(Me.ERPDataSet.AppointmentsResources.GetChanges(DataRowState.Added), ERPDataSet.AppointmentsResourcesDataTable)
            Dim modifiedChildRecords As ERPDataSet.AppointmentsResourcesDataTable = TryCast(Me.ERPDataSet.AppointmentsResources.GetChanges(DataRowState.Modified), ERPDataSet.AppointmentsResourcesDataTable)
            Try
                If deletedChildRecords IsNot Nothing Then
                    AppointmentsResourcesTableAdapter.Update(deletedChildRecords)
                End If
                AppointmentsTableAdapter.Update(Me.ERPDataSet.Appointments)
                If newChildRecords IsNot Nothing Then
                    AppointmentsResourcesTableAdapter.Update(newChildRecords)
                End If
                If modifiedChildRecords IsNot Nothing Then
                    AppointmentsResourcesTableAdapter.Update(modifiedChildRecords)
                End If
                Me.ERPDataSet.AcceptChanges()
            Catch ex As Exception
                '    MessageBox.Show(String.Format("An error occurred during the update process:" & vbLf & "{0}", ex.Message))
            Finally
                If deletedChildRecords IsNot Nothing Then
                    deletedChildRecords.Dispose()
                End If
                If newChildRecords IsNot Nothing Then
                    newChildRecords.Dispose()
                End If
                If modifiedChildRecords IsNot Nothing Then
                    modifiedChildRecords.Dispose()
                End If
            End Try
        End Sub
  2. George
    Admin
    George avatar
    500 posts

    Posted 15 Oct 2013 Link to this post

    Hello Klayton,

    Thank you for contacting us.

    This behavior occurs because RadScheduler does a lot of internal operations which throw CollectionChanged with Batch action. This causes the Update operation of the table adapter to be called numerous times, which causes duplications. To prevent this behavior I would recommend to update the database on any action except Batch:
    void Appointments_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
    {
        if (e.Action != Telerik.WinControls.Data.NotifyCollectionChangedAction.Batch)
        {
            this.appointmentsTableAdapter.Update(this.schedulerDataDataSet);
        }
    }

    I hope this helps. Let me know If there is anything else I can do for you.

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. SwiftPOS
    SwiftPOS avatar
    1 posts
    Member since:
    Aug 2012

    Posted 29 Apr 2014 in reply to George Link to this post

    Hi George,

    I was following example when I am using timelineView group by resource , however dragging when dragging a appointment to a different time, it calls the "batch" event, thus never gets saved.

    Is there any other way to implement automatic saves on changes?

    Cheers
  5. George
    Admin
    George avatar
    500 posts

    Posted 30 Apr 2014 Link to this post

    Hi Grahame,

    Thank you for contacting us.

    You can use the AppointmentDroppped event and save the changes in the event handler. This will cover the scenario you described.

    Let me know if you have further questions.

    Regards,
    George
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top