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

automatically save changes to the schedule

5 Answers 177 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Klayton
Top achievements
Rank 1
Veteran
Klayton asked on 11 Oct 2013, 12:41 AM
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

5 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 15 Oct 2013, 12:54 PM
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 >>
0
SwiftPOS
Top achievements
Rank 1
answered on 30 Apr 2014, 01:31 AM
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
0
George
Telerik team
answered on 30 Apr 2014, 08:30 AM
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.
 
0
Gianluca
Top achievements
Rank 1
answered on 22 Feb 2017, 02:31 PM

I am searching for an answer to this as well..

"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?"

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Feb 2017, 07:46 AM
Hello Gianluca,

Thank you for writing.  

Please refer to the following help article which demonstrates how to save the changes from RadScheduler to your database: http://docs.telerik.com/devtools/winforms/scheduler/data-binding/data-binding-walkthrough

Thus, if you subscribe to the event mentioned by Georgi and perform the code snippet for storing the executed changes, you will save them to the database.

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

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Scheduler and Reminder
Asked by
Klayton
Top achievements
Rank 1
Veteran
Answers by
George
Telerik team
SwiftPOS
Top achievements
Rank 1
Gianluca
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or