예제 #1
0
        private void ValidateText()
        {
            PersianDate date;

            string txt = this.Text.Replace('_', ' ');

            if (PersianDate.TryParse(txt, out date))
            {
                this.PersianSelectedDate = date;
                this.DisplayDate         = date;
                this.Text = date.ToString();
            }
            else
            {
                this.PersianSelectedDate = null;
                this.DisplayDate         = this.PersianSelectedDate ?? PersianDate.Today;
                if (this.AllowNull)
                {
                    this.Text = "____/__/__";
                }
                else
                {
                    this.Text = this.PersianSelectedDate.ToString();
                }
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string)
            {
                string converting = (string)value;
                if (string.IsNullOrEmpty(converting))
                {
                    return(null);
                }

                if (CultureHelper.IsFarsiCulture())
                {
                    PersianDate pd;
                    if (PersianDate.TryParse(converting, out pd))
                    {
                        return(pd);
                    }
                }
                else
                {
                    DateTime dt;
                    if (DateTime.TryParse(converting, out dt))
                    {
                        return(dt.ToPersianDate());
                    }
                }
            }

            return(null);
        }
예제 #3
0
        static void OnSelectedDateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PersianDatePicker pdp = d as PersianDatePicker;
            var date = e.NewValue as DateTime?;

            if (date != null)
            {
                if (pdp.PersianSelectedDate == null || pdp.PersianSelectedDate.ToDateTime() != date.Value)
                {
                    PersianDate newDate;
                    if (PersianDate.TryParse(date.Value, out newDate))
                    {
                        d.SetValue(PersianSelectedDateProperty, newDate);
                    }
                    else
                    {
                        d.SetValue(PersianSelectedDateProperty, null);
                    }
                }
            }
            else
            {
                d.SetValue(PersianSelectedDateProperty, null);
            }
        }
예제 #4
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
                                      DataGridViewElementStates cellState, object value, object formattedValue,
                                      string errorText, DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            if (DataGridView == null)
            {
                return;
            }

            // First paint the borders and background of the cell.
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts & ~(DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.ContentForeground));

            var ptCurrentCell = DataGridView.CurrentCellAddress;
            var cellCurrent   = ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex;
            var cellEdited    = cellCurrent && DataGridView.EditingControl != null;

            // If the cell is in editing mode, there is nothing else to paint
            if (!cellEdited && value != null && IsValueEmpty(value))
            {
                PersianDate pd = null;
                if (value is DateTime)
                {
                    pd = (DateTime)value;
                }
                else if (value is string)
                {
                    PersianDate.TryParse(value.ToString(), out pd);
                }

                var column = GetColumn();

                if (pd != null)
                {
                    using (var brFG = new SolidBrush(cellStyle.ForeColor))
                        using (var brSelected = new SolidBrush(cellStyle.SelectionForeColor))
                            using (var fmt = new StringFormat())
                            {
                                fmt.LineAlignment = column.VerticalAlignment;
                                fmt.Alignment     = column.HorizontalAlignment;
                                fmt.Trimming      = StringTrimming.None;
                                fmt.FormatFlags   = StringFormatFlags.LineLimit;

                                var dateFormat = DateEditBase.GetFormatByFormatInfo(column.FormatInfo);
                                var dateString = pd.ToString(dateFormat);

                                graphics.DrawString(dateString, cellStyle.Font, IsInState(cellState, DataGridViewElementStates.Selected) ? brSelected : brFG, cellBounds, fmt);
                            }
                }
            }

            if (PartPainted(paintParts, DataGridViewPaintParts.ErrorIcon))
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, DataGridViewPaintParts.ErrorIcon);
            }
        }
예제 #5
0
        public void Try_Parse_With_Correct_Value_Returns_True()
        {
            PersianDate pd       = null;
            bool        canParse = false;

            canParse = PersianDate.TryParse("1384/1/1", out pd);
            Assert.True(canParse);
            Assert.NotNull(pd);
        }
예제 #6
0
 void validateText()
 {
     PersianDate date;
     if (PersianDate.TryParse(dateTextBox.Text, out date))
     {
         this.SelectedDate = date;
         this.DisplayDate = date;
     }
     this.Text = this.SelectedDate.ToString();
 }
        void validateText()
        {
            if (dateTextBox.Text.Trim() == "")
            {
                return;
            }
            PersianDate date;

            if (PersianDate.TryParse(dateTextBox.Text, out date))
            {
                this.SelectedDate = date;
                this.DisplayDate  = date;
            }
            this.Text = this.SelectedDate.ToString();
        }
예제 #8
0
        public void Try_Parse_With_Invalid_Or_Null_Values_Returns_False()
        {
            PersianDate pd       = null;
            bool        canParse = false;

            canParse = PersianDate.TryParse(null, out pd);
            Assert.False(canParse);
            Assert.Null(pd);

            canParse = PersianDate.TryParse(string.Empty, out pd);
            Assert.False(canParse);
            Assert.Null(pd);

            canParse = PersianDate.TryParse("1234", out pd);
            Assert.False(canParse);
            Assert.Null(pd);
        }