Exemple #1
0
        public DbfFile(DataTable dt)
        {
            int millenium = 2000; //Free Y3K bug

            this.Header = DbfFileHeader.GetDefaultHeader();
            this.Header.NumberOfRecords = dt.Rows.Count;// + 1;
            this.Header.LastEdited      = new byte[] { (byte)(DateTime.Today.Year - millenium), (byte)DateTime.Today.Month, (byte)DateTime.Today.Day };

            this.Header.LengthOfHeader = (short)
                                         (sizeof(byte)    //version
                                          + this.Header.LastEdited.Length
                                          + sizeof(int)   //NumberOfRecords
                                          + sizeof(short) //LengthOfHeader
                                          + sizeof(short) //LengthOfRecord
                                          + this.Header.ReservedOne.Length
                                          + sizeof(byte)  //IncompleteTransaction
                                          + sizeof(byte)  //EncryptionFlag
                                          + this.Header.FreeRecordThread.Length
                                          + this.Header.ReservedMultiUser.Length
                                          + sizeof(byte) //MdxFlag
                                          + sizeof(byte) //Language
                                          + this.Header.ReservedTwo.Length
                                                         //+ (this.Header.NumberOfRecords * this.Header.LengthOfRecord)
                                                         //+ (this.Header.NumberOfRecords * FieldDescriptor.Size)
                                          + sizeof(byte) //Terminator
                                         );

            this._dataTable = dt;
        }