Question

In: Computer Science

Be sure to statically disable both the Enter Subtotal label and the Enter Subtotal textbox. If...

  1. Be sure to statically disable both the Enter Subtotal label and the Enter Subtotal textbox. If you do not know what this means, ask.
  2. Add a label, a text box, and an OK button (see Exercise 3.1 X if you need a refresher) to your form to enable the user to enter his or her name and click OK.

3. In the handler code for the OK button, first check (as you did in Exercise 1 X) to ensure that the name is not blank. If the name is blank generate a message as requested in Exercise 1 X, reset focus and have the user try again to enter a non-blank name.

4. Once a non-blank name has been entered, dynamically (in your own code) enable the Enter Subtotal label and the Enter Subtotal text box.

5. Now in your handler code for btnCalculate, insert try-catch code (see p. 193 for an example) to catch an invalid decimal value entry and ask the user to re-enter his or her data.  

6. Test your project and if the code you have added does not catch a negative input value, make sure you correct this problem and retest your project.

This is the code that I have.

namespace InvoiceTotal
{
   public partial class frmInvoiceTotal : Form
   {
public frmInvoiceTotal()
       {
           InitializeComponent();
       }

       int numberOfInvoices = 0;
       decimal totalOfInvoices = 0m;
       decimal invoiceAverage = 0m;
       decimal largestInvoice = 0m;
       decimal smallestInvoice = Decimal.MaxValue;

       private void btnCalculate_Click(object sender, EventArgs e)
       {
           decimal subtotal = Convert.ToDecimal(txtEnterSubtotal.Text);
           decimal discountPercent = .25m;
           decimal discountAmount = Math.Round(subtotal * discountPercent, 2);
           decimal invoiceTotal = subtotal - discountAmount;

           txtSubtotal.Text = subtotal.ToString("c");
           txtDiscountPercent.Text = discountPercent.ToString("p1");
           txtDiscountAmount.Text = discountAmount.ToString("c");
           txtTotal.Text = invoiceTotal.ToString("c");

           numberOfInvoices++;
           totalOfInvoices += invoiceTotal;
           invoiceAverage = totalOfInvoices / numberOfInvoices;
           largestInvoice = Math.Max(largestInvoice, invoiceTotal);
           smallestInvoice = Math.Min(smallestInvoice, invoiceTotal);

           txtNumberOfInvoices.Text = numberOfInvoices.ToString();
           txtTotalOfInvoices.Text = totalOfInvoices.ToString("c");
           txtInvoiceAverage.Text = invoiceAverage.ToString("c");
           txtLargestInvoice.Text = largestInvoice.ToString("c");
           txtSmallestInvoice.Text = smallestInvoice.ToString("c");

           txtEnterSubtotal.Text = "";
           txtEnterSubtotal.Focus();
       }

       private void btnClearTotals_Click(object sender, System.EventArgs e)
       {
           numberOfInvoices = 0;
           totalOfInvoices = 0m;
           invoiceAverage = 0m;
           largestInvoice = 0m;
           smallestInvoice = Decimal.MaxValue;

           txtNumberOfInvoices.Text = "";
           txtTotalOfInvoices.Text = "";
           txtInvoiceAverage.Text = "";
           txtLargestInvoice.Text = "";
           txtSmallestInvoice.Text = "";

           txtEnterSubtotal.Focus();
       }

       private void btnExit_Click(object sender, EventArgs e)
       {
           this.Close();
       }

   }
}

Solutions

Expert Solution

Check the below code:

int numberOfInvoices = 0;
decimal totalOfInvoices = 0m;
decimal invoiceAverage = 0m;
decimal largestInvoice = 0m;
decimal smallestInvoice = Decimal.MaxValue;

private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text=="")
{
MessageBox.Show("Name is null, please enter the name");
}   

else
{
// display sub total names and values
}
}

private void button2_Click(object sender, EventArgs e)
{
decimal subtotal = Convert.ToDecimal(txtEnterSubtotal.Text);
decimal discountPercent = .25m;
decimal discountAmount = Math.Round(subtotal * discountPercent, 2);
decimal invoiceTotal = subtotal - discountAmount;


try
{
txtSubtotal.Text = subtotal.ToString("c");
txtDiscountPercent.Text = discountPercent.ToString("p1");
txtDiscountAmount.Text = discountAmount.ToString("c");
txtTotal.Text = invoiceTotal.ToString("c");

numberOfInvoices++;
totalOfInvoices += invoiceTotal;
invoiceAverage = totalOfInvoices / numberOfInvoices;
largestInvoice = Math.Max(largestInvoice, invoiceTotal);
smallestInvoice = Math.Min(smallestInvoice, invoiceTotal);

txtNumberOfInvoices.Text = numberOfInvoices.ToString();
txtTotalOfInvoices.Text = totalOfInvoices.ToString("c");
txtInvoiceAverage.Text = invoiceAverage.ToString("c");
txtLargestInvoice.Text = largestInvoice.ToString("c");
txtSmallestInvoice.Text = smallestInvoice.ToString("c");

txtEnterSubtotal.Text = "";
txtEnterSubtotal.Focus();

}
catch
{
MessageBox.Show("Invalid data, renter the values");
}

  

}

