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
15
Problem with 2 recurring appointments
posted

Hi, I'm working on a custom web schedule provider.  This system has appointments and recurring appointments.  The problem I'm having is that if I have 2 recurring appointments in a month and they do not overlap, the monthly calendar shows the dates between as bold and if I look at one of those dates it has the first recurring appointment in it.  For example, I have one appoint from 1/5 - 1/13 and another from 1/19 - 1/27.  It looks as if the first appointment goes until 1/27.

I'm currently running on v7.1, but I've also tested on 2009 vol 2 with the same result.

The following is a snippet of the current code (I've been modifying it a lot so this might not be the best try, but they all seem to have the same result).  I've also attached a screen shot to show what I am seeing.  Thanks for any help at all!

Mike Witt

 

        private const string recurAppointmentKey = "RecurrenceAppointmentList";

        private List<Appointment> appointmentList;

 

        /// <summary>

/// Fetches WebSchedule objects from the underlying data source.

/// </summary>

/// <param name="context">A DataContext subclass containing parameter values for use when carrying out a fetch operation.</param>

public void Fetch(DataContext context)

{

// Take action based on the operation provided

            try

            {

                switch (context.Operation)

                {

                    case "FetchActivities":

                        if (HttpContext.Current.Session[recurAppointmentKey] != null) HttpContext.Current.Session.Remove(recurAppointmentKey);

                        appointmentList = new List<Appointment>();

                        FetchActivities((FetchActivitiesContext)context);

                        if (appointmentList.Count > 0) HttpContext.Current.Session.Add(recurAppointmentKey, appointmentList);

                        break;

                    case "FetchRecurrences":

                        FetchRecurrences((FetchRecurrencesContext)context);

                        break;

                }

            }

            finally

            {

                if (context.Operation == "FetchRecurrences" && HttpContext.Current.Session[recurAppointmentKey] != null) HttpContext.Current.Session.Remove(recurAppointmentKey);

            }

}

 

/// <summary>

/// Selects activities from the WebSchedule data store by date range and organizer.

/// </summary>

/// <param name="context">Describes the <see cref="Activities"/> being selected, in particular,

/// their organizing resource and date range of interest.</param>

private void FetchActivities(FetchActivitiesContext context)

{

// Clear any existing activities

context.Activities.Clear();

 

            //Recurrence recurrence ;

 

// get the trips

// REMOVED DATA ACCESS FOR SIMPLICITY OF SAMPLE - fetched the "employees" list.

foreach (Trip_EmployeeSchedule employee in employees)

{

// Create a new Appointment with a reference to the ScheduleInfo object that requested the fetch

Appointment appointment = new Appointment(this.WebScheduleInfo);

 

// Configure the Appointment with the information in the data source

                appointment.Key = employee.RecordID.ToString();

                appointment.Subject = employee.Subject;

                appointment.Description = employee.Description;

                //appointment.RecurrenceKey = employee.Recurrence;

 

                appointment.StartDateTime = new SmartDate(employee.StartDateTime);

                appointment.EndDateTime = new SmartDate(employee.EndDateTime);

 

appointment.EnableReminder = false;

 

                appointment.ShowTimeAs = ShowTimeAs.OutofOffice;

 

                appointment.RecurrenceKey = employee.RecordID.ToString() + " " + appointment.Subject;

                if (employee.Recurrence == "Y") appointmentList.Add(appointment);

 

                // Add the Appointment to the Activities list in the context

                ((IList)context.Activities).Add(appointment);

}

 

            Trip_TripDriverVehicleService DriverVehicleServ = new Trip_TripDriverVehicleService();

            DataSet dsTripInfo = DriverVehicleServ.GetTripItemsForSechedule(this.EmployeeID, startDate, endDate);

            int iKey = 0;

 

            foreach (DataRow drAppointment in dsTripInfo.Tables[0].Rows)

            {

                // Create a new Appointment with a reference to the ScheduleInfo object that requested the fetch

                Appointment appointment = new Appointment(this.WebScheduleInfo);

 

                // Configure the Appointment with the information in the data source

                iKey = (int)drAppointment["RecordID"];

                iKey = -iKey;

                appointment.Key = iKey.ToString();

                appointment.Subject = drAppointment["TripName"].ToString();

                appointment.Description = string.Empty;

                appointment.StartDateTime = new SmartDate(Convert.ToDateTime(drAppointment["OriginDepartureTime"]));

                appointment.EndDateTime = new SmartDate(Convert.ToDateTime(drAppointment["OriginReturnTime"]));

                appointment.EnableReminder = false;

 

 

                appointment.ShowTimeAs = ShowTimeAs.Busy;

 

                // Add the Appointment to the Activities list in the context

                ((IList)context.Activities).Add(appointment);

            }

 

 

}

 

 

        private void FetchRecurrences(FetchRecurrencesContext context)

        {

 

            // Clear any existing activities

            //context.Activities.Clear();

 

            context.Recurrences.Clear();

 

            //Recurrence recurrence ;

 

            // get the trips

// REMOVED DATA ACCESS FOR SIMPLICITY OF SAMPLE - fetched the "employees" list.

 

            foreach (Trip_EmployeeSchedule employee in employees)

            {

 

                // Create a new Appointment with a reference to the ScheduleInfo object that requested the fetch

 

                if (employee.RecurrencePeriod != null)

                {

 

                    string recurrenceKey = employee.RecordID.ToString() + " " + employee.Subject;

 

                    // Find the appointment from the cache

                    Appointment myAppt = null;

                    foreach (Appointment appt in appointmentList)

                    {

                        if (appt.RecurrenceKey == recurrenceKey)

                        {

                            myAppt = appt;

                            break;

                        }

                    }

 

                    if (myAppt == null) continue;

 

                    myAppt.CreateRecurrence();

 

                    Recurrence recurrence = myAppt.Recurrence;

 

                    recurrence.Key = recurrenceKey;

 

 

                    if (employee.RecurrencePeriod == Convert.ToInt32(TripTrackerUtilities.ScheduleEnumerations.RecurrencePeriod.Daily))

                    {

                        recurrence.Period = Infragistics.WebUI.WebSchedule.RecurrencePeriod.Daily;

                    }

                    else if (employee.RecurrencePeriod == Convert.ToInt32(TripTrackerUtilities.ScheduleEnumerations.RecurrencePeriod.Weekly))

                    {

                        recurrence.Period = Infragistics.WebUI.WebSchedule.RecurrencePeriod.Weekly;

                    }

                    else if (employee.RecurrencePeriod == Convert.ToInt32(TripTrackerUtilities.ScheduleEnumerations.RecurrencePeriod.Monthly))

                    {

                        recurrence.Period = Infragistics.WebUI.WebSchedule.RecurrencePeriod.Monthly;

                        if (employee.RecurrenceDay.HasValue)

                        {

                            recurrence.DayOfMonth = (int)employee.RecurrenceDay;

                        }

 

                    }

                    else if (employee.RecurrencePeriod == Convert.ToInt32(TripTrackerUtilities.ScheduleEnumerations.RecurrencePeriod.Monthly))

                    {

                        recurrence.Period = Infragistics.WebUI.WebSchedule.RecurrencePeriod.Yearly;

                    }

                    else if (employee.RecurrencePeriod == Convert.ToInt32(TripTrackerUtilities.ScheduleEnumerations.RecurrencePeriod.EveryWeekday))

                    {

                        recurrence.DayOfWeekMaskUtc = RecurrenceDayOfWeekMask.AllWeekdays;

                    }

 

 

                    if (employee.RecurrencePeriodMultiple.HasValue)

                    {

                        recurrence.PeriodMultiple = (int)employee.RecurrencePeriodMultiple;

                    }

 

                    if (employee.RecurrenceEndDate.HasValue)

                    {

                        recurrence.EndDateUtc.Value = (DateTime)employee.RecurrenceEndDate;

                    }

                    else

                    {

                        recurrence.EndDateUtc.Value = DateTime.Today.AddYears(2);

                    }

 

 

                    ((IList)context.Recurrences).Add(recurrence);

 

                }

 

            }

        }