Example #1
0
        internal override void OnPropertyChanged(RadPropertyEventArgs e)
        {
            base.OnPropertyChanged(e);

            if (e.Key == DisplayDatePropertyKey)
            {
                DateTime oldDisplayDate = DateTime.MinValue;
                if (e.OldValue != null)
                {
                    oldDisplayDate = (DateTime)e.OldValue;
                }

                DateTime newDisplayDate = DateTime.MinValue;
                if (e.NewValue != null)
                {
                    newDisplayDate = (DateTime)e.NewValue;
                }

                if (CalendarMathHelper.IsCalendarViewChanged(oldDisplayDate, newDisplayDate, this.DisplayMode))
                {
                    this.Invalidate();
                }
            }
            else if (e.Key == DisplayModePropertyKey)
            {
                this.UpdateCurrentView();
            }
        }
Example #2
0
        internal bool MoveCurrentDown(bool isControlModifierDown)
        {
            bool handled = false;

            if (isControlModifierDown)
            {
                if (this.CurrentDate != DateTime.MinValue && this.Owner.DisplayMode != CalendarDisplayMode.MonthView)
                {
                    this.Owner.RaiseMoveToLowerCommand(this.CurrentDate);

                    // CurrentDate is not changed but we need to update the visuals on view change.
                    this.AsyncUpdateCurrencyPresenters(this.CurrentDate, this.CurrentDate);

                    handled = true;
                }
            }
            else
            {
                if (this.CurrentDate == DateTime.MinValue)
                {
                    this.CurrentDate = CalendarMathHelper.GetFirstDateForCurrentDisplayUnit(this.Owner.DisplayDate, this.Owner.DisplayMode);
                }
                else
                {
                    DateTime dateToNavigate = CalendarMathHelper.IncrementByCell(this.CurrentDate, this.Owner.Model.ColumnCount, this.Owner.DisplayMode);

                    this.Owner.RaiseMoveToDateCommand(dateToNavigate);
                    this.CurrentDate = dateToNavigate;
                }

                handled = true;
            }

            return(handled);
        }
Example #3
0
        internal bool MoveCurrentToLast()
        {
            bool handled = true;

            this.CurrentDate = CalendarMathHelper.GetLastDateForCurrentDisplayUnit(this.Owner.DisplayDate, this.Owner.DisplayMode);

            return(handled);
        }
Example #4
0
        internal DateTime GetFirstDateToRenderForDisplayMode(DateTime date, CalendarDisplayMode displayMode)
        {
            date = date.Date;
            DateTime firstDateToRender = date;

            if (displayMode == CalendarDisplayMode.MultiDayView)
            {
                DayOfWeek firstDayOfWeek         = this.GetFirstDayOfWeek();
                DateTime  firstDateOfCurrentWeek = CalendarMathHelper.GetFirstDayOfCurrentWeek(date, firstDayOfWeek);

                if (!(firstDateOfCurrentWeek.Date <= date.Date && firstDateOfCurrentWeek.AddDays(7).Date >= date.Date))
                {
                    firstDateToRender = firstDateOfCurrentWeek;
                }

                if (!this.multiDayViewSettings.WeekendsVisible)
                {
                    firstDateToRender = CalendarMathHelper.AddBusinessDays(date, -this.multiDayViewSettings.VisibleDays);
                }
                else
                {
                    firstDateToRender = date.AddDays(-this.multiDayViewSettings.VisibleDays);
                }
            }
            else if (displayMode == CalendarDisplayMode.MonthView)
            {
                DayOfWeek firstDayOfWeekToUse = this.GetFirstDayOfWeek();

                DateTime monthStartDate = CalendarMathHelper.GetFirstDateOfMonth(date);

                int daysToSubtract = (int)monthStartDate.DayOfWeek - (int)firstDayOfWeekToUse;
                if (daysToSubtract <= 0)
                {
                    daysToSubtract += 7;
                }

                firstDateToRender = monthStartDate.Date == DateTime.MinValue.Date ? monthStartDate : monthStartDate.AddDays(-daysToSubtract);
            }
            else if (displayMode == CalendarDisplayMode.YearView)
            {
                firstDateToRender = CalendarMathHelper.GetFirstDateOfYear(date);
            }
            else if (displayMode == CalendarDisplayMode.DecadeView)
            {
                firstDateToRender = CalendarMathHelper.GetFirstDateOfDecade(date);
            }
            else if (displayMode == CalendarDisplayMode.CenturyView)
            {
                firstDateToRender = CalendarMathHelper.GetFirstDateOfCentury(date);
            }

            return(firstDateToRender);
        }
        internal override DateTime GetFirstDateToRender(DateTime date)
        {
            DayOfWeek firstDayOfWeek         = this.Calendar.GetFirstDayOfWeek();
            DateTime  firstDateOfCurrentWeek = CalendarMathHelper.GetFirstDayOfCurrentWeek(date, firstDayOfWeek);

            if (firstDateOfCurrentWeek.Date <= date.Date && firstDateOfCurrentWeek.AddDays(7).Date >= date.Date)
            {
                return(date);
            }

            return(firstDateOfCurrentWeek);
        }
