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

Recurrence Exception problem in custom EditAppointmentDialog

8 Answers 246 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 09 Aug 2010, 07:10 PM
Hello,
I need a recurring functionality for my project. Also I have created a custom EditAppointmentDialog, as well as a custom Appointment class derived from Telerik.WinControls.UI.Appointment. I need one custom field for my appointment.

Everything works fine except two scenarios.

1. At first I create a recurrence appointment which generates a number of occurrences in the scheduler view. Then clicking on one of the occurrences in the scheduler I get a Message Box which allows me to select whether I would like to open  this occurrence or the whole series. I select "Open this occurrence". After that LoadSettingsFromEvent() method is called. In that method I have the following code.

 protected override void LoadSettingsFromEvent(Telerik.WinControls.UI.IEvent sourceEvent)
        {
            base.LoadSettingsFromEvent(sourceEvent);

            var workSchedule = sourceEvent as WorkSchedule;

            if (workSchedule != null && !string.IsNullOrEmpty(workSchedule.WorkScheduleType))
            {
                cbbxType.Text = workSchedule.WorkScheduleType;
            }
        }

The sourceEvent object could not be casted to WorkSchedule (a derived class from Telerik.WinControls.UI.Appointment which holds my custom field WorkScheduleType), however it is not null and is easily casted to Telerik.WinControls.UI.Appointment class. that's why I cannot read and set this WorkScheduleType field which I certainly need for this occurrence.

It happens only when a recurrence exception is generated. If it is a normal or recurring appointment everything works just fine.

2. I want the following scenario. I would like to create a recurring appointment (say each week on Mondays and Thursdays at 6 p.m. I would like to go to the gym). I create a recurring appointment which generates a number of occurrences in the scheduler view. Then I want to remove a single occurrence for the next week for Thursday (I have different plans for next Thursday). I click on that occurrence in the scheduler. After that I try to delete this occurrence. The view shows me that it is deleted, however when I recheck DB and then reopen scheduler nothing changes. However an exception in DB is created.

How may I properly implement the above mentioned process?

8 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 12 Aug 2010, 02:47 PM
Hi Peter,

To receive assistance please refer to Support Ticket 337076. Once a solution is available we will share it here.

Regards,
Stefan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Richard
Top achievements
Rank 1
answered on 06 Sep 2011, 06:45 AM
Hi,

Has a solution been found? I have implemented something similar, where I have a custom Appointment class "JobAppointment" derived from Telerik.WinControls.UI.Appointment. I use a CustomEditDialog and enabled recurring appointments.

My question is specifically to do with recurrence exceptions - how do we deal with them. What is the normal practice?

For example, clicking on one of the occurrences in the scheduler we get a Message Box which allows us to select whether we would like to open this occurrence or the whole series. If we select "Open this occurrence" and edit something on this occurence, this creates an exception.. I then need some way of recognising that this is an exception and should now be represented as a proper appointment (stored in my database) rather than a recurring appointment occurrence created at runtime.

In addition to this, I want the recurrence rule on the master event to change to reflect that an exception has been added, so that in the future we do not get the appointment being shown up as a recurring appointment (as the appointment has been already saved and loaded from the database and no longer belongs to the recurring appointments list).

How do we do this?

Regards. 

0
Ivan Todorov
Telerik team
answered on 09 Sep 2011, 09:42 AM
Hello Richard,

Thank you for your question.

I was not able to run the code you have sent with your support ticket since there are some missing parts of it, but I could notice a few things.

First, when you edit an occurrence and apply the new settings to it, you should add it as an exception to the master event and indicate this with the RecurrenceId property. It should look similar to the following:

'the result of the OpenRecurringAppointmentDialog:
Me.editOccurrence = Me.openRecurringAppointmentDialog.EditOccurrence
 
Protected Overridable Sub ApplySettingsToEvent(targetEvent As IEvent)
    '...
    If Me.editOccurrence Then
        Me.AddException(targetEvent)
    End If
    '...
End Sub
 
Private Sub AddException(appointment As IEvent)
    Dim exceptions As ObservableCollection(Of IEvent) = Me.appointment.MasterEvent.Exceptions
    If Not exceptions.Contains(appointment) Then
        appointment.RecurrenceId = Me.recurrenceId
        exceptions.Add(appointment)
    End If
End Sub

