Пример #1
0
 //Конструктор
 public DBFFieldDescriptor(DBFHeader parent, ushort id)
 {
     Parent          = parent;
     _id             = id;
     strName         = new byte[11];
     bFieldType      = 0;
     dwAddress       = 0;
     bFieldSize      = 0;
     bFractionalSize = 0;
     wReserved       = 0;
     bWorkAreaID     = 0;
     wMutiUser       = 0;
     bSetFields      = 0;
     baReserved      = new byte[2];
     bMDXIDIncluded  = 0;
 }
Пример #2
0
		//Конструктор
        public DBFFieldDescriptor(DBFHeader parent, ushort id)
        {
            Parent = parent;
            _id = id;
            strName = new byte[11];
            bFieldType = 0;
            dwAddress = 0;
            bFieldSize = 0;
            bFractionalSize = 0;
            wReserved = 0;
            bWorkAreaID = 0;
            wMutiUser = 0;
            bSetFields = 0;
            baReserved = new byte[2];
            bMDXIDIncluded = 0;
        }
Пример #3
0
        //Загрузка таблицы из файла
        public bool LoadFrom(string tablePath)
        {
            ushort i;
            uint   j;

            if (!File.Exists(tablePath))
            {
                _bLastError = ErrCantOpenTable;
                return(false);
            }

            Header = new DBFHeader(this);
            Index  = new DBFIndex(this);

            var f = new FileStream(tablePath, FileMode.Open, FileAccess.Read);
            var r = new BinaryReader(f);

            Header.bFlags               = r.ReadByte();
            Header.bYear                = r.ReadByte();
            Header.bMonth               = r.ReadByte();
            Header.bDay                 = r.ReadByte();
            Header.dwRecordsCount       = r.ReadUInt32();
            Header.wHeaderSize          = r.ReadUInt16();
            Header.wRecordSize          = r.ReadUInt16();
            Header.wReserved            = r.ReadUInt16();
            Header.bTransactionFlags    = r.ReadByte();
            Header.bEncryption          = r.ReadByte();
            Header.baUseUserEnvironment = r.ReadBytes(12);
            Header.bUseIndex            = r.ReadByte();
            Header.bCodePage            = r.ReadByte();
            Header.wReserved2           = r.ReadUInt16();

            var wFieldsCount = (ushort)(((short)Header.wHeaderSize - 32 - 1) / 32);

            Header.Field = new DBFFieldDescriptor[wFieldsCount];

            for (i = 0; i < wFieldsCount; i++)
            {
                Header.Field[i] = new DBFFieldDescriptor(Header, i)
                {
                    strName         = r.ReadBytes(11),
                    bFieldType      = r.ReadByte(),
                    dwAddress       = r.ReadUInt32(),
                    bFieldSize      = r.ReadByte(),
                    bFractionalSize = r.ReadByte(),
                    wReserved       = r.ReadUInt16(),
                    bWorkAreaID     = r.ReadByte(),
                    wMutiUser       = r.ReadUInt16(),
                    bSetFields      = r.ReadByte(),
                    baReserved      = r.ReadBytes(7),
                    bMDXIDIncluded  = r.ReadByte()
                };
            }
            byte c = r.ReadByte();

            if (c != 13)
            {
                r.Close();
                f.Close();
                _bLastError = ErrWrongFileFormat;
                return(false);
            }
            Record = new DBFRecord[Header.dwRecordsCount];
            for (j = 0; j < Header.dwRecordsCount; j++)
            {
                Record[j] = new DBFRecord(this, wFieldsCount);
                if (r.ReadByte() != 0x20)
                {
                    Record[j].Delete();
                }
                else
                {
                    Record[j].Restore();
                }
                Record[j].Field = new DBFField[wFieldsCount];

                for (i = 0; i < wFieldsCount; i++)
                {
                    Record[j].Field[i] = new DBFField(Header.Field[i], Record[j])
                    {
                        Value = r.ReadBytes(Header.Field[i].bFieldSize)
                    };
                }
            }
            r.Close();
            f.Close();
            //r = null;
            //f = null;

            switch (Header.bCodePage)
            {
            case 0x01: Options.dwCodePage = 437; break;

            case 0x02: Options.dwCodePage = 850; break;

            case 0x65: Options.dwCodePage = 866; break;

            case 0x26: Options.dwCodePage = 866; break;

            case 0xC8: Options.dwCodePage = 1250; break;

            default: Options.dwCodePage = 1251; break;
            }

            _bLastError = ErrNoErrors;
            return(true);
        }
