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.

This commit is contained in:
2017-01-20 18:30:36 -06:00
parent 84f43538d1
commit 9fa2e3c44a
9 changed files with 253 additions and 195 deletions
+10 -3
View File
@@ -70,9 +70,16 @@ namespace AdvertsingProfitControl
return dateId; return dateId;
} }
public string RetrieveDateIdByDateString(string dateString, string connectionString) /// <summary>
/// Returns the date ID of the date string that is passed.
/// Preferred format is short date (1/20/2017).
/// </summary>
/// <param name="dateString">The date to be looked up.</param>
/// <param name="connectionString">The connection to the database.</param>
/// <returns>The date ID or zero (0) on fail.</returns>
public int RetrieveDateIdByDateString(string dateString, string connectionString)
{ {
var dateId = "0"; var dateId = 0;
var oleDbCommand = new OleDbCommand() var oleDbCommand = new OleDbCommand()
{ {
CommandText = "SELECT WeekEnding.ID FROM WeekEnding WHERE WeekEnding.EndOfWeekDate = ?" CommandText = "SELECT WeekEnding.ID FROM WeekEnding WHERE WeekEnding.EndOfWeekDate = ?"
@@ -90,7 +97,7 @@ namespace AdvertsingProfitControl
{ {
while(reader != null && reader.Read()) while(reader != null && reader.Read())
{ {
dateId = reader[0].ToString(); dateId = int.Parse(reader[0].ToString());
} }
} }
} }
+3 -3
View File
@@ -1195,7 +1195,7 @@ namespace AdvertsingProfitControl
var databaseWriter = new DatabaseWriter(databaseTracker.DatabaseConnectionString); var databaseWriter = new DatabaseWriter(databaseTracker.DatabaseConnectionString);
if (weekEndingDateMaskedTextBox.MaskCompleted) 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. //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. //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; var commentsText = commentsTextBox.Text;
if (Regex.Replace(commentsText, @"\s+", "") != "") 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. //Send the table's data to their respective functions.
_gLogConsole.WriteToLog(FrmLogConsole.Level.Info, "Added the following rows to the APC table:"); _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) foreach (var i in rowsEffected)
{ {
_gLogConsole.WriteToLog(FrmLogConsole.Level.Info, (i + 1).ToString()); _gLogConsole.WriteToLog(FrmLogConsole.Level.Info, (i + 1).ToString());
+7 -7
View File
@@ -45,14 +45,14 @@ namespace AdvertsingProfitControl
var databaseWriter = new DatabaseWriter(databaseTracker.DatabaseConnectionString); var databaseWriter = new DatabaseWriter(databaseTracker.DatabaseConnectionString);
var dateId = databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text, 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 " + informationLabel.Text = "An error has occurred trying to obtain the ID\nfor the date " +
monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text + "."; monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text + ".";
} }
var supplierName = dataGridView.Rows[e.Row.Index].Cells[0].EditedFormattedValue.ToString(); var supplierName = dataGridView.Rows[e.Row.Index].Cells[0].EditedFormattedValue.ToString();
var invoiceNumber = dataGridView.Rows[e.Row.Index].Cells[1].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) if (count == 1)
{ {
@@ -85,8 +85,8 @@ namespace AdvertsingProfitControl
var dateId = var dateId =
databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" +
yearComboBox.Text, databaseTracker.DatabaseConnectionString); yearComboBox.Text, databaseTracker.DatabaseConnectionString);
if (dateId == "0"){ informationLabel.Text = "unable to find date in database."; return; } if (dateId == 0){ informationLabel.Text = "unable to find date in database."; return; }
var recordsAffected = datbaseWriter.UpdateCommentsByDateId(commentsTextBox.Text, dateId); var recordsAffected = datbaseWriter.UpdateCommentsByDateId(commentsTextBox.Text, dateId.ToString());
if (recordsAffected == true) if (recordsAffected == true)
{ {
informationLabel.Text = "Successfully updated the comments for the selected date."; 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 dateId = databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString);
var adItemName = e.Row.Cells[0].EditedFormattedValue.ToString(); var adItemName = e.Row.Cells[0].EditedFormattedValue.ToString();
var adItemId = databaseReader.RetrieveAdItemId(adItemName, databaseTracker.DatabaseConnectionString); var adItemId = databaseReader.RetrieveAdItemId(adItemName, databaseTracker.DatabaseConnectionString);
var count = databaseWriter.RemoveRecord(adItemId, dateId); var count = databaseWriter.RemoveRecord(adItemId, dateId.ToString());
if (count == 1) if (count == 1)
{ {
@@ -176,7 +176,7 @@ namespace AdvertsingProfitControl
else else
{ {
//ELSE IF one was passed, then use it's ID to build the tables. //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."); _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") if (dateId == "0")
{ {
@@ -424,7 +424,7 @@ namespace AdvertsingProfitControl
var dateId = var dateId =
databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" +
yearComboBox.Text, databaseTracker.DatabaseConnectionString); yearComboBox.Text, databaseTracker.DatabaseConnectionString);
var recordsAffected = databaseWriter.RemoveAllEntriesAndYearById(dateId); var recordsAffected = databaseWriter.RemoveAllEntriesAndYearById(dateId.ToString());
if (recordsAffected > 0) if (recordsAffected > 0)
{ {
informationLabel.Text = "Successfully removed " + recordsAffected.ToString() + informationLabel.Text = "Successfully removed " + recordsAffected.ToString() +
+10 -3
View File
@@ -79,7 +79,7 @@ namespace AdvertsingProfitControl
else else
{ {
//ELSE IF one was passed, then use it's ID to build the tables. //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."); _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") if (dateId == "0")
{ {
@@ -727,11 +727,11 @@ namespace AdvertsingProfitControl
double remaingingSales = _departmentSales - _SalesProducedByAdItems; double remaingingSales = _departmentSales - _SalesProducedByAdItems;
double totalProfitReturnFromReminaingSales = remaingingSales*.3; double totalProfitReturnFromReminaingSales = remaingingSales*.3;
double totalProfitReturn = _TotalProfitReturnFromAdItems + totalProfitReturnFromReminaingSales; double totalProfitReturn = _TotalProfitReturnFromAdItems + totalProfitReturnFromReminaingSales;
test.BuildFormFrontCompressedLayout(dateId, _departmentSales, _SalesProducedByAdItems, remaingingSales, test.BuildFormFrontCompressedLayout(dateId.ToString(), _departmentSales, _SalesProducedByAdItems, remaingingSales,
_TotalProfitReturnFromAdItems, totalProfitReturnFromReminaingSales, totalProfitReturn, _TotalProfitReturnFromAdItems, totalProfitReturnFromReminaingSales, totalProfitReturn,
commentsTextBox.Text); commentsTextBox.Text);
test.RenderHtmlToImage(); test.RenderHtmlToImage();
backPageTest.GenerateWeeklyInventoryControlPage(dateId); backPageTest.GenerateWeeklyInventoryControlPage(dateId.ToString());
backPageTest.RenderHtmlToImage(); backPageTest.RenderHtmlToImage();
} }
else else
@@ -765,6 +765,13 @@ namespace AdvertsingProfitControl
var form = new NewModifyRecord(date); var form = new NewModifyRecord(date);
form.ShowDialog(); 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 //http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children
+11 -11
View File
@@ -640,7 +640,7 @@ namespace AdvertsingProfitControl
{ {
var databaseTracker = new DatabaseTracker(); var databaseTracker = new DatabaseTracker();
var databaseReader = new DatabaseReader(); 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() private void FillDateSuggestionComboBoxes()
@@ -817,7 +817,7 @@ namespace AdvertsingProfitControl
//Now re-register the event handlers //Now re-register the event handlers
monthComboBox.SelectedIndexChanged += UpdateDaysOfMonth; monthComboBox.SelectedIndexChanged += UpdateDaysOfMonth;
dayComboBox.SelectedIndexChanged += UpdateDataGridViewInformation; 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 #endregion
@@ -1334,7 +1334,7 @@ namespace AdvertsingProfitControl
if (_adSpecialIndex == -1 || currentRowIndex < _adSpecialIndex) if (_adSpecialIndex == -1 || currentRowIndex < _adSpecialIndex)
{ {
//Clear the database of the item. //Clear the database of the item.
var count = databaseWriter.RemoveRecord(adItemId, dateId); var count = databaseWriter.RemoveRecord(adItemId, dateId.ToString());
if (count == 1) if (count == 1)
{ {
@@ -1356,7 +1356,7 @@ namespace AdvertsingProfitControl
else if (currentRowIndex > _adSpecialIndex) else if (currentRowIndex > _adSpecialIndex)
{ {
//Clear the database of the item. //Clear the database of the item.
var count = databaseWriter.RemoveRecord(adItemId, dateId); var count = databaseWriter.RemoveRecord(adItemId, dateId.ToString());
if (count == 1) if (count == 1)
{ {
@@ -1398,7 +1398,7 @@ namespace AdvertsingProfitControl
if (adItemName == "") break; if (adItemName == "") break;
adItemId = databaseReader.RetrieveAdItemId(adItemName, databaseTracker.DatabaseConnectionString); adItemId = databaseReader.RetrieveAdItemId(adItemName, databaseTracker.DatabaseConnectionString);
//Clear the database of the item. //Clear the database of the item.
var count = databaseWriter.RemoveRecord(adItemId, dateId); var count = databaseWriter.RemoveRecord(adItemId, dateId.ToString());
if (count == 1) if (count == 1)
{ {
@@ -2497,8 +2497,8 @@ namespace AdvertsingProfitControl
var dateId = var dateId =
databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" +
yearComboBox.Text, databaseTracker.DatabaseConnectionString); yearComboBox.Text, databaseTracker.DatabaseConnectionString);
if (dateId == "0") { notificationLabel.Text = "unable to find date in database."; return; } if (dateId == 0) { notificationLabel.Text = "unable to find date in database."; return; }
var recordsAffected = databaseWriter.UpdateCommentsByDateId(commentsTextBox.Text, dateId); var recordsAffected = databaseWriter.UpdateCommentsByDateId(commentsTextBox.Text, dateId.ToString());
if (recordsAffected == true) if (recordsAffected == true)
{ {
notificationLabel.Text = "Successfully updated the comments for the selected date."; notificationLabel.Text = "Successfully updated the comments for the selected date.";
@@ -2506,7 +2506,7 @@ namespace AdvertsingProfitControl
else else
{ {
//Try adding a new record as there could be no comments in the database. //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) if (rowsEffected)
{ {
notificationLabel.Text = "Successfully added the comments for the selected date."; notificationLabel.Text = "Successfully added the comments for the selected date.";
@@ -2654,9 +2654,9 @@ namespace AdvertsingProfitControl
var databaseTracker = new DatabaseTracker(); var databaseTracker = new DatabaseTracker();
var databaseReader = new DatabaseReader(); var databaseReader = new DatabaseReader();
var dateId = databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString); var dateId = databaseReader.RetrieveDateIdByDateString(monthComboBox.Text + "/" + dayComboBox.Text + "/" + yearComboBox.Text, databaseTracker.DatabaseConnectionString);
UpdateApcTables(dateId); UpdateApcTables(dateId.ToString());
UpdateInvoicesTable(dateId); UpdateInvoicesTable(dateId.ToString());
UpdateWeeklySales(dateId); UpdateWeeklySales(dateId.ToString());
} }
} }
} }
+25 -36
View File
@@ -1052,6 +1052,7 @@ namespace AdvertsingProfitControl
} }
} }
actualSalesDataGridView.Rows.Add(rowContents); 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. //Build a collection of objects for the inventory table to use.
var inventoryNewRow = new object[inventoryDataGridView.ColumnCount]; var inventoryNewRow = new object[inventoryDataGridView.ColumnCount];
//Spin through the DataGridViewCells in the row and add their contents to an array. //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.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. //Set the row headers of the other tables to show up as pending; this row is valid without a doubt.
if (e.RowIndex != _adSpecialIndex) if (e.RowIndex != _adSpecialIndex)
{ {
@@ -1398,7 +1400,9 @@ namespace AdvertsingProfitControl
} }
} }
projectionsDataGridView.Rows.Add(rowContents); projectionsDataGridView.Rows.Add(rowContents);
projectionsDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString();
actualSalesDataGridView.Rows.Add(rowContents); actualSalesDataGridView.Rows.Add(rowContents);
actualSalesDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString();
if (e.RowIndex != _adSpecialIndex) if (e.RowIndex != _adSpecialIndex)
{ {
//Apply color coding to the respective row headers on the other tables. //Apply color coding to the respective row headers on the other tables.
@@ -1570,6 +1574,7 @@ namespace AdvertsingProfitControl
} }
} }
projectionsDataGridView.Rows.Add(rowContents); 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. //Build a collection of objects for the inventory table to use.
var inventoryNewRow = new object[inventoryDataGridView.ColumnCount]; var inventoryNewRow = new object[inventoryDataGridView.ColumnCount];
//Spin through the DataGridViewCells in the row and add their contents to an array. //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.Add(inventoryNewRow);
inventoryDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString();
if (e.RowIndex != _adSpecialIndex) if (e.RowIndex != _adSpecialIndex)
{ {
//Apply color coding to the respective row headers on the other tables. //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 dbW = new DatabaseWriter(dbT.DatabaseConnectionString);
var dbR = new DatabaseReader(); var dbR = new DatabaseReader();
//Obtain the date ID. //Obtain the date ID.
int dateId; var dateId = dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), dbT.DatabaseConnectionString);
if ( //If the ID is zero (0) that means the date isn't in the database so simply insert it.
int.TryParse(dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), if (dateId == 0)
dbT.DatabaseConnectionString), out dateId))
{ {
//If the ID is zero (0) that means the date isn't in the database so simply insert it. //Try inserting the date string.
if (dateId == 0) if (dbW.InsertIntoWeekEnding(weekEndingCalendar.SelectionStart.ToString("d")))
{ {
//Try inserting the date string. dateId = dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), dbT.DatabaseConnectionString);
if (dbW.InsertIntoWeekEnding(weekEndingCalendar.SelectionStart.ToString("d"))) //Now if its still zero (0) then that means something went really wrong and failed to insert.
if (dateId == 0)
{ {
if ( MessageBox.Show(
int.TryParse( @"Failed to retrieve date ID after supposedly inserting the date into the database.",
dbR.RetrieveDateIdByDateString(weekEndingCalendar.SelectionStart.ToString("d"), @"Failed To Get Date ID", MessageBoxButtons.OK, MessageBoxIcon.Error);
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);
return; 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 = ""; informationLabel.Text = "";
//Run the row parsing engine on all the APC tables. //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[0] = sundayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(sundayWeeklySalesTextBox.Text);
weeklySales[1] = mondayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(mondayWeeklySalesTextBox.Text); weeklySales[1] = mondayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(mondayWeeklySalesTextBox.Text);
weeklySales[2] = tuesdayWeeklySalesTextBox.Text == "" ? 0 : double.Parse(tuesdayWeeklySalesTextBox.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 == "" weeklySales[4] = thursdayWeeklySalesTextBox.Text == ""
? 0 ? 0
: double.Parse(thursdayWeeklySalesTextBox.Text); : double.Parse(thursdayWeeklySalesTextBox.Text);
+184 -129
View File
@@ -12,6 +12,7 @@ namespace AdvertsingProfitControl
{ {
public partial class NewModifyRecord : Form 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; private static readonly FrmLogConsole LogConsole = FrmLogConsole.GetStaticInstance;
//Create an array that contains all the ad items from the database. //Create an array that contains all the ad items from the database.
private readonly List<string> _adItemCollection; private readonly List<string> _adItemCollection;
@@ -28,7 +29,7 @@ namespace AdvertsingProfitControl
private readonly List<string>[] _usedAdItems = new List<string>[2]; private readonly List<string>[] _usedAdItems = new List<string>[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. //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. //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. //Flag showing whether or not the AdSpecialRow has been made in this session.
private int _adSpecialIndex = -1; private int _adSpecialIndex = -1;
private readonly AdvertisingProfitControlTableHelper _tableHelperFunctions = new AdvertisingProfitControlTableHelper(); private readonly AdvertisingProfitControlTableHelper _tableHelperFunctions = new AdvertisingProfitControlTableHelper();
@@ -173,7 +174,7 @@ namespace AdvertsingProfitControl
private void StoreBeginningTextBoxValue(object sender, EventArgs e) private void StoreBeginningTextBoxValue(object sender, EventArgs e)
{ {
var textBox = (TextBox)sender; var textBox = (TextBox)sender;
_beginningCellValue = textBox.Text; _beginningCellValue = textBox.Text.Trim();
} }
#endregion #endregion
@@ -192,7 +193,7 @@ namespace AdvertsingProfitControl
if (dataGridView.Rows[e.RowIndex].IsNewRow) return; if (dataGridView.Rows[e.RowIndex].IsNewRow) return;
DateTime dateTime; DateTime dateTime;
//Check to make sure the Invoice Date, Invoice Number and the Supplier values are set. //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; dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"An invoice date must be specified.", @"Invalid Invoice Date", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(@"An invoice date must be specified.", @"Invalid Invoice Date", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -201,7 +202,7 @@ namespace AdvertsingProfitControl
return; 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; dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"A supplier must be specified.", @"Invalid Supplier", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(@"A supplier must be specified.", @"Invalid Supplier", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -212,7 +213,7 @@ namespace AdvertsingProfitControl
if ( if (
dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue dataGridView.Rows[e.RowIndex].Cells[(int)InvoiceTableColumns.InvoiceNumber].EditedFormattedValue
.ToString() == "") .ToString().Trim().Length == 0)
{ {
dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError; dataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"An invoice number must be specified.", @"Invalid Invoice Number", MessageBoxButtons.OK, MessageBox.Show(@"An invoice number must be specified.", @"Invalid Invoice Number", MessageBoxButtons.OK,
@@ -253,8 +254,8 @@ namespace AdvertsingProfitControl
{ {
case (int)InvoiceTableColumns.InvoiceDate: case (int)InvoiceTableColumns.InvoiceDate:
//Clear any error text a cell has for this column. //Clear any error text a cell has for this column.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = string.Empty;
if (userInput != "") if (userInput != string.Empty)
{ {
DateTime date; DateTime date;
//Try parsing the date to make sure its valid, otherwise clear it from the cell and inform the user. //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); 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].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 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"; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "An Invoice Date is Required";
} }
break; break;
case (int)InvoiceTableColumns.InvoiceNumber: case (int)InvoiceTableColumns.InvoiceNumber:
//Clear any error text a cell has for this column. //Clear any error text a cell has for this column.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = string.Empty;
if (userInput != "") if (userInput != string.Empty)
{ {
long parsedNumber; long parsedNumber;
if (long.TryParse(userInput, out parsedNumber)) if (long.TryParse(userInput, out parsedNumber))
@@ -292,20 +293,20 @@ namespace AdvertsingProfitControl
else else
{ {
MessageBox.Show(@"The invoice number must be a numeric value.", @"Non Numeric Invoice Number", MessageBoxButtons.OK, MessageBoxIcon.Error); 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"; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Invoice Number Must be Numeric";
} }
} }
else 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"; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "An Invoice Number is Required";
} }
break; break;
case (int)InvoiceTableColumns.Supplier: case (int)InvoiceTableColumns.Supplier:
//Clear any error text a cell has for this column. //Clear any error text a cell has for this column.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = ""; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = string.Empty;
if (userInput != "") if (userInput != string.Empty)
{ {
//TODO: Create a custom engine to do this. //TODO: Create a custom engine to do this.
//Pretty up the entered text since there is something here. //Pretty up the entered text since there is something here.
@@ -315,7 +316,7 @@ namespace AdvertsingProfitControl
} }
else 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"; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "A Supplier is Required";
} }
break; break;
@@ -329,10 +330,10 @@ namespace AdvertsingProfitControl
if (e.ColumnIndex != (int)InvoiceTableColumns.Id && if (e.ColumnIndex != (int)InvoiceTableColumns.Id &&
e.ColumnIndex < (int)InvoiceTableColumns.InvoiceNote) 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 //Now check to make sure the user input isn't null
//Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US")); //Math.Round(parsedNumber, 2).ToString("N", new CultureInfo("en-US"));
if (userInput != "") if (userInput != string.Empty)
{ {
double parsedNumber; double parsedNumber;
if (double.TryParse(userInput, out parsedNumber)) if (double.TryParse(userInput, out parsedNumber))
@@ -344,7 +345,7 @@ namespace AdvertsingProfitControl
} }
else 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."; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Only Numeric Values Allowed.";
} }
} }
@@ -381,7 +382,7 @@ namespace AdvertsingProfitControl
{ {
var rowIndex = e.Row.Index; var rowIndex = e.Row.Index;
//See if there is an ID number in the ID column. //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. //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); 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) if (result == DialogResult.Yes)
@@ -420,10 +421,11 @@ namespace AdvertsingProfitControl
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private static void DisplayRowNumbers(object sender, DataGridViewRowsAddedEventArgs e) private void DisplayRowNumbers(object sender, DataGridViewRowsAddedEventArgs e)
{ {
var table = ((DataGridView)sender); var table = ((DataGridView)sender);
table.Rows[e.RowIndex].HeaderCell.Value = (e.RowIndex + 1).ToString(); table.Rows[e.RowIndex].HeaderCell.Value = (e.RowIndex + 1).ToString();
LogConsole.WriteToLog(FrmLogConsole.Level.Info, "Added row at Index " + e.RowIndex + " in " + table.Name + ".");
} }
/// <summary> /// <summary>
@@ -467,7 +469,7 @@ namespace AdvertsingProfitControl
//Paint the rows to identify what group they belong to. //Paint the rows to identify what group they belong to.
_tableHelperFunctions.PaintRowGroupsFromIndex(e.RowIndex, dataGridView); _tableHelperFunctions.PaintRowGroupsFromIndex(e.RowIndex, dataGridView);
//Add in used Ad Items to the list. //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. //Clear the old ad item out of the used ad item collection.
var parser = new RowParsing(); var parser = new RowParsing();
if (parser.GetRowAttribute(dataGridView.Rows[e.RowIndex]) == RowAttribute.AdSpecialRow) if (parser.GetRowAttribute(dataGridView.Rows[e.RowIndex]) == RowAttribute.AdSpecialRow)
@@ -480,14 +482,12 @@ namespace AdvertsingProfitControl
{ {
if (_usedAdItems[0].Contains(userInput)) return; if (_usedAdItems[0].Contains(userInput)) return;
_usedAdItems[0].Add(userInput); _usedAdItems[0].Add(userInput);
LogConsole.WriteToLog(FrmLogConsole.Level.Debug, "Adding \"" + userInput + "\" to section one (1).");
} }
//Section two (2) detected. //Section two (2) detected.
else else
{ {
if (_usedAdItems[1].Contains(userInput)) return; if (_usedAdItems[1].Contains(userInput)) return;
_usedAdItems[1].Add(userInput); _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 (_adSpecialIndex == -1)
{ {
//If the ID number is set, i.e. not equal to null then attempt to remove it from the database. //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); 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) if (result == DialogResult.Yes)
@@ -592,7 +592,7 @@ namespace AdvertsingProfitControl
else if (currentRowIndex < _adSpecialIndex) 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 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); 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) if (result == DialogResult.Yes)
@@ -623,7 +623,7 @@ namespace AdvertsingProfitControl
else if (currentRowIndex > _adSpecialIndex) 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 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); 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) if (result == DialogResult.Yes)
@@ -671,7 +671,7 @@ namespace AdvertsingProfitControl
if (projectionsDataGridView.RowCount == inventoryDataGridView.RowCount && if (projectionsDataGridView.RowCount == inventoryDataGridView.RowCount &&
projectionsDataGridView.RowCount == actualSalesDataGridView.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. //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 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) private void ChangeAutoCompleteListOnKeyCombo(object sender, KeyEventArgs e)
{ {
var textBox = (TextBox)sender; var textBox = (TextBox)sender;
informationLabel.Text = ""; informationLabel.Text = string.Empty;
if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.S) if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.S)
{ {
@@ -855,10 +855,10 @@ namespace AdvertsingProfitControl
{ {
case (int)SalesTableColumns.AdItem: //Ad Item 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 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. //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. //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); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = TextFormat.FormatAdItemText(userInput);
var parser = new RowParsing(); var parser = new RowParsing();
@@ -905,12 +905,12 @@ namespace AdvertsingProfitControl
} }
else else
{ {
if (userInput == "") if (userInput == string.Empty)
{ {
return; return;
} }
MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected"); 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(); dataGridView.RefreshEdit();
e.Cancel = true; e.Cancel = true;
return; return;
@@ -925,9 +925,9 @@ namespace AdvertsingProfitControl
{ {
//Grab the input and split it at the forward slash (/) for formatting. //Grab the input and split it at the forward slash (/) for formatting.
var input = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString(); 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. //Remove any dollar signs as these cause errors.
input = input.Replace("$", ""); input = input.Replace("$", string.Empty);
var stringArray = input.Split('/'); var stringArray = input.Split('/');
//Format the last number as Currency, and round it up if necessary. //Format the last number as Currency, and round it up if necessary.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value =
@@ -947,12 +947,12 @@ namespace AdvertsingProfitControl
} }
else else
{ {
if (userInput == "") if (userInput == string.Empty)
{ {
return; return;
} }
MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected"); 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(); dataGridView.RefreshEdit();
e.Cancel = true; e.Cancel = true;
return; return;
@@ -970,12 +970,12 @@ namespace AdvertsingProfitControl
} }
else else
{ {
if (userInput == "") if (userInput == string.Empty)
{ {
return; return;
} }
MessageBox.Show(@"Non numeric characters in column " + (e.ColumnIndex + 1) + @" are not allowed.", @"Invalid Characters Detected"); 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(); dataGridView.RefreshEdit();
e.Cancel = true; e.Cancel = true;
return; return;
@@ -1008,7 +1008,7 @@ namespace AdvertsingProfitControl
return; return;
} }
//Clear all whitespace and check for a null value in the ad item column. //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; projectionsDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified"); MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified");
@@ -1064,9 +1064,9 @@ namespace AdvertsingProfitControl
break; break;
case (int)SalesTableColumns.SalePrice: 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 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 place the value from the Projections table into the array, since Sale Price can be determined before actual data is used.
else else
@@ -1076,9 +1076,9 @@ namespace AdvertsingProfitControl
break; break;
case (int)SalesTableColumns.Cost: 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 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 place the value from the Projections table into the array, since Cost can be determined before actual data is used.
else else
@@ -1096,11 +1096,12 @@ namespace AdvertsingProfitControl
rowContents[i] = false; rowContents[i] = false;
break; break;
default: default:
rowContents[i] = ""; rowContents[i] = string.Empty;
break; break;
} }
} }
actualSalesDataGridView.Rows.Add(rowContents); 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. //Build a collection of objects for the inventory table to use.
var inventoryNewRow = new object[inventoryDataGridView.ColumnCount]; var inventoryNewRow = new object[inventoryDataGridView.ColumnCount];
//Spin through the DataGridViewCells in the row and add their contents to an array. //Spin through the DataGridViewCells in the row and add their contents to an array.
@@ -1110,7 +1111,7 @@ namespace AdvertsingProfitControl
switch (i) switch (i)
{ {
case (int)SalesTableColumns.Id: case (int)SalesTableColumns.Id:
inventoryNewRow[(int)InventoryTableColumns.Id] = ""; inventoryNewRow[(int)InventoryTableColumns.Id] = string.Empty;
break; break;
case (int)SalesTableColumns.AdItem: case (int)SalesTableColumns.AdItem:
inventoryNewRow[(int)InventoryTableColumns.AdItem] = inventoryNewRow[(int)InventoryTableColumns.AdItem] =
@@ -1127,11 +1128,12 @@ namespace AdvertsingProfitControl
break; break;
default: default:
if (i > (int)InventoryTableColumns.IsHeaderRow) continue; if (i > (int)InventoryTableColumns.IsHeaderRow) continue;
inventoryNewRow[i] = ""; inventoryNewRow[i] = string.Empty;
break; break;
} }
} }
inventoryDataGridView.Rows.Add(inventoryNewRow); 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. //Set the row headers of the other tables to show up as pending; this row is valid without a doubt.
if (e.RowIndex != _adSpecialIndex) if (e.RowIndex != _adSpecialIndex)
{ {
@@ -1304,10 +1306,10 @@ namespace AdvertsingProfitControl
{ {
case (int)InventoryTableColumns.AdItem: 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 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. //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. //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); dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = TextFormat.FormatAdItemText(userInput);
var parser = new RowParsing(); var parser = new RowParsing();
@@ -1348,7 +1350,7 @@ namespace AdvertsingProfitControl
} }
double parsedNumber; double parsedNumber;
//Try parsing the text entered as a number and if that fails then break out and clear the value entered. //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. //Add the value to the cell.
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = userInput; dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = userInput;
@@ -1357,10 +1359,10 @@ namespace AdvertsingProfitControl
return; 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. //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"); 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(); dataGridView.RefreshEdit();
e.Cancel = true; e.Cancel = true;
} }
@@ -1388,7 +1390,7 @@ namespace AdvertsingProfitControl
return; return;
} }
//Clear all whitespace and check for a null value in the ad item column. //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; inventoryDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified"); MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified");
@@ -1451,12 +1453,14 @@ namespace AdvertsingProfitControl
rowContents[i] = false; rowContents[i] = false;
break; break;
default: default:
rowContents[i] = ""; rowContents[i] = string.Empty;
break; break;
} }
} }
projectionsDataGridView.Rows.Add(rowContents); projectionsDataGridView.Rows.Add(rowContents);
projectionsDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString();
actualSalesDataGridView.Rows.Add(rowContents); actualSalesDataGridView.Rows.Add(rowContents);
actualSalesDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString();
if (e.RowIndex != _adSpecialIndex) if (e.RowIndex != _adSpecialIndex)
{ {
//Apply color coding to the respective row headers on the other tables. //Apply color coding to the respective row headers on the other tables.
@@ -1554,7 +1558,7 @@ namespace AdvertsingProfitControl
return; return;
} }
//Clear all whitespace and check for a null value in the ad item column. //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; actualSalesDataGridView.Rows[e.RowIndex].HeaderCell.Style.BackColor = ApplicationColors.RowError;
MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified"); MessageBox.Show(@"An ad item is required.", @"No Ad Item Specified");
@@ -1624,11 +1628,12 @@ namespace AdvertsingProfitControl
rowContents[i] = false; rowContents[i] = false;
break; break;
default: default:
rowContents[i] = ""; rowContents[i] = string.Empty;
break; break;
} }
} }
projectionsDataGridView.Rows.Add(rowContents); 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. //Build a collection of objects for the inventory table to use.
var inventoryNewRow = new object[inventoryDataGridView.ColumnCount]; var inventoryNewRow = new object[inventoryDataGridView.ColumnCount];
//Spin through the DataGridViewCells in the row and add their contents to an array. //Spin through the DataGridViewCells in the row and add their contents to an array.
@@ -1652,12 +1657,12 @@ namespace AdvertsingProfitControl
break; break;
default: default:
if (i > (int)InventoryTableColumns.IsHeaderRow) continue; if (i > (int)InventoryTableColumns.IsHeaderRow) continue;
inventoryNewRow[i] = ""; inventoryNewRow[i] = string.Empty;
break; break;
} }
} }
inventoryDataGridView.Rows.Add(inventoryNewRow); inventoryDataGridView.Rows.Add(inventoryNewRow);
inventoryDataGridView.Rows[e.RowIndex + 1].HeaderCell.Value = (e.RowIndex + 2).ToString();
if (e.RowIndex != _adSpecialIndex) if (e.RowIndex != _adSpecialIndex)
{ {
//Apply color coding to the respective row headers on the other tables. //Apply color coding to the respective row headers on the other tables.
@@ -1918,7 +1923,7 @@ namespace AdvertsingProfitControl
{ {
if (commentsTextBox.Text == _beginningCellValue) return; if (commentsTextBox.Text == _beginningCellValue) return;
//Clear white spaces and check if the string is null. //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. //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. //So the comments are no longer dirty.
@@ -1948,7 +1953,7 @@ namespace AdvertsingProfitControl
var textBox = (TextBox)sender; var textBox = (TextBox)sender;
if (_beginningCellValue == textBox.Text) return; if (_beginningCellValue == textBox.Text) return;
//There was a change to the starting value of the text box if we've made it this far. //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; double dollarValue;
if (double.TryParse(textBox.Text.Trim(), out dollarValue)) if (double.TryParse(textBox.Text.Trim(), out dollarValue))
@@ -1959,12 +1964,12 @@ namespace AdvertsingProfitControl
//And apply formatting. //And apply formatting.
textBox.Text = Math.Round(dollarValue, 2).ToString("N", new CultureInfo("en-US")); 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". //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 else
{ {
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric"); MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = ""; textBox.Text = string.Empty;
} }
} }
if (isWeeklySalesDirtyCheckBox.Tag != null) if (isWeeklySalesDirtyCheckBox.Tag != null)
@@ -1974,13 +1979,13 @@ namespace AdvertsingProfitControl
} }
//Update the total sales text box before returning. //Update the total sales text box before returning.
var totalWeeklySales = 0.00; var totalWeeklySales = 0.00;
if (sundayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(sundayWeeklySalesTextBox.Text); if (sundayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(sundayWeeklySalesTextBox.Text);
if (mondayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(mondayWeeklySalesTextBox.Text); if (mondayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(mondayWeeklySalesTextBox.Text);
if (tuesdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(tuesdayWeeklySalesTextBox.Text); if (tuesdayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(tuesdayWeeklySalesTextBox.Text);
if (wednesdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(wednesdayWeeklySalesTextBox.Text); if (wednesdayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(wednesdayWeeklySalesTextBox.Text);
if (thursdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(thursdayWeeklySalesTextBox.Text); if (thursdayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(thursdayWeeklySalesTextBox.Text);
if (fridayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(fridayWeeklySalesTextBox.Text); if (fridayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(fridayWeeklySalesTextBox.Text);
if (saturdayWeeklySalesTextBox.Text != "") totalWeeklySales += double.Parse(saturdayWeeklySalesTextBox.Text); if (saturdayWeeklySalesTextBox.Text != string.Empty) totalWeeklySales += double.Parse(saturdayWeeklySalesTextBox.Text);
if (Math.Abs(totalWeeklySales) > 0) if (Math.Abs(totalWeeklySales) > 0)
{ {
totalWeeklySalesTextBox.Text = totalWeeklySales.ToString("N", new CultureInfo("en-US")); 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. //If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag.
isWeeklySalesDirtyCheckBox.Checked = false; 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 //If the user has already added the fields to the database but has removed a value
//update that accordingly. //update that accordingly.
isWeeklySalesDirtyCheckBox.Checked = true; isWeeklySalesDirtyCheckBox.Checked = true;
_isFormDirty = true; _isFormDirty = true;
} }
totalWeeklySalesTextBox.Text = ""; totalWeeklySalesTextBox.Text = string.Empty;
} }
} }
@@ -2018,7 +2023,7 @@ namespace AdvertsingProfitControl
var textBox = (TextBox)sender; var textBox = (TextBox)sender;
if (_beginningCellValue == textBox.Text) return; if (_beginningCellValue == textBox.Text) return;
//There was a change to the starting value of the text box if we've made it this far. //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; double dollarValue;
if (double.TryParse(textBox.Text.Trim(), out dollarValue)) if (double.TryParse(textBox.Text.Trim(), out dollarValue))
@@ -2029,12 +2034,12 @@ namespace AdvertsingProfitControl
//And apply formatting. //And apply formatting.
textBox.Text = Math.Round(dollarValue, 2).ToString("N", new CultureInfo("en-US")); 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". //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 else
{ {
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric"); MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = ""; textBox.Text = string.Empty;
} }
} }
if (isTaxableDirtyCheckBox.Tag != null) if (isTaxableDirtyCheckBox.Tag != null)
@@ -2044,13 +2049,13 @@ namespace AdvertsingProfitControl
} }
//Update the total sales text box before returning. //Update the total sales text box before returning.
var totalTaxable = 0.00; var totalTaxable = 0.00;
if (sundayTaxableTextBox.Text != "") totalTaxable += double.Parse(sundayTaxableTextBox.Text); if (sundayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(sundayTaxableTextBox.Text);
if (mondayTaxableTextBox.Text != "") totalTaxable += double.Parse(mondayTaxableTextBox.Text); if (mondayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(mondayTaxableTextBox.Text);
if (tuesdayTaxableTextBox.Text != "") totalTaxable += double.Parse(tuesdayTaxableTextBox.Text); if (tuesdayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(tuesdayTaxableTextBox.Text);
if (wednesdayTaxableTextBox.Text != "") totalTaxable += double.Parse(wednesdayTaxableTextBox.Text); if (wednesdayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(wednesdayTaxableTextBox.Text);
if (thursdayTaxableTextBox.Text != "") totalTaxable += double.Parse(thursdayTaxableTextBox.Text); if (thursdayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(thursdayTaxableTextBox.Text);
if (fridayTaxableTextBox.Text != "") totalTaxable += double.Parse(fridayTaxableTextBox.Text); if (fridayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(fridayTaxableTextBox.Text);
if (saturdayTaxableTextBox.Text != "") totalTaxable += double.Parse(saturdayTaxableTextBox.Text); if (saturdayTaxableTextBox.Text != string.Empty) totalTaxable += double.Parse(saturdayTaxableTextBox.Text);
if (Math.Abs(totalTaxable) > 0) if (Math.Abs(totalTaxable) > 0)
{ {
totalTaxableTextBox.Text = totalTaxable.ToString("N", new CultureInfo("en-US")); 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. //If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag.
isTaxableDirtyCheckBox.Checked = false; 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 //If the user has already added the fields to the database but has removed a value
//update that accordingly. //update that accordingly.
isTaxableDirtyCheckBox.Checked = true; isTaxableDirtyCheckBox.Checked = true;
_isFormDirty = true; _isFormDirty = true;
} }
totalTaxableTextBox.Text = ""; totalTaxableTextBox.Text = string.Empty;
} }
} }
@@ -2088,7 +2093,7 @@ namespace AdvertsingProfitControl
var textBox = (TextBox)sender; var textBox = (TextBox)sender;
if (_beginningCellValue == textBox.Text) return; if (_beginningCellValue == textBox.Text) return;
//There was a change to the starting value of the text box if we've made it this far. //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; double value;
if (double.TryParse(textBox.Text.Trim(), out value)) if (double.TryParse(textBox.Text.Trim(), out value))
@@ -2099,12 +2104,12 @@ namespace AdvertsingProfitControl
//And apply formatting. //And apply formatting.
textBox.Text = Math.Round(value, 2).ToString("N", new CultureInfo("en-US")); 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". //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 else
{ {
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric"); MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = ""; textBox.Text = string.Empty;
} }
} }
else else
@@ -2113,31 +2118,31 @@ namespace AdvertsingProfitControl
if (isCostAnalysisDirtyCheckBox.Tag == null) if (isCostAnalysisDirtyCheckBox.Tag == null)
{ {
//Since it hasn't check to see if the other text boxes are empty. //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) if (isDirty)
{ {
isCostAnalysisDirtyCheckBox.Checked = false; isCostAnalysisDirtyCheckBox.Checked = false;
return; return;
} }
isDirty = salaryPercentageTextBox.Text.Trim() == ""; isDirty = salaryPercentageTextBox.Text.Trim() == string.Empty;
if (isDirty) if (isDirty)
{ {
isCostAnalysisDirtyCheckBox.Checked = false; isCostAnalysisDirtyCheckBox.Checked = false;
return; return;
} }
isDirty = salaryDollarsTextBox.Text.Trim() == ""; isDirty = salaryDollarsTextBox.Text.Trim() == string.Empty;
if (isDirty) if (isDirty)
{ {
isCostAnalysisDirtyCheckBox.Checked = false; isCostAnalysisDirtyCheckBox.Checked = false;
return; return;
} }
isDirty = suppliesTextBox.Text.Trim() == ""; isDirty = suppliesTextBox.Text.Trim() == string.Empty;
if (isDirty) if (isDirty)
{ {
isCostAnalysisDirtyCheckBox.Checked = false; 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 //If the user has already added the fields to the database but has removed a value
//update that accordingly. //update that accordingly.
@@ -2156,17 +2161,18 @@ namespace AdvertsingProfitControl
if (e.Start == _currentActiveDate || !weekEndingCalendar.BoldedDates.Contains(e.Start)) return; if (e.Start == _currentActiveDate || !weekEndingCalendar.BoldedDates.Contains(e.Start)) return;
if (_isFormDirty) 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) if (result == DialogResult.Yes)
{ {
//_currentActiveDate = e.Start;
//Save the changes made to the database then clear and load the date picked by the user. //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; weekEndingCalendar.SelectionStart = _currentActiveDate;
return; return;
} }
//The "No" button doesn't need to be processed since it just means continue on with the method.
} }
_currentActiveDate = e.Start; _currentActiveDate = e.Start;
Text = @"Modify Record (Current Record: " + e.Start.ToString("d") + @")"; Text = @"Modify Record (Current Record: " + e.Start.ToString("d") + @")";
@@ -2242,8 +2248,8 @@ namespace AdvertsingProfitControl
suppliesTextBox.Enter -= StoreBeginningTextBoxValue; suppliesTextBox.Enter -= StoreBeginningTextBoxValue;
suppliesTextBox.Validating -= ValidateCostAnalysisValues; suppliesTextBox.Validating -= ValidateCostAnalysisValues;
//Clear errors and information. //Clear errors and information.
informationLabel.Text = ""; informationLabel.Text = string.Empty;
errorLabel.Text = ""; errorLabel.Text = string.Empty;
//Clear projections //Clear projections
projectionsDataGridView.Rows.Clear(); projectionsDataGridView.Rows.Clear();
//Clear inventory //Clear inventory
@@ -2253,7 +2259,7 @@ namespace AdvertsingProfitControl
//Reset the ad special index. //Reset the ad special index.
_adSpecialIndex = -1; _adSpecialIndex = -1;
//Clear the beginning cell value variable. //Clear the beginning cell value variable.
_beginningCellValue = ""; _beginningCellValue = string.Empty;
//Reset the form's dirty flag //Reset the form's dirty flag
_isFormDirty = false; _isFormDirty = false;
//Clear the used ad items //Clear the used ad items
@@ -2265,40 +2271,40 @@ namespace AdvertsingProfitControl
isCommentDirtyCheckBox.Checked = false; isCommentDirtyCheckBox.Checked = false;
isCommentDirtyCheckBox.Text = @"IsCommentDirty"; isCommentDirtyCheckBox.Text = @"IsCommentDirty";
isCommentDirtyCheckBox.Tag = null; isCommentDirtyCheckBox.Tag = null;
commentsTextBox.Text = ""; commentsTextBox.Text = string.Empty;
commentsGroupBox.Text = @"Comments (Characters Remaining: " + commentsTextBox.MaxLength + @")"; commentsGroupBox.Text = @"Comments (Characters Remaining: " + commentsTextBox.MaxLength + @")";
//Clear weekly sales. //Clear weekly sales.
isWeeklySalesDirtyCheckBox.Checked = false; isWeeklySalesDirtyCheckBox.Checked = false;
isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty"; isWeeklySalesDirtyCheckBox.Text = @"IsWeeklySalesDirty";
isWeeklySalesDirtyCheckBox.Tag = null; isWeeklySalesDirtyCheckBox.Tag = null;
sundayWeeklySalesTextBox.Text = ""; sundayWeeklySalesTextBox.Text = string.Empty;
mondayWeeklySalesTextBox.Text = ""; mondayWeeklySalesTextBox.Text = string.Empty;
tuesdayWeeklySalesTextBox.Text = ""; tuesdayWeeklySalesTextBox.Text = string.Empty;
wednesdayWeeklySalesTextBox.Text = ""; wednesdayWeeklySalesTextBox.Text = string.Empty;
thursdayWeeklySalesTextBox.Text = ""; thursdayWeeklySalesTextBox.Text = string.Empty;
fridayWeeklySalesTextBox.Text = ""; fridayWeeklySalesTextBox.Text = string.Empty;
saturdayWeeklySalesTextBox.Text = ""; saturdayWeeklySalesTextBox.Text = string.Empty;
totalWeeklySalesTextBox.Text = ""; totalWeeklySalesTextBox.Text = string.Empty;
//Clear taxable. //Clear taxable.
isTaxableDirtyCheckBox.Checked = false; isTaxableDirtyCheckBox.Checked = false;
isTaxableDirtyCheckBox.Text = @"IsTaxableDirty"; isTaxableDirtyCheckBox.Text = @"IsTaxableDirty";
isTaxableDirtyCheckBox.Tag = null; isTaxableDirtyCheckBox.Tag = null;
sundayTaxableTextBox.Text = ""; sundayTaxableTextBox.Text = string.Empty;
mondayTaxableTextBox.Text = ""; mondayTaxableTextBox.Text = string.Empty;
tuesdayTaxableTextBox.Text = ""; tuesdayTaxableTextBox.Text = string.Empty;
wednesdayTaxableTextBox.Text = ""; wednesdayTaxableTextBox.Text = string.Empty;
thursdayTaxableTextBox.Text = ""; thursdayTaxableTextBox.Text = string.Empty;
fridayTaxableTextBox.Text = ""; fridayTaxableTextBox.Text = string.Empty;
saturdayTaxableTextBox.Text = ""; saturdayTaxableTextBox.Text = string.Empty;
totalTaxableTextBox.Text = ""; totalTaxableTextBox.Text = string.Empty;
//Clear cost analysis //Clear cost analysis
isCostAnalysisDirtyCheckBox.Checked = false; isCostAnalysisDirtyCheckBox.Checked = false;
isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty"; isCostAnalysisDirtyCheckBox.Text = @"IsCostAnalysisDirty";
isCostAnalysisDirtyCheckBox.Tag = null; isCostAnalysisDirtyCheckBox.Tag = null;
salesPerManHourTextBox.Text = ""; salesPerManHourTextBox.Text = string.Empty;
salaryPercentageTextBox.Text = ""; salaryPercentageTextBox.Text = string.Empty;
salaryDollarsTextBox.Text = ""; salaryDollarsTextBox.Text = string.Empty;
suppliesTextBox.Text = ""; suppliesTextBox.Text = string.Empty;
//Re-enable the events for all the controls. //Re-enable the events for all the controls.
projectionsDataGridView.CellEnter += StoreBeginningCellValue; projectionsDataGridView.CellEnter += StoreBeginningCellValue;
projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
@@ -2375,14 +2381,14 @@ namespace AdvertsingProfitControl
var databaseTracker = new DatabaseTracker(); var databaseTracker = new DatabaseTracker();
var databaseReader = new DatabaseReader(); var databaseReader = new DatabaseReader();
var dateId = databaseReader.RetrieveDateIdByDateString(date.ToString("d"), databaseTracker.DatabaseConnectionString); var dateId = databaseReader.RetrieveDateIdByDateString(date.ToString("d"), databaseTracker.DatabaseConnectionString);
var projections = databaseReader.ReturnProjectionsTable(dateId, databaseTracker.DatabaseConnectionString); var projections = databaseReader.ReturnProjectionsTable(dateId.ToString(), databaseTracker.DatabaseConnectionString);
var inventory = databaseReader.ReturnInventoryTable(dateId, databaseTracker.DatabaseConnectionString); var inventory = databaseReader.ReturnInventoryTable(dateId.ToString(), databaseTracker.DatabaseConnectionString);
var actualSales = databaseReader.ReturnActualSales(dateId, databaseTracker.DatabaseConnectionString); var actualSales = databaseReader.ReturnActualSales(dateId.ToString(), databaseTracker.DatabaseConnectionString);
LoadProjectionsTable(projections); LoadProjectionsTable(projections);
LoadInventory(inventory); LoadInventory(inventory);
LoadActualSales(actualSales); LoadActualSales(actualSales);
var invoices = databaseReader.ReturnInvoiceTable(dateId, databaseTracker.DatabaseConnectionString); var invoices = databaseReader.ReturnInvoiceTable(dateId.ToString(), databaseTracker.DatabaseConnectionString);
var comments = databaseReader.RetrieveComments(int.Parse(dateId), databaseTracker.DatabaseConnectionString); var comments = databaseReader.RetrieveComments(int.Parse(dateId.ToString()), databaseTracker.DatabaseConnectionString);
if (comments.Count == 2) if (comments.Count == 2)
{ {
LoadComments(int.Parse(comments[0]), comments[1]); LoadComments(int.Parse(comments[0]), comments[1]);
@@ -2391,7 +2397,7 @@ namespace AdvertsingProfitControl
{ {
informationLabel.Text += @"No comments to display." + Environment.NewLine; informationLabel.Text += @"No comments to display." + Environment.NewLine;
} }
var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId, var weeklySales = databaseReader.ReturnWeeklySalesFromDateId(dateId.ToString(),
databaseTracker.DatabaseConnectionString); databaseTracker.DatabaseConnectionString);
if (weeklySales.Rows.Count == 1) if (weeklySales.Rows.Count == 1)
{ {
@@ -2402,7 +2408,7 @@ namespace AdvertsingProfitControl
informationLabel.Text += @"No sales to display." + Environment.NewLine; 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) if (taxable.Rows.Count == 1)
{ {
LoadTaxable(taxable); LoadTaxable(taxable);
@@ -2412,7 +2418,7 @@ namespace AdvertsingProfitControl
informationLabel.Text += @"No taxable data to display." + Environment.NewLine; informationLabel.Text += @"No taxable data to display." + Environment.NewLine;
} }
LoadInvoices(invoices); LoadInvoices(invoices);
var costAnalysis = databaseReader.ReturnCostAnalysis(int.Parse(dateId), var costAnalysis = databaseReader.ReturnCostAnalysis(dateId,
databaseTracker.DatabaseConnectionString); databaseTracker.DatabaseConnectionString);
if (costAnalysis.Rows.Count == 1) if (costAnalysis.Rows.Count == 1)
{ {
@@ -2453,7 +2459,7 @@ namespace AdvertsingProfitControl
{ {
if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0") if (projections.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
{ {
var cell = new DataGridViewTextBoxCell {Value = ""}; var cell = new DataGridViewTextBoxCell {Value = string.Empty};
newRow.Cells.Add(cell); newRow.Cells.Add(cell);
} }
else else
@@ -2521,6 +2527,8 @@ namespace AdvertsingProfitControl
} }
projectionsDataGridView.Rows.Add(newRow); 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 //Re-enable the events
projectionsDataGridView.CellEnter += StoreBeginningCellValue; projectionsDataGridView.CellEnter += StoreBeginningCellValue;
projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; projectionsDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
@@ -2559,7 +2567,7 @@ namespace AdvertsingProfitControl
{ {
if (inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0") if (inventoryTable.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
{ {
var cell = new DataGridViewTextBoxCell { Value = "" }; var cell = new DataGridViewTextBoxCell { Value = string.Empty };
newRow.Cells.Add(cell); newRow.Cells.Add(cell);
} }
else else
@@ -2613,6 +2621,8 @@ namespace AdvertsingProfitControl
} }
inventoryDataGridView.Rows.Add(newRow); 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 //Re-enable the events
inventoryDataGridView.CellEnter += StoreBeginningCellValue; inventoryDataGridView.CellEnter += StoreBeginningCellValue;
inventoryDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; inventoryDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
@@ -2651,7 +2661,7 @@ namespace AdvertsingProfitControl
{ {
if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0") if (actualSales.Rows[rowIndex].ItemArray[cellIndex].ToString() == "0")
{ {
var cell = new DataGridViewTextBoxCell { Value = "" }; var cell = new DataGridViewTextBoxCell { Value = string.Empty };
newRow.Cells.Add(cell); newRow.Cells.Add(cell);
} }
else else
@@ -2705,6 +2715,8 @@ namespace AdvertsingProfitControl
} }
actualSalesDataGridView.Rows.Add(newRow); 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 //Re-enable the events
actualSalesDataGridView.CellEnter += StoreBeginningCellValue; actualSalesDataGridView.CellEnter += StoreBeginningCellValue;
actualSalesDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave; actualSalesDataGridView.RowLeave += UpdateUsedAdItemCollectionOnRowLeave;
@@ -3055,8 +3067,51 @@ namespace AdvertsingProfitControl
#region Database Update/Insertion Methods #region Database Update/Insertion Methods
private bool SaveRecords()
{
var success = false;
//Get the date ID for the current active date.
return success;
}
/// <summary>
/// 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.
/// </summary>
/// <param name="date">The date string.</param>
/// <returns>The date ID, otherwise zero (0) on fail.</returns>
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 #endregion
//private void NormalizeApcTables(DataTable projections, DataTable inventory, DataTable actualSales, string dateId) //private void NormalizeApcTables(DataTable projections, DataTable inventory, DataTable actualSales, string dateId)
@@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms> </dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>ib1gNsn2WoDzAPiOU+0/4RFlwIEfmJtvgCPloir4KFA=</dsig:DigestValue> <dsig:DigestValue>ahFX/ECRCn2uEoELdC76I+/TVakX4bXkbfjNul+1+Ow=</dsig:DigestValue>
</hash> </hash>
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
@@ -43,14 +43,14 @@
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
<dependency> <dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3607040"> <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3608576">
<assemblyIdentity name="AdvertsingProfitControl" version="0.9.5.2" language="neutral" processorArchitecture="amd64" /> <assemblyIdentity name="AdvertsingProfitControl" version="0.9.5.2" language="neutral" processorArchitecture="amd64" />
<hash> <hash>
<dsig:Transforms> <dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms> </dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>cTFWoKFn2+4/0r/55ub0w4SG/Rc39J/A3gn6JBlTdZU=</dsig:DigestValue> <dsig:DigestValue>i7aAPQL6YXJt+3MW8a9abkTz7+KcsRjrBy8WabqjtVw=</dsig:DigestValue>
</hash> </hash>
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>