You can refer to the implementation of EditAppointmentDialog if you have our source code. In general, I am not sure if your scenario requires implementing such dialog from scratch, but in case you need a custom dialog, it is recommended to extend the EditAppointmentDialog class. Doing so, you will get most of the logic already implemented in the base class.

Another thing which might be a problem is if you have not mapped correctly the properties of the appointments to the database fields. You can take a look at the related help section or you can check the Data Binding example in our demo application.

I hope this is useful. If you need further help on this, do not hesitate to contact me back.

Regards,
Ivan Todorov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Richard
Top achievements
Rank 1
answered on 12 Sep 2011, 07:24 AM
Thanks for that Ivan,
I will let you know if I have more questions (or if I am able to do what I need to)..

Thanks again.
0
Richard
Top achievements
Rank 1
answered on 13 Sep 2011, 03:27 AM
Hi Ivan,

I want to get my understanding right for various concepts related to recurrence...

RecurrenceRule: This is the rule (in iCal format) that defines when the occurrences are to be rendered. Can be stored as a Text field as part of the Appointment in the database.

MasterEvent: This is the appointment (IEvent) that the recurrence relates to. During runtime/rendering, the master Appointment's "CreateOccurrence" or "CreateOccurrenceInstance" is called, which creates the "child" appointments and links them back to the master appointment via this MasterEvent property. For exceptions, this is stored as a MasterEventID field in the database.

RecurrenceId: A nullable Date field to identify recurrences. Does not need to be stored in the database? But is only an ID used at runtime?

Exceptions: This is an Appointments collection on an Appointment that defines all the exceptions that are no longer part of the recurrence rule. This tells the scheduler to render the exceptions from the database/datasource.

====================

It does seem that I am very close to what I want to do after implementing the recommendation from your last post (Adding the appointment to the exceptions collection if an occurrence is being edited). The occurrence is being correctly identified as an exception (screenshot 1), but on a form reload I see the occurrence as well as the appointment from the database (screenshot 2), leading me to believe that I am still not storing and/or recognising the exceptions correctly from my database.

My implementation is quite different to the one in the Data binding example:

In the Databinding example, CustomAppointmentEdit form Inherits from EditAppointmentDialog, whereas I
Inherit from RadSchedulerDialog ad Implement IEditAppointmentDialog.

In the Databinding example, MappingInfo classes are being used to map the appointment fields, whereas I do this manually in my JobAppointment class.

I will keep looking into what I am missing (specifically while mapping the fields), if all else fails, I will change my implementation to follow the Data binding example.

Thanks.

0
Ivan Todorov
Telerik team
answered on 15 Sep 2011, 08:33 AM
Hello Richard,

I am glad that you have progress on this.

Your understanding of the described concepts are correct. Now the issue seems to be in saving/loading appointments from the database. In our documentation the sample databases have a MasterEventId field in the Appointments table which is a reference to the id of the master appointment in the same table. This way you can identify if a given record is an exception or a standalone appointment. Please check if this is correct on your end.

I hope this is useful. In case you experience further difficulties, you can always open a new support ticket and send us a sample project which contains only the scheduler parts. We will gladly try to provide you with a solution to your case.

Regards,
Ivan Todorov
the Telerik team

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

0
Scott
Top achievements
Rank 1
answered on 13 Jan 2017, 01:40 PM

Hello Ivan-

Will you please post a C# the snippet for your VB response to Richard?

Thank you.

-Scott

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Jan 2017, 10:44 AM
Hello Scott,

Thank you for writing.  

Here is the C# code snippet:
//the result of the OpenRecurringAppointmentDialog:
 
this.editOccurrence == this.openRecurringAppointmentDialog.EditOccurrence

protected virtual void ApplySettingsToEvent(IEvent targetEvent)
{
    //...
    if (this.editOccurrence) {
        this.AddException(targetEvent);
    }
    //...
}
 
private void AddException(IEvent appointment)
{
    ObservableCollection<IEvent> exceptions = this.appointment.MasterEvent.Exceptions;
    if (!exceptions.Contains(appointment)) {
        appointment.RecurrenceId = this.recurrenceId;
        exceptions.Add(appointment);
    }
}

Feel free to use our online Code Converter in future: http://converter.telerik.com/

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
Peter
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Richard
Top achievements
Rank 1
Ivan Todorov
Telerik team
Scott
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or