Пример #4
0
		//Загрузка таблицы из файла
        public bool LoadFrom(string tablePath)
        {
            ushort i;
            uint j;

            if( !File.Exists(tablePath) )
            {
                _bLastError = ErrCantOpenTable;
                return false;
            }

			Header = new DBFHeader(this);
			Index = new DBFIndex(this);
            
            var f = new FileStream(tablePath, FileMode.Open, FileAccess.Read);
            var r = new BinaryReader(f);
            Header.bFlags = r.ReadByte();
            Header.bYear = r.ReadByte();
            Header.bMonth = r.ReadByte();
            Header.bDay = r.ReadByte();
            Header.dwRecordsCount = r.ReadUInt32();
            Header.wHeaderSize = r.ReadUInt16();
            Header.wRecordSize = r.ReadUInt16();
            Header.wReserved = r.ReadUInt16();
            Header.bTransactionFlags = r.ReadByte();
            Header.bEncryption = r.ReadByte();
            Header.baUseUserEnvironment = r.ReadBytes(12);
            Header.bUseIndex = r.ReadByte();
            Header.bCodePage = r.ReadByte();
            Header.wReserved2 = r.ReadUInt16();

            var wFieldsCount = (ushort)(((short)Header.wHeaderSize - 32 - 1)/32);
            Header.Field = new DBFFieldDescriptor[wFieldsCount];

            for (i = 0; i < wFieldsCount; i++)
            {
                Header.Field[i] = new DBFFieldDescriptor(Header, i)
                                      {
                                          strName = r.ReadBytes(11),
                                          bFieldType = r.ReadByte(),
                                          dwAddress = r.ReadUInt32(),
                                          bFieldSize = r.ReadByte(),
                                          bFractionalSize = r.ReadByte(),
                                          wReserved = r.ReadUInt16(),
                                          bWorkAreaID = r.ReadByte(),
                                          wMutiUser = r.ReadUInt16(),
                                          bSetFields = r.ReadByte(),
                                          baReserved = r.ReadBytes(7),
                                          bMDXIDIncluded = r.ReadByte()
                                      };
            }
            byte c = r.ReadByte();
            if (c != 13)
            {
                r.Close();
				f.Close();
				_bLastError = ErrWrongFileFormat;
				return false;
            }
            Record = new DBFRecord[Header.dwRecordsCount];
            for (j = 0; j < Header.dwRecordsCount; j++)
            {
                Record[j] = new DBFRecord(this, wFieldsCount);
				if( r.ReadByte() != 0x20 ) Record[j].Delete();
							else Record[j].Restore();
                Record[j].Field = new DBFField[wFieldsCount];

                for (i = 0; i < wFieldsCount; i++)
                {
                    Record[j].Field[i] = new DBFField(Header.Field[i], Record[j])
                                             {Value = r.ReadBytes(Header.Field[i].bFieldSize)};
                }
            }
            r.Close();
            f.Close();
			//r = null;
			//f = null;

			switch( Header.bCodePage )
			{
				case 0x01: Options.dwCodePage = 437; break;
				case 0x02: Options.dwCodePage = 850; break;
				case 0x65: Options.dwCodePage = 866; break;
				case 0x26: Options.dwCodePage = 866; break;
				case 0xC8: Options.dwCodePage = 1250; break;
				default: Options.dwCodePage = 1251; break;
			}

            _bLastError = ErrNoErrors;
            return true;
        }