Ejemplo n.º 1
0
        static object coerceDisplayDateStart(DependencyObject d, object o)
        {
            PersianCalendar pc = d as PersianCalendar;

            Mohsen.PersianDate value = (Mohsen.PersianDate)o;
            return(o);
        }
Ejemplo n.º 2
0
        private void setMonthMode()
        {
            this.decadeUniformGrid.Visibility = this.yearUniformGrid.Visibility = Visibility.Collapsed;
            this.monthUniformGrid.Visibility  = Visibility.Visible;

            int year  = DisplayDate.Year;
            int month = DisplayDate.Month;

            Mohsen.PersianDate firstDayInMonth = new Mohsen.PersianDate(year, month, 1);
            for (int i = 1; i <= 6; i++)
            {
                for (int j = 1; j <= 7; j++)
                {
                    var button = monthModeButtons[i - 1, j - 1];
                    Mohsen.PersianDate date = new Mohsen.PersianDate();
                    bool dateInRange;
                    try
                    {
                        //might throw OverflowException, which means that the date cannot be stored in PersianDate
                        date        = monthModeRowColumnToDate(i - 1, j - 1, firstDayInMonth);
                        dateInRange = date >= DisplayDateStart && date <= DisplayDateEnd;
                    }
                    catch (OverflowException)
                    {
                        dateInRange = false;
                    }
                    if (dateInRange && date.Month == firstDayInMonth.Month)
                    {//we're good!
                        button.Foreground = Brushes.Black;
                        button.Content    = date.Day.ToString();
                        button.IsEnabled  = true;
                        button.Tag        = date;
                    }
                    else if (dateInRange)
                    {//belongs to the next, or the previous month
                        button.Content    = date.Day.ToString();
                        button.IsEnabled  = true;
                        button.Tag        = date;
                        button.Foreground = Brushes.LightGray;
                    }
                    else
                    {//not in [DiplayDateStart, DiplayDateEnd] range
                        button.Tag        = null;
                        button.Content    = "";
                        button.IsEnabled  = false;
                        button.Background = Brushes.Transparent;
                    }
                }
            }

            this.titleButton.Content = ((PersianMonth)month).ToString() + " " + year.ToString();
            this.todayCheck();
            this.selectedDateCheck(null);
        }
Ejemplo n.º 3
0
        static object coerceDisplayDateEnd(DependencyObject d, object o)
        {
            PersianCalendar pc = d as PersianCalendar;

            Mohsen.PersianDate value = (Mohsen.PersianDate)o;
            if (value < pc.DisplayDateStart)
            {
                return(pc.DisplayDateStart);
            }
            return(o);
        }
Ejemplo n.º 4
0
        /// <param name="row">zero-based row number</param>
        /// <param name="column">zero-based column number</param>
        private static Mohsen.PersianDate monthModeRowColumnToDate(int row, int column, Mohsen.PersianDate displayDate)
        {
            int year  = displayDate.Year;
            int month = displayDate.Month;

            Mohsen.PersianDate firstDay = new Mohsen.PersianDate(year, month, 1);
            int fstCol        = 2 + (int)firstDay.PersianDayOfWeek;
            int fstRow        = fstCol == 1 ? 2 : 1;
            int dayDifference = (row) * 7 + column + 1 - ((fstRow - 1) * 7 + fstCol);

            return(firstDay.AddDays(dayDifference));
        }
 // Overrides the ConvertFrom method of TypeConverter.
 public override object ConvertFrom(ITypeDescriptorContext context,
                                    CultureInfo culture, object value)
 {
     if (value is string)
     {
         return(PersianDate.Parse(value as string));
     }
     if (value is DateTime)
     {
         return(new PersianDate((DateTime)value));
     }
     return(base.ConvertFrom(context, culture, value));
 }
Ejemplo n.º 6
0
        /// <param name="row">zero-based row number</param>
        /// <param name="column">zero-based column number</param>
        private static void monthModeDateToRowColumn(Mohsen.PersianDate date, out int row, out int column)
        {
            int year  = date.Year;
            int month = date.Month;

            Mohsen.PersianDate firstDay = new Mohsen.PersianDate(year, month, 1);
            int fstCol = 2 + (int)firstDay.PersianDayOfWeek;
            int fstRow = fstCol == 1 ? 2 : 1;

            row    = (date.Day + fstCol - 2) / 7 + fstRow;
            column = (date.Day + fstCol - 1) % 7;
            column = column == 0 ? 7 : column;
            column--; row--;
        }
 // Overrides the ConvertTo method of TypeConverter.
 public override object ConvertTo(ITypeDescriptorContext context,
                                  CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string))
     {
         PersianDate pd = (PersianDate)value;
         return(value.ToString());
     }
     if (destinationType == typeof(DateTime))
     {
         PersianDate pd = (PersianDate)value;
         return(pd.ToDateTime());
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
Ejemplo n.º 8
0
        private void previousButton_Click(object sender, RoutedEventArgs e)
        {
            int m = this.DisplayDate.Month;
            int y = this.DisplayDate.Year;

            try
            {
                Mohsen.PersianDate newDisplayDate = DisplayDate;

                if (this.DisplayMode == CalendarMode.Month)
                {
                    if (m == 1)
                    {
                        newDisplayDate = new Mohsen.PersianDate(y - 1, 12, Mohsen.PersianDate.DaysInMonth(y - 1, 12));
                    }
                    else
                    {
                        newDisplayDate = new Mohsen.PersianDate(y, m - 1, Mohsen.PersianDate.DaysInMonth(y, m - 1));
                    }
                }
                else if (this.DisplayMode == CalendarMode.Year)
                {
                    newDisplayDate = new Mohsen.PersianDate(y - 1, 12, Mohsen.PersianDate.DaysInMonth(y - 1, 12));
                }
                else if (this.DisplayMode == CalendarMode.Decade)
                {
                    newDisplayDate = new Mohsen.PersianDate(y - y % 10 - 1, 12, Mohsen.PersianDate.DaysInMonth(y - y % 10 - 1, 12));
                }

                if (newDisplayDate >= DisplayDateStart && newDisplayDate <= DisplayDateEnd)
                {
                    this.SetCurrentValue(DisplayDateProperty, newDisplayDate);
                }
            }
            catch (ArgumentOutOfRangeException)
            {
            }
        }