//protected static void OnTableMouseLeave(System.EventArgs eventArgs)
        //{
        //}
        //protected static void OnTableMouseUp(MouseEventArgs mouseEventArgs)
        //{
        //}
        //protected Task OnDayMouseOver(MouseEventArgs eventArgs)
        //{
        //    return Task.CompletedTask;
        //}
        //protected Task OnDayMouseLeave(EventArgs eventArgs)
        //{
        //    return Task.CompletedTask;
        //}
        //protected Task OnDayMouseDown(MouseEventArgs eventArgs)
        //{
        //    return Task.CompletedTask;
        //}
        //protected Task OnDayMouseUp(MouseEventArgs eventArgs)
        //{
        //    return Task.CompletedTask;
        //}

        protected string GetDayClasses(DayInfo day)
        {
            string classNames = "";

            classNames += "dayCell";
            if (WeekCornersStyled != null && WeekCornersStyled.ContainsKey(day.WeekIndex + "_" + (day.OriginalDate.Day - 1)))
            {
                classNames += WeekCornersStyled[day.WeekIndex + "_" + (day.OriginalDate.Day - 1)];
            }
            if (day.IsSelected && (DateRangeType == DateRangeType.Week || DateRangeType == DateRangeType.WorkWeek))
            {
                classNames += " ms-Calendar-weekBackground";
            }
            if (day.IsSelected && DateRangeType == DateRangeType.Day)
            {
                classNames += " ms-Calendar-dayBackground";
            }
            if (day.IsSelected && DateRangeType == DateRangeType.Day)
            {
                classNames += " ms-Calendar-dayIsHighlighted";
            }
            if (day.IsInBounds && day.IsInMonth && DateRangeType == DateRangeType.Day)
            {
                classNames += " ms-Calendar-dayIsFocused";
            }
            if (day.IsInBounds && !day.IsInMonth && DateRangeType == DateRangeType.Day)
            {
                classNames += " ms-Calendar-dayUnFocused";
            }
            if (!day.IsInBounds && day.IsInMonth)
            {
                classNames += " ms-Calendar-dayOutsideBounds";
            }
            switch (DateRangeType)
            {
            case DateRangeType.Day:
                classNames += " ms-Calendar-daySelection";
                break;

            case DateRangeType.Week:
                //classNames += " ms-Calendar-weekSelection";
                if (HoverWeek == day.WeekIndex)
                {
                    classNames += " ms-Calendar-dayHover";
                }
                if (PressWeek == day.WeekIndex)
                {
                    classNames += " ms-Calendar-dayPress";
                }
                break;

            case DateRangeType.WorkWeek:
                //if (day.IsHighlightedOnHover)
                //    classNames += " ms-Calendar-dayIsFocused";
                if (HoverWeek == day.WeekIndex && day.IsHighlightedOnHover)
                {
                    classNames += " ms-Calendar-dayHover";
                }
                if (PressWeek == day.WeekIndex)
                {
                    classNames += " ms-Calendar-dayPress";
                }
                break;

            case DateRangeType.Month:
                classNames += " ms-Calendar-monthSelection";
                if (HoverMonth == day.OriginalDate.Month)
                {
                    classNames += " ms-Calendar-dayHover";
                }
                if (PressMonth == day.OriginalDate.Month)
                {
                    classNames += " ms-Calendar-dayPress";
                }
                break;
            }
            return(classNames);
        }
Beispiel #2
0
        private void GenerateWeeks()
        {
            var date       = new DateTime(NavigatedDate.Year, NavigatedDate.Month, 1);
            var todaysDate = DateTime.Now;

            Weeks = new List <List <DayInfo> >();

            // cycle backwards to get first day of week
            while (date.DayOfWeek != FirstDayOfWeek)
            {
                date = date - TimeSpan.FromDays(1);
            }

            // a flag to indicate whether all days of the week are in the month
            var isAllDaysOfWeekOutOfMonth = false;

            // in work week view we want to select the whole week
            var selecteDateRangeType = DateRangeType == DateRangeType.WorkWeek ? DateRangeType.Week : DateRangeType;
            var selectedDates        = DateUtilities.GetDateRangeArray(SelectedDate, selecteDateRangeType, FirstDayOfWeek, WorkWeekDays);

            if (DateRangeType != DateRangeType.Day)
            {
                selectedDates = GetBoundedDateRange(selectedDates, MinDate, MaxDate);
            }

            var shouldGetWeeks = true;

            for (var weekIndex = 0; shouldGetWeeks; weekIndex++)
            {
                List <DayInfo> week = new List <DayInfo>();
                isAllDaysOfWeekOutOfMonth = true;

                for (var dayIndex = 0; dayIndex < 7; dayIndex++)
                {
                    var originalDate = new DateTime(date.Year, date.Month, date.Day);
                    var dayInfo      = new DayInfo()
                    {
                        Key          = date.ToString(),
                        Date         = date.Date.ToString("D"),
                        OriginalDate = originalDate,
                        WeekIndex    = weekIndex,
                        IsInMonth    = date.Month == NavigatedDate.Month,
                        IsToday      = DateTime.Compare(DateTime.Now.Date, originalDate) == 0,
                        IsSelected   = IsInDateRangeArray(date, selectedDates),
                        OnSelected   = () => OnSelectDateInternal(originalDate),
                        IsInBounds   =
                            (DateTime.Compare(MinDate, date) < 1) &&
                            (DateTime.Compare(date, MaxDate) < 1) &&
                            !GetIsRestrictedDate(date)
                    };

                    week.Add(dayInfo);
                    if (dayInfo.IsInMonth)
                    {
                        isAllDaysOfWeekOutOfMonth = false;
                    }

                    date = date.AddDays(1);
                }

                // We append the condition of the loop depending upon the ShowSixWeeksByDefault parameter.
                shouldGetWeeks = ShowSixWeeksByDefault ? !isAllDaysOfWeekOutOfMonth || weekIndex <= 5 : !isAllDaysOfWeekOutOfMonth;
                if (shouldGetWeeks)
                {
                    Weeks.Add(week);
                }
            }
        }