'宣言 Public ReadOnly Property RecurringAppointmentRoot As Appointment
public Appointment RecurringAppointmentRoot {get;}
Imports Infragistics.Shared Imports Infragistics.Win Imports Infragistics.Win.UltraWinSchedule Imports System.Diagnostics Private Sub ManageRecurrences() ' In order to create recurring appointments, the ' 'AllowRecurringAppointments' must be set to true. ' Me.ultraCalendarInfo1.AllowRecurringAppointments = True ' All of the appointments, including the root ' (aka series) appointments and variances are ' maintained in the appointments collection of ' the UltraCalendarInfo. ' Dim appt As Appointment For Each appt In Me.ultraCalendarInfo1.Appointments If (appt.IsRecurringAppointmentRoot) Then ' The 'IsRecurringAppointmentRoot' can be used to ' identify the root appointment (i.e. the appointment ' that represents the series in the recurrence). ' Debug.WriteLine(String.Format("'{0} is a Root Appointment", appt)) ElseIf (appt.IsVariance) Then ' A Variance is a single occurrence of a recurring ' appointment where some of the information has ' been changed. Debug.WriteLine(String.Format("'{0}' is a variance of '{1}'", appt, appt.RecurringAppointmentRoot)) ElseIf Not appt.RecurringAppointmentRoot Is Nothing Then ' An appt that did not meet the above criteria ' but does have a reference to a root appointment ' is an instance of a recurring appointment. This ' will not happen with the Appointments collection ' but can be found when accessing the Appointments ' collection of a date specific object (e.g. ' Day.Appointment) or when using the ' GetAppointmentsInRange method of the UltraCalendarInfo. ' Debug.Write(String.Format("'{0}' is a non-variance occurrence of the recurring appointment '{1}'", appt, appt.RecurringAppointmentRoot)) Else ' Any other appointment is just a "regular" appointment ' and is not part of a recurrence. ' Debug.Write(String.Format("'{0}' is a standard non-recurrence related appointment.", appt)) End If Next ' To programatically create a recurring appointment, ' you need to create an appointment object and assign ' an 'AppointmentRecurrence' that provides the recurrence ' information. Note, an AppointmentRecurrence instance can ' only be associated with one appointment. ' Dim dt As DateTime = DateTime.Now Dim rootAppt As Appointment = Me.ultraCalendarInfo1.Appointments.Add(dt, "New Recurring Appointment") ' create a recurrence that will occur every day for 30 days rootAppt.Recurrence = New AppointmentRecurrence() rootAppt.Recurrence.PatternFrequency = RecurrencePatternFrequency.Daily rootAppt.Recurrence.PatternInterval = 1 rootAppt.Recurrence.RangeLimit = RecurrenceRangeLimit.LimitByNumberOfOccurrences rootAppt.Recurrence.RangeMaxOccurrences = 30 ' now let's get an occurence of this appointment ' we'll start by getting the appointments that occur ' tomorrow Dim appts As AppointmentsSubsetCollection = Me.ultraCalendarInfo1.GetDay(dt.AddDays(1D), True).Appointments ' now get the appointment that represents an occurrence of ' the above appt Dim occurrence As Appointment = appts(0) ' By changing values such as the StartDateTime, AllDayEvent, ' Locked, Visible, etc. of an occurrence of a recurring ' appointment, a variance is created. occurrence.AllDayEvent = True Dim moreAppts As AppointmentsSubsetCollection = Me.ultraCalendarInfo1.GetDay(dt.AddDays(2D), True).Appointments ' To remove an occurrence, you need to set the 'IsRemoved' ' property of the instance to true. ' moreAppts(0).IsRemoved = True ' Both modifying the values of an appointment or marking ' it for removal will cause the creation of a variance. ' The variances are instances of the appointment that ' relate to the original root appointment. These appointments ' will be part of the Appointments collection ' of the UltraCalendarInfo but can also be accessed using ' the Variances collection of the AppointmentRecurrence. ' Debug.WriteLine(String.Format("The Recurring Appointment '{0}' has '{1}' variance(s).", rootAppt, rootAppt.Recurrence.Variances.Count)) ' When a property of a variance has been changed, the value ' for that property is only retreived from the variance ' but the value for the remaining properties is retreived ' from the root appointment and therefore changing values ' on the root appointment will still affect the variances ' e.g. In the above example. the AllDayEvent and IsRemoved ' properties were changed in 2 occurrences so the remaining ' values should come from the root appointment. rootAppt.Subject = "Changed Root Appointment Subject" ' the following should be false since the subject for ' the occurrence should come from the root appointment ' since it has not changed. If rootAppt.Subject = occurrence.Subject Then _ Debug.WriteLine("The occurrence has a different subject then the root appointment!") ' An important point to remember is that when an ' occurrence is requested, the object references may not ' be the same but they may represent the same appointment. ' Dim occurrenceStartDate As DateTime = dt.AddDays(7D).Date Dim occurrenceEndDate As DateTime = occurrenceStartDate.AddDays(1D) Dim firstRequest As Appointment = Me.ultraCalendarInfo1.GetAppointmentsInRange(occurrenceStartDate, occurrenceEndDate)(0) Dim secondRequest As Appointment = Me.ultraCalendarInfo1.GetAppointmentsInRange(occurrenceStartDate, occurrenceEndDate)(0) ' the object references will be different If Not firstRequest Is secondRequest Then _ Debug.WriteLine("The object references are different.") ' but they represent the same logical occurrence of the recurrence If firstRequest.IsSameAppointment(secondRequest) Then _ Debug.WriteLine("The appointments represent the same occurrence of a recurring appointment.") ' To delete an entire series you need to remove ' the root appointment from the appointments collection ' Me.ultraCalendarInfo1.Appointments.Remove(rootAppt) End Sub
using Infragistics.Shared; using Infragistics.Win; using Infragistics.Win.UltraWinSchedule; using System.Diagnostics; private void ManageRecurrences() { // In order to create recurring appointments, the // 'AllowRecurringAppointments' must be set to true. // this.ultraCalendarInfo1.AllowRecurringAppointments = true; // All of the appointments, including the root // (aka series) appointments and variances are // maintained in the appointments collection of // the UltraCalendarInfo. // foreach(Appointment appt in this.ultraCalendarInfo1.Appointments) { if (appt.IsRecurringAppointmentRoot) { // The 'IsRecurringAppointmentRoot' can be used to // identify the root appointment (i.e. the appointment // that represents the series in the recurrence). // Debug.WriteLine( string.Format("'{0} is a Root Appointment", appt) ); } else if (appt.IsVariance) { // A Variance is a single occurrence of a recurring // appointment where some of the information has // been changed. Debug.WriteLine( string.Format("'{0}' is a variance of '{1}'", appt, appt.RecurringAppointmentRoot) ); } else if (appt.RecurringAppointmentRoot != null) { // An appt that did not meet the above criteria // but does have a reference to a root appointment // is an instance of a recurring appointment. This // will not happen with the Appointments collection // but can be found when accessing the Appointments // collection of a date specific object (e.g. // Day.Appointment) or when using the // GetAppointmentsInRange method of the UltraCalendarInfo. // Debug.Write( string.Format("'{0}' is a non-variance occurrence of the recurring appointment '{1}'", appt, appt.RecurringAppointmentRoot) ); } else { // Any other appointment is just a "regular" appointment // and is not part of a recurrence. // Debug.Write( string.Format("'{0}' is a standard non-recurrence related appointment.", appt) ); } } // To programatically create a recurring appointment, // you need to create an appointment object and assign // an 'AppointmentRecurrence' that provides the recurrence // information. Note, an AppointmentRecurrence instance can // only be associated with one appointment. // DateTime dt = DateTime.Now; Appointment rootAppt = this.ultraCalendarInfo1.Appointments.Add(dt, "New Recurring Appointment"); // create a recurrence that will occur every day for 30 days rootAppt.Recurrence = new AppointmentRecurrence(); rootAppt.Recurrence.PatternFrequency = RecurrencePatternFrequency.Daily; rootAppt.Recurrence.PatternInterval = 1; rootAppt.Recurrence.RangeLimit = RecurrenceRangeLimit.LimitByNumberOfOccurrences; rootAppt.Recurrence.RangeMaxOccurrences = 30; // now let's get an occurence of this appointment // we'll start by getting the appointments that occur // tomorrow AppointmentsSubsetCollection appts = this.ultraCalendarInfo1.GetDay(dt.AddDays(1d), true).Appointments; // now get the appointment that represents an occurrence of // the above appt Appointment occurrence = appts[0]; // By changing values such as the StartDateTime, AllDayEvent, // Locked, Visible, etc. of an occurrence of a recurring // appointment, a variance is created. occurrence.AllDayEvent = true; AppointmentsSubsetCollection moreAppts = this.ultraCalendarInfo1.GetDay(dt.AddDays(2d), true).Appointments; // To remove an occurrence, you need to set the 'IsRemoved' // property of the instance to true. // moreAppts[0].IsRemoved = true; // Both modifying the values of an appointment or marking // it for removal will cause the creation of a variance. // The variances are instances of the appointment that // relate to the original root appointment. These appointments // will be part of the Appointments collection // of the UltraCalendarInfo but can also be accessed using // the Variances collection of the AppointmentRecurrence. // Debug.WriteLine( string.Format("The Recurring Appointment '{0}' has '{1}' variance(s).", rootAppt, rootAppt.Recurrence.Variances.Count) ); // When a property of a variance has been changed, the value // for that property is only retreived from the variance // but the value for the remaining properties is retreived // from the root appointment and therefore changing values // on the root appointment will still affect the variances // e.g. In the above example. the AllDayEvent and IsRemoved // properties were changed in 2 occurrences so the remaining // values should come from the root appointment. rootAppt.Subject = "Changed Root Appointment Subject"; // the following should be false since the subject for // the occurrence should come from the root appointment // since it has not changed. if (rootAppt.Subject != occurrence.Subject) Debug.WriteLine("The occurrence has a different subject then the root appointment!"); // An important point to remember is that when an // occurrence is requested, the object references may not // be the same but they may represent the same appointment. // DateTime occurrenceStartDate = dt.AddDays(7d).Date; DateTime occurrenceEndDate = occurrenceStartDate.AddDays(1d); Appointment firstRequest = this.ultraCalendarInfo1.GetAppointmentsInRange(occurrenceStartDate, occurrenceEndDate)[0]; Appointment secondRequest = this.ultraCalendarInfo1.GetAppointmentsInRange(occurrenceStartDate, occurrenceEndDate)[0]; // the object references will be different if (firstRequest != secondRequest) Debug.WriteLine("The object references are different."); // but they represent the same logical occurrence of the recurrence if (firstRequest.IsSameAppointment(secondRequest)) Debug.WriteLine("The appointments represent the same occurrence of a recurring appointment."); // To delete an entire series you need to remove // the root appointment from the appointments collection // this.ultraCalendarInfo1.Appointments.Remove(rootAppt); }