(Solved Homework): I'm stuck in creating this windows form. Any help in creating the appropriate conversions would be helpful. I'm not

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.

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 Cancel

In this exercise, you’ll 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 Assignment8Ex3_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 DialogResultproperty 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 that’s 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)
discountPercent = .0m;
else if (productTotal >= 100 && productTotal < 250)
discountPercent = .1m;
else if (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 <= min || 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();
}
}
}

Show transcribed image text

Expert Answer

 Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InvoiceTotal
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmInvoiceTotal());
}
}
}

frmInvoiceTotal.Designer.cs

namespace InvoiceTotal
{
partial class frmInvoiceTotal
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name=”disposing”>true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support – do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnExit = new System.Windows.Forms.Button();
this.btnCalculate = new System.Windows.Forms.Button();
this.txtProductTotal = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.txtDiscountAmount = new System.Windows.Forms.TextBox();
this.txtTotal = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtSubtotal = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.txtTax = new System.Windows.Forms.TextBox();
this.btnChange = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnExit
//
this.btnExit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnExit.Location = new System.Drawing.Point(130, 161);
this.btnExit.Name = “btnExit”;
this.btnExit.Size = new System.Drawing.Size(75, 23);
this.btnExit.TabIndex = 16;
this.btnExit.Text = “E&xit”;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnCalculate
//
this.btnCalculate.Location = new System.Drawing.Point(36, 161);
this.btnCalculate.Name = “btnCalculate”;
this.btnCalculate.Size = new System.Drawing.Size(75, 23);
this.btnCalculate.TabIndex = 15;
this.btnCalculate.Text = “&Calculate”;
this.btnCalculate.Click += new System.EventHandler(this.btnCalculate_Click);
//
// txtProductTotal
//
this.txtProductTotal.Location = new System.Drawing.Point(121, 16);
this.txtProductTotal.Name = “txtProductTotal”;
this.txtProductTotal.Size = new System.Drawing.Size(84, 20);
this.txtProductTotal.TabIndex = 14;
//
// label3
//
this.label3.Location = new System.Drawing.Point(17, 121);
this.label3.Name = “label3”;
this.label3.Size = new System.Drawing.Size(94, 20);
this.label3.TabIndex = 5;
this.label3.Text = “Total:”;
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label2
//
this.label2.Location = new System.Drawing.Point(17, 42);
this.label2.Name = “label2”;
this.label2.Size = new System.Drawing.Size(94, 20);
this.label2.TabIndex = 8;
this.label2.Text = “Discount amount:”;
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label1
//
this.label1.Location = new System.Drawing.Point(17, 16);
this.label1.Name = “label1”;
this.label1.Size = new System.Drawing.Size(94, 20);
this.label1.TabIndex = 7;
this.label1.Text = “Product total:”;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// txtDiscountAmount
//
this.txtDiscountAmount.Location = new System.Drawing.Point(121, 42);
this.txtDiscountAmount.Name = “txtDiscountAmount”;
this.txtDiscountAmount.ReadOnly = true;
this.txtDiscountAmount.Size = new System.Drawing.Size(84, 20);
this.txtDiscountAmount.TabIndex = 18;
this.txtDiscountAmount.TabStop = false;
//
// txtTotal
//
this.txtTotal.Location = new System.Drawing.Point(121, 122);
this.txtTotal.Name = “txtTotal”;
this.txtTotal.ReadOnly = true;
this.txtTotal.Size = new System.Drawing.Size(84, 20);
this.txtTotal.TabIndex = 19;
this.txtTotal.TabStop = false;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(17, 72);
this.label4.Name = “label4”;
this.label4.Size = new System.Drawing.Size(49, 13);
this.label4.TabIndex = 20;
this.label4.Text = “Subtotal:”;
//
// txtSubtotal
//
this.txtSubtotal.Location = new System.Drawing.Point(121, 69);
this.txtSubtotal.Name = “txtSubtotal”;
this.txtSubtotal.ReadOnly = true;
this.txtSubtotal.Size = new System.Drawing.Size(84, 20);
this.txtSubtotal.TabIndex = 21;
this.txtSubtotal.TabStop = false;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(17, 99);
this.label6.Name = “label6”;
this.label6.Size = new System.Drawing.Size(66, 13);
this.label6.TabIndex = 22;
this.label6.Text = “Tax (7.75%):”;
//
// txtTax
//
this.txtTax.Location = new System.Drawing.Point(121, 96);
this.txtTax.Name = “txtTax”;
this.txtTax.ReadOnly = true;
this.txtTax.Size = new System.Drawing.Size(84, 20);
this.txtTax.TabIndex = 23;
this.txtTax.TabStop = false;
//
// btnChange
//
this.btnChange.Location = new System.Drawing.Point(230, 94);
this.btnChange.Name = “btnChange”;
this.btnChange.Size = new System.Drawing.Size(75, 23);
this.btnChange.TabIndex = 24;
this.btnChange.Text = “Change Percent”;
this.btnChange.UseVisualStyleBackColor = true;
this.btnChange.Click += new System.EventHandler(this.btnChange_Click);
//
// frmInvoiceTotal
//
this.AcceptButton = this.btnCalculate;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnExit;
this.ClientSize = new System.Drawing.Size(343, 202);
this.Controls.Add(this.btnChange);
this.Controls.Add(this.txtTax);
this.Controls.Add(this.label6);
this.Controls.Add(this.txtSubtotal);
this.Controls.Add(this.label4);
this.Controls.Add(this.txtTotal);
this.Controls.Add(this.txtDiscountAmount);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnCalculate);
this.Controls.Add(this.txtProductTotal);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = “frmInvoiceTotal”;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = “Invoice Total”;
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnCalculate;
private System.Windows.Forms.TextBox txtProductTotal;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtDiscountAmount;
private System.Windows.Forms.TextBox txtTotal;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtSubtotal;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox txtTax;
private System.Windows.Forms.Button btnChange;
}
}

