//从源文件获取字段信息 public List <R_FieldInf> GetFieldInfs(string path) { List <R_FieldInf> FieldInfs = new List <R_FieldInf>(); string dbfpath = path; #region 该部分使用FastDBF获取字段名称 返回List<string> fieldNames DbfFile dbf = new DbfFile(Encoding.Default); dbf.Open(dbfpath, FileMode.Open); DbfHeader dh = dbf.Header; List <string> fieldNames = new List <string>(); int fieldCount = dh.ColumnCount; for (int index = 0; index < fieldCount; index++) { fieldNames.Add(dh[index].Name); } dbf.Close(); #endregion #region 该部分使用Shapelib获取字段类型 返回List<string> fieldTypes //获取字段类型 IntPtr hDbf = ShapeLib.DBFOpen(dbfpath, "rb+");//"rb"(只读)"rb+"(读/写) int pointCount = ShapeLib.DBFGetRecordCount(hDbf); List <string> fieldTypes = new List <string>(); StringBuilder stringBuilder = new StringBuilder(20); int pnWidth = 10; int pnDecimals = 10; for (int index = 0; index < fieldCount; index++) { string type = TypeConvert(ShapeLib.DBFGetFieldInfo(hDbf, index, stringBuilder, ref pnWidth, ref pnDecimals).ToString()); fieldTypes.Add(type); } ShapeLib.DBFClose(hDbf); #endregion //实例化类型 for (int index = 0; index < fieldCount; index++) { FieldInfs.Add(new R_FieldInf(fieldNames[index], fieldTypes[index])); } return(FieldInfs); }
private void method_3(ICoFeature icoFeature_0, int int_0) { try { int num2; DateTime time; if (this.coLayerMapper_0 == null) { goto Label_016A; } int num = 0; Label_0011: if (num >= this.coLayerMapper_0.FieldRelation.Count) { return; } CoFieldMapper mapper = this.coLayerMapper_0.FieldRelation[num]; ICoField destField = mapper.DestField; ICoField sourceField = mapper.SourceField; object obj2 = ""; try { obj2 = icoFeature_0.GetValue(sourceField); } catch { obj2 = ""; } goto Label_010A; Label_006B: ShapeLib.DBFWriteStringAttribute(this.intptr_1, int_0, num2, obj2.ToString().ToUpper()); goto Label_0101; Label_0088: ShapeLib.DBFWriteIntegerAttribute(this.intptr_1, int_0, num2, this.method_7(obj2.ToString())); goto Label_0101; Label_00A6: ShapeLib.DBFWriteDoubleAttribute(this.intptr_1, int_0, num2, this.method_6(obj2.ToString())); goto Label_0101; Label_00C4: ShapeLib.DBFWriteLogicalAttribute(this.intptr_1, int_0, num2, this.method_5(obj2.ToString())); goto Label_0101; Label_00E2: time = DateTime.Parse(obj2.ToString()); ShapeLib.DBFWriteDateAttribute(this.intptr_1, int_0, num2, time); Label_0101: num++; goto Label_0011; Label_010A: num2 = ShapeLib.DBFGetFieldIndex(this.intptr_1, destField.Name); int num3 = 0; int num4 = 0; StringBuilder builder = new StringBuilder(destField.Name); switch (ShapeLib.DBFGetFieldInfo(this.intptr_1, num2, builder, ref num3, ref num4)) { case ShapeLib.DBFFieldType.FTString: goto Label_006B; case ShapeLib.DBFFieldType.FTInteger: goto Label_0088; case ShapeLib.DBFFieldType.FTDouble: goto Label_00A6; case ShapeLib.DBFFieldType.FTLogical: goto Label_00C4; case ShapeLib.DBFFieldType.FTInvalid: goto Label_0101; case ShapeLib.DBFFieldType.FTDate: goto Label_00E2; default: goto Label_0101; } Label_016A: using (List <ICoField> .Enumerator enumerator = icoFeature_0.Layer.Fields.GetEnumerator()) { Label_017D: if (!enumerator.MoveNext()) { return; } ICoField current = enumerator.Current; obj2 = ""; try { obj2 = icoFeature_0.GetValue(current); } catch { obj2 = ""; } goto Label_0256; Label_01B5: ShapeLib.DBFWriteStringAttribute(this.intptr_1, int_0, num2, obj2.ToString().ToUpper()); goto Label_017D; Label_01D2: ShapeLib.DBFWriteIntegerAttribute(this.intptr_1, int_0, num2, this.method_7(obj2.ToString())); goto Label_017D; Label_01F0: ShapeLib.DBFWriteDoubleAttribute(this.intptr_1, int_0, num2, this.method_6(obj2.ToString())); goto Label_017D; Label_0211: ShapeLib.DBFWriteLogicalAttribute(this.intptr_1, int_0, num2, this.method_5(obj2.ToString())); goto Label_017D; Label_0232: time = DateTime.Parse(obj2.ToString()); ShapeLib.DBFWriteDateAttribute(this.intptr_1, int_0, num2, time); goto Label_017D; Label_0256: num2 = ShapeLib.DBFGetFieldIndex(this.intptr_1, current.Name); num3 = 0; num4 = 0; builder = new StringBuilder(current.Name); switch (ShapeLib.DBFGetFieldInfo(this.intptr_1, num2, builder, ref num3, ref num4)) { case ShapeLib.DBFFieldType.FTString: goto Label_01B5; case ShapeLib.DBFFieldType.FTInteger: goto Label_01D2; case ShapeLib.DBFFieldType.FTDouble: goto Label_01F0; case ShapeLib.DBFFieldType.FTLogical: goto Label_0211; case ShapeLib.DBFFieldType.FTDate: goto Label_0232; } goto Label_017D; } } catch { } }