Question
I'm stuck in creating this windows form. Any help in creating the appropriate conversions would be helpful. I'm not sure how to code in order
I'm stuck in creating this windows form. Any help in creating the appropriate conversions would be helpful. I'm not sure how to code in order to link my forms together as shown below.
In this exercise, youll add a second form to an Invoice Total application that lets the user change the sales tax percent.
Open the project and change the name of the existing form
1. Open the InvoiceTotalStart project in the Assignment8\Ex3_InvoiceTotal directory.
2. Change the name of the existing form to frmInvoiceTotal.
Create the Sales Tax form
3. Add another form named frmSalesTax to the project.
4. Add a label, text box,
and two buttons to the new form and set the properties of the form and its controls so they appear as shown above.
When the user presses the Enter key, the Click event of the OK button should fire.
When the user presses the Esc key, the Click event of the Cancel button should fire.
5. Add code to get the sales tax, store it in the Tag property of the form, and set the DialogResult property of the form to OK when the user clicks the OK button.
Modify the code for the Invoice Total form
6. Change the SalesTax constant thats declared in the Invoice Total form so its value can be changed.
7. Add a Change Percent button to the Invoice Total form as shown above.
Then, add code that displays the Sales Tax form and gets the result when the user clicks this button.
If the user clicks the OK button on the Sales Tax form, this event handler should store the new sales tax percent in the sales tax variable and change the Tax label on the form so it displays the correct tax.
Test the application to be sure this works correctly.
8. Add data validation to the Sales Tax form to check that the user enters a decimal value between 0 and 10 (noninclusive). To make that easier, you can copy the IsPresent, IsDecimal, and IsWithinRange methods from the Invoice Total form. Test the application to be sure the validation works correctly.
ing System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace InvoiceTotal { public partial class Form1 : Form //RENAME { public Form1() { InitializeComponent(); }
const decimal SalesTaxPct = 7.75m;
private void btnCalculate_Click(object sender, EventArgs e) { if (IsValidData()) { decimal productTotal = Convert.ToDecimal(txtProductTotal.Text); decimal discountPercent = .0m;
if (productTotal = 100 && productTotal = 250) discountPercent = .25m;
decimal discountAmount = productTotal * discountPercent; decimal subtotal = productTotal - discountAmount; decimal tax = subtotal * SalesTaxPct / 100; decimal total = subtotal + tax;
txtDiscountAmount.Text = discountAmount.ToString("c"); txtSubtotal.Text = subtotal.ToString("c"); txtTax.Text = tax.ToString("c"); txtTotal.Text = total.ToString("c");
txtProductTotal.Focus(); } }
public bool IsValidData() { return IsPresent(txtProductTotal, "Subtotal") && IsDecimal(txtProductTotal, "Subtotal") && IsWithinRange(txtProductTotal, "Subtotal", 0, 1000000); }
public bool IsPresent(TextBox textBox, string name) { if (textBox.Text == "") { MessageBox.Show(name + " is a required field.", "Entry Error"); textBox.Focus(); return false; } return true; }
public bool IsDecimal(TextBox textBox, string name) { decimal number = 0m; if (Decimal.TryParse(textBox.Text, out number)) { return true; } else { MessageBox.Show(name + " must be a decimal number.", "Entry Error"); textBox.Focus(); return false; } }
public bool IsWithinRange(TextBox textBox, string name, decimal min, decimal max) { decimal number = Convert.ToDecimal(textBox.Text); if (number = max) { MessageBox.Show(name + " must be between " + min + " and " + max + ".", "Entry Error"); textBox.Focus(); return false; } return true; }
private void btnExit_Click(object sender, EventArgs e) { this.Close(); } } }
Invoice Total Product total: 225 Discount amount $22.50 Subtotal: $202.50 Tax 7.752) $15.69 Total: $218.19 Change Percent Sales Tax Sales tax pct. 7975 OK CancelStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started