예제 #1
0
 /// <summary>
 /// Adds the specified format to the formatter.
 /// </summary>
 /// <param name="part">The format to add to this formatter.</param>
 public void AddPart(FormatPartBase part)
 {
     if (part == null)
     {
         throw new ArgumentNullException("part");
     }
     if (part is Dt.Cells.Data.ConditionFormatPart)
     {
         if (this.conditionFormatPart != null)
         {
             throw new NotSupportedException(ResourceStrings.FormatterCustomNumberFormatAddPartError);
         }
         this.conditionFormatPart = part as Dt.Cells.Data.ConditionFormatPart;
         if (this.formatStringTemplate == null)
         {
             this.formatStringTemplate = new StringBuilder();
         }
         this.formatStringTemplate.Append(this.conditionFormatString);
     }
     else if (part is Dt.Cells.Data.ColorFormatPart)
     {
         if (this.colorFormatPart != null)
         {
             throw new NotSupportedException(ResourceStrings.FormatterCustomNumberFormatAddPartError);
         }
         this.colorFormatPart = part as Dt.Cells.Data.ColorFormatPart;
         if (this.formatStringTemplate == null)
         {
             this.formatStringTemplate = new StringBuilder();
         }
         this.formatStringTemplate.Append(this.colorFormatString);
     }
     else if (part is Dt.Cells.Data.LocaleIDFormatPart)
     {
         if (this.localeIDFormatPart != null)
         {
             throw new NotSupportedException(ResourceStrings.FormatterCustomNumberFormatAddPartError);
         }
         this.localeIDFormatPart = part as Dt.Cells.Data.LocaleIDFormatPart;
         if (this.formatStringTemplate == null)
         {
             this.formatStringTemplate = new StringBuilder();
         }
         this.formatStringTemplate.Append(this.localIDFormatString);
     }
     else if (part is Dt.Cells.Data.DBNumberFormatPart)
     {
         if (this.dbNumberFormatPart != null)
         {
             throw new NotSupportedException(ResourceStrings.FormatterCustomNumberFormatAddPartError);
         }
         this.dbNumberFormatPart = part as Dt.Cells.Data.DBNumberFormatPart;
         if (this.formatStringTemplate == null)
         {
             this.formatStringTemplate = new StringBuilder();
         }
         this.formatStringTemplate.Append(this.dbNumberFormatString);
     }
 }
예제 #2
0
        /// <summary>
        /// Generates an object from its XML representation.
        /// </summary>
        /// <param name="reader">The <see cref="T:System.Xml.XmlReader" /> stream from which the object is deserialized.</param>
        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (reader.NodeType == ((XmlNodeType)((int)XmlNodeType.None)))
            {
                reader.Read();
            }
            if (reader.NodeType == ((XmlNodeType)((int)XmlNodeType.XmlDeclaration)))
            {
                reader.Read();
            }
            this.conditionFormatPart = null;
            this.colorFormatPart     = null;
            this.localeIDFormatPart  = null;
            this.dbNumberFormatPart  = null;
            this.formatCached        = null;
            System.Globalization.DateTimeFormatInfo info  = null;
            System.Globalization.NumberFormatInfo   info2 = null;
            while (reader.Read())
            {
                string str;
                if ((reader.NodeType == ((XmlNodeType)((int)XmlNodeType.Element))) && ((str = reader.Name) != null))
                {
                    if (str != "FormatString")
                    {
                        if (str == "DateTimeFormatInfo")
                        {
                            goto Label_00A6;
                        }
                        if (str == "NumberFormatInfo")
                        {
                            goto Label_00AF;
                        }
                    }
                    else
                    {
                        this.formatCached = Serializer.ReadAttribute("value", reader);
                    }
                }
                continue;
Label_00A6:
                info = Serializer.DeserializeDateTimeFormatInfo(reader);
                continue;
Label_00AF:
                info2 = Serializer.DeserializeNumberFormatInfo(reader);
            }
            this.Init(this.formatCached, null);
            this.DateTimeFormatInfo = info;
            this.NumberFormatInfo   = info2;
        }
예제 #3
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);
            }
        }