//*************************************************************************** // Public Methods // public void Add(DbfField value) { if (this._owner != null) { value.Owner = this._owner; } base.Add(value); }
//*************************************************************************** // Private Methods // private DbfField ParseField(byte[] value) { DbfField retVal = new DbfField( new byte[] { value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9], value[10] }, value[11], new byte[] { value[12], value[13] }, (value[11] == 0x43) ? Convert.ToInt32(Hex.ToHex(new byte[] { value[17], value[16] }), 16) : Convert.ToInt32(Hex.ToHex(value[16]), 16), (value[11] == 0x43) ? 0 : Convert.ToInt32(Hex.ToHex(value[17]), 16), this._flds.Count); if (this._owner != null) { retVal.Owner = this._owner; } return(retVal); }
/// <summary> /// Writes a single field of data to a DBF file using the provided Stream object. This method assumes the Stream object's write position is located at the position to begin writing. /// </summary> /// <param name="s">An initialized Stream object of a DBF file with the cursor position set to the beginning of the field to be written.</param> /// <param name="fld">A DbfField object detailing the structure of the field to be written to.</param> /// <param name="value">A System.Object value whose string representation will be written to the Stream.</param> public static void WriteDbfField(Stream s, DbfField fld, object value) { // Save the Stream's current position and the size of the field. long sPos = s.Position, sLen = fld.FieldLength + fld.DecimalLength; // Get the string value of the passed Object 'value' to be written. string val = string.Empty; if (value != null) { val = (value.GetType().Name == "DateTime") ? ((DateTime)value).ToString("yyyyMMdd") : value.ToString(); } // Create a byte array from the string representation of 'value'. byte[] buffer = Encoding.ASCII.GetBytes(val.Substring(0, System.Math.Min(fld.FieldLength, val.Length)).PadRight(fld.FieldLength, ' ')); // If the passed Stream object is a FileStream object, // then lock the bytes we're about to write to. if (s.GetType().FullName == "System.IO.FileStream") { ((FileStream)s).Lock(sPos, sLen); } // Write the byte buffer. If an error occurs, just throw it back // to the calling code, but don't forget to unlock the stream. try { s.Write(buffer, 0, buffer.Length); DbfTable.SetLastUpdateTime(s); } catch { throw; } finally { if (s.GetType().FullName == "System.IO.FileStream") { ((FileStream)s).Unlock(sPos, sLen); } s.Position = sPos; } }
//*************************************************************************** // Public Methods // public void Add(DbfField value) { if (this._owner != null) value.Owner = this._owner; base.Add(value); }
//*************************************************************************** // Static Methods // /// <summary> /// Returns the System.Type equivalent to the supplied DbfHeader.dBaseFieldType. /// </summary> /// <param name="fld">A DbfField object with an initialized DbfHeader.dBaseFieldType value.</param> /// <returns>An equivalent System.Type object.</returns> public static Type GetSystemDataType(DbfField fld) { return(DbfTable.GetSystemDataType(fld.FieldDataType)); }
public DbfFieldException(string msg, DbfField field) : base(msg) { this._fld = field; }
//*************************************************************************** // Class Constructors // public DbfFieldException(DbfField field) : this("An error occured retrieving data from the specified field.", field) { }
/// <summary> /// Writes a single field of data to a DBF file using the provided Stream object. This method assumes the Stream object's write position is located at the position to begin writing. /// </summary> /// <param name="s">An initialized Stream object of a DBF file with the cursor position set to the beginning of the field to be written.</param> /// <param name="fld">A DbfField object detailing the structure of the field to be written to.</param> /// <param name="value">A System.Object value whose string representation will be written to the Stream.</param> public static void WriteDbfField(Stream s, DbfField fld, object value) { // Save the Stream's current position and the size of the field. long sPos = s.Position, sLen = fld.FieldLength + fld.DecimalLength; // Get the string value of the passed Object 'value' to be written. string val = string.Empty; if (value != null) val = (value.GetType().Name == "DateTime") ? ((DateTime)value).ToString("yyyyMMdd") : value.ToString(); // Create a byte array from the string representation of 'value'. byte[] buffer = Encoding.ASCII.GetBytes(val.Substring(0, System.Math.Min(fld.FieldLength, val.Length)).PadRight(fld.FieldLength, ' ')); // If the passed Stream object is a FileStream object, // then lock the bytes we're about to write to. if (s.GetType().FullName == "System.IO.FileStream") ((FileStream)s).Lock(sPos, sLen); // Write the byte buffer. If an error occurs, just throw it back // to the calling code, but don't forget to unlock the stream. try { s.Write(buffer, 0, buffer.Length); DbfTable.SetLastUpdateTime(s); } catch { throw; } finally { if (s.GetType().FullName == "System.IO.FileStream") ((FileStream)s).Unlock(sPos, sLen); s.Position = sPos; } }
//*************************************************************************** // Static Methods // /// <summary> /// Returns the System.Type equivalent to the supplied DbfHeader.dBaseFieldType. /// </summary> /// <param name="fld">A DbfField object with an initialized DbfHeader.dBaseFieldType value.</param> /// <returns>An equivalent System.Type object.</returns> public static Type GetSystemDataType(DbfField fld) { return DbfTable.GetSystemDataType(fld.FieldDataType); }
//*************************************************************************** // Private Methods // private DbfField ParseField(byte[] value) { DbfField retVal = new DbfField( new byte[] { value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9], value[10] }, value[11], new byte[] { value[12], value[13] }, (value[11] == 0x43) ? Convert.ToInt32(Hex.ToHex(new byte[] { value[17], value[16] }), 16) : Convert.ToInt32(Hex.ToHex(value[16]), 16), (value[11] == 0x43) ? 0 : Convert.ToInt32(Hex.ToHex(value[17]), 16), this._flds.Count); if (this._owner != null) retVal.Owner = this._owner; return retVal; }