private void button3_Click(object sender, EventArgs e)
{
numberOfInvoices = 0;
totalOfInvoices = 0m;
invoiceAverage = 0m;
largestInvoice = 0m;
smallestInvoice = Decimal.MaxValue;

txtNumberOfInvoices.Text = "";
txtTotalOfInvoices.Text = "";
txtInvoiceAverage.Text = "";
txtLargestInvoice.Text = "";
txtSmallestInvoice.Text = "";

txtEnterSubtotal.Focus();
}

private void button4_Click(object sender, EventArgs e)
{
this.Close();
}

Waiting for your valuable comments


Related Solutions

Draw a reaction coordinate for both an exothermic and an endothermic reaction. Be sure to label...
Draw a reaction coordinate for both an exothermic and an endothermic reaction. Be sure to label the axes, the average energies of the reactants and the products, then energy releasd or absorbed, and the activation energy. Solute Solubiltity 0 degrees C 50 degrees C 100 degrees C lead (ii) bromide PbBr2 0.455 1.94 4.75 silver sulfate Ag2SO4 0.573 1.08 1.41 sodium chloride NaCl 35.7 37.0 39.8 silver nitrate AgNO3 122 455 952 cesium chloride CsCl 161.4 218.5 270.4 copper (ii)...
For each of the following, draw three graphs, making sure to label the axes
For each of the following, draw three graphs, making sure to label the axes: the labor and output production function, the capital and output production function, and the labor demand curve. Starting from the original each time, draw in the effect of:A hurricane that destroys some of the capital stockAn increase in N
Writing a statically allocated linked list in ARM assembly (raspberry pi). Step 1: You will statically...
Writing a statically allocated linked list in ARM assembly (raspberry pi). Step 1: You will statically allocate some space for your link list elements. You need to make 5 elements, each elements should have two components, the next pointer first then the value stored. First initialize next pointer to NULL. The value stored at the address will be a string pointer. Step 2: You will then write a function that links the statically allocated linked list elements together. Step 3:...
Be sure to 1) give the null and alternative hypotheses, 2) label which hypothesis is the...
Be sure to 1) give the null and alternative hypotheses, 2) label which hypothesis is the claim, 3) Identify whether the test is left-tailed, right-tailed, or two-tailed, 4) name the test being used, 5) find the P-value for the sample, 6) state whether you reject or fail to reject the null hypothesis, and 7) give the conclusion in the context of the problem. 3. A student at South Plains College claims that the average cost of textbook is more than...
Show all work for credit. Be sure to label work and use sentences as appropriate to...
Show all work for credit. Be sure to label work and use sentences as appropriate to explain what steps you are taking. Be sure to clearly label any steps, results, or conclusions. Mention every single step you do. For the following function f(x) = 2x-5/x+1 Find : (a) (5 points) Find the domain (in interval notation). (b) (5 points)Find any Vertical asymptotes or holes. Provide a written explanation why you are choosing Vertical asymptote or hole. (c) (5 points)Find any...
Draw bacterial DNA replication. Be sure to draw and label all of the proteins and describe...
Draw bacterial DNA replication. Be sure to draw and label all of the proteins and describe the role of each protein in one sentence. (Don't forget DNA polymerase I)
Question 1 Draw the market for electric vehicles in initial equilibrium. Be sure to label the...
Question 1 Draw the market for electric vehicles in initial equilibrium. Be sure to label the axes and the curves/lines. Clearly demonstrate the initial equilibrium price and quantity. Suppose the cost of lithium-ion batteries, an input into the production of electric vehicles, has dropped more steeply than expected. Use the 4-step process to demonstrate the effect of this change in the market for electric vehicles. Explain why you have drawn the change you have. Has there been a change in...
For all graphs, be sure to correctly and completely label all axes and curves and use...
For all graphs, be sure to correctly and completely label all axes and curves and use arrows to indicate the direction of any shifts. Assume that the market for tea is in equilibrium. Graph the market for tea, assuming unit-elastic supply and demand. Label the equilibrium price Pe and the equilibrium quantity Qe. The price of coffee increases from $5 to $6, and the quantity demanded of tea increases from 40 thousand units to 50,000 units. What is the cross-price...
Question 1 Draw the market for electric vehicles in initial equilibrium. Be sure to label the...
Question 1 Draw the market for electric vehicles in initial equilibrium. Be sure to label the axes and the curves/lines. Clearly demonstrate the initial equilibrium price and quantity. Suppose the cost of lithium-ion batteries, an input into the production of electric vehicles, has dropped more steeply than expected. Use the 4-step process to demonstrate the effect of this change in the market for electric vehicles. Explain why you have drawn the change you have. Has there been a change in...
Do a hypothesis for the following, make sure to include and label all five steps:    ...
Do a hypothesis for the following, make sure to include and label all five steps:     Test the claim that the proportion of wins is the same whether the wear a shirt     and tie or jeans and a t-shirt. Use a .05 significance level.             Win Loss Suit and Tie 23 38 Jeans and T-shirt 28 24
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT