年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
6.8 KiB

6 months ago
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
namespace Kingo.Mobile.Shape2KOTool
{
// Token: 0x02000040 RID: 64
public class DBFDocument : IDisposable
{
// Token: 0x170000C7 RID: 199
// (get) Token: 0x060001FF RID: 511 RVA: 0x00009A2C File Offset: 0x00007C2C
public DataTable Data
{
get
{
return this.GetData();
}
}
// Token: 0x06000200 RID: 512 RVA: 0x00009A44 File Offset: 0x00007C44
public DataTable GetData()
{
DataTable dataTable = new DataTable();
foreach (Header header in this.headers)
{
DataColumn column = new DataColumn(header.FieldName);
dataTable.Columns.Add(column);
}
int count = this.headers.Count;
int num = 0;
while ((long)num < this.GetRecordCount())
{
DataRow dataRow = dataTable.NewRow();
for (int i = 0; i < count; i++)
{
dataRow[i] = this.GetRecordFieldValue(num + 1, i + 1);
}
dataTable.Rows.Add(dataRow);
num++;
}
return dataTable;
}
// Token: 0x06000201 RID: 513 RVA: 0x00009B30 File Offset: 0x00007D30
public void LoadFile(string filename)
{
using (FileStream fileStream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
this.dbfBuffer = new byte[fileStream.Length];
fileStream.Read(this.dbfBuffer, 0, this.dbfBuffer.Length);
}
this.FillFileInfo();
this.FillHeadInfos();
}
// Token: 0x06000202 RID: 514 RVA: 0x00009BA4 File Offset: 0x00007DA4
private void FillFileInfo()
{
this.fileInfo.Mark = (char)this.dbfBuffer[0];
this.fileInfo.Year = (char)this.dbfBuffer[1];
this.fileInfo.Mmonth = (char)this.dbfBuffer[2];
this.fileInfo.Day = (char)this.dbfBuffer[3];
byte[] array = new byte[4];
for (int i = 4; i < 8; i++)
{
array[i - 4] = this.dbfBuffer[i];
}
this.fileInfo.RecordCount = (long)BitConverter.ToInt32(array, 0);
array = new byte[2];
for (int i = 8; i < 10; i++)
{
array[i - 8] = this.dbfBuffer[i];
}
this.fileInfo.HeaderLength = BitConverter.ToInt16(array, 0);
array = new byte[2];
for (int i = 10; i < 12; i++)
{
array[i - 10] = this.dbfBuffer[i];
}
this.fileInfo.RecordLength = BitConverter.ToInt16(array, 0);
this.fileInfo.LanguageDriverID = (char)this.dbfBuffer[29];
if (this.fileInfo.LanguageDriverID == '\0')
{
this.CurrentEncoding = Encoding.UTF8;
}
this.fileInfo.Reserved = this.CurrentEncoding.GetString(this.dbfBuffer, 11, 20);
}
// Token: 0x06000203 RID: 515 RVA: 0x00009D04 File Offset: 0x00007F04
private void FillHeadInfos()
{
int num = 0;
while (this.dbfBuffer[(num + 1) * 32] != 13 && num < this.GetFieldCount())
{
byte[] array = new byte[32];
for (int i = (num + 1) * 32; i < (num + 1) * 32 + 32; i++)
{
array[i - (num + 1) * 32] = this.dbfBuffer[i];
}
Header item = new Header();
this.FillHeaderInfo(ref item, array, (num + 1) * 32);
this.headers.Add(item);
num++;
}
}
// Token: 0x06000204 RID: 516 RVA: 0x00009DAC File Offset: 0x00007FAC
private int GetFieldCount()
{
return (int)(this.fileInfo.HeaderLength / 32 - 1);
}
// Token: 0x06000205 RID: 517 RVA: 0x00009DD0 File Offset: 0x00007FD0
private string GetFieldName(int FieldNum)
{
string result;
if (FieldNum < 1 || FieldNum > this.headers.Count)
{
result = null;
}
else if (FieldNum < 1)
{
result = "";
}
else
{
result = this.headers[FieldNum - 1].FieldName;
}
return result;
}
// Token: 0x06000206 RID: 518 RVA: 0x00009E28 File Offset: 0x00008028
private int GetFieldLength(int FieldNum)
{
int result;
if (FieldNum < 1)
{
result = -1;
}
else
{
result = (int)this.headers[FieldNum - 1].FieldLength;
}
return result;
}
// Token: 0x06000207 RID: 519 RVA: 0x00009E5C File Offset: 0x0000805C
private string GetFieldType(int FieldNum)
{
string result;
if (FieldNum < 1)
{
result = "#";
}
else
{
result = new string(new char[]
{
this.headers[FieldNum - 1].FieldType
});
}
return result;
}
// Token: 0x06000208 RID: 520 RVA: 0x00009EA4 File Offset: 0x000080A4
private int GetDecimal(int FieldNum)
{
int result;
if (FieldNum < 1)
{
result = -1;
}
else
{
result = (int)this.headers[FieldNum - 1].Decimal;
}
return result;
}
// Token: 0x06000209 RID: 521 RVA: 0x00009ED8 File Offset: 0x000080D8
private long GetRecordCount()
{
return this.fileInfo.RecordCount;
}
// Token: 0x0600020A RID: 522 RVA: 0x00009EF8 File Offset: 0x000080F8
private int GetRecordLength()
{
return (int)this.fileInfo.RecordLength;
}
// Token: 0x0600020B RID: 523 RVA: 0x00009F18 File Offset: 0x00008118
private string GetRecord(int RecordNum)
{
string result;
if (RecordNum < 1)
{
result = "";
}
else
{
int index = (int)(this.fileInfo.HeaderLength + 1) + (RecordNum - 1) * this.GetRecordLength();
string @string = this.CurrentEncoding.GetString(this.dbfBuffer, index, this.GetRecordLength() - 1);
result = @string;
}
return result;
}
// Token: 0x0600020C RID: 524 RVA: 0x00009F74 File Offset: 0x00008174
private string GetRecordFieldValue(int RecordNum, int FieldNum)
{
string result;
if (RecordNum < 1 || FieldNum < 1)
{
result = "";
}
else
{
int num = (int)(this.fileInfo.HeaderLength + 1) + (RecordNum - 1) * this.GetRecordLength();
int num2 = 1;
while (num2 < FieldNum && num2 <= this.headers.Count)
{
num += this.GetFieldLength(num2);
num2++;
}
string @string = this.CurrentEncoding.GetString(this.dbfBuffer, num, this.GetFieldLength(FieldNum));
result = @string;
}
return result;
}
// Token: 0x0600020D RID: 525 RVA: 0x0000A008 File Offset: 0x00008208
private void FillHeaderInfo(ref Header dbfInfoHeader, byte[] buffer, int position)
{
dbfInfoHeader.FieldName = this.CurrentEncoding.GetString(buffer, 0, 9);
dbfInfoHeader.Reserved1 = (char)buffer[10];
dbfInfoHeader.FieldType = (char)buffer[11];
byte[] array = new byte[4];
for (int i = 12; i < 16; i++)
{
array[i - 12] = buffer[i];
}
dbfInfoHeader.Offset = (long)BitConverter.ToInt32(array, 0);
dbfInfoHeader.FieldLength = (char)buffer[16];
dbfInfoHeader.Decimal = (char)buffer[17];
dbfInfoHeader.Reserved = this.CurrentEncoding.GetString(buffer, 18, 14);
}
// Token: 0x0600020E RID: 526 RVA: 0x0000A0A2 File Offset: 0x000082A2
public void Dispose()
{
this.dbfBuffer = null;
GC.Collect();
}
// Token: 0x04000160 RID: 352
private Encoding CurrentEncoding = Encoding.Default;
// Token: 0x04000161 RID: 353
private FileInfo fileInfo = new FileInfo();
// Token: 0x04000162 RID: 354
private List<Header> headers = new List<Header>();
// Token: 0x04000163 RID: 355
private byte[] dbfBuffer;
}
}