Finished validation code for the cost analysis, weekly sales and taxable. Fixed a bug with the update flag not being set if an ID number was set. Wrote comment and weekly sales database writing functions; untested.
This commit is contained in:
@@ -135,6 +135,77 @@ namespace AdvertsingProfitControl
|
||||
saturdayTaxableTextBox.Validating += ValidateTaxableFields;
|
||||
totalTaxableTextBox.Enter += StoreBeginningTextBoxValue;
|
||||
totalTaxableTextBox.Validating += ValidateTaxableFields;
|
||||
//Subscribe the Cost Analysis text boxes to the validation and update events.
|
||||
salesPerManHourTextBox.Enter += StoreBeginningTextBoxValue;
|
||||
salesPerManHourTextBox.Validating += ValidateCostAnalysisValues;
|
||||
salaryPercentageTextBox.Enter += StoreBeginningTextBoxValue;
|
||||
salaryPercentageTextBox.Validating += ValidateCostAnalysisValues;
|
||||
salaryDollarsTextBox.Enter += StoreBeginningTextBoxValue;
|
||||
salaryDollarsTextBox.Validating += ValidateCostAnalysisValues;
|
||||
suppliesTextBox.Enter += StoreBeginningTextBoxValue;
|
||||
suppliesTextBox.Validating += ValidateCostAnalysisValues;
|
||||
}
|
||||
|
||||
private void ValidateCostAnalysisValues(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 value;
|
||||
if (double.TryParse(textBox.Text.Trim(), out value))
|
||||
{
|
||||
//Input is valid so mark the section as dirty.
|
||||
isCostAnalysisDirtyCheckBox.Checked = true;
|
||||
//And apply formatting.
|
||||
textBox.Text = Math.Round(value, 2).ToString("N", new CultureInfo("en-US"));
|
||||
//Check to see if the number is equal to zero (0) i.e. "0.00".
|
||||
if (textBox.Text == @"0.00") textBox.Text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show(@"The value must be numeric.", @"Input Must be Numeric");
|
||||
textBox.Text = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Since the text box that fired this event is empty check to see if this group has been committed to the database.
|
||||
if (isCostAnalysisDirtyCheckBox.Tag == null)
|
||||
{
|
||||
//Since it hasn't check to see if the other text boxes are empty.
|
||||
var isDirty = salesPerManHourTextBox.Text.Trim() == "";
|
||||
if (isDirty)
|
||||
{
|
||||
isCostAnalysisDirtyCheckBox.Checked = false;
|
||||
return;
|
||||
}
|
||||
isDirty = salaryPercentageTextBox.Text.Trim() == "";
|
||||
if (isDirty)
|
||||
{
|
||||
isCostAnalysisDirtyCheckBox.Checked = false;
|
||||
return;
|
||||
}
|
||||
isDirty = salaryDollarsTextBox.Text.Trim() == "";
|
||||
if (isDirty)
|
||||
{
|
||||
isCostAnalysisDirtyCheckBox.Checked = false;
|
||||
return;
|
||||
}
|
||||
isDirty = suppliesTextBox.Text.Trim() == "";
|
||||
if (isDirty)
|
||||
{
|
||||
isCostAnalysisDirtyCheckBox.Checked = false;
|
||||
}
|
||||
}
|
||||
else if (isCostAnalysisDirtyCheckBox.Tag != null && textBox.Text == "")
|
||||
{
|
||||
//If the user has already added the fields to the database but has removed a value
|
||||
//update that accordingly.
|
||||
isCostAnalysisDirtyCheckBox.Checked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateTaxableFields(object sender, CancelEventArgs e)
|
||||
@@ -153,8 +224,6 @@ namespace AdvertsingProfitControl
|
||||
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
|
||||
{
|
||||
@@ -183,6 +252,12 @@ namespace AdvertsingProfitControl
|
||||
//If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag.
|
||||
isTaxableDirtyCheckBox.Checked = false;
|
||||
}
|
||||
else if (isTaxableDirtyCheckBox.Tag != null && textBox.Text == "")
|
||||
{
|
||||
//If the user has already added the fields to the database but has removed a value
|
||||
//update that accordingly.
|
||||
isTaxableDirtyCheckBox.Checked = true;
|
||||
}
|
||||
totalTaxableTextBox.Text = "";
|
||||
}
|
||||
}
|
||||
@@ -209,8 +284,6 @@ namespace AdvertsingProfitControl
|
||||
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
|
||||
{
|
||||
@@ -239,6 +312,12 @@ namespace AdvertsingProfitControl
|
||||
//If the tag doesn't have an ID in it then we're clear to simply clear the is dirty flag.
|
||||
isWeeklySalesDirtyCheckBox.Checked = false;
|
||||
}
|
||||
else if(isWeeklySalesDirtyCheckBox.Tag != null && textBox.Text == "")
|
||||
{
|
||||
//If the user has already added the fields to the database but has removed a value
|
||||
//update that accordingly.
|
||||
isWeeklySalesDirtyCheckBox.Checked = true;
|
||||
}
|
||||
totalWeeklySalesTextBox.Text = "";
|
||||
}
|
||||
}
|
||||
@@ -1709,12 +1788,6 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
}
|
||||
|
||||
private void StoreBeginningTextValue(object sender, EventArgs e)
|
||||
{
|
||||
//Reduce and reuse.
|
||||
_beginningCellValue = commentsTextBox.Text;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Weekly Sales Events
|
||||
@@ -2583,5 +2656,50 @@ namespace AdvertsingProfitControl
|
||||
MessageBox.Show(@"ID cleared from comments.", @"Clear ID Debug");
|
||||
}
|
||||
}
|
||||
|
||||
private void generateWeeklySalesIdButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (isWeeklySalesDirtyCheckBox.Tag == null)
|
||||
{
|
||||
var ran = new Random();
|
||||
isWeeklySalesDirtyCheckBox.Tag = ran.Next();
|
||||
MessageBox.Show(@"Weekly Sales ID is now " + isWeeklySalesDirtyCheckBox.Tag, @"Debug ID Test");
|
||||
}
|
||||
else
|
||||
{
|
||||
isWeeklySalesDirtyCheckBox.Tag = null;
|
||||
MessageBox.Show(@"ID cleared from Weekly Sales.", @"Clear ID Debug");
|
||||
}
|
||||
}
|
||||
|
||||
private void generateTaxableIdButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (isTaxableDirtyCheckBox.Tag == null)
|
||||
{
|
||||
var ran = new Random();
|
||||
isTaxableDirtyCheckBox.Tag = ran.Next();
|
||||
MessageBox.Show(@"Taxable ID is now " + isTaxableDirtyCheckBox.Tag, @"Debug ID Test");
|
||||
}
|
||||
else
|
||||
{
|
||||
isTaxableDirtyCheckBox.Tag = null;
|
||||
MessageBox.Show(@"ID cleared from Taxable.", @"Clear ID Debug");
|
||||
}
|
||||
}
|
||||
|
||||
private void generateCostAnalysisIdButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (isCostAnalysisDirtyCheckBox.Tag == null)
|
||||
{
|
||||
var ran = new Random();
|
||||
isCostAnalysisDirtyCheckBox.Tag = ran.Next();
|
||||
MessageBox.Show(@"Cost Analysis ID is now " + isCostAnalysisDirtyCheckBox.Tag, @"Debug ID Test");
|
||||
}
|
||||
else
|
||||
{
|
||||
isCostAnalysisDirtyCheckBox.Tag = null;
|
||||
MessageBox.Show(@"ID cleared from Cost Analysis.", @"Clear ID Debug");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user