/// <summary>
        /// Removes out-dated views
        /// </summary>
        /// <param name="removedViews"></param>
        /// <param name="monthWeek"></param>
        /// <param name="appointments"></param>
        /// <returns></returns>
        private void RemoveOutdatedViews(ref List<AppointmentMonthView> removedViews,
            MonthWeek monthWeek, List<Appointment> appointments)
        {
            List<AppointmentMonthView> removeList = null;

            for (int i = monthWeek.CalendarItems.Count - 1; i >= 0; i--)
            {
                AppointmentMonthView view =
                    monthWeek.CalendarItems[i] as AppointmentMonthView;

                if (view != null)
                {
                    if (!appointments.Contains(view.Appointment) || !IsAppointmentVisible(view.Appointment))
                    {
                        if (removeList == null)
                            removeList = new List<AppointmentMonthView>();

                        removeList.Add(view);
                        _View.SubItems._Remove(view);
                        view.MonthWeek = null;

                        view.IsSelectedChanged -= _View.ItemIsSelectedChanged;

                        monthWeek.CalendarItems.RemoveAt(i);
                    }
                }
            }

            if (removeList != null)
            {
                if (removedViews == null)
                    removedViews = new List<AppointmentMonthView>();

                removedViews.AddRange(removeList);
            }
        }
        private void RemoveOutdatedCustomItems(
            ref List<CustomCalendarItem> removedViews, MonthWeek monthWeek)
        {
            List<CustomCalendarItem> removeList = null;

            DateTime startTime = monthWeek.FirstDayOfWeek;
            DateTime endTime = monthWeek.FirstDayOfWeek.AddDays(7);

            for (int i = monthWeek.CalendarItems.Count - 1; i >= 0; i--)
            {
                CustomCalendarItem view =
                    monthWeek.CalendarItems[i] as CustomCalendarItem;

                if (view != null)
                {
                    if (IsValidItem(view) == false ||
                        (view.EndTime < startTime || view.StartTime >= endTime))
                    {
                        if (removeList == null)
                            removeList = new List<CustomCalendarItem>();

                        removeList.Add(view);
                        _View.SubItems._Remove(view);

                        _View.NeedRecalcSize = true;

                        view.IsSelectedChanged -= _View.ItemIsSelectedChanged;

                        monthWeek.CalendarItems.RemoveAt(i);
                    }
                }
            }

            if (removeList != null)
            {
                if (removedViews == null)
                    removedViews = new List<CustomCalendarItem>();

                removedViews.AddRange(removeList);
            }
        }
        private CustomCalendarItem GetItemFromWeek(MonthWeek monthWeek, CustomCalendarItem item)
        {
            foreach (CalendarItem citem in monthWeek.CalendarItems)
            {
                CustomCalendarItem view = citem as CustomCalendarItem;

                if (view != null && (view == item || view.BaseCalendarItem == item))
                    return (view);
            }

            return (null);
        }
        /// <summary>
        /// Gets the view from the MonthWeek list
        /// </summary>
        /// <param name="monthWeek">MonthWeek</param>
        /// <param name="appointment">Appointment</param>
        /// <returns>Appointment view</returns>
        private AppointmentMonthView GetViewFromWeek(MonthWeek monthWeek, Appointment appointment)
        {
            foreach (CalendarItem item in monthWeek.CalendarItems)
            {
                AppointmentMonthView view = item as AppointmentMonthView;

                if (view != null && view.Appointment == appointment)
                    return (view);
            }

            return (null);
        }
        private void UpdateCustomItems(
            MonthWeek monthWeek, List<CustomCalendarItem> cachedItems)
        {
            CustomCalendarItemCollection items = _View.CalendarView.CustomItems;

            if (items != null && items.Count > 0)
            {
                DateTime startTime = monthWeek.FirstDayOfWeek;
                DateTime endTime = monthWeek.FirstDayOfWeek.AddDays(7);

                for (int i = 0; i < items.Count; i++)
                {
                    CustomCalendarItem item = items[i];

                    if (IsCustomItemVisible(item) == true &&
                        (item.StartTime < endTime && item.EndTime > startTime))
                    {
                        item.CalendarView = _View.CalendarView;

                        CustomCalendarItem ci = GetItemFromWeek(monthWeek, item);

                        if (ci == null)
                        {
                            ci = GetItemFromCache(item, cachedItems) ??
                                 GetNewCustomItem(item);

                            monthWeek.CalendarItems.Add(ci);
                            _View.SubItems.Insert(0, ci);

                            ci.IsSelectedChanged += _View.ItemIsSelectedChanged;
                        }

                        if (ci.BaseCalendarItem != item)
                        {
                            ci.StartTime = item.StartTime;
                            ci.EndTime = item.EndTime;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Updates individual MonthWeek views
        /// </summary>
        /// <param name="monthWeek">MonthWeek</param>
        /// <param name="appointments">List of appointments</param>
        /// <param name="cachedViews">List of cached views</param>
        private void UpdateWeekView(MonthWeek monthWeek,
            List<Appointment> appointments, List<AppointmentMonthView> cachedViews)
        {
            // Loop through each appointment
            // updating the assoc view accordingly

            foreach (Appointment appointment in  appointments)
            {
                if (IsAppointmentVisible(appointment))
                {
                    // Get the assoc view

                    AppointmentMonthView view = (GetViewFromWeek(monthWeek, appointment) ??
                                                 GetViewFromCache(appointment, cachedViews)) ??
                                                 GetNewView(appointment);

                    // Set the view start and end times to
                    // match the assoc appointment

                    view.StartTime = appointment.StartTime;
                    view.EndTime = appointment.EndTime;

                    // And update the MonthWeek data

                    if (view.MonthWeek == null)
                    {
                        view.MonthWeek = monthWeek;

                        monthWeek.CalendarItems.Add(view);
                        _View.SubItems.Add(view);

                        view.IsSelectedChanged += _View.ItemIsSelectedChanged;
                    }
                }
            }
        }
        /// <summary>
        /// Clears individual MonthWeek view connections
        /// </summary>
        /// <param name="monthWeek">MonthWeek</param>
        private void ClearMonthWeek(MonthWeek monthWeek)
        {
            if (monthWeek.CalendarItems.Count > 0)
            {
                // Loop through each CalendarItem, resetting
                // it's associated connection

                for (int i = monthWeek.CalendarItems.Count - 1; i >= 0; i--)
                {
                    AppointmentMonthView view =
                        monthWeek.CalendarItems[i] as AppointmentMonthView;

                    if (view != null)
                    {
                        view.IsSelectedChanged -= _View.ItemIsSelectedChanged;

                        view.Appointment = null;
                        view.IsSelected = false;
                        view.MonthWeek = null;
                    }

                    monthWeek.CalendarItems.RemoveAt(i);
                }
            }
        }