Updated the UI of the add record form. Added support to clear the APC tables if even one fails to be added to the database. Fixed a crash bug with the trimming operations where Header and Member Booleans would be null.
This commit is contained in:
@@ -359,7 +359,7 @@ namespace AdvertsingProfitControl
|
||||
oleDbTransaction.Commit();
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
var rowId = RetrieveRowId(table.TableName, int.Parse(row[4].ToString()), int.Parse(row[8].ToString()), int.Parse(table.Rows[7].ToString()));
|
||||
var rowId = RetrieveRowId(table.TableName, int.Parse(row[4].ToString()), int.Parse(row[8].ToString()), int.Parse(row[7].ToString()));
|
||||
if (int.Parse(row[7].ToString()) != 0)
|
||||
{
|
||||
//Account for the ad special row.
|
||||
@@ -421,6 +421,7 @@ namespace AdvertsingProfitControl
|
||||
OleDbTransaction oleDbTransaction = null;
|
||||
try
|
||||
{
|
||||
var dirtyRowsProcessed = 0;
|
||||
oleDbConnection.Open();
|
||||
oleDbTransaction = oleDbConnection.BeginTransaction();
|
||||
oleDbCommand.Transaction = oleDbTransaction;
|
||||
@@ -432,6 +433,7 @@ namespace AdvertsingProfitControl
|
||||
lastRowProcessed = i + 1;
|
||||
continue;
|
||||
}
|
||||
dirtyRowsProcessed++;
|
||||
//Grab the supplier ID number before moving forward.
|
||||
var supplierId = RetrieveSupplierId(
|
||||
table.Rows[i].Cells[(int) InvoiceTableColumns.Supplier].EditedFormattedValue.ToString());
|
||||
@@ -439,6 +441,7 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
status.SetErrorMessage("Failed to obtain supplier ID number for " + table.Rows[i].Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue + ".");
|
||||
status.SetStatus(WritingOperationStatus.Failed);
|
||||
oleDbTransaction.Rollback();
|
||||
return status;
|
||||
}
|
||||
//Check whether or not the row is already in the database by seeing if anything is in the ID number cell.
|
||||
@@ -480,23 +483,32 @@ namespace AdvertsingProfitControl
|
||||
oleDbTransaction.Commit();
|
||||
foreach (DataGridViewRow row in table.Rows)
|
||||
{
|
||||
if (rowsAdded.Contains(row.Index))
|
||||
{
|
||||
var supplierId = RetrieveSupplierId(row.Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue.ToString());
|
||||
var invoiceIdNumber =
|
||||
RetrieveInvoiceId(
|
||||
row.Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue
|
||||
.ToString(),
|
||||
long.Parse(
|
||||
row.Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue
|
||||
.ToString()), supplierId, dateId);
|
||||
row.Cells[(int)InvoiceTableColumns.Id].Value = invoiceIdNumber;
|
||||
}
|
||||
if(row.IsNewRow) continue;
|
||||
if (!rowsAdded.Contains(row.Index)) continue;
|
||||
var supplierId = RetrieveSupplierId(row.Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue.ToString());
|
||||
var invoiceIdNumber =
|
||||
RetrieveInvoiceId(
|
||||
row.Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue
|
||||
.ToString(),
|
||||
long.Parse(
|
||||
row.Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue
|
||||
.ToString()), supplierId, dateId);
|
||||
row.Cells[(int)InvoiceTableColumns.Id].Value = invoiceIdNumber;
|
||||
row.Cells[(int)InvoiceTableColumns.IsDirty].Value = false;
|
||||
row.HeaderCell.Style.BackColor = ApplicationColors.EditingSaved;
|
||||
}
|
||||
table.RefreshEdit();
|
||||
//Set the status.
|
||||
status.SetStatus(WritingOperationStatus.InsertionSuccessful);
|
||||
//Set the message to be used on the calling form since we don't have access to the form's information label.
|
||||
if (dirtyRowsProcessed == 0)
|
||||
{
|
||||
status.SetErrorMessage("No changes to the Invoices table detected.");
|
||||
}
|
||||
else
|
||||
{
|
||||
status.SetErrorMessage("Invoices processed successfully.");
|
||||
}
|
||||
}
|
||||
catch (OleDbException e)
|
||||
{
|
||||
@@ -765,6 +777,40 @@ namespace AdvertsingProfitControl
|
||||
return status;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the contents for the specified table where the date IDs
|
||||
/// match the one sent to this method.
|
||||
/// </summary>
|
||||
/// <param name="tableName">The name of the table in the database to be trimmed.</param>
|
||||
/// <param name="dateId">The ID number for the date that is to be dropped.</param>
|
||||
/// <param name="connectionString">The connection info for the database.</param>
|
||||
public void DeleteApcDataEntriesByDate(string tableName, int dateId, string connectionString)
|
||||
{
|
||||
var oleDbConnection = new OleDbConnection(connectionString);
|
||||
var oleDbCommand = new OleDbCommand
|
||||
{
|
||||
Connection = oleDbConnection,
|
||||
CommandText = "DELETE * FROM " + tableName + " WHERE FK_DateID = ?"
|
||||
|
||||
};
|
||||
oleDbCommand.Parameters.AddWithValue("DateID", dateId);
|
||||
try
|
||||
{
|
||||
oleDbConnection.Open();
|
||||
oleDbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (OleDbException e)
|
||||
{
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
|
||||
"Failed to delete the entries in " + tableName + " with the date ID of " + dateId + ".");
|
||||
_logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
oleDbConnection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a new ad item into the database and returns the new item's ID number.
|
||||
/// Supports rolling back as to not corrupt the database.
|
||||
|
||||
Reference in New Issue
Block a user