frmInvoiceTotal.cs

using 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 frmInvoiceTotal : Form
{
public frmInvoiceTotal()
{
InitializeComponent();
}

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)
discountPercent = .0m;
else if (productTotal >= 100 && productTotal < 250)
discountPercent = .1m;
else if (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 <= min || 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();
}

private void btnChange_Click(object sender, EventArgs e)
{
frmSalesTax f = new frmSalesTax();
//f.Show();

if (f.ShowDialog() == DialogResult.OK)
{
SalesTaxPct = Convert.ToDecimal(f.Tag);
f.Close();
}
}
}
}

frmSalesTax.Designer.cs

namespace InvoiceTotal
{
partial class frmSalesTax
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name=”disposing”>true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support – do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.txtInput = new System.Windows.Forms.TextBox();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 89);
this.label1.Name = “label1”;
this.label1.Size = new System.Drawing.Size(60, 13);
this.label1.TabIndex = 0;
this.label1.Text = “Sales Tax: “;
//
// txtInput
//
this.txtInput.Location = new System.Drawing.Point(79, 86);
this.txtInput.Name = “txtInput”;
this.txtInput.Size = new System.Drawing.Size(100, 20);
this.txtInput.TabIndex = 1;
//
// btnOK
//
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Location = new System.Drawing.Point(33, 127);
this.btnOK.Name = “btnOK”;
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 2;
this.btnOK.Text = “OK”;
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(123, 127);
this.btnCancel.Name = “btnCancel”;
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 3;
this.btnCancel.Text = “Cancel”;
this.btnCancel.UseVisualStyleBackColor = true;
//
// frmSalesTax
//
this.AcceptButton = this.btnOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.txtInput);
this.Controls.Add(this.label1);
this.Name = “frmSalesTax”;
this.Text = “frmSalesTax”;
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtInput;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
}
}

frmSalesTax.cs

using 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 frmSalesTax : Form
{

public frmSalesTax()
{
InitializeComponent();
}

private void btnOK_Click(object sender, EventArgs e)
{
decimal salesTax = Convert.ToDecimal(txtInput.Text);
Tag = salesTax;
}
}
}

iWriteHomework
Order NOW for a 10% Discount
Pages (550 words)
Approximate price: -

Why Us?

Top Quality and Well-Researched Papers

All ourbpapers are written from scratch. In fact, Clients who ask for paraphrasing services are highly discouraged. We have writers ready to craft any paper from scratch and deliver quality ahead of time.

Professional and Experienced Academic Writers

Our writers keeps you posted on your papers progress - providing you with paper outline/draft. You are also at liberty to communicate directly with your writer.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time, in many cases quite ahead of time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

× Contact Live Agents