From 6813bbb341f93dae6e4f9387b922f7bf55f9e792 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Fri, 2 Dec 2016 23:12:05 -0600 Subject: [PATCH] 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. --- AdvertsingProfitControl/APCDatabase.accdb | Bin 2932736 -> 2932736 bytes AdvertsingProfitControl/DatabaseWriter.cs | 130 +++++++++++++++++ .../NewAddRecord.Designer.cs | 61 ++++++-- AdvertsingProfitControl/NewAddRecord.cs | 138 ++++++++++++++++-- AdvertsingProfitControl/NewAddRecord.resx | 3 + ...AdvertsingProfitControl.vshost.application | 2 +- ...dvertsingProfitControl.vshost.exe.manifest | 6 +- 7 files changed, 315 insertions(+), 25 deletions(-) diff --git a/AdvertsingProfitControl/APCDatabase.accdb b/AdvertsingProfitControl/APCDatabase.accdb index 6ee917a0670d3b46a6d720c6a38efa32b6d1e3ae..6096142118d7d676741307699c8d5e7060455748 100644 GIT binary patch delta 553 zcmZo@*vtsR8<_Yw_2qUlF)=bSGHw>+d(SvofsbvIz&?J)o16E`zww!#ctAmOy2Cy; z<;n8%xp?*)*#kqo!0SqLj^0MeNRh-_KDIQ z?GvRr+b2qMwNI4hZl5U4vwfm8Z$8U1173k;0vrNu4!ms+d~FW=Z4Lr$4uWkCLTwJh zZ4M%B4x()iVr>rM+Z-fB0vI)?i%yWx;{{m+d(SvofsbvIz&?J)tDE=Bzww!VFrHI$y2Cy; z<;n8%xp;|xbOqVbRA9>KUXmZ28Mvc zU>TC>51ve5jXvA=bFw(Iaf@(wLM_pl&MUwYxN+evuIU!iEaKC1q*+wkOQc!aOQc!b zOQhM_OQhM`OQbp4OQbp5OQgBlOQgBmOQd{)#n7#!86^L~<)-Y)-1@@p@n_;k?*DLqE<=>ZO$ zI@=2xq-H2iw_7A7Jw0HN6el*KJz$Ykd%z;;_JBn)?E#Bq+XEKKwFfMcZx2|c&>pZz zu{~gsQhUH6<@SI@D(wM_RNDg /// Inserts a new ad item into the database and returns the new item's ID number. /// Supports rolling back as to not corrupt the database. diff --git a/AdvertsingProfitControl/NewAddRecord.Designer.cs b/AdvertsingProfitControl/NewAddRecord.Designer.cs index 598d0a4..4a96747 100644 --- a/AdvertsingProfitControl/NewAddRecord.Designer.cs +++ b/AdvertsingProfitControl/NewAddRecord.Designer.cs @@ -105,8 +105,11 @@ this.isTaxableDirtyCheckBox = new System.Windows.Forms.CheckBox(); this.isCostAnalysisDirtyCheckBox = new System.Windows.Forms.CheckBox(); this.clearFormFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); - this.idButton = new System.Windows.Forms.Button(); + this.generateCommentIdButton = new System.Windows.Forms.Button(); this.reminderLabel = new System.Windows.Forms.Label(); + this.generateWeeklySalesIdButton = new System.Windows.Forms.Button(); + this.generateTaxableIdButton = new System.Windows.Forms.Button(); + this.generateCostAnalysisIdButton = new System.Windows.Forms.Button(); this.commentsGroupBox.SuspendLayout(); this.mainTabControl.SuspendLayout(); this.projectionTabPage.SuspendLayout(); @@ -857,8 +860,11 @@ // // debugPanel // + this.debugPanel.Controls.Add(this.generateCostAnalysisIdButton); + this.debugPanel.Controls.Add(this.generateTaxableIdButton); + this.debugPanel.Controls.Add(this.generateWeeklySalesIdButton); this.debugPanel.Controls.Add(this.reminderLabel); - this.debugPanel.Controls.Add(this.idButton); + this.debugPanel.Controls.Add(this.generateCommentIdButton); this.debugPanel.Controls.Add(this.isCostAnalysisDirtyCheckBox); this.debugPanel.Controls.Add(this.isTaxableDirtyCheckBox); this.debugPanel.Controls.Add(this.isWeeklySalesDirtyCheckBox); @@ -915,15 +921,15 @@ this.clearFormFileMainMenu.Size = new System.Drawing.Size(240, 34); this.clearFormFileMainMenu.Text = "&Clear Form"; // - // idButton + // generateCommentIdButton // - this.idButton.Location = new System.Drawing.Point(54, 283); - this.idButton.Name = "idButton"; - this.idButton.Size = new System.Drawing.Size(286, 62); - this.idButton.TabIndex = 4; - this.idButton.Text = "Create / Clear Comments ID"; - this.idButton.UseVisualStyleBackColor = true; - this.idButton.Click += new System.EventHandler(this.idButton_Click); + this.generateCommentIdButton.Location = new System.Drawing.Point(54, 283); + this.generateCommentIdButton.Name = "generateCommentIdButton"; + this.generateCommentIdButton.Size = new System.Drawing.Size(286, 62); + this.generateCommentIdButton.TabIndex = 4; + this.generateCommentIdButton.Text = "Create / Clear Comments ID"; + this.generateCommentIdButton.UseVisualStyleBackColor = true; + this.generateCommentIdButton.Click += new System.EventHandler(this.idButton_Click); // // reminderLabel // @@ -934,6 +940,36 @@ this.reminderLabel.TabIndex = 5; this.reminderLabel.Text = "These checkboxes Tag properties hold the ID for their respective elements."; // + // generateWeeklySalesIdButton + // + this.generateWeeklySalesIdButton.Location = new System.Drawing.Point(346, 283); + this.generateWeeklySalesIdButton.Name = "generateWeeklySalesIdButton"; + this.generateWeeklySalesIdButton.Size = new System.Drawing.Size(286, 62); + this.generateWeeklySalesIdButton.TabIndex = 6; + this.generateWeeklySalesIdButton.Text = "Create / Clear Weekly Sales ID"; + this.generateWeeklySalesIdButton.UseVisualStyleBackColor = true; + this.generateWeeklySalesIdButton.Click += new System.EventHandler(this.generateWeeklySalesIdButton_Click); + // + // generateTaxableIdButton + // + this.generateTaxableIdButton.Location = new System.Drawing.Point(638, 283); + this.generateTaxableIdButton.Name = "generateTaxableIdButton"; + this.generateTaxableIdButton.Size = new System.Drawing.Size(286, 62); + this.generateTaxableIdButton.TabIndex = 7; + this.generateTaxableIdButton.Text = "Create / Clear Taxable ID"; + this.generateTaxableIdButton.UseVisualStyleBackColor = true; + this.generateTaxableIdButton.Click += new System.EventHandler(this.generateTaxableIdButton_Click); + // + // generateCostAnalysisIdButton + // + this.generateCostAnalysisIdButton.Location = new System.Drawing.Point(931, 283); + this.generateCostAnalysisIdButton.Name = "generateCostAnalysisIdButton"; + this.generateCostAnalysisIdButton.Size = new System.Drawing.Size(299, 62); + this.generateCostAnalysisIdButton.TabIndex = 8; + this.generateCostAnalysisIdButton.Text = "Create / Clear Cost Analysis ID"; + this.generateCostAnalysisIdButton.UseVisualStyleBackColor = true; + this.generateCostAnalysisIdButton.Click += new System.EventHandler(this.generateCostAnalysisIdButton_Click); + // // NewAddRecord // this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); @@ -1060,7 +1096,10 @@ private System.Windows.Forms.CheckBox isTaxableDirtyCheckBox; private System.Windows.Forms.CheckBox isWeeklySalesDirtyCheckBox; private System.Windows.Forms.CheckBox isCommentDirtyCheckBox; - private System.Windows.Forms.Button idButton; + private System.Windows.Forms.Button generateCommentIdButton; private System.Windows.Forms.Label reminderLabel; + private System.Windows.Forms.Button generateCostAnalysisIdButton; + private System.Windows.Forms.Button generateTaxableIdButton; + private System.Windows.Forms.Button generateWeeklySalesIdButton; } } \ No newline at end of file diff --git a/AdvertsingProfitControl/NewAddRecord.cs b/AdvertsingProfitControl/NewAddRecord.cs index 96baa11..35b4872 100644 --- a/AdvertsingProfitControl/NewAddRecord.cs +++ b/AdvertsingProfitControl/NewAddRecord.cs @@ -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"); + } + } } } diff --git a/AdvertsingProfitControl/NewAddRecord.resx b/AdvertsingProfitControl/NewAddRecord.resx index ad2c550..ed00b2b 100644 --- a/AdvertsingProfitControl/NewAddRecord.resx +++ b/AdvertsingProfitControl/NewAddRecord.resx @@ -120,6 +120,9 @@ 17, 17 + + 17, 17 + diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application index 9784eb4..d2725be 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application @@ -14,7 +14,7 @@ - sGFYIVV7/W3lYCXVUKinGP8+HnzRtuBko/4mLniApzs= + sJa3N/qFPRThckha4aReaPFLpwQDio7tNBSSDURtnBk= diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest index 3e8a29c..3ac2ed7 100644 --- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest +++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest @@ -43,14 +43,14 @@ - + - usHPTgWtHUZgtHEvPN4oe9BDB+EUrs2IjXXHTcpDJnI= + KJrIBRsbaX/71nFWLgdvuorK6BWoYWZ05mGNqVbM0Y0= @@ -84,7 +84,7 @@ - EXv832xgnrJTLbEvUhk+7ekkWAMvfBMCvVv0Y6BILg0= + dX2Dundhh4161Q3VUoRkM0RkUhpDPmRvgqyLNfiU3Nk=