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

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

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

                        removeList.Add(view);

                        view.DayColumn.NeedRecalcLayout = true;
                        view.DayColumn = null;

                        _View.NeedRecalcSize = true;
                        _View.SubItems._Remove(view);

                        dayColumn.CalendarItems.RemoveAt(i);

                        view.IsSelectedChanged -= _View.ItemIsSelectedChanged;
                    }
                }
            }

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

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

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

                if (view != null)
                {
                    if (IsValidItem(view) == false ||
                        (view.EndTime < dayColumn.Date || view.StartTime > dayColumn.Date.AddDays(1)))
                    {
                        if (removeList == null)
                            removeList = new List<CustomCalendarItem>();

                        removeList.Add(view);

                        _View.SubItems._Remove(view);
                        _View.NeedRecalcSize = true;

                        dayColumn.NeedRecalcLayout = true;
                        dayColumn.CalendarItems.RemoveAt(i);

                        view.IsSelectedChanged -= _View.ItemIsSelectedChanged;
                    }
                }
            }

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

                removedItems.AddRange(removeList);
            }
        }
        /// <summary>
        /// GetWorkDays
        /// </summary>
        /// <param name="dayColumn"></param>
        /// <param name="workDays"></param>
        /// <returns></returns>
        private bool GetWorkDays(
            DayColumn dayColumn, WorkDayCollection workDays)
        {
            if (workDays != null && workDays.Count > 0)
            {
                WorkDay wd = workDays[dayColumn.Date.DayOfWeek];

                if (wd != null)
                {
                    dayColumn.WorkStartTime = wd.WorkStartTime;
                    dayColumn.WorkEndTime = wd.WorkEndTime;
                }
                else
                {
                    dayColumn.WorkStartTime = new WorkTime();
                    dayColumn.WorkEndTime = new WorkTime();
                }

                return (true);
            }

            return (false);
        }
        /// <summary>
        /// Gets the view from the DayColumn list
        /// </summary>
        /// <param name="dayColumn">DayColumn</param>
        /// <param name="appointment">Appointment</param>
        /// <returns>Appointment view</returns>
        private AppointmentWeekDayView GetViewFromColumn(DayColumn dayColumn, Appointment appointment)
        {
            foreach (CalendarItem item in dayColumn.CalendarItems)
            {
                AppointmentWeekDayView view = item as AppointmentWeekDayView;

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

            return (null);
        }
        /// <summary>
        /// Updates DayColumn workday details
        /// </summary>
        /// <param name="dayColumn">DayColumn to update</param>
        private void UpdateWorkDayDetails(DayColumn dayColumn)
        {
            // Update workDay timings

            Owner owner = _Model.Owners[_View.OwnerKey];

            if (owner == null || GetCalendarWorkDays(dayColumn, owner.CalendarWorkDays) == false)
            {
                if (GetCalendarWorkDays(dayColumn, _Model.CalendarWorkDays) == false)
                {
                    if (owner == null || GetWorkDays(dayColumn, owner.WorkDays) == false)
                    {
                        if (GetWorkDays(dayColumn, _Model.WorkDays) == false)
                        {
                            dayColumn.WorkStartTime = new WorkTime();
                            dayColumn.WorkEndTime = new WorkTime();
                        }
                    }
                }
            }
        }
        /// <summary>
        /// GetCalendarWorkDays
        /// </summary>
        /// <param name="dayColumn"></param>
        /// <param name="calendarWorkDays"></param>
        /// <returns></returns>
        private bool GetCalendarWorkDays(
            DayColumn dayColumn, CalendarWorkDayCollection calendarWorkDays)
        {
            if (calendarWorkDays != null && calendarWorkDays.Count > 0)
            {
                CalendarWorkDay cwd = calendarWorkDays[dayColumn.Date];

                if (cwd != null)
                {
                    dayColumn.WorkStartTime = cwd.WorkStartTime;
                    dayColumn.WorkEndTime = cwd.WorkEndTime;

                    return (true);
                }
            }

            return (false);
        }
        private CustomCalendarItem GetItemFromColumn(DayColumn dayColumn, CustomCalendarItem item)
        {
            foreach (CalendarItem citem in dayColumn.CalendarItems)
            {
                CustomCalendarItem view = citem as CustomCalendarItem;

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

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

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

                    if (IsCustomItemVisible(item) == true && item.IsMultiDayOrAllDayEvent == false &&
                        (item.StartTime < dayColumn.Date.AddDays(1) && item.EndTime > dayColumn.Date))
                    {
                        item.CalendarView = _View.CalendarView;

                        CustomCalendarItem ci = GetItemFromColumn(dayColumn, item);

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

                            dayColumn.CalendarItems.Add(ci);
                            dayColumn.NeedRecalcLayout = true;

                            _View.SubItems.Add(ci);
                            _View.UpdateItemOrder(ci);

                            ci.IsSelectedChanged += _View.ItemIsSelectedChanged;
                        }

                        ci.StartTime = item.StartTime;
                        ci.EndTime = item.EndTime;

                        dayColumn.NeedRecalcLayout = true;
                    }
                }
            }
        }
        /// <summary>
        /// Updates individual DayColumn views
        /// </summary>
        /// <param name="dayColumn">DayColumn</param>
        /// <param name="appointments">List of appointments</param>
        /// <param name="cachedViews">List of cached views</param>
        private void UpdateColumnAppts(DayColumn dayColumn,
            List<Appointment> appointments, List<AppointmentWeekDayView> cachedViews)
        {
            // Loop through each appointment
            // updating the assoc view accordingly

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

                    if (appointment.IsMultiDayOrAllDayEvent == false)
                    {
                        AppointmentWeekDayView view = (GetViewFromColumn(dayColumn, appointment) ??
                                                       GetViewFromCache(appointment, cachedViews)) ??
                                                       GetNewView(appointment);

                        if (view.StartTime != appointment.StartTime || view.EndTime != appointment.EndTime)
                            dayColumn.NeedRecalcLayout = true;

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

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

                        // Update the DayColumn data

                        if (view.DayColumn == null)
                        {
                            view.DayColumn = dayColumn;

                            dayColumn.CalendarItems.Add(view);
                            dayColumn.NeedRecalcLayout = true;

                            _View.SubItems.Add(view);
                            _View.UpdateItemOrder(view);

                            view.IsSelectedChanged += _View.ItemIsSelectedChanged;
                        }
                    }
                }
            }

            // Update workDay details

            UpdateWorkDayDetails(dayColumn);
        }
        /// <summary>
        /// Clears individual DayColumn view connections
        /// </summary>
        /// <param name="dayColumn">DayColumn</param>
        private void ClearWeekDayColumn(DayColumn dayColumn)
        {
            if (dayColumn.CalendarItems.Count > 0)
            {
                // Loop through each CalendarItem, resetting
                // it's associated connection

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

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

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

                    dayColumn.CalendarItems.RemoveAt(i);
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Allocates out DayColumns
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        private void AllocateDayColumns(DateTime startDate, DateTime endDate)
        {
            // Allocate our DayColumns array to
            // hold our info

            _NumberOfColumns = (endDate - startDate).Days + 1;
            _NumberOfColumns = Math.Max(_NumberOfColumns, 1);
            _NumberOfColumns = Math.Min(_NumberOfColumns, MaxNumberOfColumns);

            if (_DayColumns == null || _DayColumns.Length != _NumberOfColumns)
                _DayColumns = new DayColumn[_NumberOfColumns];

            // Prepare to update display info on each time slot

            Rectangle r = ViewRect;
            r.Y += _VScrollPos;

            // Loop through each day column

            float dcWidth = DayColumnWidth;
            float x1 = r.X;

            // Update each DayColumn

            for (int i = 0; i < _NumberOfColumns; i++)
            {
                if (_DayColumns[i] == null)
                    _DayColumns[i] = new DayColumn(0);

                _DayColumns[i].Date = startDate.AddDays(i);

                float x2 = (i == _NumberOfColumns - 1) ? r.Right - 1 : x1 + dcWidth;

                if (IsLayoutNeeded(i) == true)
                    _DayColumns[i].Bounds = new Rectangle((int) x1, r.Y, (int) x2 - (int) x1, r.Height);

                x1 = x2;
            }
        }