From 1f700869c74cb393f5666f4db4a9e5e080b3e6b6 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Fri, 11 Nov 2016 17:42:59 -0600 Subject: [PATCH] Improved information and error feedback to the user. --- AdvertsingProfitControl/NewAddRecord.cs | 178 +++++++++++++----- .../bin/Debug/APCDatabase.accdb | Bin 2932736 -> 2932736 bytes .../Debug/AdvertsingProfitControl.application | 2 +- .../AdvertsingProfitControl.exe.manifest | 4 +- ...AdvertsingProfitControl.vshost.application | 2 +- ...dvertsingProfitControl.vshost.exe.manifest | 4 +- .../Debug/AdvertsingProfitControl.application | 2 +- .../AdvertsingProfitControl.exe.manifest | 4 +- 8 files changed, 140 insertions(+), 56 deletions(-) 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 775633edbdbf35199b1a0e66ff750a686cf38692..8dbf2bc923864d418bafa943dc3a210194f1bf8a 100644 GIT binary patch delta 2341 zcmZo@*vtsR8<_Ywy<~SXF)=bSGHw>+d(SvofsbvIz&3tHhUV?^?c3!U+qcUzwQrYa zZr?7?(!O1uwSBuhTl;o-_U+r{IXoXoGcvaDDKIgB0XxGv{yF?v{1*Id{8#uEY!|%1 ztjjlXLqt6f13Op&i1`1%6GSmEFfcPPfW`e77#Iv03>nm*P>F$s;W}!=oEe59MzA3u;{X5Y5B711Xq%#` zVPp*9D}*XzXE??`i9dp0j{gbYD!u|(P-`&rFtAToEZ`8X#}>-}|5@r87#J{UF=#O` zG5kjgV-AqTP>e0C|Nk>b(+LVvkOoc=0mUHigP6<=3@Y$2$J7c6TaYr2$rJL$r>~x& z$fb&IIw&wfN$1KO+&(d?vxKK>IB-e}b%X4O;uqro%1>;cJ3PQBHkokCEiCoi+GZFHZC;dspnys z$-uw>iY1V5LGi4_z`%e#by(;b7(mj983QPlK+?zz1_lO@J`e_(1H#zTh#6QvC@$gp zBlvk3rb7(?X#_bPvp~rg=4^0^n*L|HqB`TGi3^3> zb@p+!>+Iuh*V)I@uCtG~U1uL(yUsrTcAb3!?K=Aex9jW^x>krgnaINug#s*5fEeJk zpbJYlez0WH2}&KHWU>pCxTYH#3Cp+J83}Ka54lj zz{wEA04GBb18g;j!8hITkceWt!y%D&heM*<9S(_I@CD}*_UWPm;(ENGUM$hKWkf$1S{n}c|pgG8HyWSfIjn}c+l zgG`%)>^28ErVq?G?PRf%hgqTkvjoHdo2?6Th#$<_PLORNYj-g)Oa$5bh_}r_zRf{l zn}edj0Z4d&N{y)+O47K3WNVF*p#1bdd8{tef9J94Z&OfWn!x;!S7Ey1XC`ccG65DS z6JUWd0Tw6|V1Y6L7AOf3}4`P6g2Qk3L zgBW1rK@6zzZ4Jt84JvI7s%;Hw+ZxoF6ma_l9Mlk}D=;uXoDO1ujnrjefOyZ3fdS%~ zPLLmHfXeM(A>5`3+ySZVFvOPB+Ni&!8`@A7$gGo6vP^k2-pQ62Fz0h J+RF-b0s#FW???au delta 711 zcmZo@*vtsR8<_YwU1fJNF)=bSGHw>+d(SvofsbvIz&3tH=H~74?c3!U+qcUzwQrYa zZr?7?(!O1uwSBuhTl;o-_U+r{IXoXs;jv(y$iTojaeLr$w)GqvH;Aw=6W|e;mcY)k zokf9@M}d`rfq`Mtm&Nh8!1->a87v5%^ z{=kuuMPU*H!)o^W1_lNkjOm6&obuD{ia3Sf1ZR6d5$E=RBCbugGCz2yfXruLVBlal zaK7QZ-FdF_r_Obq^ExMXZhN5t(+^%|9)?L17YeuQ?BiosbUPzqAvnR= z9$+NAJ-|q0Q!m1xgCZO^28ErVq>td}u1=+Z+_OIVcJon0{zIv&2*l zCF$wvpP3*wY^_lOTQKc`pyhT;1*Mby%nE!8+Z8`E-RIf3L56wT0VSpl7)CZIw>7A= pHK?{VsBLRdXHr1b)3!mqZG%SJ2F-07w7{B?%xf#qURIzJ003Sv-bDZa 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=