Exemplo n.º 1
0
        public void ToString_With_Custom_FormatProvider_And_No_Specific_Format_Uses_Generic()
        {
            PersianDate pd     = new PersianDate(1383, 4, 5);
            var         value1 = pd.ToString(new TestFormatProvider());
            var         value2 = pd.ToString("G");

            Assert.AreEqual(value2, value1);
        }
Exemplo n.º 2
0
        public void ToString_With_Empty_Parameter_Returns_Generic_Format()
        {
            var pd      = new PersianDate(1380, 1, 1);
            var am      = PersianDateTimeFormatInfo.AMDesignator;
            var result1 = pd.ToString();
            var result2 = pd.ToString(null, null);

            Assert.AreEqual("1380/01/01 00:00:00 " + am, pd.ToString());
            Assert.AreEqual(result1, result2);
        }
Exemplo n.º 3
0
        public void PersianDate_Instance_Creates_StringBased_HashCode()
        {
            PersianDate pd       = PersianDate.Now;
            int         hashcode = pd.ToString("s").GetHashCode();

            Assert.AreEqual(hashcode, pd.GetHashCode());
        }
Exemplo n.º 4
0
        public void ToString_With_General_Parameter_Returns_Date_And_Time()
        {
            var pd = new PersianDate(1380, 1, 1);
            var am = PersianDateTimeFormatInfo.AMDesignator;

            Assert.AreEqual("1380/01/01 00:00:00 " + am, pd.ToString("G"));
        }
Exemplo n.º 5
0
        private void btnToday_Click(object sender, EventArgs e)
        {
            PersianDate pd = PersianDate.Now;

            lblMessage.Text   = pd.ToString();
            lblToWritten.Text = pd.ToWritten();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Convert DateTime to a formatted string(ShortDatePattern)
        /// </summary>
        /// <param name="value">DateTime</param>
        /// <param name="targetType">string</param>
        /// <param name="parameter">null</param>
        /// <param name="culture"></param>
        /// <returns>formatted or empty string</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }

            DateTimeFormatInfo dateTimeFormat = culture.DateTimeFormat;

            if (dateTimeFormat == null)
            {
                throw new ArgumentNullException("culture");
            }

            if (value != null && value is DateTime)
            {
                DateTime date = (DateTime)value;

                if (CultureHelper.IsFarsiCulture)
                {
                    PersianDate pd = date;
                    return(pd.ToString("g"));
                }
                else
                {
                    return(date.ToString(dateTimeFormat.ShortDatePattern, dateTimeFormat));
                }
            }

            return(string.Empty);
        }
Exemplo n.º 7
0
        private void btnDeductDays(object sender, EventArgs e)
        {
            PersianDate pd = new PersianDate(calendar.AddDays(DateTime.Now, -66));

            lblMessage.Text   = pd.ToString();
            lblToWritten.Text = pd.ToWritten();
        }
Exemplo n.º 8
0
        private void btnAddMonth_Click(object sender, EventArgs e)
        {
            PersianDate pd = new PersianDate(calendar.AddMonths(DateTime.Now, 2));

            lblMessage.Text   = pd.ToString();
            lblToWritten.Text = pd.ToWritten();
        }
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (value != null && value is PersianDate)
            {
                if (destinationType == typeof(InstanceDescriptor) && value != null)
                {
                    PersianDate     pd   = (PersianDate)value;
                    ConstructorInfo ctor = typeof(PersianDate).GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int) });
                    object[]        args = new object[] { pd.Year, pd.Month, pd.Day };

                    if (ctor != null)
                    {
                        return(new InstanceDescriptor(ctor, args));
                    }
                }
                else if (destinationType == typeof(string))
                {
                    PersianDate pd = (PersianDate)value;
                    return(pd.ToString());
                }
                else if (destinationType == typeof(PersianDate))
                {
                    PersianDate pd = (PersianDate)value;
                    return(pd);
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Exemplo n.º 10
0
        public void ToString_With_Custom_FormatProvider()
        {
            string      format = "CustomYearMonth";
            PersianDate pd     = new PersianDate(1383, 4, 5);
            var         value  = pd.ToString(format, new TestFormatProvider());

            Assert.AreEqual(pd.Year + " -- " + pd.Month, value);
        }
        public void Can_Convert_Strings_ToDateTime()
        {
            PersianDate pd        = new PersianDate(1380, 1, 1);
            DateTime    converted = pd.ToDateTime();
            DateTime    dt        = PersianDateConverter.ToGregorianDateTime(pd.ToString());

            Assert.AreEqual(dt, converted);
        }
        public void Can_Convert_Strings_ToDateTime()
        {
            PersianDate pd = new PersianDate(1380, 1, 1);
            DateTime converted = pd.ToDateTime();
            DateTime dt = PersianDateConverter.ToGregorianDateTime(pd.ToString());

            Assert.AreEqual(dt, converted);
        }
Exemplo n.º 13
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);
            }
        }
        protected virtual string FormatDateValue(DateTime date, DateTimeFormatInfo dateTimeFormat)
        {
            if (CultureHelper.IsFarsiCulture())
            {
                PersianDate pd = date;
                return(pd.ToString("d"));
            }

            return(date.ToString(dateTimeFormat.ShortDatePattern, dateTimeFormat));
        }
