96 lines
3.3 KiB
C#
96 lines
3.3 KiB
C#
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<int, int> _rowIds;
|
|
private string _errorMessage;
|
|
|
|
public DbTableWriterStatus()
|
|
{
|
|
_rowIds = new Dictionary<int, int>();
|
|
}
|
|
|
|
public void SetStatus(WritingOperationStatus status)
|
|
{
|
|
_status = status;
|
|
}
|
|
/// <summary>
|
|
/// Gets the status from the operation.
|
|
/// </summary>
|
|
/// <returns>A status indicating whether or not it was successful, default is failed.</returns>
|
|
public WritingOperationStatus GetWritingOperationStatus()
|
|
{
|
|
return _status;
|
|
}
|
|
/// <summary>
|
|
/// Adds a row to the Rows Dictionary that keeps track of what rows have been
|
|
/// added to the database including their IDs.
|
|
/// </summary>
|
|
/// <param name="rowIndex">The index of the row that was added to the database.</param>
|
|
/// <param name="rowIdNumber">The ID number of the row as represented in the database.</param>
|
|
public void AddRowId(int rowIndex, int rowIdNumber)
|
|
{
|
|
_rowIds.Add(rowIndex, rowIdNumber);
|
|
}
|
|
/// <summary>
|
|
/// Removes a row from the Rows collection.
|
|
/// </summary>
|
|
/// <param name="key">The row's index that is to be deleted.</param>
|
|
public void DeleteRow(int key)
|
|
{
|
|
_rowIds.Remove(key);
|
|
}
|
|
/// <summary>
|
|
/// Clears the collection of row IDs.
|
|
/// </summary>
|
|
public void ClearRowCollection()
|
|
{
|
|
_rowIds.Clear();
|
|
}
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
/// <returns>The rows that have been added to the database.</returns>
|
|
public Dictionary<int, int> GetRowCollection()
|
|
{
|
|
return _rowIds;
|
|
}
|
|
/// <summary>
|
|
/// Sets an error message.
|
|
/// </summary>
|
|
/// <param name="message">The error message to be set.</param>
|
|
public void SetErrorMessage(string message)
|
|
{
|
|
_errorMessage = message;
|
|
}
|
|
/// <summary>
|
|
/// Gets any error message set by the Insertion/Update operation function.
|
|
/// If none are set returns an empty string.
|
|
/// </summary>
|
|
/// <returns>The error message, string.Empty if no message is set.</returns>
|
|
public string GetErrorMessage()
|
|
{
|
|
//If the error message is null then return string.Empty.
|
|
//Otherwise return the error message.
|
|
return _errorMessage ?? string.Empty;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Operation status emus to keep things consistent.
|
|
/// </summary>
|
|
public enum WritingOperationStatus
|
|
{
|
|
Failed = 0,
|
|
InsertionSuccessful = 1,
|
|
UpdateSuccessful = 2
|
|
}
|
|
}
|