Пример #1
0
        private static void OnDateTimeInvalidated(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CalendarDay c = (CalendarDay)d;

            DateTime oldValue = (DateTime)e.OldValue;
            DateTime newValue = (DateTime)e.NewValue;

            c.OnDateTimeChanged(oldValue, newValue);
        }
Пример #2
0
        /// <summary>
        /// Updates the date list with new dates
        /// </summary>
        public void UpdateDate()
        {
            this.Days = new AdvancedObservableCollection <CalendarDay>();
            //current day
            DateTime currentDay = this.DateTimeContainer.DateTime;

            Console.WriteLine(currentDay);
            currentDay = new DateTime(currentDay.Year, currentDay.Month, currentDay.Day);

            //last month
            DateTime lastMonth = new DateTime(currentDay.Year, currentDay.Month, 1);

            lastMonth = lastMonth.AddMonths(-1);
            Console.WriteLine(lastMonth);
            Console.WriteLine(currentDay.Month);

            //this month
            DateTime currentMonth = new DateTime(currentDay.Year, currentDay.Month, 1);

            //next month
            DateTime nextMonth = new DateTime(currentDay.Year, currentDay.Month, 1);

            nextMonth = nextMonth.AddMonths(1);

            for (int i = (int)currentMonth.DayOfWeek - 1; i >= 0; i--)
            {
                CalendarDay cd = new CalendarDay();
                cd.IsLastMonth   = true;
                cd.DateTime      = new DateTime(lastMonth.Year, lastMonth.Month, (DateTime.DaysInMonth(lastMonth.Year, lastMonth.Month) - i));
                cd.IsStartOfWeek = cd.DateTime.DayOfWeek == DayOfWeek.Sunday;
                cd.IsEndOfWeek   = cd.DateTime.DayOfWeek == DayOfWeek.Saturday;
                cd.IsCurrentDay  = (cd.DateTime.Day == DateTime.Now.Day && cd.DateTime.Month == DateTime.Now.Month && cd.DateTime.Year == DateTime.Now.Year);
                this.Days.Add(cd);
            }

            for (int i = 1; i <= DateTime.DaysInMonth(currentMonth.Year, currentMonth.Month); i++)
            {
                CalendarDay cd = new CalendarDay();
                cd.IsSelectedMonth = true;
                cd.DateTime        = new DateTime(currentMonth.Year, currentMonth.Month, i);
                cd.IsStartOfWeek   = cd.DateTime.DayOfWeek == DayOfWeek.Sunday;
                cd.IsEndOfWeek     = cd.DateTime.DayOfWeek == DayOfWeek.Saturday;
                cd.IsCurrentDay    = (cd.DateTime.Day == DateTime.Now.Day && cd.DateTime.Month == DateTime.Now.Month && cd.DateTime.Year == DateTime.Now.Year);
                this.Days.Add(cd);
            }

            int counter = 0;

            for (int i = (int)nextMonth.DayOfWeek; i <= (int)DayOfWeek.Saturday; i++)
            {
                counter++;
                CalendarDay cd = new CalendarDay();
                cd.IsNextMonth   = true;
                cd.DateTime      = new DateTime(nextMonth.Year, nextMonth.Month, counter);
                cd.IsStartOfWeek = cd.DateTime.DayOfWeek == DayOfWeek.Sunday;
                cd.IsEndOfWeek   = cd.DateTime.DayOfWeek == DayOfWeek.Saturday;
                cd.IsCurrentDay  = (cd.DateTime.Day == DateTime.Now.Day && cd.DateTime.Month == DateTime.Now.Month && cd.DateTime.Year == DateTime.Now.Year);
                this.Days.Add(cd);
            }
            this.Day   = currentDay.Day.ToString();
            this.Month = currentDay.Month.ToString();
            this.Year  = currentDay.Year.ToString();
        }