Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Dt.Cells.Data.NumberFormatDigital" /> class.
        /// </summary>
        /// <param name="format">The format.</param>
        /// <param name="partLocaleID">The part locale ID.</param>
        /// <param name="dbNumberFormatPart">The number format part.</param>
        /// <param name="culture">The culture.</param>
        public NumberFormatDigital(string format, object partLocaleID, object dbNumberFormatPart, CultureInfo culture) : base(partLocaleID, dbNumberFormatPart, culture)
        {
            this.excelFormatString = string.Empty;
            string s = NumberFormatBase.TrimNotSupportSymbol(format);

            this.fullFormatString  = DefaultTokens.Filter(s, DefaultTokens.LeftSquareBracket, DefaultTokens.RightSquareBracket);
            this.excelFormatString = s;
            if (partLocaleID != null)
            {
                string str2 = s;
                s = DefaultTokens.ReplaceKeyword(str2, base.PartLocaleID.OriginalToken, base.PartLocaleID.CurrencySymbol);
            }
            if (base.PartDBNumberFormat != null)
            {
                this.excelFormatString = DefaultTokens.ReplaceKeyword(this.excelFormatString, base.PartDBNumberFormat.OriginalToken, base.PartDBNumberFormat.ToString());
            }
            s = DefaultTokens.Filter(s, DefaultTokens.LeftSquareBracket, DefaultTokens.RightSquareBracket);
            if (s.IndexOf(DefaultTokens.SolidusSign) > -1)
            {
                s = s.Replace(DefaultTokens.QuestionMark, DefaultTokens.Zero);
                string[] strArray = DefaultTokens.Split(s, DefaultTokens.SolidusSign);
                if ((strArray != null) && (strArray.Length == 2))
                {
                    this.fractionDenominatorFormat = strArray[1];
                    string[] integerAndNumeratorParts = this.GetIntegerAndNumeratorParts(strArray[0]);
                    if ((integerAndNumeratorParts != null) && (integerAndNumeratorParts.Length == 3))
                    {
                        this.fractionIntegerFormat   = integerAndNumeratorParts[0];
                        this.constString             = integerAndNumeratorParts[1];
                        this.fractionNumeratorFormat = integerAndNumeratorParts[2];
                    }
                }
            }
            this.numberFormatString = s;
        }
Exemple #2
0
 /// <summary>
 /// Determines whether the format string is valid.
 /// </summary>
 /// <param name="format">The token to evaluate.</param>
 /// <returns>
 /// <c>true</c> if the specified format contains the text; otherwise, <c>false</c>.
 /// </returns>
 public static bool EvaluateFormat(string format)
 {
     if ((format == null) || (format == string.Empty))
     {
         return(false);
     }
     return(NumberFormatBase.ContainsKeywords(format, new string[] { NumberFormatBase.General.ToLower() }));
 }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Dt.Cells.Data.NumberFormatDateTime" /> class.
        /// </summary>
        /// <param name="format">The format</param>
        /// <param name="absTimeParts">The abs time parts.</param>
        /// <param name="partLocaleID">The part locale ID.</param>
        /// <param name="dbNumberFormatPart">The db number format part.</param>
        /// <param name="culture">The culture.</param>
        internal NumberFormatDateTime(string format, ABSTimeFormatPart[] absTimeParts, object partLocaleID, object dbNumberFormatPart, CultureInfo culture) : base(partLocaleID, dbNumberFormatPart, culture)
        {
            this.absoluteTime = null;
            this.ExactlyMatch = false;
            this.formatString = this.FixFormat(NumberFormatBase.TrimNotSupportSymbol(format));
            string formatString = this.formatString;

            this.absTimeParts = absTimeParts;
            if (!EvaluateFormat(formatString))
            {
                throw new ArgumentException(ResourceStrings.FormatIllegalFormatError);
            }
            bool flag = this.ProcessAMPM(ref formatString);

            this.hasJD = this.Replace(formatString, MonthJD, "\"" + PlaceholderMonthJD + "\"", true, false, out formatString, false, false);
            this.Replace(formatString, MonthUnabbreviated, StandardMonthUnabbreviated, true, false, out formatString, false, false);
            this.Replace(formatString, MonthAbbreviation, StandardMonthAbbreviation, true, false, out formatString, false, false);
            this.Replace(formatString, MonthTwoDigit, StandardMonthTwoDigit, true, false, out formatString, false, false);
            this.Replace(formatString, MonthSingleDigit, StandardMonthSingleDigit, true, false, out formatString, false, false);
            this.Replace(formatString, DayWeekDayAbbreviation, StandardDayWeekDayAbbreviation, true, true, out formatString, false, true);
            this.Replace(formatString, DayWeekDayUnabbreviated, StandardDayWeekDayUnabbreviated, true, true, out formatString, false, true);
            this.Replace(formatString, MinuteSingleDigit, StandardMinuteSingleDigit, false, true, out formatString, false, false);
            if (!flag)
            {
                this.Replace(formatString, HoursSingleDigit, StandardHourSingleDigit, true, true, out formatString, false, false);
                this.Replace(formatString, HoursTwoDigit, StandardHourTwoDigit, true, true, out formatString, false, false);
            }
            this.Replace(formatString, SecondSingleDigit, StandardSecondSingleDigit, true, true, out formatString, false, true);
            this.Replace(formatString, SubSecondThreeDigit, StandardSubSecondThreeDigit, true, true, out formatString, false, true);
            this.Replace(formatString, SubSecondTwoDigit, StandardSubSecondTwoDigit, true, true, out formatString, false, true);
            this.Replace(formatString, SubSecondSingleDigit, StandardSubSecondSingleDigit, true, true, out formatString, false, true);
            if ((base.PartDBNumberFormat != null) && (base.PartLocaleID != null))
            {
                this.hasYearDelay |= this.Replace(formatString, YearFourDigit, "\"" + DefaultTokens.ReplacePlaceholder + YearFourDigit + "\"", true, false, out formatString, false, true);
                this.hasYearDelay |= this.Replace(formatString, YearTwoDigit, "\"" + DefaultTokens.ReplacePlaceholder + YearTwoDigit + "\"", true, false, out formatString, false, true);
            }
            if (this.IsJanpaneseCulture())
            {
                this.Replace(formatString, EraYear, YearSingleDigit, true, false, out formatString, false, true);
                this.Replace(formatString, EraYear + EraYear, YearTwoDigit, true, false, out formatString, false, true);
                this.Replace(formatString, EraYear + EraYear + EraYear, YearTwoDigit, true, false, out formatString, false, true);
            }
            else
            {
                this.Replace(formatString, EraYear, YearFourDigit, true, false, out formatString, false, true);
                this.Replace(formatString, EraYear + EraYear, YearFourDigit, true, false, out formatString, false, true);
                this.Replace(formatString, EraYear + EraYear + EraYear, YearFourDigit, true, false, out formatString, false, true);
            }
            this.Replace(formatString, YearSingleDigit, StandardYearSingleDigit, true, false, out formatString, false, true);
            if (this.absTimeParts != null)
            {
                foreach (ABSTimeFormatPart part in this.absTimeParts)
                {
                    this.Replace(formatString, part.Token, "\"" + DefaultTokens.ReplacePlaceholder + part.Token + "\"", true, true, out formatString, false, true);
                }
            }
            this.validDateTimeFormatString = formatString;
        }
Exemple #4
0
 /// <summary>
 /// Creates a new custom number format.
 /// </summary>
 public CustomNumberFormat()
 {
     this.conditionFormatString = "[conditionFormaString]";
     this.colorFormatString     = "[colorFormatString]";
     this.localIDFormatString   = "[localIDFormatString]";
     this.dbNumberFormatString  = "[dbNumberFormatString]";
     this.formatCached          = NumberFormatBase.General;
     this.numberFormat          = new NumberFormatGeneral();
 }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Dt.Cells.Data.NumberFormatText" /> class.
        /// </summary>
        /// <param name="format">The format string</param>
        /// <param name="partLocaleID">The part locale ID.</param>
        /// <param name="dbNumberFormatPart">The db number format part.</param>
        /// <param name="culture">The culture.</param>
        internal NumberFormatText(string format, object partLocaleID, object dbNumberFormatPart, CultureInfo culture) : base(partLocaleID, dbNumberFormatPart, culture)
        {
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            string s = NumberFormatBase.TrimNotSupportSymbol(format, false);

            if (partLocaleID != null)
            {
                s = DefaultTokens.ReplaceKeyword(s, base.PartLocaleID.OriginalToken, base.PartLocaleID.CurrencySymbol);
            }
            this.excelFormatString = s;
            s = DefaultTokens.TrimEscape(DefaultTokens.Filter(s, DefaultTokens.LeftSquareBracket, DefaultTokens.RightSquareBracket));
            this.formatString = s;
        }
Exemple #6
0
 /// <summary>
 /// Determines whether the format string is valid.
 /// </summary>
 /// <param name="format">The token to evaluate.</param>
 /// <returns>
 /// <c>true</c> if the specified format contains the text; otherwise, <c>false</c>.
 /// </returns>
 public static bool EvaluateFormat(string format)
 {
     return(NumberFormatBase.ContainsKeywords(format, keywords));
 }
