Added support for deleting records from the APC and invoice tables that have been committed to the database. Fixed the color coding bug where the Ad Special row would get the pending edit color instead of no coloring.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
@@ -1066,6 +1067,118 @@ namespace AdvertsingProfitControl
|
||||
return id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the row with the specified ID number from the provided table.
|
||||
/// </summary>
|
||||
/// <param name="projectionsRowId">The ID number of the row to be deleted.</param>
|
||||
/// <param name="inventoryRowId">The ID number of the row to be deleted.</param>
|
||||
/// <param name="actualSalesRowId">The ID number of the row to be deleted.</param>
|
||||
/// <returns>True if the operation was successful; false if not.</returns>
|
||||
public bool DeleteApcRow(int projectionsRowId, int inventoryRowId, int actualSalesRowId)
|
||||
{
|
||||
var result = false;
|
||||
var tableName = "Projections"; //Starting point.
|
||||
var oleDbCommand = new OleDbCommand
|
||||
{
|
||||
CommandText = "DELETE FROM Projections WHERE ID = ?",
|
||||
Connection = _oleDbConnection
|
||||
};
|
||||
oleDbCommand.Parameters.AddWithValue("ID", projectionsRowId);
|
||||
OleDbTransaction oleDbTransaction = null;
|
||||
try
|
||||
{
|
||||
_oleDbConnection.Open();
|
||||
oleDbTransaction = _oleDbConnection.BeginTransaction();
|
||||
oleDbCommand.Transaction = oleDbTransaction;
|
||||
var rowsEffected = oleDbCommand.ExecuteNonQuery();
|
||||
if (rowsEffected == 1)
|
||||
{
|
||||
tableName = "Inventory";
|
||||
oleDbCommand.Parameters.Clear();
|
||||
oleDbCommand.CommandText = "DELETE FROM Inventory WHERE ID = ?";
|
||||
oleDbCommand.Parameters.AddWithValue("ID", inventoryRowId);
|
||||
rowsEffected = oleDbCommand.ExecuteNonQuery();
|
||||
if (rowsEffected == 1)
|
||||
{
|
||||
tableName = "ActualSales";
|
||||
oleDbCommand.Parameters.Clear();
|
||||
oleDbCommand.CommandText = "DELETE FROM ActualSales WHERE ID = ?";
|
||||
oleDbCommand.Parameters.AddWithValue("ID", inventoryRowId);
|
||||
rowsEffected = oleDbCommand.ExecuteNonQuery();
|
||||
if (rowsEffected == 1)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!result)
|
||||
{
|
||||
oleDbTransaction?.Rollback();
|
||||
}
|
||||
else
|
||||
{
|
||||
oleDbTransaction.Commit();
|
||||
}
|
||||
}
|
||||
catch (OleDbException e)
|
||||
{
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to delete row with the ID of " + inventoryRowId + " from " + tableName + ".");
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message);
|
||||
oleDbTransaction?.Rollback();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_oleDbConnection.Close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the invoice record with the specified internal ID number.
|
||||
/// </summary>
|
||||
/// <param name="rowId">The ID of the row to delete.</param>
|
||||
/// <returns>Whether or not the removal was a success or not.</returns>
|
||||
public bool DeleteInvoiceRow(int rowId)
|
||||
{
|
||||
var result = false;
|
||||
var oleDbCommand = new OleDbCommand
|
||||
{
|
||||
CommandText = "DELETE FROM Invoice WHERE ID = ?",
|
||||
Connection = _oleDbConnection
|
||||
};
|
||||
oleDbCommand.Parameters.AddWithValue("ID", rowId);
|
||||
OleDbTransaction oleDbTransaction = null;
|
||||
try
|
||||
{
|
||||
_oleDbConnection.Open();
|
||||
oleDbTransaction = _oleDbConnection.BeginTransaction();
|
||||
oleDbCommand.Transaction = oleDbTransaction;
|
||||
var rowsEffected = oleDbCommand.ExecuteNonQuery();
|
||||
if (rowsEffected == 1)
|
||||
{
|
||||
result = true;
|
||||
oleDbTransaction.Commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
oleDbTransaction?.Rollback();
|
||||
}
|
||||
}
|
||||
catch (OleDbException e)
|
||||
{
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to delete row with the ID of " + rowId + " from the Invoice table.");
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message);
|
||||
oleDbTransaction?.Rollback();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_oleDbConnection.Close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//10 to 1 ratio of tries to code
|
||||
|
||||
Reference in New Issue
Block a user