/// <summary> /// Loads the file from the specified stream. /// </summary> /// <param name="stream">The stream to load from.</param> /// <exception cref="Revise.Exceptions.FileIdentifierMismatchException">Thrown when the specified file has the incorrect file header expected.</exception> /// <exception cref="Revise.Exceptions.InvalidVersionException">Thrown when the version of the file is invalid.</exception> public override void Load(Stream stream) { BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR")); string identifier = reader.ReadString(3); if (string.Compare(identifier, FILE_IDENTIFIER, false) != 0) { throw new FileIdentifierMismatchException(FilePath, FILE_IDENTIFIER, identifier); } int version = (byte)(reader.ReadByte() - '0'); if (version != FILE_VERSION) { throw new InvalidVersionException(version); } reader.BaseStream.Seek(4, SeekOrigin.Current); int rowCount = reader.ReadInt32(); int columnCount = reader.ReadInt32(); RowHeight = reader.ReadInt32(); SetRootColumnWidth(reader.ReadInt16()); for (int i = 0; i < columnCount; i++) { columns.Add(new DataColumn()); SetColumnWidth(i, reader.ReadInt16()); } SetRootColumnName(reader.ReadShortString()); for (int i = 0; i < columnCount; i++) { SetColumnName(i, reader.ReadShortString()); } for (int i = 0; i < rowCount - 1; i++) { DataRow row = new DataRow(columnCount); row[0] = reader.ReadShortString(); rows.Add(row); } for (int i = 0; i < rowCount - 1; i++) { DataRow row = rows[i]; for (int j = 1; j < columnCount; j++) { row[j] = reader.ReadShortString(); } } }
/// <summary> /// Removes the specified row. /// </summary> /// <param name="row">The row to remove.</param> /// <exception cref="System.ArgumentException">Thrown when the file does not contain the specified row.</exception> public void RemoveRow(DataRow row) { if (!rows.Contains(row)) { throw new ArgumentException("row", "File does not contain the specified row"); } int rowIndex = rows.IndexOf(row); RemoveRow(rowIndex); }
/// <summary> /// Adds a new row. /// </summary> /// <returns>The row created.</returns> public DataRow AddRow() { DataRow row = new DataRow(ColumnCount); rows.Add(row); return row; }