Exemple #7
0
        /// <summary>
        /// Initializes the specified format.
        /// </summary>
        /// <param name="format">Format String</param>
        /// <param name="culture">The culture.</param>
        void Init(string format, CultureInfo culture)
        {
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            this.conditionFormatPart = null;
            this.colorFormatPart     = null;
            this.localeIDFormatPart  = null;
            this.dbNumberFormatPart  = null;
            this.formatCached        = format;
            StringBuilder            builder  = null;
            StringBuilder            builder2 = null;
            bool                     flag     = false;
            bool                     flag2    = false;
            List <ABSTimeFormatPart> list     = new List <ABSTimeFormatPart>();

            for (int i = 0; i < format.Length; i++)
            {
                char ch = format[i];
                if ((ch == DefaultTokens.LeftSquareBracket) && !flag2)
                {
                    if (flag)
                    {
                        throw new FormatException(ResourceStrings.FormatIllegalFormatError);
                    }
                    if (builder2 != null)
                    {
                        if (builder == null)
                        {
                            builder = new StringBuilder();
                        }
                        builder.Append(builder2.ToString());
                        if (this.formatStringTemplate == null)
                        {
                            this.formatStringTemplate = new StringBuilder();
                        }
                        this.formatStringTemplate.Append(builder2.ToString());
                        builder2 = null;
                    }
                    builder2 = new StringBuilder();
                    builder2.Append(ch);
                    flag = true;
                }
                else if ((ch == DefaultTokens.RightSquareBracket) && !flag2)
                {
                    if (!flag)
                    {
                        throw new FormatException(ResourceStrings.FormatIllegalFormatError);
                    }
                    if (builder2 == null)
                    {
                        throw new FormatException(ResourceStrings.FormatIllegalFormatError);
                    }
                    if (builder2 == null)
                    {
                        builder2 = new StringBuilder();
                    }
                    builder2.Append(ch);
                    FormatPartBase part = FormatPartBase.Create(builder2.ToString());
                    if ((part != null) && !(part is ABSTimeFormatPart))
                    {
                        this.AddPart(part);
                    }
                    else
                    {
                        if (!(part is ABSTimeFormatPart))
                        {
                            throw new FormatException(ResourceStrings.FormatIllegalFormatError);
                        }
                        list.Add(part as ABSTimeFormatPart);
                        if (builder == null)
                        {
                            builder = new StringBuilder();
                        }
                        builder.Append(builder2.ToString());
                        if (this.formatStringTemplate == null)
                        {
                            this.formatStringTemplate = new StringBuilder();
                        }
                        this.formatStringTemplate.Append(builder2.ToString());
                    }
                    builder2 = null;
                    flag     = false;
                }
                else
                {
                    if (builder2 == null)
                    {
                        builder2 = new StringBuilder();
                    }
                    builder2.Append(ch);
                }
                if (ch == DefaultTokens.ReverseSolidusSign)
                {
                    flag2 = !flag2;
                }
                else
                {
                    flag2 = false;
                }
            }
            if (builder2 != null)
            {
                if (flag)
                {
                    throw new FormatException(ResourceStrings.FormatIllegalFormatError);
                }
                if (builder == null)
                {
                    builder = new StringBuilder();
                }
                builder.Append(builder2.ToString());
                if (this.formatStringTemplate == null)
                {
                    this.formatStringTemplate = new StringBuilder();
                }
                this.formatStringTemplate.Append(builder2.ToString());
            }
            string str2 = (builder != null) ? builder.ToString() : string.Empty;

            if (NumberFormatGeneral.EvaluateFormat(str2))
            {
                this.numberFormat = new NumberFormatGeneral(str2, this.LocaleIDFormatPart, this.dbNumberFormatPart, culture);
            }
            else if (NumberFormatDateTime.EvaluateFormat(str2) && !this.ContainsCurrencySymbol(str2))
            {
                ABSTimeFormatPart[] absTimeParts = (list.Count > 0) ? list.ToArray() : null;
                this.numberFormat = new NumberFormatDateTime(str2, absTimeParts, this.LocaleIDFormatPart, this.dbNumberFormatPart, culture);
            }
            else if (NumberFormatDigital.EvaluateFormat(str2))
            {
                this.numberFormat = new NumberFormatDigital(format, this.LocaleIDFormatPart, this.dbNumberFormatPart, culture);
            }
            else
            {
                if (!NumberFormatText.EvaluateFormat(str2))
                {
                    throw new FormatException(ResourceStrings.FormatIllegalFormatError);
                }
                this.numberFormat = new NumberFormatText(format, this.LocaleIDFormatPart, this.dbNumberFormatPart, culture);
            }
        }