Back to Devexpress

How to: Create Hourly Recurrence

wpf-119643-controls-and-libraries-scheduler-examples-recurrence-how-to-create-hourly-recurrence.md

latest3.7 KB
Original Source

How to: Create Hourly Recurrence

  • Jun 07, 2019

  • 2 minutes to read

  • XAML

xaml
<dxsch:SchedulerControl.AppointmentItems>
    <!--Every 3 hours. Five occurrences.-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="Every 3 hours. Five occurrences."
        RecurrenceInfo="{dxsch:RecurrenceHourly Start='1/1/2020 13:00:00', Interval=3, OccurrenceCount=5}" />
    <!--Every 5 hours. Infinite (no end date).-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="Every 5 hours. Infinite (no end date)."
        RecurrenceInfo="{dxsch:RecurrenceHourly Start='1/1/2020 13:00:00', Interval=5}" />
    <!--Every hour. Series duration is 24 hours.-->
    <dxsch:AppointmentItem 
        Type="Pattern"
        Start="1/1/2020 13:00:00"
        End="1/1/2020 14:00:00"
        Subject="Every hour. Series duration is 24 hours."
        RecurrenceInfo="{dxsch:RecurrenceHourly Start='1/1/2020 13:00:00', End='1/2/2020 13:00:00'}" />
</dxsch:SchedulerControl.AppointmentItems>
csharp
public AppointmentItem CreateAppointmentPattern(string subj, int categoryId) {
    AppointmentItem apt = new AppointmentItem(AppointmentType.Pattern);
    apt.Start = DateTime.Today.AddHours(9);
    apt.End = apt.Start.AddMinutes(5);
    apt.Subject = subj;
    apt.LabelId = categoryId;
    return apt;
}
    // An appointment is set every 3 hours. Five occurrences.
    AppointmentItem apt1 = CreateAppointmentPattern("Every 3 hours. Five occurrences.", 1);
    apt1.SetRecurrenceInfo(RecurrenceBuilder.Hourly(apt1.Start, 5).Interval(3).Build());
    scheduler.AppointmentItems.Add(apt1);

    // An appointment is set every 5 hours. Infinite (no end date).
    AppointmentItem apt2 = CreateAppointmentPattern("Every 5 hours. Infinite (no end date).", 1);
    apt3.SetRecurrenceInfo(RecurrenceBuilder.Hourly(apt2.Start).Interval(5).Build());
    scheduler.AppointmentItems.Add(apt2);

    // An appointment is set every hour. Appointment series duration is 24 hours.
    AppointmentItem apt3 = CreateAppointmentPattern("Every hour. Series duration is 24 hours.", 1);
    apt3.SetRecurrenceInfo(RecurrenceBuilder.Hourly(apt3.Start, apt3.Start.AddHours(24)).Build());
    scheduler.AppointmentItems.Add(apt3);
vb
Public Function CreateAppointmentPattern(ByVal subj As String, ByVal categoryId As Integer) As AppointmentItem
    Dim apt As New AppointmentItem(AppointmentType.Pattern)
    apt.Start = Date.Today.AddHours(9)
    apt.End = apt.Start.AddMinutes(5)
    apt.Subject = subj
    apt.LabelId = categoryId
    Return apt
End Function
    ' An appointment is set every 3 hours. Five occurrences.
    Private apt1 As AppointmentItem = CreateAppointmentPattern("Every 3 hours. Five occurrences.", 1)
    apt1.SetRecurrenceInfo(RecurrenceBuilder.Hourly(apt1.Start, 5).Interval(3).Build())
    scheduler.AppointmentItems.Add(apt1)

    ' An appointment is set every 5 hours. Infinite (no end date).
    Dim apt2 As AppointmentItem = CreateAppointmentPattern("Every 5 hours. Infinite (no end date).", 1)
    apt3.SetRecurrenceInfo(RecurrenceBuilder.Hourly(apt2.Start).Interval(5).Build())
    scheduler.AppointmentItems.Add(apt2)

    ' An appointment is set every hour. Appointment series duration is 24 hours.
    Dim apt3 As AppointmentItem = CreateAppointmentPattern("Every hour. Series duration is 24 hours.", 1)
    apt3.SetRecurrenceInfo(RecurrenceBuilder.Hourly(apt3.Start, apt3.Start.AddHours(24)).Build())
    scheduler.AppointmentItems.Add(apt3)