Example #6
0
        internal override DateTime GetFirstDateToRender(DateTime date)
        {
            DayOfWeek firstDayOfWeekToUse = this.Calendar.GetFirstDayOfWeek();

            DateTime monthStartDate = CalendarMathHelper.GetFirstDateOfMonth(date);

            int daysToSubtract = (int)monthStartDate.DayOfWeek - (int)firstDayOfWeekToUse;

            if (daysToSubtract <= 0)
            {
                daysToSubtract += 7;
            }

            return(monthStartDate.Date == DateTime.MinValue.Date ? monthStartDate : monthStartDate.AddDays(-daysToSubtract));
        }
Example #7
0
        internal static DateTime GetCellDateForViewLevel(DateTime date, CalendarDisplayMode displayMode)
        {
            switch (displayMode)
            {
            case CalendarDisplayMode.YearView:
                return(CalendarMathHelper.GetFirstDateOfMonth(date));

            case CalendarDisplayMode.DecadeView:
                return(CalendarMathHelper.GetFirstDateOfYear(date));

            case CalendarDisplayMode.CenturyView:
                return(CalendarMathHelper.GetFirstDateOfDecade(date));

            default:
                return(date);
            }
        }
        internal override DateTime GetNextDateToRender(DateTime date)
        {
            if (date.Date == DateTime.MaxValue.Date)
            {
                return(date);
            }

            if (!this.Calendar.multiDayViewSettings.WeekendsVisible)
            {
                date = CalendarMathHelper.AddBusinessDays(date, 1);
            }
            else
            {
                date = date.AddDays(1);
            }

            return(date);
        }
Example #9
0
        internal static DateTime GetLastDateForCurrentDisplayUnit(DateTime date, CalendarDisplayMode displayMode)
        {
            // NOTE: Ignore time part for calendar calculations.
            date = date.Date;

            switch (displayMode)
            {
            case CalendarDisplayMode.YearView:
                return(CalendarMathHelper.GetLastDateOfYearView(date));

            case CalendarDisplayMode.DecadeView:
                return(CalendarMathHelper.GetLastDateOfDecadeView(date));

            case CalendarDisplayMode.CenturyView:
                return(CalendarMathHelper.GetLastDateOfCenturyView(date));

            default:
                return(CalendarMathHelper.GetLastDateOfMonthView(date));
            }
        }
Example #10
0
        internal static bool IsCalendarViewChanged(DateTime displayDate, DateTime newDisplayDate, CalendarDisplayMode displayMode)
        {
            // NOTE: Ignore time part for calendar calculations.
            displayDate    = displayDate.Date;
            newDisplayDate = newDisplayDate.Date;

            switch (displayMode)
            {
            case CalendarDisplayMode.YearView:
                return(displayDate.Year != newDisplayDate.Year);

            case CalendarDisplayMode.DecadeView:
                return(CalendarMathHelper.GetFirstDateOfDecade(displayDate) != CalendarMathHelper.GetFirstDateOfDecade(newDisplayDate));

            case CalendarDisplayMode.CenturyView:
                return(CalendarMathHelper.GetFirstDateOfCentury(displayDate) != CalendarMathHelper.GetFirstDateOfCentury(newDisplayDate));

            default:
                return(CalendarMathHelper.GetFirstDateOfMonth(displayDate) != CalendarMathHelper.GetFirstDateOfMonth(newDisplayDate));
            }
        }
        internal override DateTime GetFirstDateToRender(DateTime date)
        {
            DayOfWeek firstDayOfWeek         = this.Calendar.GetFirstDayOfWeek();
            DateTime  firstDateOfCurrentWeek = CalendarMathHelper.GetFirstDayOfCurrentWeek(date, firstDayOfWeek);

            if (!(firstDateOfCurrentWeek.Date <= date.Date && firstDateOfCurrentWeek.AddDays(7).Date >= date.Date))
            {
                date = firstDateOfCurrentWeek;
            }

            if (!this.Calendar.multiDayViewSettings.WeekendsVisible)
            {
                date = CalendarMathHelper.AddBusinessDays(date, -this.BufferItemsCount);
            }
            else
            {
                date = date.AddDays(-this.BufferItemsCount);
            }

            return(date);
        }
