Added dirty flags to the comments, cost analysis, weekly sales and taxable, as well as formatting, validation and auto summing for the latter two. The Tag properties of the check boxes for the dirty flags will contain the IDs.

This commit is contained in:
2016-12-02 18:45:31 -06:00
parent 1907ce1702
commit 8dcc290aef
11 changed files with 473 additions and 127 deletions
+199 -1
View File
@@ -98,6 +98,149 @@ namespace AdvertsingProfitControl
invoicesDataGridView.EditingControlShowing += DisplaySupplierAutoComleteOnEditingShadowControl;
//Finally build the last DataGridView for the form.
ConstructInvoicesDataGridView();//No weekly sales table is nice.
//Subscribe the comments text box to check if changes have been made on leave.
commentsTextBox.Enter += StoreBeginningTextBoxValue;
commentsTextBox.Leave += CheckForTextChangeOnLeave;
//Subscribe the weekly sales text boxes to validation, update required checks and auto-complete methods.
sundayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
sundayWeeklySalesTextBox.Validating += ValidateWeeklySales;
mondayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
mondayWeeklySalesTextBox.Validating += ValidateWeeklySales;
tuesdayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
tuesdayWeeklySalesTextBox.Validating += ValidateWeeklySales;
wednesdayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
wednesdayWeeklySalesTextBox.Validating += ValidateWeeklySales;
thursdayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
thursdayWeeklySalesTextBox.Validating += ValidateWeeklySales;
fridayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
fridayWeeklySalesTextBox.Validating += ValidateWeeklySales;
saturdayWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
saturdayWeeklySalesTextBox.Validating += ValidateWeeklySales;
totalWeeklySalesTextBox.Enter += StoreBeginningTextBoxValue;
totalWeeklySalesTextBox.Validating += ValidateWeeklySales;
//Subscribe the taxable text boxes to validation and update events.
sundayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
sundayTaxableTextBox.Validating += ValidateTaxableFields;
mondayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
mondayTaxableTextBox.Validating += ValidateTaxableFields;
tuesdayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
tuesdayTaxableTextBox.Validating += ValidateTaxableFields;
wednesdayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
wednesdayTaxableTextBox.Validating += ValidateTaxableFields;
thursdayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
thursdayTaxableTextBox.Validating += ValidateTaxableFields;
fridayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
fridayTaxableTextBox.Validating += ValidateTaxableFields;
saturdayTaxableTextBox.Enter += StoreBeginningTextBoxValue;
saturdayTaxableTextBox.Validating += ValidateTaxableFields;
totalTaxableTextBox.Enter += StoreBeginningTextBoxValue;
totalTaxableTextBox.Validating += ValidateTaxableFields;
}
private void ValidateTaxableFields(object sender, CancelEventArgs e)
{
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 != "")
{
double dollarValue;
if (double.TryParse(textBox.Text.Trim(), out dollarValue))
{
//Input is valid so mark the section as dirty.
isTaxableDirtyCheckBox.Checked = true;
//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 = "";
//Check to see if this is not the total weekly sales text box.
if (textBox.Name == totalTaxableTextBox.Name) return;
}
else
{
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = "";
}
}
//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 (Math.Abs(totalTaxable) > 0)
{
totalTaxableTextBox.Text = totalTaxable.ToString("N", new CultureInfo("en-US"));
}
else
{
//Check to see if the weekly sales have been added to the database.
if (isTaxableDirtyCheckBox.Tag == null)
{
//If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag.
isTaxableDirtyCheckBox.Checked = false;
}
totalTaxableTextBox.Text = "";
}
}
private void StoreBeginningTextBoxValue(object sender, EventArgs e)
{
var textBox = (TextBox) sender;
_beginningCellValue = textBox.Text;
}
private void ValidateWeeklySales(object sender, CancelEventArgs e)
{
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 != "")
{
double dollarValue;
if (double.TryParse(textBox.Text.Trim(), out dollarValue))
{
//Input is valid so mark the section as dirty.
isWeeklySalesDirtyCheckBox.Checked = true;
//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 = "";
//Check to see if this is not the total weekly sales text box.
if (textBox.Name == totalWeeklySalesTextBox.Name) return;
}
else
{
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
textBox.Text = "";
}
}
//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 (Math.Abs(totalWeeklySales) > 0)
{
totalWeeklySalesTextBox.Text = totalWeeklySales.ToString("N", new CultureInfo("en-US"));
}
else
{
//Check to see if the weekly sales have been added to the database.
if (isWeeklySalesDirtyCheckBox.Tag == null)
{
//If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag.
isWeeklySalesDirtyCheckBox.Checked = false;
}
totalWeeklySalesTextBox.Text = "";
}
}
#region Invoice Table Events
@@ -288,7 +431,7 @@ namespace AdvertsingProfitControl
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DisplayRowNumbers(object sender, DataGridViewRowsAddedEventArgs e)
private static void DisplayRowNumbers(object sender, DataGridViewRowsAddedEventArgs e)
{
var table = ((DataGridView)sender);
table.Rows[e.RowIndex].HeaderCell.Value = (e.RowIndex + 1).ToString();
@@ -1547,6 +1690,46 @@ namespace AdvertsingProfitControl
commentsGroupBox.ForeColor = (double)commentsTextBox.TextLength / commentsTextBox.MaxLength < .8 ? default(Color) : Color.DarkRed;
commentsGroupBox.Text = @"Comments (Characters Remaining: " + (commentsTextBox.MaxLength - commentsTextBox.TextLength) + @")";
}
private void CheckForTextChangeOnLeave(object sender, EventArgs e)
{
if (commentsTextBox.Text == _beginningCellValue) return;
//Clear white spaces and check if the string is null.
if (commentsTextBox.Text.Trim() == "" && 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.
isCommentDirtyCheckBox.Checked = false;
}
else
{
//Otherwise the comment(s) were committed to the database and will need updating.
//If its empty then the record will be cleared from the database.
isCommentDirtyCheckBox.Checked = true;
}
}
private void StoreBeginningTextValue(object sender, EventArgs e)
{
//Reduce and reuse.
_beginningCellValue = commentsTextBox.Text;
}
#endregion
#region Weekly Sales Events
#endregion
#region Taxable Events
#endregion
#region Cost Analysis Events
#endregion
#region DateTime Events
@@ -2385,5 +2568,20 @@ namespace AdvertsingProfitControl
}
#endregion
private void idButton_Click(object sender, EventArgs e)
{
if (isCommentDirtyCheckBox.Tag == null)
{
var ran = new Random();
isCommentDirtyCheckBox.Tag = ran.Next();
MessageBox.Show(@"Comment ID is now " + isCommentDirtyCheckBox.Tag, @"Debug ID Test");
}
else
{
isCommentDirtyCheckBox.Tag = null;
MessageBox.Show(@"ID cleared from comments.", @"Clear ID Debug");
}
}
}
}