예제 #1
0
        /// <summary>
        /// Numbers the string.
        /// </summary>
        /// <param name="s">The string to replace</param>
        /// <param name="dbNumber">The db number</param>
        /// <param name="isNumber">Indicates whether the number should be formatted by number rules</param>
        /// <returns>Returns the formatted value</returns>
        internal string ReplaceNumberString(string s, DBNumber dbNumber, bool isNumber)
        {
            if ((s == null) || (s == string.Empty))
            {
                return(s);
            }
            string str        = s;
            string str2       = s;
            int    num        = -1;
            int    startIndex = -1;
            bool   flag       = false;

            for (int i = s.Length - 1; i >= 0; i--)
            {
                char c = str2[i];
                if (char.IsNumber(c) || (DefaultTokens.IsEquals(c, DefaultTokens.DecimalSeparator, false) && !flag))
                {
                    if (DefaultTokens.IsEquals(c, DefaultTokens.DecimalSeparator, false))
                    {
                        flag = true;
                    }
                    if (num == -1)
                    {
                        num = i;
                    }
                    startIndex = i;
                }
                else if ((startIndex > -1) && (num > -1))
                {
                    double num4;
                    string str3 = str2.Substring(startIndex, (num - startIndex) + 1);
                    if (double.TryParse(str3, out num4))
                    {
                        string str4 = this.NumberString(str3, dbNumber, isNumber);
                        str = str.Remove(startIndex, (num - startIndex) + 1).Insert(startIndex, str4);
                    }
                    num        = -1;
                    startIndex = -1;
                    flag       = false;
                }
            }
            if ((startIndex > -1) && (num > -1))
            {
                double num5;
                string str5 = str2.Substring(startIndex, (num - startIndex) + 1);
                if (double.TryParse(str5, out num5))
                {
                    string str6 = this.NumberString(str5, dbNumber, isNumber);
                    str = str.Remove(startIndex, (num - startIndex) + 1).Insert(startIndex, str6);
                }
                num        = -1;
                startIndex = -1;
                flag       = false;
            }
            return(str);
        }
예제 #2
0
 /// <summary>
 /// Converts a specified number string to another representation.
 /// </summary>
 /// <param name="number">The formatted data string.</param>
 /// <param name="value">The original data value.</param>
 /// <param name="isGeneralNumber">Whether the number is a general format number.</param>
 /// <param name="locale">A <see cref="T:Dt.Cells.Data.LocaleIDFormatPart" /> object that specifies the locale information.</param>
 /// <param name="dbNumber">A <see cref="T:Dt.Cells.Data.DBNumberFormatPart" /> object that specifies the number format information.</param>
 /// <returns>
 /// Returns the string that represents the original data value.
 /// </returns>
 public string ConvertTo(string number, object value, bool isGeneralNumber, LocaleIDFormatPart locale, DBNumberFormatPart dbNumber)
 {
     if ((locale != null) && (dbNumber != null))
     {
         DBNumber dBNumber = locale.GetDBNumber(dbNumber.Type);
         if (dBNumber != null)
         {
             return(dbNumber.ReplaceNumberString(number, dBNumber, isGeneralNumber));
         }
     }
     return(number);
 }
        /// <summary>
        /// Converts a specified number string to another representation.
        /// </summary>
        /// <param name="number">The formatted data string.</param>
        /// <param name="value">The original data value.</param>
        /// <param name="isGeneralNumber">Whether the number is a general format number.</param>
        /// <param name="locale">A <see cref="T:Dt.Cells.Data.LocaleIDFormatPart" /> object that specifies the locale information.</param>
        /// <param name="dbNumber">A <see cref="T:Dt.Cells.Data.DBNumberFormatPart" /> object that specifies the number format information.</param>
        /// <returns>
        /// Returns the string that represents the original data value.
        /// </returns>
        public string ConvertTo(string number, object value, bool isGeneralNumber, LocaleIDFormatPart locale, DBNumberFormatPart dbNumber)
        {
            string s = number;

            if (((locale != null) && (dbNumber != null)) && (value is DateTime))
            {
                DBNumber dBNumber = locale.GetDBNumber(dbNumber.Type);
                DateTime time     = (DateTime)value;
                DateTime time2    = (DateTime)value;
                s = dbNumber.ReplaceNumberString(s, dBNumber, true).Replace(DefaultTokens.ReplacePlaceholder + NumberFormatDateTime.YearFourDigit, time.ToString(NumberFormatDateTime.YearFourDigit)).Replace(DefaultTokens.ReplacePlaceholder + NumberFormatDateTime.YearTwoDigit, time2.ToString(NumberFormatDateTime.YearTwoDigit));
                s = dbNumber.ReplaceNumberString(s, dBNumber, false);
            }
            return(s);
        }
예제 #4
0
 /// <summary>
 /// Converts numbers the string.
 /// </summary>
 /// <param name="s">The string to convert</param>
 /// <param name="dbNumber">Data number part.</param>
 /// <param name="isNumber">Indicates whether the number should be formatted by number rules</param>
 /// <returns>Returns the formatted value.</returns>
 internal string NumberString(string s, DBNumber dbNumber, bool isNumber)
 {
     string[] strArray = s.Split(new char[] { '.' });
     if (strArray != null)
     {
         if (strArray.Length == 1)
         {
             return(FormatNumberString(strArray[0], isNumber ? dbNumber.Units : null, dbNumber.Numbers));
         }
         if (strArray.Length == 2)
         {
             string str  = FormatNumberString(strArray[0], isNumber ? dbNumber.Units : null, dbNumber.Numbers);
             string str2 = FormatNumberString(strArray[1], dbNumber.Numbers);
             return(str + "." + str2);
         }
     }
     throw new ArgumentException(ResourceStrings.FormatterIllegalValueError);
 }
예제 #5
0
 /// <summary>
 /// Converts numbers the string.
 /// </summary>
 /// <param name="value">The value to convert.</param>
 /// <param name="dbNumber">The db number.</param>
 /// <param name="isNumber">if set to <c>true</c> to convert the number to string with the special number char.</param>
 /// <returns>Returns the formatted value.</returns>
 internal string NumberString(long value, DBNumber dbNumber, bool isNumber)
 {
     return(FormatNumberString(Convert.ToString(value), isNumber ? dbNumber.Units : null, dbNumber.Numbers));
 }
예제 #6
0
        /// <summary>
        /// Converts numbers the string.
        /// </summary>
        /// <param name="value">The value to convert</param>
        /// <param name="dbNumber">Data number part.</param>
        /// <param name="isNumber">if set to <c>true</c> to convert the number to string with the special number char.</param>
        /// <returns>Returns the formatted value.</returns>
        internal string NumberString(double value, DBNumber dbNumber, bool isNumber)
        {
            string s = Convert.ToString(value);

            return(this.ReplaceNumberString(s, dbNumber, isNumber));
        }