From 9fa2e3c44aeed6e124c424d1012e437cfbe59488 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Fri, 20 Jan 2017 18:30:36 -0600 Subject: [PATCH] Cleaned up the code in the new modify record form and changed the return value from string to integer in the date ID get method. Fixed a crash bug in the new add record form and fixed the row number bug in both forms. --- AdvertsingProfitControl/DatabaseReader.cs | 13 +- AdvertsingProfitControl/FrmAddRecord.cs | 6 +- AdvertsingProfitControl/FrmDeleteRecord.cs | 14 +- AdvertsingProfitControl/FrmMain.cs | 13 +- AdvertsingProfitControl/FrmModifyRecord.cs | 22 +- AdvertsingProfitControl/NewAddRecord.cs | 61 ++-- AdvertsingProfitControl/NewModifyRecord.cs | 313 ++++++++++-------- ...AdvertsingProfitControl.vshost.application | 2 +- ...dvertsingProfitControl.vshost.exe.manifest | 4 +- 9 files changed, 253 insertions(+), 195 deletions(-) diff --git a/AdvertsingProfitControl/DatabaseReader.cs b/AdvertsingProfitControl/DatabaseReader.cs index ed5d404..7532ecb 100644 --- a/AdvertsingProfitControl/DatabaseReader.cs +++ b/AdvertsingProfitControl/DatabaseReader.cs @@ -70,9 +70,16 @@ namespace AdvertsingProfitControl return dateId; } - public string RetrieveDateIdByDateString(string dateString, string connectionString) + /// + /// Returns the date ID of the date string that is passed. + /// Preferred format is short date (1/20/2017). + /// + /// The date to be looked up. + /// The connection to the database. + /// The date ID or zero (0) on fail. + public int RetrieveDateIdByDateString(string dateString, string connectionString) { - var dateId = "0"; + var dateId = 0; var oleDbCommand = new OleDbCommand() { CommandText = "SELECT WeekEnding.ID FROM WeekEnding WHERE WeekEnding.EndOfWeekDate = ?" @@ -90,7 +97,7 @@ namespace AdvertsingProfitControl { while(reader != null && reader.Read()) { - dateId = reader[0].ToString(); + dateId = int.Parse(reader[0].ToString()); } } } diff --git a/AdvertsingProfitControl/FrmAddRecord.cs b/AdvertsingProfitControl/FrmAddRecord.cs index 347706e..19a9ebf 100644 --- a/AdvertsingProfitControl/FrmAddRecord.cs +++ b/AdvertsingProfitControl/FrmAddRecord.cs @@ -1195,7 +1195,7 @@ namespace AdvertsingProfitControl var databaseWriter = new DatabaseWriter(databaseTracker.DatabaseConnectionString); if (weekEndingDateMaskedTextBox.MaskCompleted) { - if (databaseReader.RetrieveDateIdByDateString(weekEndingDateMaskedTextBox.Text, databaseTracker.DatabaseConnectionString) == "0") + if (databaseReader.RetrieveDateIdByDateString(weekEndingDateMaskedTextBox.Text, databaseTracker.DatabaseConnectionString) == 0) { //Assume the date is correct and add it to the database. //TODO: Check the date vs the last date entered (obtained by sorting dates) and check to see if the two are seven (7) or more days apart. @@ -1217,12 +1217,12 @@ namespace AdvertsingProfitControl var commentsText = commentsTextBox.Text; if (Regex.Replace(commentsText, @"\s+", "") != "") { - databaseWriter.RedundantlessInsertIntoComments(commentsTextBox.Text, dateIdString); + databaseWriter.RedundantlessInsertIntoComments(commentsTextBox.Text, dateIdString.ToString()); } //Send the table's data to their respective functions. _gLogConsole.WriteToLog(FrmLogConsole.Level.Info, "Added the following rows to the APC table:"); - var rowsEffected = BuildAPCAndSendToDatabase(dateIdString); + var rowsEffected = BuildAPCAndSendToDatabase(dateIdString.ToString()); foreach (var i in rowsEffected) { _gLogConsole.WriteToLog(FrmLogConsole.Level.Info, (i + 1).ToString()); diff --git a/AdvertsingProfitControl/FrmDeleteRecord.cs b/AdvertsingProfitControl/FrmDeleteRecord.cs index f205d0f..bde3c19 100644 --- a/AdvertsingProfitControl/FrmDeleteRecord.cs +++ b/AdvertsingProfitControl/FrmDeleteRecord.cs @@ -45,14 +45,14 @@ namespace AdvertsingProfitControl var databaseWriter = new DatabaseWriter(databaseTracker.DatabaseConnectionString); var dateId = databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString); - if (dateId == "0") + if (dateId == 0) { informationLabel.Text = "An error has occurred trying to obtain the ID\nfor the date " + monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text + "."; } var supplierName = dataGridView.Rows[e.Row.Index].Cells[0].EditedFormattedValue.ToString(); var invoiceNumber = dataGridView.Rows[e.Row.Index].Cells[1].EditedFormattedValue.ToString(); - var count = databaseWriter.RemoveInvoice(invoiceNumber, dateId); + var count = databaseWriter.RemoveInvoice(invoiceNumber, dateId.ToString()); if (count == 1) { @@ -85,8 +85,8 @@ namespace AdvertsingProfitControl var dateId = databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString); - if (dateId == "0"){ informationLabel.Text = "unable to find date in database."; return; } - var recordsAffected = datbaseWriter.UpdateCommentsByDateId(commentsTextBox.Text, dateId); + if (dateId == 0){ informationLabel.Text = "unable to find date in database."; return; } + var recordsAffected = datbaseWriter.UpdateCommentsByDateId(commentsTextBox.Text, dateId.ToString()); if (recordsAffected == true) { informationLabel.Text = "Successfully updated the comments for the selected date."; @@ -115,7 +115,7 @@ namespace AdvertsingProfitControl var dateId = databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString); var adItemName = e.Row.Cells[0].EditedFormattedValue.ToString(); var adItemId = databaseReader.RetrieveAdItemId(adItemName, databaseTracker.DatabaseConnectionString); - var count = databaseWriter.RemoveRecord(adItemId, dateId); + var count = databaseWriter.RemoveRecord(adItemId, dateId.ToString()); if (count == 1) { @@ -176,7 +176,7 @@ namespace AdvertsingProfitControl else { //ELSE IF one was passed, then use it's ID to build the tables. - dateId = dataBaseReader.RetrieveDateIdByDateString(dateString, databaseTracker.DatabaseConnectionString); + dateId = dataBaseReader.RetrieveDateIdByDateString(dateString, databaseTracker.DatabaseConnectionString).ToString(); _console.WriteToLog(FrmLogConsole.Level.Info, dateId != "0" ? "Date ID for " + dateString + " is resolved to have the ID of " + dateId + "." : "The date " + dateString + " could not be found in the database."); if (dateId == "0") { @@ -424,7 +424,7 @@ namespace AdvertsingProfitControl var dateId = databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString); - var recordsAffected = databaseWriter.RemoveAllEntriesAndYearById(dateId); + var recordsAffected = databaseWriter.RemoveAllEntriesAndYearById(dateId.ToString()); if (recordsAffected > 0) { informationLabel.Text = "Successfully removed " + recordsAffected.ToString() + diff --git a/AdvertsingProfitControl/FrmMain.cs b/AdvertsingProfitControl/FrmMain.cs index 100864e..442075b 100644 --- a/AdvertsingProfitControl/FrmMain.cs +++ b/AdvertsingProfitControl/FrmMain.cs @@ -79,7 +79,7 @@ namespace AdvertsingProfitControl else { //ELSE IF one was passed, then use it's ID to build the tables. - dateId = dataBaseReader.RetrieveDateIdByDateString(dateString, databaseTracker.DatabaseConnectionString); + dateId = dataBaseReader.RetrieveDateIdByDateString(dateString, databaseTracker.DatabaseConnectionString).ToString(); _console.WriteToLog(FrmLogConsole.Level.Info, dateId != "0" ? "Date ID for " + dateString + " is resolved to have the ID of " + dateId + "." : "The date " + dateString + " could not be found in the database."); if (dateId == "0") { @@ -727,11 +727,11 @@ namespace AdvertsingProfitControl double remaingingSales = _departmentSales - _SalesProducedByAdItems; double totalProfitReturnFromReminaingSales = remaingingSales*.3; double totalProfitReturn = _TotalProfitReturnFromAdItems + totalProfitReturnFromReminaingSales; - test.BuildFormFrontCompressedLayout(dateId, _departmentSales, _SalesProducedByAdItems, remaingingSales, + test.BuildFormFrontCompressedLayout(dateId.ToString(), _departmentSales, _SalesProducedByAdItems, remaingingSales, _TotalProfitReturnFromAdItems, totalProfitReturnFromReminaingSales, totalProfitReturn, commentsTextBox.Text); test.RenderHtmlToImage(); - backPageTest.GenerateWeeklyInventoryControlPage(dateId); + backPageTest.GenerateWeeklyInventoryControlPage(dateId.ToString()); backPageTest.RenderHtmlToImage(); } else @@ -765,6 +765,13 @@ namespace AdvertsingProfitControl var form = new NewModifyRecord(date); form.ShowDialog(); } + + public enum FormRoll + { + AddRecords = 0, + ModifyRecords = 1, + DeleteRecords = 2 + } } //http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children diff --git a/AdvertsingProfitControl/FrmModifyRecord.cs b/AdvertsingProfitControl/FrmModifyRecord.cs index d33a64c..9819de3 100644 --- a/AdvertsingProfitControl/FrmModifyRecord.cs +++ b/AdvertsingProfitControl/FrmModifyRecord.cs @@ -640,7 +640,7 @@ namespace AdvertsingProfitControl { var databaseTracker = new DatabaseTracker(); var databaseReader = new DatabaseReader(); - FillDataGridViews(databaseReader.RetrieveDateIdByDateString(monthComboBox.SelectedItem + "/" + dayComboBox.SelectedItem + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString)); + FillDataGridViews(databaseReader.RetrieveDateIdByDateString(monthComboBox.SelectedItem + "/" + dayComboBox.SelectedItem + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString).ToString()); } private void FillDateSuggestionComboBoxes() @@ -817,7 +817,7 @@ namespace AdvertsingProfitControl //Now re-register the event handlers monthComboBox.SelectedIndexChanged += UpdateDaysOfMonth; dayComboBox.SelectedIndexChanged += UpdateDataGridViewInformation; - FillDataGridViews(databaseReader.RetrieveDateIdByDateString(monthComboBox.SelectedItem + "/" + dayComboBox.SelectedItem + "/" + year, databaseTracker.DatabaseConnectionString)); + FillDataGridViews(databaseReader.RetrieveDateIdByDateString(monthComboBox.SelectedItem + "/" + dayComboBox.SelectedItem + "/" + year, databaseTracker.DatabaseConnectionString).ToString()); } #endregion @@ -1334,7 +1334,7 @@ namespace AdvertsingProfitControl if (_adSpecialIndex == -1 || currentRowIndex < _adSpecialIndex) { //Clear the database of the item. - var count = databaseWriter.RemoveRecord(adItemId, dateId); + var count = databaseWriter.RemoveRecord(adItemId, dateId.ToString()); if (count == 1) { @@ -1356,7 +1356,7 @@ namespace AdvertsingProfitControl else if (currentRowIndex > _adSpecialIndex) { //Clear the database of the item. - var count = databaseWriter.RemoveRecord(adItemId, dateId); + var count = databaseWriter.RemoveRecord(adItemId, dateId.ToString()); if (count == 1) { @@ -1398,7 +1398,7 @@ namespace AdvertsingProfitControl if (adItemName == "") break; adItemId = databaseReader.RetrieveAdItemId(adItemName, databaseTracker.DatabaseConnectionString); //Clear the database of the item. - var count = databaseWriter.RemoveRecord(adItemId, dateId); + var count = databaseWriter.RemoveRecord(adItemId, dateId.ToString()); if (count == 1) { @@ -2497,8 +2497,8 @@ namespace AdvertsingProfitControl var dateId = databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString); - if (dateId == "0") { notificationLabel.Text = "unable to find date in database."; return; } - var recordsAffected = databaseWriter.UpdateCommentsByDateId(commentsTextBox.Text, dateId); + if (dateId == 0) { notificationLabel.Text = "unable to find date in database."; return; } + var recordsAffected = databaseWriter.UpdateCommentsByDateId(commentsTextBox.Text, dateId.ToString()); if (recordsAffected == true) { notificationLabel.Text = "Successfully updated the comments for the selected date."; @@ -2506,7 +2506,7 @@ namespace AdvertsingProfitControl else { //Try adding a new record as there could be no comments in the database. - var rowsEffected = databaseWriter.RedundantlessInsertIntoComments(commentsTextBox.Text, dateId); + var rowsEffected = databaseWriter.RedundantlessInsertIntoComments(commentsTextBox.Text, dateId.ToString()); if (rowsEffected) { notificationLabel.Text = "Successfully added the comments for the selected date."; @@ -2654,9 +2654,9 @@ namespace AdvertsingProfitControl var databaseTracker = new DatabaseTracker(); var databaseReader = new DatabaseReader(); var dateId = databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString); - UpdateApcTables(dateId); - UpdateInvoicesTable(dateId); - UpdateWeeklySales(dateId); + UpdateApcTables(dateId.ToString()); + UpdateInvoicesTable(dateId.ToString()); + UpdateWeeklySales(dateId.ToString()); } } } diff --git a/AdvertsingProfitControl/NewAddRecord.cs b/AdvertsingProfitControl/NewAddRecord.cs index 0a2cde5..f69a127 100644 --- a/AdvertsingProfitControl/NewAddRecord.cs +++ b/AdvertsingProfitControl/NewAddRecord.cs @@ -1052,6 +1052,7 @@ namespace AdvertsingProfitControl } } actualSalesDataGridView.Rows.Add(rowContents); + actualSalesDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); //Build a collection of objects for the inventory table to use. var inventoryNewRow = new object[inventoryDataGridView.ColumnCount]; //Spin through the DataGridViewCells in the row and add their contents to an array. @@ -1083,6 +1084,7 @@ namespace AdvertsingProfitControl } } inventoryDataGridView.Rows.Add(inventoryNewRow); + inventoryDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); //Set the row headers of the other tables to show up as pending; this row is valid without a doubt. if (e.RowIndex != _adSpecialIndex) { @@ -1398,7 +1400,9 @@ namespace AdvertsingProfitControl } } projectionsDataGridView.Rows.Add(rowContents); + projectionsDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); actualSalesDataGridView.Rows.Add(rowContents); + actualSalesDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); if (e.RowIndex != _adSpecialIndex) { //Apply color coding to the respective row headers on the other tables. @@ -1570,6 +1574,7 @@ namespace AdvertsingProfitControl } } projectionsDataGridView.Rows.Add(rowContents); + projectionsDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); //Build a collection of objects for the inventory table to use. var inventoryNewRow = new object[inventoryDataGridView.ColumnCount]; //Spin through the DataGridViewCells in the row and add their contents to an array. @@ -1598,7 +1603,7 @@ namespace AdvertsingProfitControl } } inventoryDataGridView.Rows.Add(inventoryNewRow); - + inventoryDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); if (e.RowIndex != _adSpecialIndex) { //Apply color coding to the respective row headers on the other tables. @@ -2094,47 +2099,31 @@ namespace AdvertsingProfitControl var dbW = new DatabaseWriter(dbT.DatabaseConnectionString); var dbR = new DatabaseReader(); //Obtain the date ID. - int dateId; - if ( - int.TryParse(dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), - dbT.DatabaseConnectionString), out dateId)) + var dateId = dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), dbT.DatabaseConnectionString); + //If the ID is zero (0) that means the date isn't in the database so simply insert it. + if (dateId == 0) { - //If the ID is zero (0) that means the date isn't in the database so simply insert it. - if (dateId == 0) + //Try inserting the date string. + if (dbW.InsertIntoWeekEnding(weekEndingCalendar.SelectionStart.ToString("d"))) { - //Try inserting the date string. - if (dbW.InsertIntoWeekEnding(weekEndingCalendar.SelectionStart.ToString("d"))) + dateId = dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), dbT.DatabaseConnectionString); + //Now if its still zero (0) then that means something went really wrong and failed to insert. + if (dateId == 0) { - if ( - int.TryParse( - dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), - dbT.DatabaseConnectionString), out dateId)) - { - //Now if its still zero (0) then that means something went really wrong and failed to insert. - if (dateId == 0) - { - MessageBox.Show( - @"Failed to retrieve date ID after supposedly inserting the date into the database.", - @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - else - { - MessageBox.Show( - @"You really should not be able to see this message. If you are well that means something really weird happened converting text into a number, that is hard-coded to not fail on conversion. Either way I couldn't get the date ID due to some error, check the logs if you're curious.", - @"Well This Is Awkwardly Nested...", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - else - { - //The above method reports that it failed to insert the date into the database. - MessageBox.Show(@"Failed to insert the date '" + weekEndingCalendar.SelectionStart.ToString("d") + @"' into the database.", @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show( + @"Failed to retrieve date ID after supposedly inserting the date into the database.", + @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } + else + { + //The above method reports that it failed to insert the date into the database. + MessageBox.Show(@"Failed to insert the date '" + weekEndingCalendar.SelectionStart.ToString("d") + @"' into the database.", @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } } + informationLabel.Text = ""; //Run the row parsing engine on all the APC tables. @@ -2242,7 +2231,7 @@ namespace AdvertsingProfitControl 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] = wednesdayTaxableTextBox.Text == "" ? 0 : double.Parse(wednesdayWeeklySalesTextBox.Text); + weeklySales[3] = wednesdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(wednesdayWeeklySalesTextBox.Text); weeklySales[4] = thursdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(thursdayWeeklySalesTextBox.Text); diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs index 8e4779f..3af6f9f 100644 --- a/AdvertsingProfitControl/NewModifyRecord.cs +++ b/AdvertsingProfitControl/NewModifyRecord.cs @@ -12,6 +12,7 @@ namespace AdvertsingProfitControl { public partial class NewModifyRecord : Form { + //http://stackoverflow.com/questions/6219454/efficient-way-to-remove-all-whitespace-from-string private static readonly FrmLogConsole LogConsole = FrmLogConsole.GetStaticInstance; //Create an array that contains all the ad items from the database. private readonly List _adItemCollection; @@ -28,7 +29,7 @@ namespace AdvertsingProfitControl private readonly List[] _usedAdItems = new List[2]; //This string keeps track of the last ad item used. This item can then be used to safely remove an ad item from the list of used items. //Used in the OnCellValidating event to store the last ad item used in the event that the user changes a row that already exists. - private string _beginningCellValue = ""; + private string _beginningCellValue = string.Empty; //Flag showing whether or not the AdSpecialRow has been made in this session. private int _adSpecialIndex = -1; private readonly AdvertisingProfitControlTableHelper _tableHelperFunctions = new AdvertisingProfitControlTableHelper(); @@ -173,7 +174,7 @@ namespace AdvertsingProfitControl private void StoreBeginningTextBoxValue(object sender, EventArgs e) { var textBox = (TextBox)sender; - _beginningCellValue = textBox.Text; + _beginningCellValue = textBox.Text.Trim(); } #endregion @@ -192,7 +193,7 @@ namespace AdvertsingProfitControl if (dataGridView.Rows[e.RowIndex].IsNewRow) return; DateTime dateTime; //Check to make sure the Invoice Date, Invoice Number and the Supplier values are set. - if (dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString() == "" || !DateTime.TryParse(dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString(), out dateTime)) + if (dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString().Length == 0 || !DateTime.TryParse(dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.InvoiceDate].EditedFormattedValue.ToString(), out dateTime)) { dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError; MessageBox.Show(@"An invoice date must be specified.", @"Invalid Invoice Date", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -201,7 +202,7 @@ namespace AdvertsingProfitControl return; } - if (dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue.ToString() == "") + if (dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.Supplier].EditedFormattedValue.ToString().Trim().Length == 0) { dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError; MessageBox.Show(@"A supplier must be specified.", @"Invalid Supplier", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -212,7 +213,7 @@ namespace AdvertsingProfitControl if ( dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue - .ToString() == "") + .ToString().Trim().Length == 0) { dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError; MessageBox.Show(@"An invoice number must be specified.", @"Invalid Invoice Number", MessageBoxButtons.OK, @@ -253,8 +254,8 @@ namespace AdvertsingProfitControl { case (int)InvoiceTableColumns.InvoiceDate: //Clear any error text a cell has for this column. - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; - if (userInput != "") + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = string.Empty; + if (userInput != string.Empty) { DateTime date; //Try parsing the date to make sure its valid, otherwise clear it from the cell and inform the user. @@ -268,19 +269,19 @@ namespace AdvertsingProfitControl { MessageBox.Show(@"The date '" + userInput + @"' is not a valid date.", @"Invalid Date", MessageBoxButtons.OK, MessageBoxIcon.Error); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Invoice Date Must be in a Valid Format"; - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; } } else { - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "An Invoice Date is Required"; } break; case (int)InvoiceTableColumns.InvoiceNumber: //Clear any error text a cell has for this column. - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; - if (userInput != "") + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = string.Empty; + if (userInput != string.Empty) { long parsedNumber; if (long.TryParse(userInput, out parsedNumber)) @@ -292,20 +293,20 @@ namespace AdvertsingProfitControl else { MessageBox.Show(@"The invoice number must be a numeric value.", @"Non Numeric Invoice Number", MessageBoxButtons.OK, MessageBoxIcon.Error); - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Invoice Number Must be Numeric"; } } else { - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "An Invoice Number is Required"; } break; case (int)InvoiceTableColumns.Supplier: //Clear any error text a cell has for this column. - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; - if (userInput != "") + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = string.Empty; + if (userInput != string.Empty) { //TODO: Create a custom engine to do this. //Pretty up the entered text since there is something here. @@ -315,7 +316,7 @@ namespace AdvertsingProfitControl } else { - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "A Supplier is Required"; } break; @@ -329,10 +330,10 @@ namespace AdvertsingProfitControl if (e.ColumnIndex != (int)InvoiceTableColumns.Id && e.ColumnIndex < (int)InvoiceTableColumns.InvoiceNote) { - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = string.Empty; //Now check to make sure the user input isn't null //Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US")); - if (userInput != "") + if (userInput != string.Empty) { double parsedNumber; if (double.TryParse(userInput, out parsedNumber)) @@ -344,7 +345,7 @@ namespace AdvertsingProfitControl } else { - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Only Numeric Values Allowed."; } } @@ -381,7 +382,7 @@ namespace AdvertsingProfitControl { var rowIndex = e.Row.Index; //See if there is an ID number in the ID column. - if (invoicesDataGridView.Rows[rowIndex].Cells[(int)InvoiceTableColumns.Id].EditedFormattedValue.ToString() == "") return; + if (invoicesDataGridView.Rows[rowIndex].Cells[(int)InvoiceTableColumns.Id].EditedFormattedValue.ToString() == string.Empty) return; //Ask the user to make damn sure they want to remove this record. var result = MessageBox.Show(@"Deleting this row will remove it from the database permanently. Do you wish to continue?", @"Remove Invoice Number " + invoicesDataGridView.Rows[rowIndex].Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) @@ -420,10 +421,11 @@ namespace AdvertsingProfitControl /// /// /// - private static void DisplayRowNumbers(object sender, DataGridViewRowsAddedEventArgs e) + private void DisplayRowNumbers(object sender, DataGridViewRowsAddedEventArgs e) { var table = ((DataGridView)sender); table.Rows[e.RowIndex].HeaderCell.Value = (e.RowIndex + 1).ToString(); + LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Added row at Index " + e.RowIndex + " in " + table.Name + "."); } /// @@ -467,7 +469,7 @@ namespace AdvertsingProfitControl //Paint the rows to identify what group they belong to. _tableHelperFunctions.PaintRowGroupsFromIndex(e.RowIndex, dataGridView); //Add in used Ad Items to the list. - if (userInput == "") return; + if (userInput == string.Empty) return; //Clear the old ad item out of the used ad item collection. var parser = new RowParsing(); if (parser.GetRowAttribute(dataGridView.Rows[e.RowIndex]) == RowAttribute.AdSpecialRow) @@ -480,14 +482,12 @@ namespace AdvertsingProfitControl { if (_usedAdItems[0].Contains(userInput)) return; _usedAdItems[0].Add(userInput); - LogConsole.WriteToLog(FrmLogConsole.Level.Debug, "Adding \"" + userInput + "\" to section one (1)."); } //Section two (2) detected. else { if (_usedAdItems[1].Contains(userInput)) return; _usedAdItems[1].Add(userInput); - LogConsole.WriteToLog(FrmLogConsole.Level.Debug, "Adding \"" + userInput + "\" to section two (2)."); } } @@ -563,7 +563,7 @@ namespace AdvertsingProfitControl if (_adSpecialIndex == -1) { //If the ID number is set, i.e. not equal to null then attempt to remove it from the database. - if (dataGridView.Rows[currentRowIndex].Cells[0].EditedFormattedValue.ToString() != "") + if (dataGridView.Rows[currentRowIndex].Cells[0].EditedFormattedValue.ToString() != string.Empty) { var result = MessageBox.Show(@"Removing this row will permanently delete this record from the database. Do you wish to continue?", @"Remove " + dataGridView.Rows[currentRowIndex].Cells[1].EditedFormattedValue, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) @@ -592,7 +592,7 @@ namespace AdvertsingProfitControl else if (currentRowIndex < _adSpecialIndex) { //If the ID number is set, i.e. not equal to null then attempt to remove it from the database. - if (dataGridView.Rows[currentRowIndex].Cells[0].EditedFormattedValue.ToString() != "") + if (dataGridView.Rows[currentRowIndex].Cells[0].EditedFormattedValue.ToString() != string.Empty) { var result = MessageBox.Show(@"Removing this row will permanently delete this record from the database. Do you wish to continue?", @"Remove " + dataGridView.Rows[currentRowIndex].Cells[1].EditedFormattedValue, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) @@ -623,7 +623,7 @@ namespace AdvertsingProfitControl else if (currentRowIndex > _adSpecialIndex) { //If the ID number is set, i.e. not equal to null then attempt to remove it from the database. - if (dataGridView.Rows[currentRowIndex].Cells[0].EditedFormattedValue.ToString() != "") + if (dataGridView.Rows[currentRowIndex].Cells[0].EditedFormattedValue.ToString() != string.Empty) { var result = MessageBox.Show(@"Removing this row will permanently delete this record from the database. Do you wish to continue?", @"Remove " + dataGridView.Rows[currentRowIndex].Cells[1].EditedFormattedValue, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) @@ -671,7 +671,7 @@ namespace AdvertsingProfitControl if (projectionsDataGridView.RowCount == inventoryDataGridView.RowCount && projectionsDataGridView.RowCount == actualSalesDataGridView.RowCount) { - if (dataGridView.Rows[currentRowIndex].Cells[(int)SalesTableColumns.Id].EditedFormattedValue.ToString() != "") + 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()); @@ -730,7 +730,7 @@ namespace AdvertsingProfitControl private void ChangeAutoCompleteListOnKeyCombo(object sender, KeyEventArgs e) { var textBox = (TextBox)sender; - informationLabel.Text = ""; + informationLabel.Text = string.Empty; if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.S) { @@ -855,10 +855,10 @@ namespace AdvertsingProfitControl { case (int)SalesTableColumns.AdItem: //Ad Item //If there is text after all the whitespace has been cleared, clear the error text property regardless of whether or not it is set. - if (!string.IsNullOrEmpty(Regex.Replace(userInput, @"\s+", ""))) + if (!string.IsNullOrEmpty(Regex.Replace(userInput, @"\s+", string.Empty))) { //Clear the error text since there is in fact an item entered. - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = string.Empty; //Send the ad item text through the formatting engine and assign the new value to the cell. dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = TextFormat.FormatAdItemText(userInput); var parser = new RowParsing(); @@ -905,12 +905,12 @@ namespace AdvertsingProfitControl } else { - if (userInput == "") + if (userInput == string.Empty) { return; } MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected"); - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; dataGridView.RefreshEdit(); e.Cancel = true; return; @@ -925,9 +925,9 @@ namespace AdvertsingProfitControl { //Grab the input and split it at the forward slash (/) for formatting. var input = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString(); - input = input.Replace(" ", ""); + input = input.Replace(" ", string.Empty); //Remove any dollar signs as these cause errors. - input = input.Replace("$", ""); + input = input.Replace("$", string.Empty); var stringArray = input.Split('/'); //Format the last number as Currency, and round it up if necessary. dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = @@ -947,12 +947,12 @@ namespace AdvertsingProfitControl } else { - if (userInput == "") + if (userInput == string.Empty) { return; } MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected"); - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; dataGridView.RefreshEdit(); e.Cancel = true; return; @@ -970,12 +970,12 @@ namespace AdvertsingProfitControl } else { - if (userInput == "") + if (userInput == string.Empty) { return; } MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected"); - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; dataGridView.RefreshEdit(); e.Cancel = true; return; @@ -1008,7 +1008,7 @@ namespace AdvertsingProfitControl return; } //Clear all whitespace and check for a null value in the ad item column. - if (Regex.Replace(projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", "") == "") + if (Regex.Replace(projectionsDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", string.Empty) == string.Empty) { projectionsDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError; MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified"); @@ -1064,9 +1064,9 @@ namespace AdvertsingProfitControl break; case (int)SalesTableColumns.SalePrice: //IF the Sale Price cell is empty then place 0.00 into the array as a place holder value (assuming this row is a HeaderRow). - if (projectionsDataGridView.Rows[e.RowIndex].Cells[i].EditedFormattedValue.ToString() == "") + if (projectionsDataGridView.Rows[e.RowIndex].Cells[i].EditedFormattedValue.ToString() == string.Empty) { - rowContents[i] = ""; + rowContents[i] = string.Empty; } //ELSE place the value from the Projections table into the array, since Sale Price can be determined before actual data is used. else @@ -1076,9 +1076,9 @@ namespace AdvertsingProfitControl break; case (int)SalesTableColumns.Cost: //IF the Cost cell is empty then place 0.00 into the array as a place holder value (assuming this row is a HeaderRow). - if (projectionsDataGridView.Rows[e.RowIndex].Cells[i].EditedFormattedValue.ToString() == "") + if (projectionsDataGridView.Rows[e.RowIndex].Cells[i].EditedFormattedValue.ToString() == string.Empty) { - rowContents[i] = ""; + rowContents[i] = string.Empty; } //ELSE place the value from the Projections table into the array, since Cost can be determined before actual data is used. else @@ -1096,11 +1096,12 @@ namespace AdvertsingProfitControl rowContents[i] = false; break; default: - rowContents[i] = ""; + rowContents[i] = string.Empty; break; } } actualSalesDataGridView.Rows.Add(rowContents); + actualSalesDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); //Build a collection of objects for the inventory table to use. var inventoryNewRow = new object[inventoryDataGridView.ColumnCount]; //Spin through the DataGridViewCells in the row and add their contents to an array. @@ -1110,7 +1111,7 @@ namespace AdvertsingProfitControl switch (i) { case (int)SalesTableColumns.Id: - inventoryNewRow[(int)InventoryTableColumns.Id] = ""; + inventoryNewRow[(int)InventoryTableColumns.Id] = string.Empty; break; case (int)SalesTableColumns.AdItem: inventoryNewRow[(int)InventoryTableColumns.AdItem] = @@ -1127,11 +1128,12 @@ namespace AdvertsingProfitControl break; default: if (i > (int)InventoryTableColumns.IsHeaderRow) continue; - inventoryNewRow[i] = ""; + inventoryNewRow[i] = string.Empty; break; } } inventoryDataGridView.Rows.Add(inventoryNewRow); + inventoryDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); //Set the row headers of the other tables to show up as pending; this row is valid without a doubt. if (e.RowIndex != _adSpecialIndex) { @@ -1304,10 +1306,10 @@ namespace AdvertsingProfitControl { case (int)InventoryTableColumns.AdItem: //If there is text after all the whitespace has been cleared, clear the error text property regardless of whether or not it is set. - if (!string.IsNullOrEmpty(Regex.Replace(userInput, @"\s+", ""))) + if (!string.IsNullOrEmpty(Regex.Replace(userInput, @"\s+", string.Empty))) { //Clear the error text since there is in fact an item entered. - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = string.Empty; //Send the ad item text through the formatting engine and assign the new value to the cell. dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = TextFormat.FormatAdItemText(userInput); var parser = new RowParsing(); @@ -1348,7 +1350,7 @@ namespace AdvertsingProfitControl } double parsedNumber; //Try parsing the text entered as a number and if that fails then break out and clear the value entered. - if (userInput != "" && double.TryParse(userInput, out parsedNumber)) + if (userInput != string.Empty && double.TryParse(userInput, out parsedNumber)) { //Add the value to the cell. dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = userInput; @@ -1357,10 +1359,10 @@ namespace AdvertsingProfitControl return; } //Prevent the user from being bombarded by message boxes. All validation has been completed at this point so there's nothing to worry about. - if (userInput != "") + if (userInput != string.Empty) { MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected"); - dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ""; + dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty; dataGridView.RefreshEdit(); e.Cancel = true; } @@ -1388,7 +1390,7 @@ namespace AdvertsingProfitControl return; } //Clear all whitespace and check for a null value in the ad item column. - if (Regex.Replace(inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", "") == "") + if (Regex.Replace(inventoryDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", string.Empty) == string.Empty) { inventoryDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError; MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified"); @@ -1451,12 +1453,14 @@ namespace AdvertsingProfitControl rowContents[i] = false; break; default: - rowContents[i] = ""; + rowContents[i] = string.Empty; break; } } projectionsDataGridView.Rows.Add(rowContents); + projectionsDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); actualSalesDataGridView.Rows.Add(rowContents); + actualSalesDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); if (e.RowIndex != _adSpecialIndex) { //Apply color coding to the respective row headers on the other tables. @@ -1554,7 +1558,7 @@ namespace AdvertsingProfitControl return; } //Clear all whitespace and check for a null value in the ad item column. - if (Regex.Replace(actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", "") == "") + if (Regex.Replace(actualSalesDataGridView.Rows[e.RowIndex].Cells[adItemIndex].EditedFormattedValue.ToString(), @"\s+", string.Empty) == string.Empty) { actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError; MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified"); @@ -1624,11 +1628,12 @@ namespace AdvertsingProfitControl rowContents[i] = false; break; default: - rowContents[i] = ""; + rowContents[i] = string.Empty; break; } } projectionsDataGridView.Rows.Add(rowContents); + projectionsDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); //Build a collection of objects for the inventory table to use. var inventoryNewRow = new object[inventoryDataGridView.ColumnCount]; //Spin through the DataGridViewCells in the row and add their contents to an array. @@ -1652,12 +1657,12 @@ namespace AdvertsingProfitControl break; default: if (i > (int)InventoryTableColumns.IsHeaderRow) continue; - inventoryNewRow[i] = ""; + inventoryNewRow[i] = string.Empty; break; } } inventoryDataGridView.Rows.Add(inventoryNewRow); - + inventoryDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString(); if (e.RowIndex != _adSpecialIndex) { //Apply color coding to the respective row headers on the other tables. @@ -1918,7 +1923,7 @@ namespace AdvertsingProfitControl { if (commentsTextBox.Text == _beginningCellValue) return; //Clear white spaces and check if the string is null. - if (commentsTextBox.Text.Trim() == "" && isCommentDirtyCheckBox.Tag == null) + if (commentsTextBox.Text.Trim() == string.Empty && isCommentDirtyCheckBox.Tag == null) { //The user cleared the comment(s) they were making but the comments were never committed to the database. //So the comments are no longer dirty. @@ -1948,7 +1953,7 @@ namespace AdvertsingProfitControl var textBox = (TextBox)sender; if (_beginningCellValue == textBox.Text) return; //There was a change to the starting value of the text box if we've made it this far. - if (textBox.Text != "") + if (textBox.Text != string.Empty) { double dollarValue; if (double.TryParse(textBox.Text.Trim(), out dollarValue)) @@ -1959,12 +1964,12 @@ namespace AdvertsingProfitControl //And apply formatting. textBox.Text = Math.Round(dollarValue, 2).ToString("N", new CultureInfo("en-US")); //Check to see if the number is equal to zero (0) i.e. "0.00". - if (textBox.Text == @"0.00") textBox.Text = ""; + if (textBox.Text == @"0.00") textBox.Text = string.Empty; } else { MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric"); - textBox.Text = ""; + textBox.Text = string.Empty; } } if (isWeeklySalesDirtyCheckBox.Tag != null) @@ -1974,13 +1979,13 @@ namespace AdvertsingProfitControl } //Update the total sales text box before returning. var totalWeeklySales = 0.00; - if (sundayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(sundayWeeklySalesTextBox.Text); - if (mondayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(mondayWeeklySalesTextBox.Text); - if (tuesdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(tuesdayWeeklySalesTextBox.Text); - if (wednesdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(wednesdayWeeklySalesTextBox.Text); - if (thursdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(thursdayWeeklySalesTextBox.Text); - if (fridayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(fridayWeeklySalesTextBox.Text); - if (saturdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(saturdayWeeklySalesTextBox.Text); + if (sundayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(sundayWeeklySalesTextBox.Text); + if (mondayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(mondayWeeklySalesTextBox.Text); + if (tuesdayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(tuesdayWeeklySalesTextBox.Text); + if (wednesdayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(wednesdayWeeklySalesTextBox.Text); + if (thursdayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(thursdayWeeklySalesTextBox.Text); + if (fridayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(fridayWeeklySalesTextBox.Text); + if (saturdayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(saturdayWeeklySalesTextBox.Text); if (Math.Abs(totalWeeklySales) > 0) { totalWeeklySalesTextBox.Text = totalWeeklySales.ToString("N", new CultureInfo("en-US")); @@ -1993,14 +1998,14 @@ namespace AdvertsingProfitControl //If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag. isWeeklySalesDirtyCheckBox.Checked = false; } - else if (isWeeklySalesDirtyCheckBox.Tag != null && textBox.Text == "") + else if (isWeeklySalesDirtyCheckBox.Tag != null && textBox.Text == string.Empty) { //If the user has already added the fields to the database but has removed a value //update that accordingly. isWeeklySalesDirtyCheckBox.Checked = true; _isFormDirty = true; } - totalWeeklySalesTextBox.Text = ""; + totalWeeklySalesTextBox.Text = string.Empty; } } @@ -2018,7 +2023,7 @@ namespace AdvertsingProfitControl var textBox = (TextBox)sender; if (_beginningCellValue == textBox.Text) return; //There was a change to the starting value of the text box if we've made it this far. - if (textBox.Text != "") + if (textBox.Text != string.Empty) { double dollarValue; if (double.TryParse(textBox.Text.Trim(), out dollarValue)) @@ -2029,12 +2034,12 @@ namespace AdvertsingProfitControl //And apply formatting. textBox.Text = Math.Round(dollarValue, 2).ToString("N", new CultureInfo("en-US")); //Check to see if the number is equal to zero (0) i.e. "0.00". - if (textBox.Text == @"0.00") textBox.Text = ""; + if (textBox.Text == @"0.00") textBox.Text = string.Empty; } else { MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric"); - textBox.Text = ""; + textBox.Text = string.Empty; } } if (isTaxableDirtyCheckBox.Tag != null) @@ -2044,13 +2049,13 @@ namespace AdvertsingProfitControl } //Update the total sales text box before returning. var totalTaxable = 0.00; - if (sundayTaxableTextBox.Text != "") totalTaxable += double.Parse(sundayTaxableTextBox.Text); - if (mondayTaxableTextBox.Text != "") totalTaxable += double.Parse(mondayTaxableTextBox.Text); - if (tuesdayTaxableTextBox.Text != "") totalTaxable += double.Parse(tuesdayTaxableTextBox.Text); - if (wednesdayTaxableTextBox.Text != "") totalTaxable += double.Parse(wednesdayTaxableTextBox.Text); - if (thursdayTaxableTextBox.Text != "") totalTaxable += double.Parse(thursdayTaxableTextBox.Text); - if (fridayTaxableTextBox.Text != "") totalTaxable += double.Parse(fridayTaxableTextBox.Text); - if (saturdayTaxableTextBox.Text != "") totalTaxable += double.Parse(saturdayTaxableTextBox.Text); + if (sundayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(sundayTaxableTextBox.Text); + if (mondayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(mondayTaxableTextBox.Text); + if (tuesdayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(tuesdayTaxableTextBox.Text); + if (wednesdayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(wednesdayTaxableTextBox.Text); + if (thursdayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(thursdayTaxableTextBox.Text); + if (fridayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(fridayTaxableTextBox.Text); + if (saturdayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(saturdayTaxableTextBox.Text); if (Math.Abs(totalTaxable) > 0) { totalTaxableTextBox.Text = totalTaxable.ToString("N", new CultureInfo("en-US")); @@ -2063,14 +2068,14 @@ namespace AdvertsingProfitControl //If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag. isTaxableDirtyCheckBox.Checked = false; } - else if (isTaxableDirtyCheckBox.Tag != null && textBox.Text == "") + else if (isTaxableDirtyCheckBox.Tag != null && textBox.Text == string.Empty) { //If the user has already added the fields to the database but has removed a value //update that accordingly. isTaxableDirtyCheckBox.Checked = true; _isFormDirty = true; } - totalTaxableTextBox.Text = ""; + totalTaxableTextBox.Text = string.Empty; } } @@ -2088,7 +2093,7 @@ namespace AdvertsingProfitControl var textBox = (TextBox)sender; if (_beginningCellValue == textBox.Text) return; //There was a change to the starting value of the text box if we've made it this far. - if (textBox.Text != "") + if (textBox.Text != string.Empty) { double value; if (double.TryParse(textBox.Text.Trim(), out value)) @@ -2099,12 +2104,12 @@ namespace AdvertsingProfitControl //And apply formatting. textBox.Text = Math.Round(value, 2).ToString("N", new CultureInfo("en-US")); //Check to see if the number is equal to zero (0) i.e. "0.00". - if (textBox.Text == @"0.00") textBox.Text = ""; + if (textBox.Text == @"0.00") textBox.Text = string.Empty; } else { MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric"); - textBox.Text = ""; + textBox.Text = string.Empty; } } else @@ -2113,31 +2118,31 @@ namespace AdvertsingProfitControl if (isCostAnalysisDirtyCheckBox.Tag == null) { //Since it hasn't check to see if the other text boxes are empty. - var isDirty = salesPerManHourTextBox.Text.Trim() == ""; + var isDirty = salesPerManHourTextBox.Text.Trim() == string.Empty; if (isDirty) { isCostAnalysisDirtyCheckBox.Checked = false; return; } - isDirty = salaryPercentageTextBox.Text.Trim() == ""; + isDirty = salaryPercentageTextBox.Text.Trim() == string.Empty; if (isDirty) { isCostAnalysisDirtyCheckBox.Checked = false; return; } - isDirty = salaryDollarsTextBox.Text.Trim() == ""; + isDirty = salaryDollarsTextBox.Text.Trim() == string.Empty; if (isDirty) { isCostAnalysisDirtyCheckBox.Checked = false; return; } - isDirty = suppliesTextBox.Text.Trim() == ""; + isDirty = suppliesTextBox.Text.Trim() == string.Empty; if (isDirty) { isCostAnalysisDirtyCheckBox.Checked = false; } } - else if (isCostAnalysisDirtyCheckBox.Tag != null && textBox.Text == "") + else if (isCostAnalysisDirtyCheckBox.Tag != null && textBox.Text == string.Empty) { //If the user has already added the fields to the database but has removed a value //update that accordingly. @@ -2156,17 +2161,18 @@ namespace AdvertsingProfitControl if (e.Start == _currentActiveDate || !weekEndingCalendar.BoldedDates.Contains(e.Start)) return; if (_isFormDirty) { - var result = MessageBox.Show(@"Would you like to save the changes you have made to this record?", @"Changes Detected", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + var result = MessageBox.Show(@"Would you like to save the changes you have made to this record?", @"Changes Detected", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Yes) { - //_currentActiveDate = e.Start; //Save the changes made to the database then clear and load the date picked by the user. } - else + else if (result == DialogResult.Cancel) { + //Cancel this method, select the active current date and return. weekEndingCalendar.SelectionStart = _currentActiveDate; return; } + //The "No" button doesn't need to be processed since it just means continue on with the method. } _currentActiveDate = e.Start; Text = @"Modify Record (Current Record: " + e.Start.ToString("d") + @")"; @@ -2242,8 +2248,8 @@ namespace AdvertsingProfitControl suppliesTextBox.Enter -= StoreBeginningTextBoxValue; suppliesTextBox.Validating -= ValidateCostAnalysisValues; //Clear errors and information. - informationLabel.Text = ""; - errorLabel.Text = ""; + informationLabel.Text = string.Empty; + errorLabel.Text = string.Empty; //Clear projections projectionsDataGridView.Rows.Clear(); //Clear inventory @@ -2253,7 +2259,7 @@ namespace AdvertsingProfitControl //Reset the ad special index. _adSpecialIndex = -1; //Clear the beginning cell value variable. - _beginningCellValue = ""; + _beginningCellValue = string.Empty; //Reset the form's dirty flag _isFormDirty = false; //Clear the used ad items @@ -2265,40 +2271,40 @@ namespace AdvertsingProfitControl isCommentDirtyCheckBox.Checked = false; isCommentDirtyCheckBox.Text = @"IsCommentDirty"; isCommentDirtyCheckBox.Tag = null; - commentsTextBox.Text = ""; + commentsTextBox.Text = string.Empty; commentsGroupBox.Text = @"Comments (Characters Remaining: " + commentsTextBox.MaxLength + @")"; //Clear weekly sales. isWeeklySalesDirtyCheckBox.Checked = false; isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty"; isWeeklySalesDirtyCheckBox.Tag = null; - sundayWeeklySalesTextBox.Text = ""; - mondayWeeklySalesTextBox.Text = ""; - tuesdayWeeklySalesTextBox.Text = ""; - wednesdayWeeklySalesTextBox.Text = ""; - thursdayWeeklySalesTextBox.Text = ""; - fridayWeeklySalesTextBox.Text = ""; - saturdayWeeklySalesTextBox.Text = ""; - totalWeeklySalesTextBox.Text = ""; + sundayWeeklySalesTextBox.Text = string.Empty; + mondayWeeklySalesTextBox.Text = string.Empty; + tuesdayWeeklySalesTextBox.Text = string.Empty; + wednesdayWeeklySalesTextBox.Text = string.Empty; + thursdayWeeklySalesTextBox.Text = string.Empty; + fridayWeeklySalesTextBox.Text = string.Empty; + saturdayWeeklySalesTextBox.Text = string.Empty; + totalWeeklySalesTextBox.Text = string.Empty; //Clear taxable. isTaxableDirtyCheckBox.Checked = false; isTaxableDirtyCheckBox.Text = @"IsTaxableDirty"; isTaxableDirtyCheckBox.Tag = null; - sundayTaxableTextBox.Text = ""; - mondayTaxableTextBox.Text = ""; - tuesdayTaxableTextBox.Text = ""; - wednesdayTaxableTextBox.Text = ""; - thursdayTaxableTextBox.Text = ""; - fridayTaxableTextBox.Text = ""; - saturdayTaxableTextBox.Text = ""; - totalTaxableTextBox.Text = ""; + sundayTaxableTextBox.Text = string.Empty; + mondayTaxableTextBox.Text = string.Empty; + tuesdayTaxableTextBox.Text = string.Empty; + wednesdayTaxableTextBox.Text = string.Empty; + thursdayTaxableTextBox.Text = string.Empty; + fridayTaxableTextBox.Text = string.Empty; + saturdayTaxableTextBox.Text = string.Empty; + totalTaxableTextBox.Text = string.Empty; //Clear cost analysis isCostAnalysisDirtyCheckBox.Checked = false; isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty"; isCostAnalysisDirtyCheckBox.Tag = null; - salesPerManHourTextBox.Text = ""; - salaryPercentageTextBox.Text = ""; - salaryDollarsTextBox.Text = ""; - suppliesTextBox.Text = ""; + salesPerManHourTextBox.Text = string.Empty; + salaryPercentageTextBox.Text = string.Empty; + salaryDollarsTextBox.Text = string.Empty; + suppliesTextBox.Text = string.Empty; //Re-enable the events for all the controls. projectionsDataGridView.CellEnter += StoreBeginningCellValue; projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; @@ -2375,14 +2381,14 @@ namespace AdvertsingProfitControl var databaseTracker = new DatabaseTracker(); var databaseReader = new DatabaseReader(); var dateId = databaseReader.RetrieveDateIdByDateString(date.ToString("d"), databaseTracker.DatabaseConnectionString); - var projections = databaseReader.ReturnProjectionsTable(dateId, databaseTracker.DatabaseConnectionString); - var inventory = databaseReader.ReturnInventoryTable(dateId, databaseTracker.DatabaseConnectionString); - var actualSales = databaseReader.ReturnActualSales(dateId, databaseTracker.DatabaseConnectionString); + var projections = databaseReader.ReturnProjectionsTable(dateId.ToString(), databaseTracker.DatabaseConnectionString); + var inventory = databaseReader.ReturnInventoryTable(dateId.ToString(), databaseTracker.DatabaseConnectionString); + var actualSales = databaseReader.ReturnActualSales(dateId.ToString(), databaseTracker.DatabaseConnectionString); LoadProjectionsTable(projections); LoadInventory(inventory); LoadActualSales(actualSales); - var invoices = databaseReader.ReturnInvoiceTable(dateId, databaseTracker.DatabaseConnectionString); - var comments = databaseReader.RetrieveComments(int.Parse(dateId), databaseTracker.DatabaseConnectionString); + var invoices = databaseReader.ReturnInvoiceTable(dateId.ToString(), databaseTracker.DatabaseConnectionString); + var comments = databaseReader.RetrieveComments(int.Parse(dateId.ToString()), databaseTracker.DatabaseConnectionString); if (comments.Count == 2) { LoadComments(int.Parse(comments[0]), comments[1]); @@ -2391,7 +2397,7 @@ namespace AdvertsingProfitControl { informationLabel.Text += @"No comments to display." + Environment.NewLine; } - var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId, + var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId.ToString(), databaseTracker.DatabaseConnectionString); if (weeklySales.Rows.Count == 1) { @@ -2402,7 +2408,7 @@ namespace AdvertsingProfitControl informationLabel.Text += @"No sales to display." + Environment.NewLine; } - var taxable = databaseReader.ReturnTaxableFromDateId(dateId, databaseTracker.DatabaseConnectionString); + var taxable = databaseReader.ReturnTaxableFromDateId(dateId.ToString(), databaseTracker.DatabaseConnectionString); if (taxable.Rows.Count == 1) { LoadTaxable(taxable); @@ -2412,7 +2418,7 @@ namespace AdvertsingProfitControl informationLabel.Text += @"No taxable data to display." + Environment.NewLine; } LoadInvoices(invoices); - var costAnalysis = databaseReader.ReturnCostAnalysis(int.Parse(dateId), + var costAnalysis = databaseReader.ReturnCostAnalysis(dateId, databaseTracker.DatabaseConnectionString); if (costAnalysis.Rows.Count == 1) { @@ -2453,7 +2459,7 @@ namespace AdvertsingProfitControl { if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0") { - var cell = new DataGridViewTextBoxCell {Value = ""}; + var cell = new DataGridViewTextBoxCell {Value = string.Empty}; newRow.Cells.Add(cell); } else @@ -2521,6 +2527,8 @@ namespace AdvertsingProfitControl } projectionsDataGridView.Rows.Add(newRow); } + //Manually write the row number to the new row. + projectionsDataGridView.Rows[projectionsDataGridView.Rows.Count - 1].HeaderCell.Value = projectionsDataGridView.Rows.Count.ToString(); //Re-enable the events projectionsDataGridView.CellEnter += StoreBeginningCellValue; projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; @@ -2559,7 +2567,7 @@ namespace AdvertsingProfitControl { if (inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0") { - var cell = new DataGridViewTextBoxCell { Value = "" }; + var cell = new DataGridViewTextBoxCell { Value = string.Empty }; newRow.Cells.Add(cell); } else @@ -2613,6 +2621,8 @@ namespace AdvertsingProfitControl } inventoryDataGridView.Rows.Add(newRow); } + //Manually write the row number to the new row. + inventoryDataGridView.Rows[inventoryDataGridView.Rows.Count - 1].HeaderCell.Value = inventoryDataGridView.Rows.Count.ToString(); //Re-enable the events inventoryDataGridView.CellEnter += StoreBeginningCellValue; inventoryDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; @@ -2651,7 +2661,7 @@ namespace AdvertsingProfitControl { if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0") { - var cell = new DataGridViewTextBoxCell { Value = "" }; + var cell = new DataGridViewTextBoxCell { Value = string.Empty }; newRow.Cells.Add(cell); } else @@ -2705,6 +2715,8 @@ namespace AdvertsingProfitControl } actualSalesDataGridView.Rows.Add(newRow); } + //Manually write the row number to the new row. + actualSalesDataGridView.Rows[actualSalesDataGridView.Rows.Count - 1].HeaderCell.Value = actualSalesDataGridView.Rows.Count.ToString(); //Re-enable the events actualSalesDataGridView.CellEnter += StoreBeginningCellValue; actualSalesDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; @@ -3055,8 +3067,51 @@ namespace AdvertsingProfitControl #region Database Update/Insertion Methods + private bool SaveRecords() + { + var success = false; + //Get the date ID for the current active date. + return success; + } + + /// + /// Attempts to get the date ID for the date supplied (short date format required, 'Merica!). + /// Failing that, it will insert the date into the database and return the date ID. + /// + /// The date string. + /// The date ID, otherwise zero (0) on fail. + private int GetDateId(string date) + { + var dbT = new DatabaseTracker(); + var dbW = new DatabaseWriter(dbT.DatabaseConnectionString); + var dbR = new DatabaseReader(); + var dateId = dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), dbT.DatabaseConnectionString); + //If the ID is zero (0) that means the date isn't in the database so simply insert it. + if (dateId == 0) + { + //Try inserting the date string. + if (dbW.InsertIntoWeekEnding(weekEndingCalendar.SelectionStart.ToString("d"))) + { + dateId = dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), dbT.DatabaseConnectionString); + //Now if its still zero (0) then that means something went really wrong and failed to insert. + if (dateId == 0) + { + MessageBox.Show( + @"Failed to retrieve date ID after supposedly inserting the date into the database.", + @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else + { + //The above method reports that it failed to insert the date into the database. + MessageBox.Show(@"Failed to insert the date '" + weekEndingCalendar.SelectionStart.ToString("d") + @"' into the database.", @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + return dateId; + } + #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 2f951b4..d0b0acc 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application @@ -14,7 +14,7 @@ - ib1gNsn2WoDzAPiOU+0/4RFlwIEfmJtvgCPloir4KFA= + ahFX/ECRCn2uEoELdC76I+/TVakX4bXkbfjNul+1+Ow= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest index edd7034..f2311fc 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest @@ -43,14 +43,14 @@ - + - cTFWoKFn2+4/0r/55ub0w4SG/Rc39J/A3gn6JBlTdZU= + i7aAPQL6YXJt+3MW8a9abkTz7+KcsRjrBy8WabqjtVw=