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,31 +2187,43 @@ 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);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
//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;
|
||||
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.";
|
||||
}
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedUpdateTable:
|
||||
informationLabel.Text += Environment.NewLine + @"Updating changes made to the " + tableName + @" table.";
|
||||
dbWriterStatus = dbW.UpdateSalesTable(updateTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
//Spin through the collection and update the affected rows.
|
||||
foreach (var rowIndex in dbWriterStatus.GetRowCollection())
|
||||
{
|
||||
@@ -2208,46 +2231,75 @@ namespace AdvertsingProfitControl
|
||||
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.";
|
||||
}
|
||||
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);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
//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);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
//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 + @"All operations completed successfully.";
|
||||
informationLabel.Text += Environment.NewLine + tableName + @" table successfully updated.";
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to update the " + trimmedTable + @" table.";
|
||||
successful = false;
|
||||
}
|
||||
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);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
//Spin through the collection and update the affected rows.
|
||||
foreach (var rowIndex in dbWriterStatus.GetRowCollection())
|
||||
{
|
||||
@@ -2255,10 +2307,18 @@ namespace AdvertsingProfitControl
|
||||
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.";
|
||||
}
|
||||
break;
|
||||
case TrimmingOperationResult.CreatedUpdateTable:
|
||||
informationLabel.Text += Environment.NewLine + @"Updating changes made to the Inventory table.";
|
||||
dbWriterStatus = dbW.UpdateInventoryTable(updateTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
//Spin through the collection and update the affected rows.
|
||||
foreach (var rowIndex in dbWriterStatus.GetRowCollection())
|
||||
{
|
||||
@@ -2266,31 +2326,55 @@ namespace AdvertsingProfitControl
|
||||
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.";
|
||||
}
|
||||
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);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
//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;
|
||||
}
|
||||
//... and update the existing values.
|
||||
informationLabel.Text += Environment.NewLine + @"Updating changes made to the Inventory table.";
|
||||
informationLabel.Text += Environment.NewLine + @"Inventory table successfully added to the database.";
|
||||
successful = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorLabel.Text = @"Failed to insert Inventory table into the database.";
|
||||
}
|
||||
dbWriterStatus = dbW.UpdateInventoryTable(updateTable, dbT.DatabaseConnectionString);
|
||||
if (dbWriterStatus.GetErrorMessage() == string.Empty)
|
||||
{
|
||||
//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;
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -14,7 +14,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>RAx8Npq1SZBvpDMCKEn72t59h34L92CEq1Pbw42lEP0=</dsig:DigestValue>
|
||||
<dsig:DigestValue>b+dnpfYfjG4ZhWDVMNt4VWQJIitMpgUqU/izPcTmc9E=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
@@ -43,14 +43,14 @@
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3521536">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3522560">
|
||||
<assemblyIdentity name="AdvertsingProfitControl" version="0.9.5.2" language="neutral" processorArchitecture="amd64" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>WhwHiylhNOOwlXzM3cD3DBPd29Ezk+2JmpmdTTNjSDI=</dsig:DigestValue>
|
||||
<dsig:DigestValue>C6TdhIcXFKDjcoa3VS25QEYS1igSVlAG0W3BGBQN3Vw=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>RAx8Npq1SZBvpDMCKEn72t59h34L92CEq1Pbw42lEP0=</dsig:DigestValue>
|
||||
<dsig:DigestValue>b+dnpfYfjG4ZhWDVMNt4VWQJIitMpgUqU/izPcTmc9E=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
@@ -43,14 +43,14 @@
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3521536">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3522560">
|
||||
<assemblyIdentity name="AdvertsingProfitControl" version="0.9.5.2" language="neutral" processorArchitecture="amd64" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>WhwHiylhNOOwlXzM3cD3DBPd29Ezk+2JmpmdTTNjSDI=</dsig:DigestValue>
|
||||
<dsig:DigestValue>C6TdhIcXFKDjcoa3VS25QEYS1igSVlAG0W3BGBQN3Vw=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>RAx8Npq1SZBvpDMCKEn72t59h34L92CEq1Pbw42lEP0=</dsig:DigestValue>
|
||||
<dsig:DigestValue>b+dnpfYfjG4ZhWDVMNt4VWQJIitMpgUqU/izPcTmc9E=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
@@ -43,14 +43,14 @@
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3521536">
|
||||
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3522560">
|
||||
<assemblyIdentity name="AdvertsingProfitControl" version="0.9.5.2" language="neutral" processorArchitecture="amd64" />
|
||||
<hash>
|
||||
<dsig:Transforms>
|
||||
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
|
||||
</dsig:Transforms>
|
||||
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
|
||||
<dsig:DigestValue>WhwHiylhNOOwlXzM3cD3DBPd29Ezk+2JmpmdTTNjSDI=</dsig:DigestValue>
|
||||
<dsig:DigestValue>C6TdhIcXFKDjcoa3VS25QEYS1igSVlAG0W3BGBQN3Vw=</dsig:DigestValue>
|
||||
</hash>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
|
||||
Reference in New Issue
Block a user