Improved information and error feedback to the user.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user