using System.Collections.Generic; namespace AdvertsingProfitControl { internal class DbTableWriterStatus { //Initialize the _status to failed just to have it not be null. private WritingOperationStatus _status = WritingOperationStatus.Failed; private readonly Dictionary _rowIds; private string _errorMessage; public DbTableWriterStatus() { _rowIds = new Dictionary(); } public void SetStatus(WritingOperationStatus status) { _status = status; } /// /// Gets the status from the operation. /// /// A status indicating whether or not it was successful, default is failed. public WritingOperationStatus GetWritingOperationStatus() { return _status; } /// /// Adds a row to the Rows Dictionary that keeps track of what rows have been /// added to the database including their IDs. /// /// The index of the row that was added to the database. /// The ID number of the row as represented in the database. public void AddRowId(int rowIndex, int rowIdNumber) { _rowIds.Add(rowIndex, rowIdNumber); } /// /// Removes a row from the Rows collection. /// /// The row's index that is to be deleted. public void DeleteRow(int key) { _rowIds.Remove(key); } public void ClearRowCollection() { _rowIds.Clear(); } /// /// Gets the Dictionary containing rows that have been added to the database. /// The keys are the row's index and the value is the row's ID as represented /// in the database. /// Returns an empty Dictionary if no rows have been added. /// /// The rows that have been added to the database. public Dictionary GetRowCollection() { return _rowIds; } /// /// Sets an error message. /// /// The error message to be set. public void SetErrorMessage(string message) { _errorMessage = message; } /// /// Gets any error message set by the Insertion/Update operation function. /// If none are set returns an empty string. /// /// The error message. public string GetErrorMessage() { //If the error message is null then return string.Empty. //Otherwise return the error message. return _errorMessage ?? string.Empty; } } /// /// Operation status emus to keep things consistent. /// public enum WritingOperationStatus { Failed = 0, InsertionSuccessful = 1, UpdateSuccessful = 2 } }