public ViewModel() { for (int i = 0; i < 12; i++) { Months.Add(new Month(i + 1, 31, this)); //this is simplified } SelectedMonth = Months.First(); }
private void PreviousMonthOrYearOnClick(object sender, MouseButtonEventArgs e) { if (CurrentState == CalendarState.Days) { SelectedMonth = Math.Max(Months.First().Key, SelectedMonth - 1); } else if (CurrentState == CalendarState.Months) { SelectedYear = Math.Max(MinYear, SelectedYear - 1); } }
public FriendlyDateRangePicker() { var currentDate = DateTime.Now; Years = DateSegmentViewModel.GetYears(currentDate.Year - 3); SelectedYear = Years.First(p => p.Value == currentDate.Year); SelectedMonth = Months.First(p => p.Value == currentDate.Month); SelectedDay = Days.First(p => p.Value == currentDate.Day); MonthDuration = 1; InitializeComponent(); }
private void CachePreviousMonths() { var firstMonth = Months.First(); for (int i = 1; i < CachedMonthCount; i++) { var monthToInsertDateTime = firstMonth.CurrentDate.AddMonths(-i); var monthToInsert = new MonthViewModel( monthToInsertDateTime, SelectDayCommand, _toDoCalendarViewModel.GetDaysWithToDoByDateAndStatus(monthToInsertDateTime, ConstantsHelper.Active), _toDoCalendarViewModel.GetDaysWithToDoByDateAndStatus(monthToInsertDateTime, ConstantsHelper.Completed)); Months.Insert(0, monthToInsert); Months.RemoveAt(Months.Count - 1); } }
protected DateTime?NextMonth(int year, int month, int day, int hour, int minute, int second) { switch (MonthType) { case CronFieldType.Any: if (month < 12) { var nextMonth = month + 1; var daysInNextMonth = DateTime.DaysInMonth(year, nextMonth); if (day <= daysInNextMonth) { return(new DateTime(year, nextMonth, day, hour, minute, second)); } return(NextMonth(year, nextMonth, day, hour, minute, second)); } else { int nextYear = 0, nextMonth = 1; switch (YearType) { case CronFieldType.Any: nextYear = year + 1; break; case CronFieldType.Specified: var yearValues = Years.Where(x => x > year); if (yearValues.Any()) { nextYear = yearValues.First(); } break; default: throw new NotImplementedException(); } var daysInNextMonth = DateTime.DaysInMonth(nextYear, nextMonth); if (day <= daysInNextMonth) { return(new DateTime(nextYear, nextMonth, day, hour, minute, second)); } return(NextMonth(nextYear, nextMonth, day, hour, minute, second)); } case CronFieldType.Specified: var values = Months.Where(x => x > month); if (values.Any()) { var nextMonth = values.First(); var daysInNextMonth = DateTime.DaysInMonth(year, nextMonth); if (day <= daysInNextMonth) { return(new DateTime(year, nextMonth, day, hour, minute, second)); } return(NextMonth(year, nextMonth, day, hour, minute, second)); } else { int nextYear = 0, nextMonth = Months.First(); switch (YearType) { case CronFieldType.Any: nextYear = year + 1; break; case CronFieldType.Specified: var yearValues = Years.Where(x => x > year); if (yearValues.Any()) { nextYear = yearValues.First(); } break; default: throw new NotImplementedException(); } var daysInNextMonth = DateTime.DaysInMonth(nextYear, nextMonth); if (day <= daysInNextMonth) { return(new DateTime(nextYear, nextMonth, day, hour, minute, second)); } return(NextMonth(nextYear, nextMonth, day, hour, minute, second)); } default: throw new NotImplementedException(); } }