private void setYearMode() { this.monthUniformGrid.Visibility = this.decadeUniformGrid.Visibility = Visibility.Collapsed; this.yearUniformGrid.Visibility = Visibility.Visible; this.titleButton.Content = this.DisplayDate.Year.ToString(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { int month = j + i * 3 + 1; if (new PersianDate(DisplayDate.Year, month, PersianDate.DaysInMonth(DisplayDate.Year, month)) >= DisplayDateStart && new PersianDate(DisplayDate.Year, month, 1) <= DisplayDateEnd) { yearModeButtons[i, j].Content = ((PersianMonth)month).ToString(); yearModeButtons[i, j].IsEnabled = true; } else { yearModeButtons[i, j].Content = ""; yearModeButtons[i, j].IsEnabled = false; } } } }
private PersianDate AddYear(int year, int month, int day, int factor) { year += factor; if (!PersianDate.IsValid(year, month, day)) { if (PersianDate.DaysInMonth(year, month) < day) { day = PersianDate.DaysInMonth(year, month); } } return(new PersianDate(year, month, day)); }
private void previousButton_Click(object sender, RoutedEventArgs e) { int m = this.DisplayDate.Month; int y = this.DisplayDate.Year; try { PersianDate newDisplayDate = DisplayDate; if (this.DisplayMode == CalendarType.Month) { if (m == 1) { if (y != 1) { newDisplayDate = new PersianDate(y - 1, 12, PersianDate.DaysInMonth(y - 1, 12)); } } else { newDisplayDate = new PersianDate(y, m - 1, PersianDate.DaysInMonth(y, m - 1)); } } else if (this.DisplayMode == CalendarType.Year) { if (y != 1) { newDisplayDate = new PersianDate(y - 1, 12, PersianDate.DaysInMonth(y - 1, 12)); } } else if (this.DisplayMode == CalendarType.Decade) { if ((y - y % 10 - 1) >= 1) { newDisplayDate = new PersianDate(y - y % 10 - 1, 12, PersianDate.DaysInMonth(y - y % 10 - 1, 12)); } } if (newDisplayDate >= DisplayDateStart && newDisplayDate <= DisplayDateEnd) { this.SetCurrentValue(DisplayDateProperty, newDisplayDate); } } catch (ArgumentOutOfRangeException) { } }
private void setMonthMode() { this.decadeUniformGrid.Visibility = this.yearUniformGrid.Visibility = Visibility.Collapsed; this.monthUniformGrid.Visibility = Visibility.Visible; int year = DisplayDate.Year; int month = DisplayDate.Month; int days = PersianDate.DaysInMonth(year, month); PersianDate firstDay = new PersianDate(year, month, 1); int fstCol = 2 + (int)firstDay.PersianDayOfWeek; int fstRow = fstCol == 1 ? 2 : 1; for (int i = 1; i <= 6; i++) { for (int j = 1; j <= 7; j++) { monthModeButtons[i - 1, j - 1].Content = ""; monthModeButtons[i - 1, j - 1].IsEnabled = false; monthModeButtons[i - 1, j - 1].Background = Brushes.Transparent; } } for (int d = 1; d <= days; d++) { PersianDate date = new PersianDate(year, month, d); if (date >= DisplayDateStart && date <= DisplayDateEnd) { int c, r; r = (d + fstCol - 2) / 7 + fstRow; c = (d + fstCol - 1) % 7; c = c == 0 ? 7 : c; monthModeButtons[r - 1, c - 1].Content = d.ToString(); monthModeButtons[r - 1, c - 1].IsEnabled = true; monthModeButtons[r - 1, c - 1].Tag = date; } } this.titleButton.Content = ((PersianMonth)month).ToString() + " " + year.ToString(); this.todayCheck(); this.selectedDateCheck(null); }
private PersianDate AddMonth(int year, int month, int day, int factor) { month += factor; if (!PersianDate.IsValid(year, month, day)) { if (month > 12) { year++; month = 1; } else if (month < 1) { year--; month = 12; } if (PersianDate.DaysInMonth(year, month) < day) { day = PersianDate.DaysInMonth(year, month); } } return(new PersianDate(year, month, day)); }
private void SetHalfYearClick(object sender, RoutedEventArgs e) { var currentItem = (MenuItem)sender; switch (currentItem.Name) { case "hy1": if (DateFormat == DateFormat.RangeFrom || DateFormat == DateFormat.DateTime) { pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 1, 1); if (Partner != null) { Partner.pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 6, 31); } } else { pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 6, 31); if (Partner != null) { Partner.pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 1, 1); } } break; case "hy2": if (DateFormat == DateFormat.RangeFrom || DateFormat == DateFormat.DateTime) { pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 7, 1); if (Partner != null) { Partner.pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 12, PersianDate.DaysInMonth(PersianDate.Today.Year, 12)); } } else { pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 12, PersianDate.DaysInMonth(PersianDate.Today.Year, 12)); if (Partner != null) { Partner.pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 7, 1); } } break; } }
private void SetMonthClick(object sender, RoutedEventArgs e) { int index = Int32.Parse(((MenuItem)sender).Name.Substring(1)); if (DateFormat == DateFormat.RangeFrom || DateFormat == DateFormat.DateTime) { pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, index, 1); if (Partner != null) { Partner.pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, index, PersianDate.DaysInMonth(PersianDate.Today.Year, index)); } } else { pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, index, PersianDate.DaysInMonth(PersianDate.Today.Year, index)); if (Partner != null) { Partner.pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, index, 1); } } }
private void ItemClick(object sender, RoutedEventArgs e) { var currentItem = (Button)sender; switch (currentItem.Name) { case "today": pd.PersianSelectedDate = PersianDate.Today; if (DateFormat != DateFormat.DateTime && Partner != null) { Partner.pd.PersianSelectedDate = PersianDate.Today; } break; case "thisweek": var from = (int)PersianDate.Today.PersianDayOfWeek; var to = from; if (from != 6) { from++; } else { from = 0; } if (to != 6) { to = 5 - to; } if (DateFormat == DateFormat.RangeFrom || DateFormat == DateFormat.DateTime) { pd.PersianSelectedDate = PersianDate.Today.AddDays(from * (-1)); if (Partner != null) { Partner.pd.PersianSelectedDate = PersianDate.Today.AddDays(to); } } else { pd.PersianSelectedDate = PersianDate.Today.AddDays(to); if (Partner != null) { Partner.pd.PersianSelectedDate = PersianDate.Today.AddDays(from * (-1)); } } break; case "thismonth": var lastday = 30; if (PersianDate.Today.Month < 7) { lastday = 31; } else if (PersianDate.Today.Month == 12 && PersianDate.Today.IsLeapYear() == false) { lastday = 29; } if (DateFormat == DateFormat.RangeFrom || DateFormat == DateFormat.DateTime) { pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, PersianDate.Today.Month, 1); if (Partner != null) { Partner.pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, PersianDate.Today.Month, lastday); } } else { pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, PersianDate.Today.Month, lastday); if (Partner != null) { Partner.pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, PersianDate.Today.Month, 1); } } break; case "thisyear": if (DateFormat == DateFormat.RangeFrom || DateFormat == DateFormat.DateTime) { pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 1, 1); if (Partner != null) { Partner.pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 12, PersianDate.DaysInMonth(PersianDate.Today.Year, 12)); } } else { pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 12, PersianDate.DaysInMonth(PersianDate.Today.Year, 12)); if (Partner != null) { Partner.pd.PersianSelectedDate = new PersianDate(PersianDate.Today.Year, 1, 1); } } break; } suggestbtn.ContextMenu.IsOpen = false; }