private void WriteRecord(BinaryWriter dataOutput, Object[] objectArray) { dataOutput.Write((byte)' '); for (int j = 0; j < header.FieldArray.Length; j++) { /* iterate throught fields */ switch (header.FieldArray[j].DataType) { case NativeDbType.Char: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { String str_value = objectArray[j].ToString(); dataOutput.Write( Utils.textPadding(str_value, CharEncoding, header.FieldArray[j]. FieldLength ) ); } else { dataOutput.Write( Utils.textPadding("", CharEncoding, header.FieldArray[j]. FieldLength ) ); } break; case NativeDbType.Date: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { DateTime tDate = (DateTime)objectArray[j]; dataOutput.Write( CharEncoding.GetBytes(tDate.ToString("yyyyMMdd"))); } else { dataOutput.Write( Utils.FillArray(new byte[8], DBFFieldType.Space)); } break; case NativeDbType.Float: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { Double tDouble = Convert.ToDouble(objectArray[j]); dataOutput.Write( Utils.NumericFormating( tDouble, CharEncoding, header.FieldArray[j].FieldLength, header.FieldArray[j].DecimalCount ) ); } else { dataOutput.Write( Utils.textPadding( DBFFieldType.Unknown, CharEncoding, header.FieldArray[j].FieldLength, Utils.ALIGN_RIGHT ) ); } break; case NativeDbType.Numeric: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { Decimal tDecimal = Convert.ToDecimal(objectArray[j]); dataOutput.Write( Utils.NumericFormating( tDecimal, CharEncoding, header.FieldArray[j].FieldLength, header.FieldArray[j].DecimalCount ) ); } else { dataOutput.Write( Utils.textPadding( DBFFieldType.Unknown, CharEncoding, header.FieldArray[j].FieldLength, Utils.ALIGN_RIGHT ) ); } break; case NativeDbType.Logical: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { if ((bool)objectArray[j]) { dataOutput.Write(DBFFieldType.True); } else { dataOutput.Write(DBFFieldType.False); } } else { dataOutput.Write(DBFFieldType.UnknownByte); } break; case NativeDbType.Memo: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { var tMemoValue = ((MemoValue)objectArray[j]); tMemoValue.Write(this); dataOutput.Write(Utils.NumericFormating(tMemoValue.Block, CharEncoding, 10, 0)); } else { dataOutput.Write( Utils.textPadding("", CharEncoding, 10 ) ); } break; default: throw new DBFException("Unknown field type " + header.FieldArray[j].DataType); } } /* iterating through the fields */ }
private void WriteRecord(BinaryWriter dataOutput, DBFRecord record) { if (!record.IsDirty()) { return; } //var originalPosition = _BaseStream.Position; _BaseStream.Seek(record.Position, SeekOrigin.Begin); dataOutput.Write((byte)' '); for (var j = 0; j < _Header.FieldArray.Length; j++) { /* iterate throught fields */ if (!record.IsDirty(j)) { _BaseStream.Seek(_Header.FieldArray[j].FieldLength, SeekOrigin.Current); continue; } var objectArray = record.ValueArray; switch (_Header.FieldArray[j].DataType) { case NativeDbType.UnicodeChar: var str_valueU = (objectArray[j] != null && objectArray[j] != DBNull.Value) ? objectArray[j].ToString() : ""; var bufferU = Utils.textPadding(str_valueU, _UCharEncoding, _Header.FieldArray[j].FieldLength, Utils.ALIGN_LEFT, (byte)0x00 ); dataOutput.Write(bufferU); break; case NativeDbType.Char: var str_value = (objectArray[j] != null && objectArray[j] != DBNull.Value) ? objectArray[j].ToString() : ""; var buffer = Utils.textPadding(str_value, CharEncoding, _Header.FieldArray[j].FieldLength ); dataOutput.Write(buffer); break; case NativeDbType.Date: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { var tDate = (DateTime)objectArray[j]; dataOutput.Write( CharEncoding.GetBytes(tDate.ToString("yyyyMMdd"))); } else { dataOutput.Write( Utils.FillArray(new byte[8], DBFFieldType.Space)); } break; case NativeDbType.Float: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { var tDouble = Convert.ToDouble(objectArray[j]); dataOutput.Write( Utils.NumericFormating( tDouble, CharEncoding, _Header.FieldArray[j].FieldLength, _Header.FieldArray[j].DecimalCount ) ); } else { dataOutput.Write( Utils.textPadding( NullSymbol, CharEncoding, _Header.FieldArray[j].FieldLength, Utils.ALIGN_RIGHT ) ); } break; case NativeDbType.Numeric: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { var tDecimal = Convert.ToDecimal(objectArray[j]); dataOutput.Write( Utils.NumericFormating( tDecimal, CharEncoding, _Header.FieldArray[j].FieldLength, _Header.FieldArray[j].DecimalCount ) ); } else { dataOutput.Write( Utils.textPadding( NullSymbol, CharEncoding, _Header.FieldArray[j].FieldLength, Utils.ALIGN_RIGHT ) ); } break; case NativeDbType.Logical: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { if ((bool)objectArray[j]) { dataOutput.Write(DBFFieldType.True); } else { dataOutput.Write(DBFFieldType.False); } } else { dataOutput.Write(DBFFieldType.UnknownByte); } break; case NativeDbType.Memo: if (objectArray[j] != null && objectArray[j] != DBNull.Value) { var tMemoValue = ((MemoValue)objectArray[j]); tMemoValue.Write(this); dataOutput.Write(Utils.NumericFormating(tMemoValue.Block, CharEncoding, 10, 0)); } else { dataOutput.Write( Utils.textPadding("", CharEncoding, 10 ) ); } break; default: throw new DBFException("Unknown field type " + _Header.FieldArray[j].DataType); } } /* iterating through the fields */ _BinaryWriter.Flush(); //_BaseStream.Seek(originalPosition, SeekOrigin.Begin); }