Example #12
0
        private void UpdatePresenters(DateTime oldCurrentDate, DateTime newCurrentDate)
        {
            if (this.currentCellsToUpdate == null)
            {
                this.currentCellsToUpdate = new List <CalendarCellModel>();
            }
            else
            {
                this.currentCellsToUpdate.Clear();
            }

            if (oldCurrentDate != DateTime.MinValue && oldCurrentDate != newCurrentDate)
            {
                oldCurrentDate = CalendarMathHelper.GetCellDateForViewLevel(oldCurrentDate, this.Owner.DisplayMode);
                CalendarCellModel previousCell = this.Owner.GetCellByDate(oldCurrentDate);
                if (previousCell != null)
                {
                    previousCell.IsCurrent = false;
                    this.currentCellsToUpdate.Add(previousCell);
                }
            }

            if (newCurrentDate != DateTime.MinValue)
            {
                newCurrentDate = CalendarMathHelper.GetCellDateForViewLevel(newCurrentDate, this.Owner.DisplayMode);
                if (newCurrentDate == oldCurrentDate && this.currentCellsToUpdate.Count > 0)
                {
                    return;
                }

                CalendarCellModel currentCell = this.Owner.GetCellByDate(newCurrentDate);
                if (currentCell != null)
                {
                    currentCell.IsCurrent = true;
                    this.currentCellsToUpdate.Add(currentCell);
                }
            }

            this.Owner.UpdatePresenters(this.currentCellsToUpdate);
        }
Example #13
0
        internal bool MoveCurrentUp(bool isControlModifierDown)
        {
            bool handled = false;

            if (isControlModifierDown)
            {
                if (this.Owner.DisplayMode != CalendarDisplayMode.CenturyView)
                {
                    this.Owner.RaiseMoveToUpperViewCommand();

                    if (this.CurrentDate != DateTime.MinValue)
                    {
                        this.AsyncUpdateCurrencyPresenters(this.CurrentDate, this.CurrentDate);
                    }

                    handled = true;
                }
            }
            else
            {
                if (this.CurrentDate == DateTime.MinValue)
                {
                    this.CurrentDate = CalendarMathHelper.GetFirstDateForCurrentDisplayUnit(this.Owner.DisplayDate, this.Owner.DisplayMode);
                }
                else
                {
                    DateTime dateToNavigate = CalendarMathHelper.IncrementByCell(this.CurrentDate, -this.Owner.Model.ColumnCount, this.Owner.DisplayMode);

                    this.Owner.RaiseMoveToDateCommand(dateToNavigate);
                    this.CurrentDate = dateToNavigate;
                }

                handled = true;
            }

            return(handled);
        }
Example #14
0
        internal bool MoveCurrentToNext(bool isControlModifierDown)
        {
            bool handled = true;

            if (isControlModifierDown)
            {
                if (this.CurrentDate == DateTime.MinValue)
                {
                    DateTime dateToNavigate = CalendarMathHelper.IncrementByView(this.Owner.DisplayDate, 1, this.Owner.DisplayMode);
                    this.Owner.RaiseMoveToDateCommand(dateToNavigate);
                }
                else
                {
                    DateTime dateToNavigate = CalendarMathHelper.IncrementByView(this.CurrentDate, 1, this.Owner.DisplayMode);

                    this.Owner.RaiseMoveToDateCommand(dateToNavigate);
                    this.CurrentDate = dateToNavigate;
                }
            }
            else
            {
                if (this.CurrentDate == DateTime.MinValue)
                {
                    this.CurrentDate = CalendarMathHelper.GetFirstDateForCurrentDisplayUnit(this.Owner.DisplayDate, this.Owner.DisplayMode);
                }
                else
                {
                    DateTime dateToNavigate = CalendarMathHelper.IncrementByCell(this.CurrentDate, 1, this.Owner.DisplayMode);

                    this.Owner.RaiseMoveToDateCommand(dateToNavigate);
                    this.CurrentDate = dateToNavigate;
                }
            }

            return(handled);
        }
