From d429f2b931d26878dd6718f546845d1fdc450be6 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Sat, 21 Jan 2017 04:17:09 -0600 Subject: [PATCH] Fixed a bug with the invoice table failing to save an invoice number longer then 9 characters. --- AdvertsingProfitControl/APCDatabase.accdb | Bin 2932736 -> 2932736 bytes AdvertsingProfitControl/DatabaseWriter.cs | 9 +- AdvertsingProfitControl/NewModifyRecord.cs | 411 ++++++++++-------- ...AdvertsingProfitControl.vshost.application | 2 +- ...dvertsingProfitControl.vshost.exe.manifest | 6 +- 5 files changed, 231 insertions(+), 197 deletions(-) diff --git a/AdvertsingProfitControl/APCDatabase.accdb b/AdvertsingProfitControl/APCDatabase.accdb index 3d53bc00c133f39f46eb6cea9cbfd633d9db577d..90e06c4051d7e242bd0c0b6b6508154d6b0f6fe0 100644 GIT binary patch delta 2794 zcmZo@*vtsR8<_Yw4=U|sVq#=uWZW#s_nvXG0w3EZfdl+3FRRzQpL|5Vo|m1O0S?$V z2Pk~zXJTib92+3NImN)!hEZU8;XXFc$@25LCNIcg{ z?0z=2jT?NKrrYPUs84q|&&0R+LjHVq#_Y)pOXV2lH}{u^&s1_wIlH{|!4n6NO`Z&S z3}p=Y44Dkc45O@eSbcyWV??%+jbv$ z_MZmR9qd`%wl^3smGW;(U}w6(ZpsUCz~Skf1{?~^JPgd!bqqLSC3qs)7#O%2m>8HC zI9V7Nm_TY6f?OH4FEro?Wn?UxE*QijF`eIt!-nNQ1H+H$hR&R7)BkUjcH-b>U}l5bav*hMnPDTc&t%{uHyweTluybtpo6En6 zX`29V;zE4J@Itg--8u)G_GK4%6}A=dT!*-VNse{9U9cn8t4=rK{8Dz#fRTTzCE*SQ(nlcDcNiEz!HOY$7%VMy zf`MVf$~l}E(uWwQf5_#~nBL*UFSfl}i?5Y++W~fZ#Q;Ae<8ek%dIALxBg6IWfd|<7 z87FSA1Sdn9CxB@Ia+d9u0essn1Ne`}Z*$;aVFFtWN)Eqxc`UhMPIF|KE^vXXf$1do z_QEAHcbTU>;jY>)H zm@w!u=rJ%e{N?AF{=P!MScwxwrJ1?8g|V55CyF}VN&!DK6Ag__%q`4}j7`%R{Glek z<>i^)Rwj|O z4AV+OPX==&Mak6y`e?CWY-nO&WMJZo;Zz{u1HRh?iB zhP_4>#s&rkXzILc1oV};P{Ym0$kM>l$jA-Ffvq(Hx@aCTG&C|WGPHCCdl!`K_VV*g z-(Mr3ixzm6Mg|6!MouWoe%1&$qA9bmFfcbU4r72Qgd}3uS^-@Jb`+d(SvofsbvIzyW@i-_>iLPCg=E&&$lr00+#Q z0~9{F+hqCqT$2~%u<|gmFgS2DH6($=r+>_25t}Z% zpG|G!24AM>_W3O8(;dz;@om14Kc9WF{3E5!6U#$qDkWIzeU^Rj!~tZDCqo`X8ACop zCPOkqD#OX*KfDYM48Nz}z0ak*U0aZGE-!0c-6@%->1X8_C7BHVOuw7Yq1?_b&)Ci_ z&$OLeo_XU1MxOS)@0r{8zGvCK_dRR40OO&pqHMDAAcrzdzBpg3-AA5nyN^8kPlN3S z9|U&uZ%bfjy1;JF3$lIZbWQ^f1!isrrs+Bc9I;$1k!%bM%nXbSOw%tcU=!KC+X`bmHHZpNd=P}~2-yYZ`wVrq42DWVu983aRnfUqnr#slQnoa+c$Lcb1gTQo$ zd{)=(58^o#47NFN>|vSyfRT@7`++4~PTcKG3plnjE#UmOe%k?dB$8@+S+^Zv&qvXEVJDvv+jgc4 zy#M5I z!1xtOsDay}-6DW*yF~#1iFkfS#xIOMVU9i^OBfkgwi_N{`^vce0VCg3&h0aI^JlW~ zL~_IA4H>2j2(TtFo}8X2z#;|-gab>sIN7&PI?i9v!Lxyv31kcd1H&P(N{{Vf0RlFR z+h+v|i11F_z%hMYoPePa13x2!>$1$hau1$3K?^HTf|_!jV`@#*k=;@!bp$LqrTgJ&O43y&9%0M9kW5e`=@tpP>H>hzia!(H^6ENmBVbEjHV_;(V%g#N0 zIl91~G66qsf2fMLtlZP{$_4bf4WI%bE&I>~_$ts;#GwnULl^jiF5pusV9ITVWXqyT z0W)rMB!TahXtsD%p$W`H7kGs(U|o%-rMFr@mzM!-3n)bPvU5+rgDIp{BjCvG1XcwJ zwVoObZ8tH6)N3(Rm0=1U!4wj%!_b&mhZa8DG1aiu3+VD7d!{|4UZ6dsUa&o+UZ_2! zUbsD^UZg#wUbH==UaUQ&Uc5b|UZOpuUa~!;UaCE$Ub;P`UZy>yUba1?Uamc)UVeK> zy@IMEGvodP6BjzS??0f>zW;z?`~Cw;?fVZXx9>lo(!T$IYWw~JYVG?EsJHJwpwYhn zfado72eh2)d5ZX86~Y0A?E((kjf~sv7qF)CY}}B~sKvtI!N|by{~tfYiDDiGE(S&h ab{s;}Kdci>V)9^Y|LCv1{iDAQe*pmV!`_zw diff --git a/AdvertsingProfitControl/DatabaseWriter.cs b/AdvertsingProfitControl/DatabaseWriter.cs index bc5d8fe..ce22b0e 100644 --- a/AdvertsingProfitControl/DatabaseWriter.cs +++ b/AdvertsingProfitControl/DatabaseWriter.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.Runtime.InteropServices; @@ -451,7 +452,7 @@ namespace AdvertsingProfitControl oleDbCommand.CommandText = "INSERT INTO Invoice (InvoiceDate, InvoiceNumber, InvoiceNetAmountAtCost, InvoiceNetAmount, InvoiceNote, FK_Supplier, FK_DateID) VALUES(?,?,?,?,?,?,?)"; oleDbCommand.Parameters.AddWithValue("InvoiceDate", table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString()); - oleDbCommand.Parameters.AddWithValue("InvoiceNumber", long.Parse(table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue.ToString())); + oleDbCommand.Parameters.AddWithValue("InvoiceNumber", table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue.ToString()); oleDbCommand.Parameters.AddWithValue("InvoiceNetAmountAtCost", table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNetAmountAtCost].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNetAmountAtCost].EditedFormattedValue.ToString())); oleDbCommand.Parameters.AddWithValue("InvoiceNetAmount", table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNetAmount].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNetAmount].EditedFormattedValue.ToString())); oleDbCommand.Parameters.AddWithValue("InvoiceNote", table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNote].EditedFormattedValue.ToString()); @@ -467,7 +468,7 @@ namespace AdvertsingProfitControl oleDbCommand.CommandText = "UPDATE Invoice SET InvoiceDate = ?, InvoiceNumber = ?, InvoiceNetAmountAtCost = ?, InvoiceNetAmount = ?, InvoiceNote = ?, FK_Supplier = ?, FK_DateID = ? WHERE ID = ?"; oleDbCommand.Parameters.AddWithValue("InvoiceDate", table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString()); - oleDbCommand.Parameters.AddWithValue("InvoiceNumber", long.Parse(table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue.ToString())); + oleDbCommand.Parameters.AddWithValue("InvoiceNumber", table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue.ToString()); oleDbCommand.Parameters.AddWithValue("InvoiceNetAmountAtCost", table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNetAmountAtCost].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNetAmountAtCost].EditedFormattedValue.ToString())); oleDbCommand.Parameters.AddWithValue("InvoiceNetAmount", table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNetAmount].EditedFormattedValue.ToString() == "" ? 0 : double.Parse(table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNetAmount].EditedFormattedValue.ToString())); oleDbCommand.Parameters.AddWithValue("InvoiceNote", table.Rows[i].Cells[(int)InvoiceTableColumns.InvoiceNote].EditedFormattedValue.ToString()); @@ -523,7 +524,7 @@ namespace AdvertsingProfitControl else { _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed on row " + (lastRowProcessed + 1) + " due to the above error. Dumping contents of row " + (lastRowProcessed + 1) + " from Invoices."); - status.SetErrorMessage("Failed to write to the database on row " + (lastRowProcessed + 1) + "."); + status.SetErrorMessage("Failed to save invoice on row " + (lastRowProcessed + 1) + " to the database."); } oleDbTransaction?.Rollback(); _logConsole.WriteToLog(FrmLogConsole.Level.Critical, "Rollback completed successfully, Invoice table failed on update."); diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs index af3ea9c..00a880d 100644 --- a/AdvertsingProfitControl/NewModifyRecord.cs +++ b/AdvertsingProfitControl/NewModifyRecord.cs @@ -3295,7 +3295,11 @@ namespace AdvertsingProfitControl { errorLabel.Text += @"Failed to process actual sales." + Environment.NewLine; } - return success; + if (!SaveInvoices(dateId)) return false; + if (!SaveComments(dateId)) return false; + if (!SaveWeeklySales(dateId)) return false; + if (!SaveTaxable(dateId)) return false; + return SaveCostAnalysis(dateId) && success; } /// @@ -3325,6 +3329,222 @@ namespace AdvertsingProfitControl return dateId; } + private bool SaveInvoices(int dateId) + { + var dbT = new DatabaseTracker(); + var dbW = new DatabaseWriter(dbT.DatabaseConnectionString); + //Commit the Invoice table to the database. + var writerStatus = dbW.ProccessInvoiceTable(invoicesDataGridView, dateId, dbT.DatabaseConnectionString); + if (writerStatus.GetWritingOperationStatus() == WritingOperationStatus.Failed) + { + errorLabel.Text = writerStatus.GetErrorMessage(); + return false; + } + informationLabel.Text += writerStatus.GetErrorMessage() + Environment.NewLine; + return true; + } + + private bool SaveComments(int dateId) + { + var dbT = new DatabaseTracker(); + var dbW = new DatabaseWriter(dbT.DatabaseConnectionString); + //TODO: If the comments are null but there is a comment ID, delete the comments from the database. + if (isCommentDirtyCheckBox.Checked) + { + if (isCommentDirtyCheckBox.Tag == null) + { + var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString); + if (status.Status == WritingOperationStatus.Failed) + { + informationLabel.Text += @"Failed to add Comments to the database." + Environment.NewLine; + errorLabel.Text = status.ErrorMessage; + return false; + } + informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine; + var id = status.Id; + isCommentDirtyCheckBox.Tag = id; + isCommentDirtyCheckBox.Text = @"IsCommentDirty (" + id + @")"; + isCommentDirtyCheckBox.Checked = false; + return true; + } + else + { + //Check for a null comment box and delete the comment ID from the database. + //Then if all is successful clear the Tag in the isCommentsDirty check box. + var status = dbW.ProcessComments(commentsTextBox.Text, dateId, dbT.DatabaseConnectionString, + int.Parse(isCommentDirtyCheckBox.Tag.ToString())); + if (status.Status == WritingOperationStatus.Failed) + { + informationLabel.Text += @"Failed to add Comments to the database." + Environment.NewLine; + errorLabel.Text = status.ErrorMessage; + return false; + } + isCommentDirtyCheckBox.Checked = false; + informationLabel.Text += @"Comment(s) processed successfully." + Environment.NewLine; + return true; + } + } + informationLabel.Text += @"No changes detected for the comment(s)" + Environment.NewLine; + return true; + } + + private bool SaveWeeklySales(int dateId) + { + var dbT = new DatabaseTracker(); + var dbW = new DatabaseWriter(dbT.DatabaseConnectionString); + //Begin checking the Weekly Sales. + if (isWeeklySalesDirtyCheckBox.Checked) + { + //Parse out all the text boxes' values in the weekly sales group. + var weeklySales = new double[8]; + weeklySales[0] = sundayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(sundayWeeklySalesTextBox.Text); + weeklySales[1] = mondayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(mondayWeeklySalesTextBox.Text); + weeklySales[2] = tuesdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(tuesdayWeeklySalesTextBox.Text); + weeklySales[3] = wednesdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(wednesdayWeeklySalesTextBox.Text); + weeklySales[4] = thursdayWeeklySalesTextBox.Text == "" + ? 0 + : double.Parse(thursdayWeeklySalesTextBox.Text); + weeklySales[5] = fridayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(fridayWeeklySalesTextBox.Text); + weeklySales[6] = saturdayWeeklySalesTextBox.Text == "" + ? 0 + : double.Parse(saturdayWeeklySalesTextBox.Text); + weeklySales[7] = totalWeeklySalesTextBox.Text == "" ? 0 : double.Parse(totalWeeklySalesTextBox.Text); + + if (isWeeklySalesDirtyCheckBox.Tag == null) + { + //Weekly sales is not in the database. + var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString); + if (status.Status == WritingOperationStatus.Failed) + { + informationLabel.Text += @"Failed to add Weekly Sales to the database." + Environment.NewLine; + errorLabel.Text = status.ErrorMessage; + return false; + } + informationLabel.Text += @"Weekly Sales processed successfully." + Environment.NewLine; + isWeeklySalesDirtyCheckBox.Tag = status.Id; + isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty (" + status.Id + @")"; + isWeeklySalesDirtyCheckBox.Checked = false; + return true; + } + else + { + var status = dbW.ProcessWeeklySales(weeklySales, dateId, dbT.DatabaseConnectionString, + int.Parse(isWeeklySalesDirtyCheckBox.Tag.ToString())); + if (status.Status == WritingOperationStatus.Failed) + { + informationLabel.Text += @"Failed to add Weekly Sales to the database." + Environment.NewLine; + errorLabel.Text = status.ErrorMessage; + return false; + } + isWeeklySalesDirtyCheckBox.Checked = false; + informationLabel.Text += @"Weekly Sales updated successfully." + Environment.NewLine; + return true; + } + } + informationLabel.Text += @"No changes detected for Weekly Sales." + Environment.NewLine; + return true; + } + + private bool SaveTaxable(int dateId) + { + var dbT = new DatabaseTracker(); + var dbW = new DatabaseWriter(dbT.DatabaseConnectionString); + //Begin checking the Taxable. + if (isTaxableDirtyCheckBox.Checked) + { + //Parse out all the text boxes' values in the taxable group. + var taxable = new double[8]; + taxable[0] = sundayTaxableTextBox.Text == "" ? 0 : double.Parse(sundayTaxableTextBox.Text); + taxable[1] = mondayTaxableTextBox.Text == "" ? 0 : double.Parse(mondayTaxableTextBox.Text); + taxable[2] = tuesdayTaxableTextBox.Text == "" ? 0 : double.Parse(tuesdayTaxableTextBox.Text); + taxable[3] = wednesdayTaxableTextBox.Text == "" ? 0 : double.Parse(wednesdayTaxableTextBox.Text); + taxable[4] = thursdayTaxableTextBox.Text == "" ? 0 : double.Parse(thursdayTaxableTextBox.Text); + taxable[5] = fridayTaxableTextBox.Text == "" ? 0 : double.Parse(fridayTaxableTextBox.Text); + taxable[6] = saturdayTaxableTextBox.Text == "" ? 0 : double.Parse(saturdayTaxableTextBox.Text); + taxable[7] = totalTaxableTextBox.Text == "" ? 0 : double.Parse(totalTaxableTextBox.Text); + + if (isTaxableDirtyCheckBox.Tag == null) + { + //Taxable is not in the database. + var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString); + if (status.Status == WritingOperationStatus.Failed) + { + informationLabel.Text += @"Failed to add Taxable to the database." + Environment.NewLine; + errorLabel.Text = status.ErrorMessage; + return false; + } + informationLabel.Text += @"Taxable processed successfully." + Environment.NewLine; + isTaxableDirtyCheckBox.Tag = status.Id; + isTaxableDirtyCheckBox.Text = @"IsTaxableDirty (" + status.Id + @")"; + return true; + } + else + { + var status = dbW.ProcessTaxable(taxable, dateId, dbT.DatabaseConnectionString, + int.Parse(isTaxableDirtyCheckBox.Tag.ToString())); + if (status.Status == WritingOperationStatus.Failed) + { + informationLabel.Text += @"Failed to add Taxable to the database." + Environment.NewLine; + errorLabel.Text = status.ErrorMessage; + return false; + } + isTaxableDirtyCheckBox.Checked = false; + informationLabel.Text += @"Taxable updated successfully." + Environment.NewLine; + return true; + } + } + informationLabel.Text += @"No changes detected for Taxable." + Environment.NewLine; + return true; + } + + private bool SaveCostAnalysis(int dateId) + { + var dbT = new DatabaseTracker(); + var dbW = new DatabaseWriter(dbT.DatabaseConnectionString); + //Begin checking cost analysis. + if (isCostAnalysisDirtyCheckBox.Checked) + { + //Parse out the cost analysis group values. + var costAnalysis = new double[4]; + costAnalysis[0] = salesPerManHourTextBox.Text == "" ? 0 : double.Parse(salesPerManHourTextBox.Text); + costAnalysis[1] = salaryPercentageTextBox.Text == "" ? 0 : double.Parse(salaryPercentageTextBox.Text); + costAnalysis[2] = salaryDollarsTextBox.Text == "" ? 0 : double.Parse(salaryDollarsTextBox.Text); + costAnalysis[3] = suppliesTextBox.Text == "" ? 0 : double.Parse(suppliesTextBox.Text); + + if (isCostAnalysisDirtyCheckBox.Tag == null) + { + //Weekly sales is not in the database. + var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString); + if (status.Status == WritingOperationStatus.Failed) + { + informationLabel.Text += @"Failed to add Cost Analysis to the database." + Environment.NewLine; + errorLabel.Text = status.ErrorMessage; + return false; + } + informationLabel.Text += @"Costs Analysis processed successfully." + Environment.NewLine; + isCostAnalysisDirtyCheckBox.Tag = status.Id; + isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty (" + status.Id + @")"; + isCostAnalysisDirtyCheckBox.Checked = false; + return true; + } + else + { + var status = dbW.ProcessCostAnalysis(costAnalysis, dateId, dbT.DatabaseConnectionString, + int.Parse(isCostAnalysisDirtyCheckBox.Tag.ToString())); + if (status.Status == WritingOperationStatus.Failed) + { + informationLabel.Text += @"Failed to add Cost Analysis to the database." + Environment.NewLine; + errorLabel.Text = status.ErrorMessage; + return false; + } + isCostAnalysisDirtyCheckBox.Checked = false; + informationLabel.Text += @"Cost Analysis updated successfully." + Environment.NewLine; + return true; + } + } + informationLabel.Text += @"No changes made to Cost Analysis." + Environment.NewLine; + return true; + } #endregion #region Table Trimming Operations @@ -3641,200 +3861,13 @@ namespace AdvertsingProfitControl return TrimmingOperationResult.CreatedNewInsertionAndUpdateTables; } - 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); - DbTableWriterStatus dbWriterStatus; - var successful = false; - switch (operationStatus) - { - case TrimmingOperationResult.NoChangesRequired: - informationLabel.Text += @"No changes to the " + TextFormat.AddSpacesToSentence(tableName, false) + @" table detected." + Environment.NewLine; - successful = true; - break; - case TrimmingOperationResult.CreatedNewInsertionTable: - 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].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - } - informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database." + Environment.NewLine; - successful = true; - } - else - { - errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database." + Environment.NewLine; - } - break; - case TrimmingOperationResult.CreatedUpdateTable: - 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; - dataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - } - informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated." + Environment.NewLine; - successful = true; - } - else - { - errorLabel.Text = @"Failed to update the " + trimmedTable + @" table." + Environment.NewLine; - } - break; - case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables: - //Insert the new values... - 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()) - { - //Add the ID numbers to the first column since these are new additions to the database. - 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].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - } - informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully added to the database." + Environment.NewLine; - } - else - { - errorLabel.Text = @"Failed to insert " + trimmedTable + @" into the database." + Environment.NewLine; - } - //... and update the existing values. - 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; - dataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - } - informationLabel.Text += TextFormat.AddSpacesToSentence(tableName, false) + @" table successfully updated." + Environment.NewLine; - successful = true; - } - else - { - errorLabel.Text = @"Failed to update the " + trimmedTable + @" table." + Environment.NewLine; - } - break; - } - return successful; - } - - private bool ProcessTrimmingStatusForInventory(TrimmingOperationResult operationStatus, DataTable trimmedTable, DataTable updateTable) - { - //Create the database interaction objects. - var dbT = new DatabaseTracker(); - var dbW = new DatabaseWriter(dbT.DatabaseConnectionString); - DbTableWriterStatus dbWriterStatus; - var successful = false; - switch (operationStatus) - { - case TrimmingOperationResult.NoChangesRequired: - informationLabel.Text += @"No changes to the Inventory table detected." + Environment.NewLine; - successful = true; - break; - case TrimmingOperationResult.CreatedNewInsertionTable: - 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; - inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - } - informationLabel.Text += @"Inventory table successfully added to the database." + Environment.NewLine; - successful = true; - } - else - { - errorLabel.Text = @"Failed to insert Inventory table into the database." + Environment.NewLine; - } - break; - case TrimmingOperationResult.CreatedUpdateTable: - 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].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - } - informationLabel.Text += @"Inventory table successfully updated." + Environment.NewLine; - successful = true; - } - else - { - errorLabel.Text = @"Failed to update the changes in the Inventory table." + Environment.NewLine; - } - break; - case TrimmingOperationResult.CreatedNewInsertionAndUpdateTables: - //Insert the new values... - 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()) - { - //Add the ID numbers to the first column since these are new additions to the database. - inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.Id].Value = rowIndex.Value; - inventoryDataGridView.Rows[rowIndex.Key - 1].Cells[(int)InventoryTableColumns.IsDirty].Value = false; - inventoryDataGridView.Rows[rowIndex.Key - 1].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - } - informationLabel.Text += @"Inventory table successfully added to the database." + Environment.NewLine; - successful = true; - } - else - { - errorLabel.Text = @"Failed to insert Inventory table into the database." + Environment.NewLine; - } - 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].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - } - informationLabel.Text += @"Inventory table successfully updated." + Environment.NewLine; - successful = true; - } - else - { - errorLabel.Text = @"Failed to update the changes in the Inventory table." + Environment.NewLine; - } - break; - } - inventoryDataGridView.RefreshEdit(); - return successful; - } + #endregion private void addRecordButton_Click(object sender, EventArgs e) { SaveRecords(); } - #endregion - //private void NormalizeApcTables(DataTable projections, DataTable inventory, DataTable actualSales, string dateId) //{ diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application index 1315bc1..b0428ef 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application @@ -14,7 +14,7 @@ - Btzwp78H3RT2AmoucaHpeRFbGzPf83asDL/GO1dGVPA= + 1Hy88d0pyLqSm+LXJWOGDCgRmXG4f4D5il87bOZtle0= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest index da40c12..80afe5f 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest @@ -43,14 +43,14 @@ - + - xkEtzq+MLDnIJnChEMusRcJt0LD8/sPMW87LQ9g7ulE= + 9J9ugoTiC4+wY6MW3l8lpcH7ZE4DSPiDNUUMrWgEDvE= @@ -93,7 +93,7 @@ - yZCLj+jy8vUBAeTKpwbwGxsDAc4IOfwKM+XGhtNBq5M= + h0U0mLzUnhEKHaiuXsTC+7xvKixcE9+lG0nu0vBTYdI=