Exemplo n.º 15
0
            public string Format(string format, object arg, IFormatProvider formatProvider)
            {
                PersianDate pd = arg as PersianDate;

                if (pd != null)
                {
                    if (format == "CustomYearMonth")
                    {
                        return(pd.Year + " -- " + pd.Month);
                    }
                }

                return(pd.ToString(format));
            }
Exemplo n.º 16
0
        protected virtual string FormatDisplayText(object value)
        {
            if (value is PersianDate)
            {
                PersianDate pd = (PersianDate)value;
                return(pd.ToString("d"));
            }

            if (value is DateTime)
            {
                DateTime dt = (DateTime)value;
                return(dt.Date.ToShortDateString());
            }

            return(Properties.NullText);
        }
Exemplo n.º 17
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                PersianDate pd = (PersianDate)value;

                if (pd == null)
                {
                    return(string.Empty);
                }

                return(pd.ToString());
            }

            if (destinationType == typeof(DateTime))
            {
                PersianDate pd = (PersianDate)value;
                return(pd.ToDateTime());
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Exemplo n.º 18
0
        public void ToString_With_General_Parameter_Returns_Date_And_Time()
        {
            var pd = new PersianDate(1380, 1, 1);
            var am = PersianDateTimeFormatInfo.AMDesignator;

            Assert.AreEqual("1380/01/01 00:00:00 " + am, pd.ToString("G"));
        }
Exemplo n.º 19
0
        public void ToString_With_Empty_Parameter_Returns_Generic_Format()
        {
            var pd = new PersianDate(1380, 1, 1);
            var am = PersianDateTimeFormatInfo.AMDesignator;
            var result1 = pd.ToString();
            var result2 = pd.ToString(null, null);

            Assert.AreEqual("1380/01/01 00:00:00 " + am, pd.ToString());
            Assert.AreEqual(result1, result2);
        }
Exemplo n.º 20
0
        public void ToString_With_Custom_FormatProvider_And_No_Specific_Format_Uses_Generic()
        {
            PersianDate pd = new PersianDate(1383, 4, 5);
            var value1 = pd.ToString(new TestFormatProvider());
            var value2 = pd.ToString("G");

            Assert.AreEqual(value2, value1);
        }
Exemplo n.º 21
0
        public void ToString_With_Custom_FormatProvider()
        {
            string format = "CustomYearMonth";
            PersianDate pd = new PersianDate(1383, 4, 5);
            var value = pd.ToString(format, new TestFormatProvider());

            Assert.AreEqual(pd.Year + " -- " + pd.Month, value);
        }
Exemplo n.º 22
0
 private void frm15_Load(object sender, EventArgs e)
 {
     toStringD.Text  = pd.ToString("d");
     toStringDD.Text = pd.ToString("D");
     toStringF.Text  = pd.ToString("f");
     toStringFF.Text = pd.ToString("F");
     toStringG.Text  = pd.ToString("g");
     toStringGG.Text = pd.ToString("G");
     toStringM.Text  = pd.ToString("m");
     toStringMM.Text = pd.ToString("M");
     toStringS.Text  = pd.ToString("s");
     toStringT.Text  = pd.ToString("t");
     toStringTT.Text = pd.ToString("T");
 }
Exemplo n.º 23
0
 private void btnAddYears_Click(object sender, EventArgs e)
 {
     PersianDate pd = new PersianDate(calendar.AddYears(DateTime.Now, 10));
     lblMessage.Text = pd.ToString();
     lblToWritten.Text = pd.ToWritten();
 }
Exemplo n.º 24
0
 private void btnDeductDays(object sender, EventArgs e)
 {
     PersianDate pd = new PersianDate(calendar.AddDays(DateTime.Now, -66));
     lblMessage.Text = pd.ToString();
     lblToWritten.Text = pd.ToWritten();
 }
 public static string ToShortDateString(this PersianDate dateTime)
 => dateTime.ToString("d");
 public static string ToLongDateString(this PersianDate dateTime)
 => dateTime.ToString("D");