Ejemplo n.º 1
0
        public void AddRange(TextFieldCollection texValue)
        {
            int intCounter = 0;

            while (intCounter < texValue.Count)
            {
                Add(texValue[intCounter]);
                intCounter++;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a row to the datatable
        /// </summary>
        private void AddRow(DataTable dt, TextFieldCollection textFields)
        {
            DataRow dr = dt.NewRow();

            foreach (TextField field in textFields)
            {
                dr[field.Name] = field.Value;
            }

            dt.Rows.Add(dr);
        }
Ejemplo n.º 3
0
        private void ParseSchema()
        {
            m_TextFields = new TextFieldCollection();

            XmlDocument doc = new XmlDocument();

            doc.Load(m_FilePath);

            XmlNodeList lst = doc.GetElementsByTagName("TABLE");

            if (lst.Count == 0)
            {
                throw new XmlException("Could not locate the 'TABLE' node." + Environment.NewLine +
                                       "The Schema is case sensitive.");
            }

            if (lst.Count > 1)
            {
                throw new XmlException("There are multiple 'TABLE' nodes." + Environment.NewLine +
                                       "There can be only one 'TABLE' node.");
            }

            XmlNode tableNode = lst[0];

            foreach (XmlAttribute attribute in tableNode.Attributes)
            {
                switch (attribute.Name.ToLower())
                {
                case "name":
                    m_TableName = attribute.Value;
                    break;

                case "fileformat":
                    m_FileFormat = (FileFormat)Enum.Parse(typeof(FileFormat), attribute.Value);
                    break;

                case "delimiter":
                    m_FieldDelimiter = attribute.Value[0];
                    break;

                case "quotecharacter":
                    m_QuoteDelimiter = attribute.Value[0];
                    break;

                default:
                    throw new NotSupportedException("The attribute '" + attribute.Name + "' is not supported.");
                }
            }

            lst = doc.GetElementsByTagName("FIELD");
            TextField field;
            string    name = "";
            TypeCode  datatype;
            bool      quoted = false;
            int       length = 0;

            foreach (XmlNode node in lst)
            {
                name     = "";
                datatype = TypeCode.String;
                quoted   = false;
                length   = 0;

                foreach (XmlAttribute fattribute in node.Attributes)
                {
                    switch (fattribute.Name.ToLower())
                    {
                    case "name":
                        name = fattribute.Value;
                        break;

                    case "datatype":
                        datatype = (TypeCode)Enum.Parse(typeof(TypeCode), fattribute.Value);
                        break;

                    case "quoted":
                        quoted = Boolean.Parse(fattribute.Value);
                        break;

                    case "length":
                        length = Int32.Parse(fattribute.Value);
                        break;

                    default:
                        throw new NotSupportedException("The attribute '" + fattribute.Name + "' is not supported.");
                    }
                }

                if (name.Trim().Length == 0)
                {
                    throw new ArgumentException("The attribute 'Name' cannot be blank");
                }

                if (m_FileFormat == FileFormat.FixedWidth && length <= 0)
                {
                    throw new ArgumentOutOfRangeException("A 'Length' attribute > 0 must be specified for all fields in a fixed width file.");
                }

                if (m_FileFormat == FileFormat.FixedWidth)
                {
                    field = new TextField(name, datatype, length);
                }
                else
                {
                    field = new TextField(name, datatype, quoted);
                }

                m_TextFields.Add(field);
            }
        }
Ejemplo n.º 4
0
 public TextFieldEnumerator(TextFieldCollection texMappings) : base()
 {
     iEnLocal = (System.Collections.IEnumerable)texMappings;
     iEnBase  = iEnLocal.GetEnumerator();
 }
Ejemplo n.º 5
0
 public TextFieldCollection(TextFieldCollection texValue) : base()
 {
     AddRange(texValue);
 }