Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
315
2 Day appointment
posted

Hi,

 

I need to be able to programatically add an appointment that spans 2 consecutive days, with a differnt start time and duration on day 2.

 

I have added a recurrance of the appointment to get the second day - can anyone tell me how to change the start/end times for day 2?

 

Regards

 

Jon

Parents
  • 4960
    Suggested Answer
    posted

    You can start from the example given here,

    http://help.infragistics.com/Help/NetAdvantage/ASPNET/2009.2/CLR3.5/html/WebSchedule_Add_a_Recurring_Appointment_Server_Side.html

    in which you create an Appointment and a Recurrence programmatically, and then just create an AppointmentVariance for day 2 that has the different hours.  In the following example, I create a recurring activity called "Training," and on 12/21 it will be 9:00-17:00 local time; on 12/22 it will be 9:00-15:00 local time.

    In my Page_Load (just in case you shake your head at why it didn't work the first time ;) ),

    // Call DataBind() BEFORE adding objects programmatically
    // to WebScheduleInfo, otherwise a call to DataBind() may
    // Clear any contents that are already in the Activities Collection.
    this.WebScheduleInfo1.DataBind();

    // Example code for generating an in-memory Appointment,
    // Recurrence and Variance.
    this.CreateExampleVariance();

    In the method, CreateExampleVariance,

    // Create an Appointment (this is the Root Activity)
    Appointment appt = new Appointment( this.WebScheduleInfo1);
    appt.Subject = "Training";
    appt.StartDateTime = new SmartDate( 2009, 12, 21, 9, 0, 0);
    appt.Duration = new TimeSpan( 8, 0, 0);
    appt.Key = "100";
    appt.ResourceKey =
         this.WebScheduleInfo1.VisibleResources.UnassignedResource.Key;

    // Create a Daily Recurrence (for 2 occurrences of the
    // above Root Activity)
    appt.CreateRecurrence();
    appt.Recurrence.Period = RecurrencePeriod.Daily;
    appt.Recurrence.PeriodMultiple = 1;
    appt.Recurrence.MaxOccurrences = 2;

    // Create a Variance that will override the 2nd occurence
    // of the above Recurrence)
    Activity variance = appt.CreateVariance(
         appt.StartDateTimeUtc.AddDays( 1.0),
         appt.StartDateTimeUtc.AddDays( 1.0));

    // Since you are NOT changing the starting time, both args
    // passed to CreateVariance are identical.

    // Set a different duration on the Variance for Day 2, in
    // this case Training runs from 9:00 to 15:00 local time
    // instead of 9:00 to 17:00 as it did for Day 1.
    variance.Duration = new TimeSpan( 6, 0, 0);

    // Add the Root Activity to the WebScheduleInfo
    // so that it shows up.
    this.WebScheduleInfo1.Activities.Add( appt);

    // NOTE: If you want the Appointment Variance to persist,
    // you must add it to the Data Provider. You MAY need
    // the following step (depending on your DP impl) before
    // adding it to the Data Provider.
    if (appt.VarianceKey == Guid.Empty)
    {
         // You would only set this if this was the first variance
         // attached to the Root Activity's Recurrence.
         appt.VarianceKey = variance.VarianceKey = Guid.NewGuid();
    }

     

Reply Children
No Data