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

recurrence function

8 Answers 72 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
wehbi
Top achievements
Rank 1
wehbi asked on 19 Dec 2013, 02:54 PM
i am developing alarm system application using telerik 2012 q3  and i need your help in 2 questions :

1- how to convert database appointments  rows to appointments object without using rad scheduler
2- how can i select rows from appointment table before 1 hours from starting time(recurring appointments)

8 Answers, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 20 Dec 2013, 10:44 AM
Hi Wehbi,

Thank you for writing.

To get the appointments without using RadScheduler you should first setup a SchedulerBindingDataSource which is the component used when binding RadScheduler. You can find out how to achieve this in the following help article: Data Binding Walkthrough.

Then you can simply call the GetItems method of the EventProvider to get the appointments:
List<IEvent> appointments = new List<IEvent>(schedulerBindingDataSource1.EventProvider.GetItems(null));

As to your second question, recurrences are stored as string rules in the database and each occurrence is auto generated according to that rule. Therefore, you cannot do a query directly over your SQL table but you should first load the appointments as shown above and then check each of them along with their occurrences. This is demonstrated below:
private List<IEvent> GetAppointmentsAfterDate(DateTime targetDate, List<IEvent> sourceList)
{
    List<IEvent> result = new List<IEvent>();
 
    foreach (IEvent appointment in sourceList)
    {
        if(appointment.Start >= targetDate)
        {
            result.Add(appointment);
        }
        else if (appointment.RecurrenceRule != null)
        {
            OccurrenceEnumerator enumerator = new OccurrenceEnumerator(appointment, CultureInfo.CurrentCulture.DateTimeFormat,
                targetDate, targetDate.AddYears(1));
            if (enumerator.MoveNext() && enumerator.Current != null)
            {
                result.Add(appointment);
            }
        }
    }
 
    return result;
}

I hope you find this useful. Let me know if you need anything else.

Regards,
Ivan Todorov
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
wehbi
Top achievements
Rank 1
answered on 20 Dec 2013, 03:02 PM
Thank you Ivan,

My first question is solved , but for the second question , the function  GetAppointmentsAfterDate return appointments between 2 date time and doesn't search in exceptions ,
 what i need is the appointments or exceptions  that start  after a specific time not  the appointments 
that start and finished during an interval of time  (i want to send alarm notification to user before 1 hours from the starting time)

0
Ivan Todorov
Telerik team
answered on 21 Dec 2013, 09:34 AM
Hi Wehbi,

Note that the OccurrenceEnumerator might be infinite for some recurrence rules (e.g. FREQ=DAILY). Therefore, it is recommended to limit it within some acceptable range. As to the exceptions, you need to also iterate through the Exceptions collection to check them. I have modified the previous method to return a list of appointments (including occurrences and exceptions) which start within one hour from a given date. Feel free to modify it as needed to match your requirements:
private List<IEvent> GetAppointmentsInOneHour(DateTime targetDate, List<IEvent> sourceList)
{
    List<IEvent> result = new List<IEvent>();
 
    foreach (IEvent appointment in sourceList)
    {
        if (appointment.Start >= targetDate && appointment.Start <= targetDate.AddHours(1))
        {
            result.Add(appointment);
        }
        else if (appointment.RecurrenceRule != null)
        {
            OccurrenceEnumerator enumerator = new OccurrenceEnumerator(appointment, CultureInfo.CurrentCulture.DateTimeFormat,
                targetDate, targetDate.AddYears(1));
 
            while (enumerator.MoveNext() && enumerator.Current != null)
            {
                if (enumerator.Current.Start >= targetDate && enumerator.Current.Start <= targetDate.AddHours(1))
                {
                    result.Add(enumerator.Current);
                }
                else
                {
                    break;
                }
            }
 
            foreach (IEvent exception in appointment.Exceptions)
            {
                if (exception.Start >= targetDate && exception.Start <= targetDate.AddHours(1))
                {
                    result.Add(appointment);
                }
            }
        }
    }
 
    return result;
}

Let me know if you still have any questions.

Regards,
Ivan Todorov
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
wehbi
Top achievements
Rank 1
answered on 10 Jan 2014, 02:16 PM
Thank You Ivan ,

I have another question ,

If i add a new appointment to scheduler , the Record will be saved in db with visible=1 and if i delete the appointment from  the scheduler the record will be deleted from db .

but if i add a recurrence appointment  and then delete one occurrence, the recurrence record will be saved  with visible=1 and the exception will be saved with visible=0 , but in the scheduler the occurrence  is still being displayed . 
How can i remove from my scheduler the occurrence with visible=0 ? 
0
George
Telerik team
answered on 14 Jan 2014, 12:20 PM
Hi Wehbi,

Thank you for replying.

It seems that your question is not related to the initial subject of the thread. I would like to kindly ask you not to mix different questions in one thread as this makes the questions harder to find. Moreover, your question was answered in the support thread you have opened regarding this matter. I am posting the answer here, so the community can benefit from it:

"Each appointment has a property called DataItem which holds the databound item. If you cast your DataItem you will be able to get its Visible property and show/hide the appointment. For example:
For Each app As Appointment In Me.scheduler.Appointments
    If TryCast(app.DataItem, YourDataItem).Visible = 0 Then
        app.Visible = False
    End If
Next

You can also read the article regarding data binding RadScheduler here.
"

I hope this helps.

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
wehbi
Top achievements
Rank 1
answered on 14 Jan 2014, 01:36 PM
Thank you George ,

i just changed the visible column type from "int" to "bit" in sql and everything is working normally
0
wehbi
Top achievements
Rank 1
answered on 15 Jan 2014, 10:55 AM
please can i have example how to add manually List of IEvents to RadReminder 
0
George
Telerik team
answered on 15 Jan 2014, 03:53 PM
Hi Wehbi,

Thank you for replying.

As I mentioned in my last post, please ask different questions in different support threads so that they can be addressed accordingly, and found easier on the forums. I will post this answer here so the community can benefit from it. 

You can add a new appointment to the reminder using the AddRemindObject method:
RadSchedulerReminder reminder = new RadSchedulerReminder();
reminder.AddRemindObject(new Appointment(DateTime.Now.AddMinutes(-5), DateTime.Now.AddMinutes(5)));
reminder.StartReminder();

I hope this helps.

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 >>
Tags
Scheduler and Reminder
Asked by
wehbi
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
wehbi
Top achievements
Rank 1
George
Telerik team
Share this question
or