How to: Create Yearly Recurrence
- 2 minutes to read
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-create-appointments-with-various-recurrence-types-in-code-t574486.
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 occurs every seventh day of February every year. Four occurrences.
AppointmentItem apt1 = CreateAppointmentPattern("Every seventh day of February every year. Four occurrences.", 5);
apt1.RecurrenceInfo.Type = RecurrenceType.Yearly;
apt1.RecurrenceInfo.Periodicity = 1;
apt1.RecurrenceInfo.Start = apt1.Start;
apt1.RecurrenceInfo.Month = 2;
apt1.RecurrenceInfo.WeekOfMonth = WeekOfMonth.None;
apt1.RecurrenceInfo.DayNumber = 7;
apt1.RecurrenceInfo.Range = RecurrenceRange.OccurrenceCount;
apt1.RecurrenceInfo.OccurrenceCount = 4;
scheduler.AppointmentItems.Add(apt1);
// An appointment occurs the second Monday in August for 2 years. Infinite (no end date).
AppointmentItem apt2 = CreateAppointmentPattern("The second Monday in August for 2 years. Infinite (no end date).", 5);
apt2.RecurrenceInfo.Type = RecurrenceType.Yearly;
apt2.RecurrenceInfo.Periodicity = 2;
apt2.RecurrenceInfo.Start = apt2.Start;
apt2.RecurrenceInfo.Month = 8;
apt2.RecurrenceInfo.WeekOfMonth = WeekOfMonth.Second;
apt2.RecurrenceInfo.WeekDays = WeekDays.Monday;
apt2.RecurrenceInfo.Range = RecurrenceRange.NoEndDate;
scheduler.AppointmentItems.Add(apt2);
// An appointment occurs on the last day of every year for 10 years.
AppointmentItem apt3 = CreateAppointmentPattern("The last day of every year for 10 years.", 5);
apt3.RecurrenceInfo.Type = RecurrenceType.Yearly;
apt3.RecurrenceInfo.Periodicity = 1;
apt3.RecurrenceInfo.Start = apt3.Start;
apt3.RecurrenceInfo.Month = 12;
apt3.RecurrenceInfo.WeekOfMonth = WeekOfMonth.Last;
apt3.RecurrenceInfo.WeekDays = WeekDays.EveryDay;
apt3.RecurrenceInfo.Range = RecurrenceRange.EndByDate;
apt3.RecurrenceInfo.End = apt3.RecurrenceInfo.Start.AddYears(10);
scheduler.AppointmentItems.Add(apt3);