private void CalculateMonth(int thisYear, int thisMonth) { yearForNavigating = thisYear; monthForNavigating = thisMonth; System.DateTime tempDateTime = persianCalendar.ToDateTime(yearForNavigating, monthForNavigating, 15, 01, 01, 01, 01); int thisDay = 1; TextBlockThisMonth.Text = string.Empty; TextBlockThisMonth.Text = monthForNavigating.ConvertToPersianMonth() + " " + yearForNavigating.ConvertToPersianNumber(); //Different between first place of calendar and first place of this month //اختلاف بین خانه شروع ماه و اولین خانه تقویم string DayOfWeek = persianCalendar.GetDayOfWeek(persianCalendar.ToDateTime(thisYear, thisMonth, 01, 01, 01, 01, 01)).ToString(); int span = CalculatePersianSpan(DayOfWeek.ConvertToPersianDay()); DecreasePersianDay(ref thisYear, ref thisMonth, ref thisDay, span); string persianDate;//حاوی تاریخ روزهای شمسی Contains the date of Persian //////////////////////////////////// for (int i = 0; i < 6 * 7; i++) { tempDateTime = persianCalendar.ToDateTime(thisYear, thisMonth, thisDay, 01, 01, 01, 01); persianDate = thisDay.ConvertToPersianNumber(); DayOfWeek = persianCalendar.GetDayOfWeek(tempDateTime).ToString(); //RectangleStyleEventedDay if (thisMonth == monthForNavigating) // ماه کنونی { if (thisDay == currentDay && thisMonth == currentMonth && thisYear == currentYear) // امروز { ChangeProperties(i, persianDate, "RectangleStyleToday", "TextBlockStyle1"); SelectedDateTime = new AAk.Utils.PersianDate(thisYear, thisMonth, thisDay); RaiseSelectedDateTimeChangedEvent(); } else // سایر روزهای ماه کنونی { ChangeProperties(i, persianDate, "RectangleStyleNone", "TextBlockStyle1"); } } else // ماه های دیگر { ChangeProperties(i, persianDate, "RectangleStyleNone", "TextBlockStyleForOtherMonths"); } IncreasePersianDay(ref thisYear, ref thisMonth, ref thisDay, 1); } }
public void GoToDate(AAk.Utils.PersianDate persianDate) { currentYear = persianDate.Year; currentMonth = persianDate.Month; currentDay = persianDate.Day; CalculateMonth(persianDate.Year, persianDate.Month); }
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ((value is string) == false) { return(null); } string strValue = value as string; AAk.Utils.PersianDate oPersianDate = new AAk.Utils.PersianDate(strValue); return(AAk.Utils.PersianDateConverter.ToGregorianDateTime(oPersianDate)); }
public void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { int todayIndex; foreach (System.Windows.Shapes.Rectangle item in Rectangles) { item.Style = (System.Windows.Style)FindResource("RectangleStyleNone"); if (item.Style == (System.Windows.Style)FindResource("RectangleStyleToday")) { todayIndex = Rectangles.IndexOf(item); } } SelectedRectangleBaseName = System.Text.RegularExpressions.Regex.Replace((sender as System.Windows.Controls.Grid).Name, @"Grid", string.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Windows.Shapes.Rectangle SelectedRectangle = FindName("Rectangle" + SelectedRectangleBaseName) as System.Windows.Shapes.Rectangle; int Index = Rectangles.IndexOf(SelectedRectangle); System.Windows.Controls.TextBlock SelectedTextBlock = TextBlocks.ElementAt(Index); if ((SelectedRectangle.Style == FindResource("RectangleStyleNone") && SelectedTextBlock.Style == FindResource("TextBlockStyleForOtherMonths"))) { return; } SelectedRectangle.Style = (System.Windows.Style)FindResource("RectangleStyleToday"); PreviousRectangle = SelectedRectangle; ////بدست آوردن اطلاعات امروز this.yearPersian = this.yearForNavigating; this.monthPersian = this.monthForNavigating; this.dayPersian = (FindName("TextBlock" + SelectedRectangleBaseName) as System.Windows.Controls.TextBlock).Text.ConvertToInteger(); SelectedDateTime = new AAk.Utils.PersianDate(yearPersian, monthPersian, dayPersian); RaiseSelectedDateTimeChangedEvent(); if (e.ClickCount == 2) { RaiseMouseDoubleClickEvent(); } }
public MonthView() { this.InitializeComponent(); GetRectangles(); GetTextBoxes(); PreviousRectangle = Rectangles .Where(current => current.Style == (System.Windows.Style)FindResource("RectangleStyleToday")) .FirstOrDefault(); PreviousRectangle.Style = (System.Windows.Style)FindResource("RectangleStyleNone"); SelectedDateTime = AAk.Utils.PersianDate.Now; currentYear = SelectedDateTime.Year; currentMonth = SelectedDateTime.Month; currentDay = SelectedDateTime.Day; CalculateMonth(currentYear, currentMonth); RaiseSelectedDateTimeChangedEvent(); }
private void ToggleButton_Click(object sender, System.Windows.RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(PersianDateTextBox.Text.Trim()) == true) { PersianDateTextBox.Focus(); return; } System.Text.RegularExpressions.Regex oRegex = new System.Text.RegularExpressions.Regex(AAk.Text.RegularExpressions.Patterns.PersianDate); if (oRegex.IsMatch(PersianDateTextBox.Text) == true) { AAk.Utils.PersianDate oPersianDate = new AAk.Utils.PersianDate(PersianDateTextBox.Text); MonthView.SelectedDateTime = oPersianDate; MonthView.GoToDate(oPersianDate); SelectedDateTime = AAk.Utils.PersianDateConverter.ToGregorianDateTime(oPersianDate); SelectedPersianDateTime = oPersianDate; DatePickerPopup.IsOpen = true; } else { MonthView.GoToDate(SelectedPersianDateTime); SelectedDateTime = AAk.Utils.PersianDateConverter.ToGregorianDateTime(AAk.Utils.PersianDate.Today); SelectedPersianDateTime = AAk.Utils.PersianDate.Today; } Text = PersianDateTextBox.Text; }