Reads dBase-files.
Inheritance: IDisposable
Ejemplo n.º 1
0
        /// <summary>
        /// Reads a dBase file and merges dBase records with shapes.
        /// </summary>
        /// <param name="dbaseFile">The dBase file name</param>
        public void ReadAttributes(string dbaseFile)
        {
            if (string.IsNullOrEmpty(dbaseFile))
            {
                throw new ArgumentNullException("dbaseFile");
            }

            // отсутствие файла атрибутов - не ошибка
            if (!File.Exists(dbaseFile))
            {
                return;
            }

            using (DbaseReader reader = new DbaseReader(dbaseFile))
            {
                reader.Open();

                if (reader.DbaseHeader.Encoding == Encoding.UTF8)
                {
                    reader.DbaseHeader.Encoding = _attributesEncoding;
                }

                // чтение наименований атрибутов
                DataTable schema = reader.GetSchemaTable();
                _attributeNames.Clear();
                for (int i = 0; i < schema.Rows.Count; i++)
                {
                    _attributeNames.Add(schema.Rows[i]["ColumnName"].ToString());
                }

                // чтение значений атрибутов
                DataTable table = reader.NewTable;
                for (int i = 0; i < Records.Count; i++)
                {
                    table.Rows.Add(reader.GetRow((uint)_records[i].RecordNumber - 1, table));
                }

                //byte lEndFile = reader.ReadByte();
                //if (lEndFile != default(byte))
                //{
                //}

                MergeAttributes(table);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads a dBase file and merges dBase records with shapes.
        /// </summary>
        /// <param name="dbaseFile">The dBase file name</param>
        public void ReadAttributes(string dbaseFile)
        {
            if (string.IsNullOrEmpty(dbaseFile))
                throw new ArgumentNullException("dbaseFile");

            // отсутствие файла атрибутов - не ошибка
            if (!File.Exists(dbaseFile))
                return;

            using (DbaseReader reader = new DbaseReader(dbaseFile))
            {
                reader.Open();

                if (reader.DbaseHeader.Encoding == Encoding.UTF8)
                    reader.DbaseHeader.Encoding = _attributesEncoding;                          

                // чтение наименований атрибутов
                DataTable schema = reader.GetSchemaTable();
                _attributeNames.Clear();
                for (int i = 0; i < schema.Rows.Count; i++)
                    _attributeNames.Add(schema.Rows[i]["ColumnName"].ToString());

                // чтение значений атрибутов
                DataTable table = reader.NewTable;
                for (int i = 0; i < Records.Count; i++)
                    table.Rows.Add(reader.GetRow((uint)_records[i].RecordNumber - 1, table));

                //byte lEndFile = reader.ReadByte();
                //if (lEndFile != default(byte))
                //{
                //}

                MergeAttributes(table);
            }
        }