From 26575238885ca60c06d4454c33599e8c7bd7ae66 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Tue, 24 Jan 2017 13:45:25 -0600 Subject: [PATCH] Added a tool to remove an entire date and all records associated with it. Updated row deletion code to handle unbalanced tables or missing row IDs. --- AdvertsingProfitControl/APCDatabase.accdb | Bin 864256 -> 864256 bytes AdvertsingProfitControl/DatabaseWriter.cs | 154 +++++++++++++----- AdvertsingProfitControl/FrmMain.Designer.cs | 20 ++- AdvertsingProfitControl/FrmMain.cs | 38 ++++- .../NewAddRecord.Designer.cs | 17 +- AdvertsingProfitControl/NewAddRecord.cs | 30 +++- .../NewModifyRecord.Designer.cs | 3 + AdvertsingProfitControl/NewModifyRecord.cs | 90 +++++++--- AdvertsingProfitControl/NewModifyRecord.resx | 3 + .../Properties/AssemblyInfo.cs | 4 +- ...AdvertsingProfitControl.vshost.application | 21 --- ...dvertsingProfitControl.vshost.exe.manifest | 139 ---------------- 12 files changed, 277 insertions(+), 242 deletions(-) delete mode 100644 AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application delete mode 100644 AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest diff --git a/AdvertsingProfitControl/APCDatabase.accdb b/AdvertsingProfitControl/APCDatabase.accdb index 4739dec595ad9be55a2696d3cee7f72675b1a69c..bf3181a36ff55e30e0083b9efdffcbce0a2e4ec2 100644 GIT binary patch delta 2461 zcmZp8VAAlwWCIf)a}$f|WL!KT zK1?01lkes@b98)lVqkE{=-Ie1g=u<$AB)+ve0KiHI@$W03QnwJ?dK`pzkm8!IYvpw zl=kOxjN6~fG3gdEPMt0~fk{s?jR66;5ln_D(*qosO{dQ_V3FOvZUR$|;&$atObN`a zI~W*F>TR#z$`sG2Ti?LIaG!zUq#`kljSIhWY&*bolg)@5WCTbH(G0NO3n0ByVS0&X zfb=ReGMe*uL4C)~@R9!!|7HFo{9E~#@lWUP;IHJ*;*Z`eC}6?Q&%^)=goKAr9GKg) z-ZO2_de6MdfpN-o$MUUtPBh#9$;++Fm2on3?=R$Z3Gw)Z4EGOlVRHMFs8t5 zo4_KnfpP72Q3uwy`bwP~As~Mx%X!m@kXB&o$+-RdLQY3k)*XwMN6*@ByPQ*>b^4#v zoIKNgvw3)@2b|_Ko4$JuXCFw+AH?$7{%9?y0@GF|HZ}qFJuCk6FfyoZ78H=?pKg%D z$}!#VE-S}&D|xoI07mxh2lLq+FL28b)8Ga6du%!&)!YmW z$BAKVS5#*G#ngf3u?_;O5K*frfhf=8wOzyr?q0}r^iA9%p+ z)XzPaxeA&X^``R{@C5R(A3?y43$>U8c)-aUs)%92lS|ks3|BE|Nk@5Gca%%5?V#DIe0sJ3D0k7ZeM0i zh;JG6r}IwW3FKorf`B`jH!gh0SkJ>S6{-eAO_;(9qTm=?$igJiLzpa+>cOT_#VE2& zg4ho(Bw+<5*c=8123j}@BaDn;wt;Elf_wYl$vmtvJRiAWnJSfGy1)mX6WcjH^88|& ZxWQ<;Wd@hn_Cv;;Rm|Hbedo!u003FpE(rht delta 1041 zcmZp8VAAlwWCIf)^F-~L}dGX1O^qalhdq!WdE+ ziWrI+G8yt2@)#Hxu7QkAWMEhsvqyM3Vy5C(^j_p?R zY;6IIY}*g!vpHVi)@E{sn&~{9*MYr#`lS6_E*m#IXWYKui9IwH9()Vfr3u9B_K6GF zeIa3ZfgKu#4`7TB>;eVT1r9JvPS;G}kYZ#6r-kj62^_rglMAw4Cl_R!ZfoG!&Ce<@ zVPeOT=?D5bq?s6|O&Iefw#eL$XPWSB1SfU{@ghRy8L{Udl(wjX%F*~`wvz_6@9I#;ffd`!J z2Oe;3Kk$Itsh@i#a}`J{0|SG`blw7u=H09fEH>i_@% diff --git a/AdvertsingProfitControl/DatabaseWriter.cs b/AdvertsingProfitControl/DatabaseWriter.cs index dd38de0..e365042 100644 --- a/AdvertsingProfitControl/DatabaseWriter.cs +++ b/AdvertsingProfitControl/DatabaseWriter.cs @@ -490,22 +490,6 @@ namespace AdvertsingProfitControl table.Rows[rowIndex].Cells[(int)InvoiceTableColumns.IsDirty].Value = false; table.Rows[rowIndex].HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; } - //foreach (DataGridViewRow row in table.Rows) - //{ - // if(row.IsNewRow) continue; - // if (!rowsAdded.Contains(row.Index)) continue; - // var supplierId = RetrieveSupplierId(row.Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue.ToString()); - // var invoiceIdNumber = - // RetrieveInvoiceId( - // row.Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue - // .ToString(), - // long.Parse( - // row.Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue - // .ToString()), supplierId, dateId); - // row.Cells[(int)InvoiceTableColumns.Id].Value = invoiceIdNumber; - // row.Cells[(int)InvoiceTableColumns.IsDirty].Value = false; - // row.HeaderCell.Style.BackColor = ApplicationColors.EditingSaved; - //} table.RefreshEdit(); //Set the status. status.SetStatus(WritingOperationStatus.InsertionSuccessful); @@ -820,6 +804,36 @@ namespace AdvertsingProfitControl } } + public bool DeleteTableEntry(int rowId, string tableName, string connectionString) + { + var oleDbConnection = new OleDbConnection(connectionString); + var status = false; + var oleDbCommand = new OleDbCommand + { + Connection = oleDbConnection, + CommandText = "DELETE * FROM " + tableName + " WHERE ID = ?" + + }; + oleDbCommand.Parameters.AddWithValue("RowID", rowId); + try + { + oleDbConnection.Open(); + oleDbCommand.ExecuteNonQuery(); + status = true; + } + catch (OleDbException e) + { + _logConsole.WriteToLog(FrmLogConsole.Level.Error, + "Failed to delete the entries in " + tableName + " with the row ID of " + rowId + "."); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message); + } + finally + { + oleDbConnection.Close(); + } + return status; + } + /// /// Inserts a new ad item into the database and returns the new item's ID number. /// Supports rolling back as to not corrupt the database. @@ -1084,11 +1098,11 @@ namespace AdvertsingProfitControl /// True if the operation was successful; false if not. public bool DeleteApcRow(int projectionsRowId, int inventoryRowId, int actualSalesRowId) { - var result = false; + var result = true; var tableName = "Projections"; //Starting point. var oleDbCommand = new OleDbCommand { - CommandText = "DELETE FROM Projections WHERE ID = ?", + CommandText = "DELETE * FROM Projections WHERE ID = ?", Connection = _oleDbConnection }; oleDbCommand.Parameters.AddWithValue("ID", projectionsRowId); @@ -1098,41 +1112,54 @@ namespace AdvertsingProfitControl _oleDbConnection.Open(); oleDbTransaction = _oleDbConnection.BeginTransaction(); oleDbCommand.Transaction = oleDbTransaction; - var rowsEffected = oleDbCommand.ExecuteNonQuery(); - if (rowsEffected == 1) + var rowsEffected = 0; + if (projectionsRowId != 0) { - tableName = "Inventory"; - oleDbCommand.Parameters.Clear(); - oleDbCommand.CommandText = "DELETE FROM Inventory WHERE ID = ?"; - oleDbCommand.Parameters.AddWithValue("ID", inventoryRowId); rowsEffected = oleDbCommand.ExecuteNonQuery(); - if (rowsEffected == 1) + if (rowsEffected == 0) { - tableName = "ActualSales"; - oleDbCommand.Parameters.Clear(); - oleDbCommand.CommandText = "DELETE FROM ActualSales WHERE ID = ?"; - oleDbCommand.Parameters.AddWithValue("ID", inventoryRowId); - rowsEffected = oleDbCommand.ExecuteNonQuery(); - if (rowsEffected == 1) - { - result = true; - } - } + oleDbTransaction?.Rollback(); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to delete row with the ID of " + projectionsRowId + " from projections. (No Exception Thrown)"); + return false; + } } - if (!result) + tableName = "Inventory"; + oleDbCommand.Parameters.Clear(); + if (inventoryRowId != 0) { - oleDbTransaction?.Rollback(); + oleDbCommand.CommandText = "DELETE * FROM Inventory WHERE ID = ?"; + oleDbCommand.Parameters.AddWithValue("ID", inventoryRowId); + rowsEffected = oleDbCommand.ExecuteNonQuery(); + if (rowsEffected == 0) + { + oleDbTransaction?.Rollback(); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to delete row with the ID of " + inventoryRowId + " from inventory. (No Exception Thrown)"); + return false; + } } - else + tableName = "ActualSales"; + oleDbCommand.Parameters.Clear(); + if (actualSalesRowId != 0) { - oleDbTransaction.Commit(); + oleDbCommand.CommandText = "DELETE * FROM ActualSales WHERE ID = ?"; + oleDbCommand.Parameters.AddWithValue("ID", actualSalesRowId); + rowsEffected = oleDbCommand.ExecuteNonQuery(); + if (rowsEffected == 0) + { + oleDbTransaction?.Rollback(); + _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to delete row with the ID of " + actualSalesRowId + " from actual sales. (No Exception Thrown)"); + return false; + } } + + oleDbTransaction?.Commit(); } catch (OleDbException e) { _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to delete row with the ID of " + inventoryRowId + " from " + tableName + "."); _logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message); oleDbTransaction?.Rollback(); + result = false; } finally { @@ -1142,6 +1169,55 @@ namespace AdvertsingProfitControl return result; } + public bool ClearDateById(int dateId) + { + var successful = true; + var oleDbCommand = new OleDbCommand + { + CommandText = "DELETE * FROM ActualSales WHERE FK_DateID = ?", + Connection = _oleDbConnection + }; + oleDbCommand.Parameters.AddWithValue("DateID", dateId); + OleDbTransaction oleDbTransaction = null; + try + { + _oleDbConnection.Open(); + oleDbTransaction = _oleDbConnection.BeginTransaction(); + oleDbCommand.Transaction = oleDbTransaction; + oleDbCommand.ExecuteNonQuery(); + oleDbCommand.CommandText = "DELETE * FROM Comment WHERE FK_DateID = ?"; + oleDbCommand.Parameters.AddWithValue("DateID", dateId); + oleDbCommand.ExecuteNonQuery(); + oleDbCommand.CommandText = "DELETE * FROM CostOfSalesAnalysis WHERE FK_DateID = ?"; + oleDbCommand.Parameters.AddWithValue("DateID", dateId); + oleDbCommand.ExecuteNonQuery(); + oleDbCommand.CommandText = "DELETE * FROM Inventory WHERE FK_DateID = ?"; + oleDbCommand.ExecuteNonQuery(); + oleDbCommand.CommandText = "DELETE * FROM Invoice WHERE FK_DateID = ?"; + oleDbCommand.ExecuteNonQuery(); + oleDbCommand.CommandText = "DELETE * FROM Projections WHERE FK_DateID = ?"; + oleDbCommand.ExecuteNonQuery(); + oleDbCommand.CommandText = "DELETE * FROM Taxable WHERE FK_DateID = ?"; + oleDbCommand.ExecuteNonQuery(); + oleDbCommand.CommandText = "DELETE * FROM WeekEnding WHERE ID = ?"; + oleDbCommand.ExecuteNonQuery(); + oleDbCommand.CommandText = "DELETE * FROM WeeklySales WHERE FK_DateID = ?"; + oleDbCommand.ExecuteNonQuery(); + oleDbTransaction.Commit(); + } + catch (OleDbException e) + { + _logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message); + oleDbTransaction?.Rollback(); + successful = false; + } + finally + { + _oleDbConnection.Close(); + } + return successful; + } + public bool NormalizeApcTables(int dateId) { var successful = false; diff --git a/AdvertsingProfitControl/FrmMain.Designer.cs b/AdvertsingProfitControl/FrmMain.Designer.cs index d3fd5e2..8147a02 100644 --- a/AdvertsingProfitControl/FrmMain.Designer.cs +++ b/AdvertsingProfitControl/FrmMain.Designer.cs @@ -102,6 +102,7 @@ this.grossProfitEstimatedWeeklyDeptmartmentExpenseLabel = new System.Windows.Forms.Label(); this.perfectGrossProfitLabel = new System.Windows.Forms.Label(); this.grossProfitDollarGrossProfitLabel = new System.Windows.Forms.Label(); + this.clearSelectedDateToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.mainMenu.SuspendLayout(); this.mainTableLayoutPanel.SuspendLayout(); this.commentMainTableLayoutPanel.SuspendLayout(); @@ -206,23 +207,25 @@ // this.toolsMainMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.adSpecialKeyWordsToolsMainMenu, - this.manageItemsToolsMainMenu}); + this.manageItemsToolsMainMenu, + this.clearSelectedDateToolsMainMenu}); this.toolsMainMenu.Name = "toolsMainMenu"; this.toolsMainMenu.Size = new System.Drawing.Size(72, 34); this.toolsMainMenu.Text = "&Tools"; - this.toolsMainMenu.Visible = false; // // adSpecialKeyWordsToolsMainMenu // this.adSpecialKeyWordsToolsMainMenu.Name = "adSpecialKeyWordsToolsMainMenu"; - this.adSpecialKeyWordsToolsMainMenu.Size = new System.Drawing.Size(282, 34); + this.adSpecialKeyWordsToolsMainMenu.Size = new System.Drawing.Size(286, 34); this.adSpecialKeyWordsToolsMainMenu.Text = "&Register Ad Special"; + this.adSpecialKeyWordsToolsMainMenu.Visible = false; // // manageItemsToolsMainMenu // this.manageItemsToolsMainMenu.Name = "manageItemsToolsMainMenu"; - this.manageItemsToolsMainMenu.Size = new System.Drawing.Size(282, 34); + this.manageItemsToolsMainMenu.Size = new System.Drawing.Size(286, 34); this.manageItemsToolsMainMenu.Text = "&Manage Ad Items"; + this.manageItemsToolsMainMenu.Visible = false; this.manageItemsToolsMainMenu.Click += new System.EventHandler(this.manageItemsToolsMainMenu_Click); // // helpMainMenu @@ -928,6 +931,13 @@ this.grossProfitDollarGrossProfitLabel.TabIndex = 2; this.grossProfitDollarGrossProfitLabel.Text = "Dollar Gross Profit: "; // + // clearSelectedDateToolsMainMenu + // + this.clearSelectedDateToolsMainMenu.Name = "clearSelectedDateToolsMainMenu"; + this.clearSelectedDateToolsMainMenu.Size = new System.Drawing.Size(286, 34); + this.clearSelectedDateToolsMainMenu.Text = "&Clear Selected Date"; + this.clearSelectedDateToolsMainMenu.Click += new System.EventHandler(this.clearSelectedDateToolsMainMenu_Click); + // // FrmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); @@ -939,6 +949,7 @@ this.Name = "FrmMain"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Advertising Profit Control"; + this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.Load += new System.EventHandler(this.frmMain_Load); this.mainMenu.ResumeLayout(false); this.mainMenu.PerformLayout(); @@ -1048,6 +1059,7 @@ private System.Windows.Forms.DataGridView invoicesDataGridView; private System.Windows.Forms.ToolStripMenuItem debugToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem debugToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem clearSelectedDateToolsMainMenu; } } diff --git a/AdvertsingProfitControl/FrmMain.cs b/AdvertsingProfitControl/FrmMain.cs index 3e49f51..665f90f 100644 --- a/AdvertsingProfitControl/FrmMain.cs +++ b/AdvertsingProfitControl/FrmMain.cs @@ -157,7 +157,7 @@ namespace AdvertsingProfitControl private void modifyRecordMainMenu_Click(object sender, EventArgs e) { - var form = new NewModifyRecord(monthCalendar.SelectionStart); + var form = new NewModifyRecord(_currentActiveDate); form.ShowDialog(); //On return reload the date that was just modified by the modify record form. LoadDate(monthCalendar.SelectionStart); @@ -1235,6 +1235,42 @@ namespace AdvertsingProfitControl var databaseReader = new DatabaseReader(); monthCalendar.BoldedDates = databaseReader.RetrieveDates(databaseTracker.DatabaseConnectionString).ToArray(); } + + public enum FormDefaultRoll + { + AddNewRecord = 0, + ModifyExistingRecord = 1 + } + + private void clearSelectedDateToolsMainMenu_Click(object sender, EventArgs e) + { + var result = MessageBox.Show(@"Are you sure you want to delete all records for the date " + _currentActiveDate.ToShortDateString() + @"?", @"Clear Date", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (result == DialogResult.No) + { + return; + } + var dbT = new DatabaseTracker(); + var dbW = new DatabaseWriter(dbT.DatabaseConnectionString); + var dbR = new DatabaseReader(); + var dateId = dbR.RetrieveDateIdByDateString(_currentActiveDate.ToShortDateString(), dbT.DatabaseConnectionString); + if (dateId != 0) + { + if (dbW.ClearDateById(dateId)) + { + RefreshDateListing(); + var date = dbR.RetrieveMostRecentDate(dbT.DatabaseConnectionString); + LoadDate(date); + } + else + { + errorLabel.Text = @"Failed to clear the selected date."; + } + } + else + { + errorLabel.Text = @"Failed to get the date ID number."; + } + } } } //http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children diff --git a/AdvertsingProfitControl/NewAddRecord.Designer.cs b/AdvertsingProfitControl/NewAddRecord.Designer.cs index cb8442b..f639ab9 100644 --- a/AdvertsingProfitControl/NewAddRecord.Designer.cs +++ b/AdvertsingProfitControl/NewAddRecord.Designer.cs @@ -56,6 +56,7 @@ this.FileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.clearFormFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.exitFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.debugMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.mainLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.costAnalysisGroupBox = new System.Windows.Forms.GroupBox(); this.suppliesTextBox = new System.Windows.Forms.TextBox(); @@ -107,7 +108,6 @@ this.informationPanel = new System.Windows.Forms.Panel(); this.errorLabel = new System.Windows.Forms.Label(); this.addRecordButton = new System.Windows.Forms.Button(); - this.debugMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.commentsGroupBox.SuspendLayout(); this.mainTabControl.SuspendLayout(); this.projectionTabPage.SuspendLayout(); @@ -449,6 +449,13 @@ this.exitFileMainMenu.Size = new System.Drawing.Size(205, 34); this.exitFileMainMenu.Text = "E&xit"; // + // debugMainMenu + // + this.debugMainMenu.Name = "debugMainMenu"; + this.debugMainMenu.Size = new System.Drawing.Size(87, 31); + this.debugMainMenu.Text = "&Debug"; + this.debugMainMenu.Click += new System.EventHandler(this.debugMainMenu_Click); + // // mainLayoutPanel // this.mainLayoutPanel.ColumnCount = 4; @@ -943,13 +950,6 @@ this.addRecordButton.UseVisualStyleBackColor = true; this.addRecordButton.Click += new System.EventHandler(this.AddRecordsButtonClick); // - // debugMainMenu - // - this.debugMainMenu.Name = "debugMainMenu"; - this.debugMainMenu.Size = new System.Drawing.Size(87, 31); - this.debugMainMenu.Text = "&Debug"; - this.debugMainMenu.Click += new System.EventHandler(this.debugMainMenu_Click); - // // NewAddRecord // this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); @@ -962,6 +962,7 @@ this.MinimumSize = new System.Drawing.Size(1000, 1000); this.Name = "NewAddRecord"; this.Text = "Add New Record"; + this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.commentsGroupBox.ResumeLayout(false); this.commentsGroupBox.PerformLayout(); this.mainTabControl.ResumeLayout(false); diff --git a/AdvertsingProfitControl/NewAddRecord.cs b/AdvertsingProfitControl/NewAddRecord.cs index f858765..ef7869b 100644 --- a/AdvertsingProfitControl/NewAddRecord.cs +++ b/AdvertsingProfitControl/NewAddRecord.cs @@ -560,9 +560,13 @@ namespace AdvertsingProfitControl if (result == DialogResult.Yes) { //Attempt to delete the row from the database by its ID number. - var projectionsRowId = int.Parse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var inventoryRowId = int.Parse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var actualSalesRowId = int.Parse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); + int projectionsRowId; + int inventoryRowId; + int actualSalesRowId; + //Attempt to delete the row from the database by its ID number. + int.TryParse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out projectionsRowId); + int.TryParse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out inventoryRowId); + int.TryParse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out actualSalesRowId); if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId)) { informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database."; @@ -589,9 +593,13 @@ namespace AdvertsingProfitControl if (result == DialogResult.Yes) { //Attempt to delete the row from the database by its ID number. - var projectionsRowId = int.Parse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var inventoryRowId = int.Parse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var actualSalesRowId = int.Parse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); + int projectionsRowId; + int inventoryRowId; + int actualSalesRowId; + //Attempt to delete the row from the database by its ID number. + int.TryParse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out projectionsRowId); + int.TryParse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out inventoryRowId); + int.TryParse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out actualSalesRowId); if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId)) { informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database."; @@ -620,9 +628,13 @@ namespace AdvertsingProfitControl if (result == DialogResult.Yes) { //Attempt to delete the row from the database by its ID number. - var projectionsRowId = int.Parse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int) SalesTableColumns.Id].EditedFormattedValue.ToString()); - var inventoryRowId = int.Parse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var actualSalesRowId = int.Parse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); + int projectionsRowId; + int inventoryRowId; + int actualSalesRowId; + //Attempt to delete the row from the database by its ID number. + int.TryParse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out projectionsRowId); + int.TryParse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out inventoryRowId); + int.TryParse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out actualSalesRowId); if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId)) { informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database."; diff --git a/AdvertsingProfitControl/NewModifyRecord.Designer.cs b/AdvertsingProfitControl/NewModifyRecord.Designer.cs index 4c87e43..79224c1 100644 --- a/AdvertsingProfitControl/NewModifyRecord.Designer.cs +++ b/AdvertsingProfitControl/NewModifyRecord.Designer.cs @@ -953,6 +953,9 @@ this.MinimumSize = new System.Drawing.Size(1000, 1000); this.Name = "NewModifyRecord"; this.Text = "Modify Record"; + this.WindowState = System.Windows.Forms.FormWindowState.Maximized; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.NewModifyRecord_FormClosing); + this.Load += new System.EventHandler(this.NewModifyRecord_Load); this.mainLayoutPanel.ResumeLayout(false); this.mainLayoutPanel.PerformLayout(); this.mainMenuStrip.ResumeLayout(false); diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs index cf05366..3691828 100644 --- a/AdvertsingProfitControl/NewModifyRecord.cs +++ b/AdvertsingProfitControl/NewModifyRecord.cs @@ -46,10 +46,9 @@ namespace AdvertsingProfitControl var databaseTracker = new DatabaseTracker(); var databaseReader = new DatabaseReader(); weekEndingCalendar.BoldedDates = databaseReader.RetrieveDates(databaseTracker.DatabaseConnectionString).ToArray(); - weekEndingCalendar.SelectionStart = date; - weekEndingCalendar.DateChanged += ValidateDateChanged; - _currentActiveDate = date; - Text = @"Modify Record (Current Record: " + date.ToString("d") + @")"; + weekEndingCalendar.SelectionStart = date; + _currentActiveDate = date; + weekEndingCalendar.DateChanged += ValidateDateChanged; //next pull all the ad items into memory. _adItemCollection = databaseReader.GetAdItemsSuggestionList(databaseTracker.DatabaseConnectionString); //Now pull all the suppliers and the ad special list into memory. @@ -159,6 +158,7 @@ namespace AdvertsingProfitControl // _debugTabPage = mainTabControl.TabPages[4]; mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]); + Text = @"Modify Record (Current Record: " + date.ToString("d") + @")"; LoadDate(date); } @@ -573,9 +573,13 @@ namespace AdvertsingProfitControl if (result == DialogResult.Yes) { //Attempt to delete the row from the database by its ID number. - var projectionsRowId = int.Parse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var inventoryRowId = int.Parse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var actualSalesRowId = int.Parse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); + int projectionsRowId; + int inventoryRowId; + int actualSalesRowId; + //Attempt to delete the row from the database by its ID number. + int.TryParse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out projectionsRowId); + int.TryParse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out inventoryRowId); + int.TryParse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out actualSalesRowId); if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId)) { informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database."; @@ -602,9 +606,13 @@ namespace AdvertsingProfitControl if (result == DialogResult.Yes) { //Attempt to delete the row from the database by its ID number. - var projectionsRowId = int.Parse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var inventoryRowId = int.Parse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var actualSalesRowId = int.Parse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); + int projectionsRowId; + int inventoryRowId; + int actualSalesRowId; + //Attempt to delete the row from the database by its ID number. + int.TryParse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out projectionsRowId); + int.TryParse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out inventoryRowId); + int.TryParse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out actualSalesRowId); if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId)) { informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database."; @@ -678,12 +686,16 @@ namespace AdvertsingProfitControl if (dataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString() != string.Empty) { //Attempt to delete the row from the database by its ID number. - var projectionsRowId = int.Parse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var inventoryRowId = int.Parse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); - var actualSalesRowId = int.Parse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString()); + int projectionsRowId; + int inventoryRowId; + int actualSalesRowId; + //Attempt to delete the row from the database by its ID number. + int.TryParse(projectionsDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out projectionsRowId); + int.TryParse(inventoryDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out inventoryRowId); + int.TryParse(actualSalesDataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString(), out actualSalesRowId); if (dbWriter.DeleteApcRow(projectionsRowId, inventoryRowId, actualSalesRowId)) { - informationLabel.Text += @"Successfully removed row " + (currentRowIndex + 1) + @" from the database." + Environment.NewLine; + informationLabel.Text = @"Successfully removed row " + (currentRowIndex + 1) + @" from the database."; } else { @@ -3331,11 +3343,32 @@ namespace AdvertsingProfitControl { errorLabel.Text += @"Failed to process actual sales." + Environment.NewLine; } - if (!SaveInvoices(dateId, displayInformation)) return false; - if (!SaveComments(dateId, displayInformation)) return false; - if (!SaveWeeklySales(dateId, displayInformation)) return false; - if (!SaveTaxable(dateId, displayInformation)) return false; - return SaveCostAnalysis(dateId, displayInformation) && success; + if (SaveInvoices(dateId, displayInformation)) + { + success = false; + } + if (!SaveComments(dateId, displayInformation)) + { + success = false; + } + if (!SaveWeeklySales(dateId, displayInformation)) + { + success = false; + } + if (!SaveTaxable(dateId, displayInformation)) + { + success = false; + } + if (!SaveCostAnalysis(dateId, displayInformation)) + { + success = false; + } + //If everything went through properly then set the form as not dirty since all changes are saved. + if (success) + { + _isFormDirty = false; + } + return success; } /// @@ -3896,6 +3929,25 @@ namespace AdvertsingProfitControl SaveRecords(); } + private void NewModifyRecord_FormClosing(object sender, FormClosingEventArgs e) + { + if (!_isFormDirty) return; + var result = MessageBox.Show(@"Would you like to save the changes you have made?", @"Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + if (result == DialogResult.Yes) + { + SaveRecords(false); + } + else if(result == DialogResult.Cancel) + { + e.Cancel = true; + } + } + + private void NewModifyRecord_Load(object sender, EventArgs e) + { + + } + //private void NormalizeApcTables(DataTable projections, DataTable inventory, DataTable actualSales, string dateId) //{ diff --git a/AdvertsingProfitControl/NewModifyRecord.resx b/AdvertsingProfitControl/NewModifyRecord.resx index f80b0f3..d5065fd 100644 --- a/AdvertsingProfitControl/NewModifyRecord.resx +++ b/AdvertsingProfitControl/NewModifyRecord.resx @@ -120,4 +120,7 @@ 17, 17 + + 17, 17 + \ No newline at end of file diff --git a/AdvertsingProfitControl/Properties/AssemblyInfo.cs b/AdvertsingProfitControl/Properties/AssemblyInfo.cs index 3b6b501..43ab7aa 100644 --- a/AdvertsingProfitControl/Properties/AssemblyInfo.cs +++ b/AdvertsingProfitControl/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.0.0")] -[assembly: AssemblyFileVersion("1.9.0.0")] +[assembly: AssemblyVersion("1.9.2.0")] +[assembly: AssemblyFileVersion("1.9.2.0")] diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application deleted file mode 100644 index b72ac56..0000000 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - wL0QcvSIuG+5RpyqBvd2ao+S04py2S9hhxRGkLgzCxI= - - - - \ No newline at end of file diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest deleted file mode 100644 index fe75a8a..0000000 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ /dev/null @@ -1,139 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +wWYuietw+BCATYFQjU6MraHUChvlqs8LdDZ5zoAEB0= - - - - - - - - - - - - VGr+ZzYUr4vMefSbFien3axjDZd7ylgpjfrMKI12ink= - - - - - - - - - - - - WF/zxFwKgeKM8FANZnlU0EY/IhL18w1Px1iKE75KJWM= - - - - - - - - - - e48EkTyChGHXYJETENSLw7RKQ1LZ5ZDUghEtiv5DmqY= - - - - - - - - - 4BSEtKDqq4aQTfxV+PNjxEP3nnJgdxk0ksIfi4xSGI0= - - - - - - - - - HWMXjUaEQtZd0vBm2k4ValXtZwmVzcqV0rERViSzOOc= - - - - - - - - - EhpcVkhatavmpmzYIlqLL5P0WB1QFP8mU66foV/5u+c= - - - - - - - - - - - - - - - - - - - - true/PM - - - \ No newline at end of file