Example #15
0
 internal override DateTime GetNextDateToRender(DateTime date)
 {
     return(CalendarMathHelper.CouldAddYearsToDate(date.Year + 1) ? date.AddYears(1) : date);
 }
        private void ArrangeAllDayAppointment(RadRect viewRect)
        {
            AppointmentSource appointmentSource = this.Calendar.appointmentSource;

            if (this.allDayAppointmentInfos == null)
            {
                this.allDayAppointmentInfos = new List <CalendarAppointmentInfo>();
            }
            else
            {
                this.allDayAppointmentInfos.Clear();
            }

            if (appointmentSource != null)
            {
                MultiDayViewSettings settings = this.Calendar.multiDayViewSettings;
                double appoitmentHeight       = settings.AllDayAppointmentMinHeight;

                foreach (var cell in this.CalendarCells)
                {
                    LinkedList <IAppointment> appointments = appointmentSource.GetAppointments((IAppointment appointment) =>
                    {
                        return(cell.Date.Date >= appointment.StartDate.Date && cell.Date.Date <= appointment.EndDate.Date && appointment.IsAllDay);
                    });

                    if (appointments.Count > this.allDayAreaRowCount)
                    {
                        this.allDayAreaRowCount = appointments.Count;
                    }

                    var    sorterAppointments = appointments.OrderByDescending(a => a.EndDate.Ticks - a.StartDate.Ticks).ToList();
                    var    containedInfos     = this.allDayAppointmentInfos.Where(a => sorterAppointments.Contains(a.childAppointment));
                    double prevBottom         = cell.layoutSlot.Y - this.dayViewLayoutSlot.Y;

                    foreach (var appointment in sorterAppointments)
                    {
                        while (true)
                        {
                            int      widthCoeff;
                            int      xCoeff;
                            DateTime startAppointmentDate = appointment.StartDate;
                            if (this.Calendar.multiDayViewSettings.WeekendsVisible)
                            {
                                widthCoeff = (appointment.EndDate - startAppointmentDate).Days;
                                xCoeff     = (cell.Date - startAppointmentDate.Date).Days;
                            }
                            else
                            {
                                widthCoeff           = CalendarMathHelper.GetBusinessDaysCount(startAppointmentDate, appointment.EndDate);
                                startAppointmentDate = CalendarMathHelper.SetFirstAvailableBusinessDay(startAppointmentDate, 1);
                                xCoeff = CalendarMathHelper.GetBusinessDaysCount(startAppointmentDate.Date, cell.Date);
                            }

                            RadRect layoutSlot = new RadRect(cell.layoutSlot.X - (xCoeff * this.cellWidth), prevBottom, this.cellWidth + (this.cellWidth * widthCoeff) - this.Calendar.GridLinesThickness / 2, appoitmentHeight);
                            if (containedInfos.FirstOrDefault(a => a.layoutSlot.IntersectsWith(layoutSlot)) == null)
                            {
                                CalendarAppointmentInfo containedInfo = containedInfos.FirstOrDefault(a => a.childAppointment == appointment);
                                if (containedInfo != null)
                                {
                                    break;
                                }

                                CalendarAppointmentInfo info = new CalendarAppointmentInfo();
                                info.Date             = cell.Date;
                                info.Appointments     = appointments;
                                info.columnIndex      = cell.ColumnIndex;
                                info.Brush            = appointment.Color;
                                info.cell             = cell;
                                info.childAppointment = appointment;
                                info.DetailText       = appointment.Description;
                                info.Subject          = appointment.Subject;
                                info.IsAllDay         = appointment.IsAllDay;

                                info.layoutSlot = layoutSlot;
                                this.allDayAppointmentInfos.Add(info);
                                prevBottom = layoutSlot.Bottom + settings.AllDayAppointmentSpacing;
                                break;
                            }

                            prevBottom = layoutSlot.Bottom + settings.AllDayAppointmentSpacing;
                        }
                    }
                }

                int maxVisibleRows = settings.AllDayMaxVisibleRows;
                this.totalAllDayAreaHeight = this.allDayAreaRowCount > maxVisibleRows
                    ? maxVisibleRows * appoitmentHeight + maxVisibleRows * settings.AllDayAppointmentSpacing + appoitmentHeight / 2
                    : this.allDayAreaRowCount * appoitmentHeight + this.allDayAreaRowCount * settings.AllDayAppointmentSpacing;

                if (this.allDayAreaRowCount == 0)
                {
                    this.totalAllDayAreaHeight = 0;
                }
            }
        }
        internal void ArrangeAppointments()
        {
            AppointmentSource appointmentSource = this.Calendar.appointmentSource;

            if (this.appointmentInfos == null)
            {
                this.appointmentInfos = new List <CalendarAppointmentInfo>();
            }
            else
            {
                this.appointmentInfos.Clear();
            }

            if (appointmentSource != null)
            {
                MultiDayViewSettings settings = this.Calendar.multiDayViewSettings;
                foreach (var calendarCell in this.CalendarCells)
                {
                    LinkedList <IAppointment> appointmentsPerCell = appointmentSource.GetAppointments((IAppointment appointment) =>
                    {
                        return(calendarCell.Date.Date >= appointment.StartDate.Date &&
                               calendarCell.Date.Date <= appointment.EndDate.Date && !(appointment.IsAllDay && settings.ShowAllDayArea));
                    });

                    var orderedAppointments = new LinkedList <IAppointment>(appointmentsPerCell.OrderBy(a => a.StartDate));
                    foreach (var appointment in orderedAppointments)
                    {
                        if ((appointment.StartDate.Date == calendarCell.Date.Date && appointment.StartDate.TimeOfDay > settings.DayEndTime) ||
                            (appointment.EndDate.Date == calendarCell.Date.Date && appointment.EndDate.TimeOfDay < settings.DayStartTime))
                        {
                            continue;
                        }

                        double   startY  = this.DateToVerticalPosition(calendarCell.Date.Date, appointment.StartDate);
                        DateTime endDate = appointment.EndDate.TimeOfDay > settings.DayEndTime
                            ? appointment.EndDate.Add(TimeSpan.FromTicks(settings.DayEndTime.Ticks - appointment.EndDate.TimeOfDay.Ticks))
                            : appointment.EndDate;

                        double endY = this.DateToVerticalPosition(calendarCell.Date.Date, endDate);
                        if (startY < endY)
                        {
                            CalendarAppointmentInfo info = new CalendarAppointmentInfo();
                            info.Date             = calendarCell.Date;
                            info.Appointments     = orderedAppointments;
                            info.columnIndex      = calendarCell.ColumnIndex;
                            info.Brush            = appointment.Color;
                            info.cell             = calendarCell;
                            info.childAppointment = appointment;
                            info.DetailText       = appointment.Description;
                            info.Subject          = appointment.Subject;
                            info.IsAllDay         = appointment.IsAllDay;

                            DateTime currentAppointmentStartDate = appointment.StartDate;
                            DateTime currentAppointmentEndDate   = appointment.EndDate;
                            if (!this.Calendar.multiDayViewSettings.WeekendsVisible)
                            {
                                currentAppointmentStartDate = CalendarMathHelper.SetFirstAvailableBusinessDay(currentAppointmentStartDate, 1);
                                currentAppointmentEndDate   = CalendarMathHelper.SetFirstAvailableBusinessDay(currentAppointmentEndDate, -1);
                            }

                            info.hasPreviousDay = currentAppointmentStartDate.Date < calendarCell.Date;
                            info.hasNextDay     = currentAppointmentEndDate.Date > calendarCell.Date;
                            int     xCoeff     = (calendarCell.Date - appointment.StartDate.Date).Days;
                            RadRect layoutSlot = new RadRect(calendarCell.layoutSlot.X - this.timeRulerWidth, startY, calendarCell.layoutSlot.Width, endY - startY);
                            info.layoutSlot = layoutSlot;
                            this.appointmentInfos.Add(info);
                        }
                    }
                }

                this.ArrangeIntersectedAppointments();
            }
        }
Example #18
0
 internal override DateTime GetFirstDateToRender(DateTime date)
 {
     return(CalendarMathHelper.GetFirstDateOfCentury(date));
 }
Example #19
0
 private static DateTime GetLastDateOfCenturyView(DateTime date)
 {
     return(CalendarMathHelper.GetFirstDateOfCentury(date).AddYears(90));
 }
Example #20
0
 private static DateTime GetLastDateOfDecadeView(DateTime date)
 {
     return(CalendarMathHelper.GetFirstDateOfDecade(date).AddYears(9));
 }
Example #21
0
 private static DateTime GetLastDateOfMonthView(DateTime date)
 {
     return(CalendarMathHelper.GetFirstDateOfMonth(date).AddMonths(1).AddDays(-1));
 }
Example #22
0
 internal override DateTime GetFirstDateToRender(DateTime date)
 {
     return CalendarMathHelper.GetFirstDateOfDecade(date);
 }