diff --git a/AdvertsingProfitControl/NewAddRecord.cs b/AdvertsingProfitControl/NewAddRecord.cs
index 04130a1..8e2bac3 100644
--- a/AdvertsingProfitControl/NewAddRecord.cs
+++ b/AdvertsingProfitControl/NewAddRecord.cs
@@ -1693,22 +1693,33 @@ namespace AdvertsingProfitControl
DataTable trimmedTable;
DataTable updateTable;
informationLabel.Text = @"Compressing data tables...";
+ errorLabel.Text = "";
var operationStatus = ConstructCleanedSalesTable("Projections", dateId, out trimmedTable, out updateTable);
if (operationStatus == TrimmingOperationResult.FailedToTrim)
{
- informationLabel.Text = @"Failed to trim the Projections table.";
+ errorLabel.Text = @"Failed to trim the Projections table.";
return;
}
- ProcessTrimmingStatusResult(projectionsDataGridView, "Projections", operationStatus, trimmedTable, updateTable);
+ if (!ProcessTrimmingStatusResult(projectionsDataGridView, "Projections", operationStatus, trimmedTable, updateTable)) return;
trimmedTable.Rows.Clear();
updateTable.Rows.Clear();
operationStatus = ConstructCleanedInventoryTable(dateId, out trimmedTable, out updateTable);
if (operationStatus == TrimmingOperationResult.FailedToTrim)
{
- informationLabel.Text = @"Failed to trim the Inventory table.";
+ errorLabel.Text = @"Failed to trim the Inventory table.";
return;
}
- ProcessTrimmingStatusForInventory(operationStatus, trimmedTable, updateTable);
+ if (!ProcessTrimmingStatusForInventory(operationStatus, trimmedTable, updateTable)) return;
+ trimmedTable.Rows.Clear();
+ updateTable.Rows.Clear();
+ operationStatus = ConstructCleanedSalesTable("ActualSales", dateId, out trimmedTable, out updateTable);
+ if (operationStatus == TrimmingOperationResult.FailedToTrim)
+ {
+ errorLabel.Text = @"Failed to trim the Actual Sales table.";
+ return;
+ }
+ if (!ProcessTrimmingStatusResult(actualSalesDataGridView, "ActualSales", operationStatus, trimmedTable, updateTable)) return;
+ informationLabel.Text = @"All operations completed successfully.";
//Create the transaction scope.
//By default the TransactionScopeOption is "Required", so if an ambient transaction does not
//exist then the new transaction that is made (in the first method) becomes the root transaction.
@@ -2176,121 +2187,194 @@ namespace AdvertsingProfitControl
return TrimmingOperationResult.CreatedNewInsertionAndUpdateTables;
}
- private void ProcessTrimmingStatusResult(DataGridView dataGridView, string tableName, TrimmingOperationResult operationStatus, DataTable trimmedTable, DataTable updateTable)
+ private bool ProcessTrimmingStatusResult(DataGridView dataGridView, string tableName, TrimmingOperationResult operationStatus, DataTable trimmedTable, DataTable updateTable)
{
//Create the database interaction objects.
var dbT = new DatabaseTracker();
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
DbWriterStatus dbWriterStatus;
+ var successful = false;
switch (operationStatus)
{
case TrimmingOperationResult.NoChangesRequired:
informationLabel.Text += Environment.NewLine + @"No changes for the " + tableName + @" table detected.";
+ successful = true;
break;
case TrimmingOperationResult.CreatedNewInsertionTable:
informationLabel.Text += Environment.NewLine + @"Inserting new changes to the " + tableName + @" table.";
dbWriterStatus = dbW.InsertIntoSalesTable(trimmedTable, dbT.DatabaseConnectionString);
- //Spin through the collection and update the affected rows.
- foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
- dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.Id].Value = rowIndex.Value;
- dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ {
+ dataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.Id].Value = rowIndex.Value;
+ dataGridView.Rows[rowIndex.Key - 1].Cells[(int) SalesTableColumns.IsDirty].Value = false;
+ }
+ informationLabel.Text += Environment.NewLine + tableName + @" table successfully added to the database.";
+ successful = true;
+ }
+ else
+ {
+ errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database.";
}
- informationLabel.Text += Environment.NewLine + tableName + @" table successfully added to the database.";
break;
case TrimmingOperationResult.CreatedUpdateTable:
informationLabel.Text += Environment.NewLine + @"Updating changes made to the " + tableName + @" table.";
dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString);
- //Spin through the collection and update the affected rows.
- foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
- //Only reset the IsDirty value to false since the updates when through.
- dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ {
+ //Only reset the IsDirty value to false since the updates when through.
+ dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
+ }
+ informationLabel.Text += Environment.NewLine + tableName + @" table successfully updated.";
+ successful = true;
+ }
+ else
+ {
+ errorLabel.Text = @"Failed to update the " + trimmedTable + @" table.";
}
- informationLabel.Text += Environment.NewLine + tableName + @" table successfully updated.";
break;
case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables:
//Insert the new values...
informationLabel.Text += Environment.NewLine + @"Inserting new changes to the " + tableName + @" table.";
dbWriterStatus = dbW.InsertIntoSalesTable(trimmedTable, dbT.DatabaseConnectionString);
- //Spin through the collection and update the affected rows.
- foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
- dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.Id].Value = rowIndex.Value;
- dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ {
+ dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.Id].Value = rowIndex.Value;
+ dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
+ }
+ informationLabel.Text += Environment.NewLine + tableName + @" table successfully added to the database.";
+ successful = true;
+ }
+ else
+ {
+ errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database.";
}
//... and update the existing values.
informationLabel.Text += Environment.NewLine + @"Updating changes made to the " + tableName + @" table.";
dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString);
- //Spin through the collection and update the affected rows.
- foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
- //Only reset the IsDirty value to false since the updates when through.
- dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ {
+ //Only reset the IsDirty value to false since the updates when through.
+ dataGridView.Rows[rowIndex.Key - 1].Cells[(int)SalesTableColumns.IsDirty].Value = false;
+ }
+ informationLabel.Text += Environment.NewLine + tableName + @" table successfully updated.";
+ successful = true;
+ }
+ else
+ {
+ errorLabel.Text = @"Failed to update the " + trimmedTable + @" table.";
+ successful = false;
}
- informationLabel.Text += Environment.NewLine + @"All operations completed successfully.";
break;
}
dataGridView.RefreshEdit();
+ return successful;
}
- private void ProcessTrimmingStatusForInventory(TrimmingOperationResult operationStatus, DataTable trimmedTable, DataTable updateTable)
+ private bool ProcessTrimmingStatusForInventory(TrimmingOperationResult operationStatus, DataTable trimmedTable, DataTable updateTable)
{
//Create the database interaction objects.
var dbT = new DatabaseTracker();
var dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
DbWriterStatus dbWriterStatus;
+ var successful = false;
switch (operationStatus)
{
case TrimmingOperationResult.NoChangesRequired:
- informationLabel.Text += Environment.NewLine + @"No changes for the Inventory table detected.";
+ informationLabel.Text += Environment.NewLine + @"No changes to the Inventory table detected.";
+ successful = true;
break;
case TrimmingOperationResult.CreatedNewInsertionTable:
informationLabel.Text += Environment.NewLine + @"Inserting new changes to the Inventory table.";
dbWriterStatus = dbW.InsertIntoInventoryTable(trimmedTable, dbT.DatabaseConnectionString);
- //Spin through the collection and update the affected rows.
- foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
- inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.Id].Value = rowIndex.Value;
- inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ {
+ inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.Id].Value = rowIndex.Value;
+ inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
+ }
+ informationLabel.Text += Environment.NewLine + @"Inventory table successfully added to the database.";
+ successful = true;
+ }
+ else
+ {
+ errorLabel.Text = @"Failed to insert Inventory table into the database.";
}
- informationLabel.Text += Environment.NewLine + @"Inventory table successfully added to the database.";
break;
case TrimmingOperationResult.CreatedUpdateTable:
informationLabel.Text += Environment.NewLine + @"Updating changes made to the Inventory table.";
dbWriterStatus = dbW.UpdateInventoryTable(updateTable, dbT.DatabaseConnectionString);
- //Spin through the collection and update the affected rows.
- foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
- //Only reset the IsDirty value to false since the updates when through.
- inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ {
+ //Only reset the IsDirty value to false since the updates when through.
+ inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
+ }
+ informationLabel.Text += Environment.NewLine + @"Inventory table successfully updated.";
+ successful = true;
+ }
+ else
+ {
+ errorLabel.Text = @"Failed to update the changes in the Inventory table.";
}
- informationLabel.Text += Environment.NewLine + @"Inventory table successfully updated.";
break;
case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables:
//Insert the new values...
informationLabel.Text += Environment.NewLine + @"Inserting new changes to the Inventory table.";
dbWriterStatus = dbW.InsertIntoInventoryTable(trimmedTable, dbT.DatabaseConnectionString);
- //Spin through the collection and update the affected rows.
- foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
- inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.Id].Value = rowIndex.Value;
- inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ {
+ inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.Id].Value = rowIndex.Value;
+ inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
+ }
+ informationLabel.Text += Environment.NewLine + @"Inventory table successfully added to the database.";
+ successful = true;
+ }
+ else
+ {
+ errorLabel.Text = @"Failed to insert Inventory table into the database.";
}
- //... and update the existing values.
- informationLabel.Text += Environment.NewLine + @"Updating changes made to the Inventory table.";
dbWriterStatus = dbW.UpdateInventoryTable(updateTable, dbT.DatabaseConnectionString);
- //Spin through the collection and update the affected rows.
- foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ if (dbWriterStatus.GetErrorMessage() == string.Empty)
{
- //Only reset the IsDirty value to false since the updates when through.
- inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false;
+ //Spin through the collection and update the affected rows.
+ foreach (var rowIndex in dbWriterStatus.GetRowCollection())
+ {
+ //Only reset the IsDirty value to false since the updates when through.
+ inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int) InventoryTableColumns.IsDirty]
+ .Value = false;
+ }
+ informationLabel.Text += Environment.NewLine + @"Inventory table successfully updated.";
+ successful = true;
+ }
+ else
+ {
+ errorLabel.Text = @"Failed to update the changes in the Inventory table.";
}
- informationLabel.Text += Environment.NewLine + @"All operations completed successfully.";
break;
}
inventoryDataGridView.RefreshEdit();
+ return successful;
}
+
#endregion
}
}
diff --git a/AdvertsingProfitControl/bin/Debug/APCDatabase.accdb b/AdvertsingProfitControl/bin/Debug/APCDatabase.accdb
index 775633e..8dbf2bc 100644
Binary files a/AdvertsingProfitControl/bin/Debug/APCDatabase.accdb and b/AdvertsingProfitControl/bin/Debug/APCDatabase.accdb differ
diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.application
index 4b10d6d..7a09fc9 100644
--- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.application
+++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.application
@@ -14,7 +14,7 @@
- RAx8Npq1SZBvpDMCKEn72t59h34L92CEq1Pbw42lEP0=
+ b+dnpfYfjG4ZhWDVMNt4VWQJIitMpgUqU/izPcTmc9E=
diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.exe.manifest
index 09d88df..1aff186 100644
--- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.exe.manifest
+++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.exe.manifest
@@ -43,14 +43,14 @@
-
+
- WhwHiylhNOOwlXzM3cD3DBPd29Ezk+2JmpmdTTNjSDI=
+ C6TdhIcXFKDjcoa3VS25QEYS1igSVlAG0W3BGBQN3Vw=
diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application
index 4b10d6d..7a09fc9 100644
--- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application
+++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application
@@ -14,7 +14,7 @@
- RAx8Npq1SZBvpDMCKEn72t59h34L92CEq1Pbw42lEP0=
+ b+dnpfYfjG4ZhWDVMNt4VWQJIitMpgUqU/izPcTmc9E=
diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest
index 09d88df..1aff186 100644
--- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest
+++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest
@@ -43,14 +43,14 @@
-
+
- WhwHiylhNOOwlXzM3cD3DBPd29Ezk+2JmpmdTTNjSDI=
+ C6TdhIcXFKDjcoa3VS25QEYS1igSVlAG0W3BGBQN3Vw=
diff --git a/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.application b/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.application
index 4b10d6d..7a09fc9 100644
--- a/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.application
+++ b/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.application
@@ -14,7 +14,7 @@
- RAx8Npq1SZBvpDMCKEn72t59h34L92CEq1Pbw42lEP0=
+ b+dnpfYfjG4ZhWDVMNt4VWQJIitMpgUqU/izPcTmc9E=
diff --git a/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.exe.manifest b/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.exe.manifest
index 09d88df..1aff186 100644
--- a/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.exe.manifest
+++ b/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.exe.manifest
@@ -43,14 +43,14 @@
-
+
- WhwHiylhNOOwlXzM3cD3DBPd29Ezk+2JmpmdTTNjSDI=
+ C6TdhIcXFKDjcoa3VS25QEYS1igSVlAG0W3BGBQN3Vw=