Created a container object to house messages, operation status and the rows added for the methods that add new items and update existing items in the database.
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
internal class DbWriterStatus
|
||||
{
|
||||
//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 DbWriterStatus()
|
||||
{
|
||||
_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="key">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 key, int rowIdNumber)
|
||||
{
|
||||
_rowIds.Add(key, 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);
|
||||
}
|
||||
|
||||
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 ?? new Dictionary<int, int>();
|
||||
}
|
||||
/// <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.</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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user