Question

Lab #2 - Book Sale Calculator Submit Assignment Download Work file Download Runtime Be sure to...

Lab #2 - Book Sale Calculator

Submit Assignment Download Work file Download Runtime

  • Be sure to include comments at the top of each procedure and at the top of the file.
  • Be sure to use meaningful names for all buttons and labels.
  1. In this project, R 'n R Refreshment needs to expand the book sale project done previously. In addition to calculating individual sales and discounts, management wants to know the total number of books sold, the total number of discoutns given, the total discounted amount, and the average discount per sale.

    Add error handling to the program, so that missing or nonnumeric data will not cause a run-time error.
  2. Planning the Form

      
  3. Planning Objects and Properties
    Object Property Setting
    Main Form Name BookSaleForm
    Text R 'n R - For Reading and Refreshment
    StartPosition CenterScreen
    AcceptButton CalculateButton
    CancelButton ClearButton
    Label1 Text Book Sales
    Font Bold, 12 point
    GroupBox1 Text blank
    Label2 Text &Quantity
    QuantityTextBox Name QuantityTextBox
    Text blank
    Label3 Text &Title
    TitleTextBox Name TitleTextBox
    Text blank
    Label4 Text &Price
    PriceTextBox Name PriceTextBox
    Text blank
    GroupBox2 Name GroupBox2
    Text blank
    Label5 Text Extended Price
    ExtendedPriceTextBox Name ExtendedPriceTextBox
    Text blank
    ReadOnly true
    TextAlign Right
    Label6 Text 15% Discount
    DiscountTextBox Name DiscountTextBox
    Text blank
    ReadOnly true
    TextAlign Right
    Label7 Text Discounted Price
    DiscountedPriceTextBox Name DiscountedPriceTextBox
    Text blank
    TextAlign Right
    ReadOnly true
    Calculate Button Name CalculateButton
    Text &Calculate
    ClearButton Name ClearButton
    Text Clear &Sale
    ExitButton Name ExitButton
    Text E&xit
    GroupBox3 Name GroupBox3
    Text Summary
    Label8 Text Total Number of Books
    QuantitySumTextBox Name QuantitySumTextBox
    Text blank
    ReadOnly true
    TextAlign Right
    Label9 Text Total Discounts Given
    DiscountSumTextBox Name DiscountSumTextBox
    Text blank
    ReadOnly True
    TextAlign Right
    Label10 Text Total Discounted Amounts
    DiscountedAmountSumTextBox Name DiscountedAmountSumTextBox
    Text blank
    ReadOnly true
    TextAlign Right
    Label11 Text AverageDiscount
    AverageDiscountTextBox Name AverageDiscountTextBox
    Text blank
    ReadOnly true
    TextAlign Right
  4. Planning Event Procedures
    Procedure Actions - Pseudocode
    ExitButton_Click End the project
    ClearButton_Click Clear each text box except Summary fields
    Set the focus in the first text box
    CalculateButton_Click Declare the variables
    Try
    Convert the input Quantity to number.
    Try
    Convert the input Price to numeric
    Calculate Extended Price = Quantity * Price
    Calculate Discount = Extended Price * Discount Rate
    Calculate Discounted Price = Extended Price - Discount
    Calculate the summary values:
    Add Quantity to Quantity Sum
    Add Discount to Discount Sum
    Add Discounted Price to Discounted Price Sum
    Add 1 to Sale Count
    Calculate Average Discount = Discount Sum / Sale Count
    Format and display sale output
    Format and display summary values
    Catch any Price exception
    Display error message and reset the focus to Price
    Catch any Quantity Exception
    Display error message and reset the focus to Quantity
    Catch any generic exception
    Display error message
0 0
Add a comment Improve this question Transcribed image text
Answer #1

BookSalesForm.Designer.cs

namespace COMP1004_Lesson03
{
    partial class BookSaleForm
    {
        /// <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.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BookSaleForm));
            this.label1 = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.priceTextBox = new System.Windows.Forms.TextBox();
            this.titleTextBox = new System.Windows.Forms.TextBox();
            this.quantityTextBox = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.discountedPriceTextBox = new System.Windows.Forms.TextBox();
            this.discountTextBox = new System.Windows.Forms.TextBox();
            this.extendedPriceTextBox = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.averageDiscountTextBox = new System.Windows.Forms.TextBox();
            this.discountedAmountSumTextBox = new System.Windows.Forms.TextBox();
            this.discountSumTextBox = new System.Windows.Forms.TextBox();
            this.quantitySumTextBox = new System.Windows.Forms.TextBox();
            this.label11 = new System.Windows.Forms.Label();
            this.label10 = new System.Windows.Forms.Label();
            this.label9 = new System.Windows.Forms.Label();
            this.label8 = new System.Windows.Forms.Label();
            this.calculateButton = new System.Windows.Forms.Button();
            this.clearButton = new System.Windows.Forms.Button();
            this.exitButton = new System.Windows.Forms.Button();
            this.byLabel = new System.Windows.Forms.Label();
            this.printForm1 = new Microsoft.VisualBasic.PowerPacks.Printing.PrintForm(this.components);
            this.printForm = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.SuspendLayout();
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.Location = new System.Drawing.Point(131, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(131, 25);
            this.label1.TabIndex = 0;
            this.label1.Text = "Book Sales";
            //
            // groupBox1
            //
            this.groupBox1.Controls.Add(this.priceTextBox);
            this.groupBox1.Controls.Add(this.titleTextBox);
            this.groupBox1.Controls.Add(this.quantityTextBox);
            this.groupBox1.Controls.Add(this.label4);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Location = new System.Drawing.Point(12, 37);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(368, 100);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Input";
            //
            // priceTextBox
            //
            this.priceTextBox.Location = new System.Drawing.Point(60, 73);
            this.priceTextBox.Name = "priceTextBox";
            this.priceTextBox.Size = new System.Drawing.Size(100, 20);
            this.priceTextBox.TabIndex = 5;
            //
            // titleTextBox
            //
            this.titleTextBox.Location = new System.Drawing.Point(60, 49);
            this.titleTextBox.Name = "titleTextBox";
            this.titleTextBox.Size = new System.Drawing.Size(295, 20);
            this.titleTextBox.TabIndex = 3;
            //
            // quantityTextBox
            //
            this.quantityTextBox.Location = new System.Drawing.Point(60, 25);
            this.quantityTextBox.Name = "quantityTextBox";
            this.quantityTextBox.Size = new System.Drawing.Size(100, 20);
            this.quantityTextBox.TabIndex = 1;
            //
            // label4
            //
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(7, 73);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(31, 13);
            this.label4.TabIndex = 4;
            this.label4.Text = "&Price";
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(7, 49);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(27, 13);
            this.label3.TabIndex = 2;
            this.label3.Text = "&Title";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(7, 25);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(46, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "&Quantity";
            //
            // groupBox2
            //
            this.groupBox2.Controls.Add(this.discountedPriceTextBox);
            this.groupBox2.Controls.Add(this.discountTextBox);
            this.groupBox2.Controls.Add(this.extendedPriceTextBox);
            this.groupBox2.Controls.Add(this.label7);
            this.groupBox2.Controls.Add(this.label6);
            this.groupBox2.Controls.Add(this.label5);
            this.groupBox2.Location = new System.Drawing.Point(12, 144);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(368, 92);
            this.groupBox2.TabIndex = 2;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Sale Value";
            //
            // discountedPriceTextBox
            //
            this.discountedPriceTextBox.Location = new System.Drawing.Point(255, 65);
            this.discountedPriceTextBox.Name = "discountedPriceTextBox";
            this.discountedPriceTextBox.ReadOnly = true;
            this.discountedPriceTextBox.Size = new System.Drawing.Size(100, 20);
            this.discountedPriceTextBox.TabIndex = 8;
            this.discountedPriceTextBox.TabStop = false;
            this.discountedPriceTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            //
            // discountTextBox
            //
            this.discountTextBox.Location = new System.Drawing.Point(255, 39);
            this.discountTextBox.Name = "discountTextBox";
            this.discountTextBox.ReadOnly = true;
            this.discountTextBox.Size = new System.Drawing.Size(100, 20);
            this.discountTextBox.TabIndex = 7;
            this.discountTextBox.TabStop = false;
            this.discountTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            //
            // extendedPriceTextBox
            //
            this.extendedPriceTextBox.Location = new System.Drawing.Point(255, 13);
            this.extendedPriceTextBox.Name = "extendedPriceTextBox";
            this.extendedPriceTextBox.ReadOnly = true;
            this.extendedPriceTextBox.Size = new System.Drawing.Size(100, 20);
            this.extendedPriceTextBox.TabIndex = 6;
            this.extendedPriceTextBox.TabStop = false;
            this.extendedPriceTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            //
            // label7
            //
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(138, 68);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(88, 13);
            this.label7.TabIndex = 2;
            this.label7.Text = "Discounted Price";
            //
            // label6
            //
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(138, 42);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(72, 13);
            this.label6.TabIndex = 1;
            this.label6.Text = "15% Discount";
            //
            // label5
            //
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(138, 16);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(79, 13);
            this.label5.TabIndex = 0;
            this.label5.Text = "Extended Price";
            //
            // groupBox3
            //
            this.groupBox3.Controls.Add(this.averageDiscountTextBox);
            this.groupBox3.Controls.Add(this.discountedAmountSumTextBox);
            this.groupBox3.Controls.Add(this.discountSumTextBox);
            this.groupBox3.Controls.Add(this.quantitySumTextBox);
            this.groupBox3.Controls.Add(this.label11);
            this.groupBox3.Controls.Add(this.label10);
            this.groupBox3.Controls.Add(this.label9);
            this.groupBox3.Controls.Add(this.label8);
            this.groupBox3.Location = new System.Drawing.Point(12, 243);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(368, 139);
            this.groupBox3.TabIndex = 3;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "Summary";
            //
            // averageDiscountTextBox
            //
            this.averageDiscountTextBox.Location = new System.Drawing.Point(255, 101);
            this.averageDiscountTextBox.Name = "averageDiscountTextBox";
            this.averageDiscountTextBox.ReadOnly = true;
            this.averageDiscountTextBox.Size = new System.Drawing.Size(100, 20);
            this.averageDiscountTextBox.TabIndex = 12;
            this.averageDiscountTextBox.TabStop = false;
            this.averageDiscountTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            //
            // discountedAmountSumTextBox
            //
            this.discountedAmountSumTextBox.Location = new System.Drawing.Point(255, 74);
            this.discountedAmountSumTextBox.Name = "discountedAmountSumTextBox";
            this.discountedAmountSumTextBox.ReadOnly = true;
            this.discountedAmountSumTextBox.Size = new System.Drawing.Size(100, 20);
            this.discountedAmountSumTextBox.TabIndex = 11;
            this.discountedAmountSumTextBox.TabStop = false;
            this.discountedAmountSumTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            //
            // discountSumTextBox
            //
            this.discountSumTextBox.Location = new System.Drawing.Point(255, 47);
            this.discountSumTextBox.Name = "discountSumTextBox";
            this.discountSumTextBox.ReadOnly = true;
            this.discountSumTextBox.Size = new System.Drawing.Size(100, 20);
            this.discountSumTextBox.TabIndex = 10;
            this.discountSumTextBox.TabStop = false;
            this.discountSumTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            //
            // quantitySumTextBox
            //
            this.quantitySumTextBox.Location = new System.Drawing.Point(255, 20);
            this.quantitySumTextBox.Name = "quantitySumTextBox";
            this.quantitySumTextBox.ReadOnly = true;
            this.quantitySumTextBox.Size = new System.Drawing.Size(100, 20);
            this.quantitySumTextBox.TabIndex = 9;
            this.quantitySumTextBox.TabStop = false;
            this.quantitySumTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            //
            // label11
            //
            this.label11.AutoSize = true;
            this.label11.Location = new System.Drawing.Point(7, 108);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(92, 13);
            this.label11.TabIndex = 3;
            this.label11.Text = "Average Discount";
            //
            // label10
            //
            this.label10.AutoSize = true;
            this.label10.Location = new System.Drawing.Point(7, 81);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(132, 13);
            this.label10.TabIndex = 2;
            this.label10.Text = "Total Discounted Amounts";
            //
            // label9
            //
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(7, 54);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(112, 13);
            this.label9.TabIndex = 1;
            this.label9.Text = "Total Discounts Given";
            //
            // label8
            //
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(7, 27);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(116, 13);
            this.label8.TabIndex = 0;
            this.label8.Text = "Total Number of Books";
            //
            // calculateButton
            //
            this.calculateButton.Location = new System.Drawing.Point(110, 388);
            this.calculateButton.Name = "calculateButton";
            this.calculateButton.Size = new System.Drawing.Size(75, 23);
            this.calculateButton.TabIndex = 2;
            this.calculateButton.Text = "&Calculate";
            this.calculateButton.UseVisualStyleBackColor = true;
            this.calculateButton.Click += new System.EventHandler(this.calculateButton_Click);
            //
            // clearButton
            //
            this.clearButton.Location = new System.Drawing.Point(207, 389);
            this.clearButton.Name = "clearButton";
            this.clearButton.Size = new System.Drawing.Size(75, 23);
            this.clearButton.TabIndex = 3;
            this.clearButton.Text = "Clear &Sale";
            this.clearButton.UseVisualStyleBackColor = true;
            this.clearButton.Click += new System.EventHandler(this.clearButton_Click);
            //
            // exitButton
            //
            this.exitButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.exitButton.Location = new System.Drawing.Point(304, 389);
            this.exitButton.Name = "exitButton";
            this.exitButton.Size = new System.Drawing.Size(75, 23);
            this.exitButton.TabIndex = 4;
            this.exitButton.Text = "E&xit";
            this.exitButton.UseVisualStyleBackColor = true;
            this.exitButton.Click += new System.EventHandler(this.exitButton_Click);
            //
            // byLabel
            //
            this.byLabel.AutoSize = true;
            this.byLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.byLabel.Location = new System.Drawing.Point(274, 428);
            this.byLabel.Name = "byLabel";
            this.byLabel.Size = new System.Drawing.Size(106, 13);
            this.byLabel.TabIndex = 8;
            this.byLabel.Text = "By. Luis Acevedo";
            //
            // printForm1
            //
            this.printForm1.DocumentName = "document";
            this.printForm1.Form = this;
            this.printForm1.PrintAction = System.Drawing.Printing.PrintAction.PrintToPrinter;
            this.printForm1.PrinterSettings = ((System.Drawing.Printing.PrinterSettings)(resources.GetObject("printForm1.PrinterSettings")));
            this.printForm1.PrintFileName = null;
            //
            // printForm
            //
            this.printForm.Location = new System.Drawing.Point(12, 389);
            this.printForm.Name = "printForm";
            this.printForm.Size = new System.Drawing.Size(75, 23);
            this.printForm.TabIndex = 1;
            this.printForm.Text = "Print &Form";
            this.printForm.UseVisualStyleBackColor = true;
            this.printForm.Click += new System.EventHandler(this.printForm_Click);
            //
            // BookSaleForm
            //
            this.AcceptButton = this.calculateButton;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.exitButton;
            this.ClientSize = new System.Drawing.Size(392, 450);
            this.Controls.Add(this.printForm);
            this.Controls.Add(this.byLabel);
            this.Controls.Add(this.exitButton);
            this.Controls.Add(this.clearButton);
            this.Controls.Add(this.calculateButton);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.label1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.Name = "BookSaleForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "R n\' R for Reading and Refreshments";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.TextBox priceTextBox;
        private System.Windows.Forms.TextBox titleTextBox;
        private System.Windows.Forms.TextBox quantityTextBox;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.TextBox discountedPriceTextBox;
        private System.Windows.Forms.TextBox discountTextBox;
        private System.Windows.Forms.TextBox extendedPriceTextBox;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.GroupBox groupBox3;
        private System.Windows.Forms.TextBox averageDiscountTextBox;
        private System.Windows.Forms.TextBox discountedAmountSumTextBox;
        private System.Windows.Forms.TextBox discountSumTextBox;
        private System.Windows.Forms.TextBox quantitySumTextBox;
        private System.Windows.Forms.Label label11;
        private System.Windows.Forms.Label label10;
        private System.Windows.Forms.Label label9;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.Button calculateButton;
        private System.Windows.Forms.Button clearButton;
        private System.Windows.Forms.Button exitButton;
        private System.Windows.Forms.Label byLabel;
        private Microsoft.VisualBasic.PowerPacks.Printing.PrintForm printForm1;
        private System.Windows.Forms.Button printForm;
    }
}

BookSalesForm.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 COMP1004_Lesson03
{
    public partial class BookSaleForm : Form
    {
        //variable definition
        private int salesCountInteger, quantitySumInteger;
        private decimal discountSumDecimal, discountedPriceSumDecimal;

        //Methods
        public BookSaleForm()
        {
            InitializeComponent();
        }

        /*
         * It calculates the sale price, discount, and the extended price
         * It also maintains the summary information
         * Displays all the information
         */
        private void calculateButton_Click(object sender, EventArgs e)
        {
            //local variables
            int quantityInteger;
            decimal priceDecimal, discountDecimal, extendedPriceDecimal, discountedPriceDecimal, averageDiscountDecimal;

            const decimal DISCOUNT_RATE_DECIMAL = 0.15m;
            //option 2 const decimal DISCOUNT_RATE_DECIMAL = (decimal) 0.15;
            if (titleTextBox.Text != "")
            {
                try
                {
                    quantityInteger = int.Parse(quantityTextBox.Text);

                    if (quantityInteger > 0)
                    {
                        try
                        {
                            priceDecimal = decimal.Parse(priceTextBox.Text);

                            if (priceDecimal > 0)
                            {
                                //proceed with the calculations
                                extendedPriceDecimal = quantityInteger * priceDecimal;
                                discountDecimal = extendedPriceDecimal * DISCOUNT_RATE_DECIMAL;
                                discountedPriceDecimal = extendedPriceDecimal - discountDecimal;

                                //summary
                                salesCountInteger++;
                                quantitySumInteger += quantityInteger;
                                discountSumDecimal += discountDecimal;
                                discountedPriceSumDecimal += discountedPriceDecimal;
                                averageDiscountDecimal = discountSumDecimal / salesCountInteger;

                                //display the information
                                extendedPriceTextBox.Text = extendedPriceDecimal.ToString("c");
                                discountTextBox.Text = discountDecimal.ToString("c");
                                discountedPriceTextBox.Text = discountedPriceDecimal.ToString("c");

                                quantitySumTextBox.Text = quantitySumInteger.ToString("d");
                                discountSumTextBox.Text = discountSumDecimal.ToString("c");
                                discountedAmountSumTextBox.Text = discountedPriceSumDecimal.ToString("c");
                                averageDiscountTextBox.Text = averageDiscountDecimal.ToString("c");
                            }
                            else
                            {
                                MessageBox.Show("Price must be greater than Zero", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        catch (FormatException priceException)
                        {
                            MessageBox.Show("Price must be a numeric number", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            priceTextBox.SelectAll();
                            priceTextBox.Focus();
                        }
                        catch (Exception exceptionMessage2)
                        {
                            MessageBox.Show(exceptionMessage2.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please input a value greater than Zero", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                catch (FormatException quantityException)
                {
                    MessageBox.Show("Quantity must be a whole number", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    quantityTextBox.SelectAll();
                    quantityTextBox.Focus();
                }
                catch (Exception exceptionMessage)
                {
                    MessageBox.Show(exceptionMessage.Message, "Error", MessageBoxButtons.OK);
                }
            }
            else
            {
                MessageBox.Show("Please input the name of the book", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        /*
         * clear the input information and the current sale information
         * set focus quantity
         */
        private void clearButton_Click(object sender, EventArgs e)
        {
            //clear all the boxes
            quantityTextBox.Clear();
            titleTextBox.Clear();
            priceTextBox.Clear();

            extendedPriceTextBox.Clear();
            discountTextBox.Clear();
            discountedPriceTextBox.Clear();

            //Set the cursor to the established variable
            quantityTextBox.Focus();
        }
        private void exitButton_Click(object sender, EventArgs e)
        {
            //Closes the application
            this.Close();
        }
        private void printForm_Click(object sender, EventArgs e)
        {
            //Prints the form with book sale information.
            printForm1.PrintAction = System.Drawing.Printing.PrintAction.PrintToPreview;
            printForm1.Print();
        }
    }
}

Program.cs

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

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

Add a comment
Know the answer?
Add Answer to:
Lab #2 - Book Sale Calculator Submit Assignment Download Work file Download Runtime Be sure to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a...

    Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a queue. Then you are going to use the queue to store animals. 1. Write a LinkedQueue class that implements the QueueADT.java interface using links. 2. Textbook implementation uses a count variable to keep track of the elements in the queue. Don't use variable count in your implementation (points will be deducted if you use instance variable count). You may use a local integer variable...

  • Create an HTML5 page that contains a form to collect the following data. The text in...

    Create an HTML5 page that contains a form to collect the following data. The text in bold indicates the id value that should be assigned to each html control: Product (drop down list) product – iPad, iPhone 6S, Galaxy 5S, Moto X, and so on Quantity (number) quantity Unit price (number) unit_price Discount (%)(number) discount_rate Date (date)   order_date First Name (text box)   first_name Last Name (text box)   last_name Payment type (drop down list)   payment_type – Visa, Master, Discover, Amex, and...

  • Program 2 #include #include using namespace std; int main() { int total = 0; int num...

    Program 2 #include #include using namespace std; int main() { int total = 0; int num = 0; ifstream inputFile; inputFile.open("inFile.txt"); while(!inputFile.eof()) { // until we have reached the end of the file inputFile >> num; total += num; } inputFile.close(); cout << "The total value is " << total << "." << endl; Lab Questions: We should start by activating IO-exceptions. Do so using the same method in Step 3 of the Program 1 assignment above, except that instead...

  • /** * File: GradeCalculator . java * Description: Instances of this class are used to calculate...

    /** * File: GradeCalculator . java * Description: Instances of this class are used to calculate * a course average and a letter grade. In order to calculate * the average and the letter grade, a GradeCalculator must store * two essential pieces of data: the number of grades and the sum * of the grades. Therefore these are declared as object properties * (instance variables). * Each time calcAverage (grade) is called, a new grade is added to *...

  • Written in Java I have an error in the accountFormCheck block can i get help to...

    Written in Java I have an error in the accountFormCheck block can i get help to fix it please. Java code is below. I keep getting an exception error when debugging it as well Collector.java package userCreation; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import java.util.regex.Matcher; import java.util.regex.Pattern; import javafx.event.ActionEvent; import javafx.fxml.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.text.Text; import javafx.stage.*; public class Controller implements Initializable{ @FXML private PasswordField Password_text; @FXML private PasswordField Confirm_text; @FXML private TextField FirstName_text; @FXML private TextField LastName_text;...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • 18.1 Lab Lesson 11 (Part 1 of 1) Part of lab lesson 11 There in one...

    18.1 Lab Lesson 11 (Part 1 of 1) Part of lab lesson 11 There in one part to lab lesson 11. The entire lab will be worth 100 points. Lab lesson 11 part 1 is worth 100 points For part 1 you will have 80 points if you enter the program and successfully run the program tests. An additional 20 points will be based on the style and formatting of your C++ code. Style points The 20 points for coding...

  • In this practice program you are going to practice creating graphical user interface controls and placing...

    In this practice program you are going to practice creating graphical user interface controls and placing them on a form. You are given a working NetBeans project shell to start that works with a given Invoice object that keeps track of a product name, quantity of the product to be ordered and the cost of each item. You will then create the necessary controls to extract the user input and display the results of the invoice. If you have any...

  • I am really struggling with this assignment, can anyone help? It is supposed to work with...

    I am really struggling with this assignment, can anyone help? It is supposed to work with two files, one that contains this data: 5 Christine Kim # 30.00 3 1 15 Ray Allrich # 10.25 0 0 16 Adrian Bailey # 12.50 0 0 17 Juan Gonzales # 30.00 1 1 18 J. P. Morgan # 8.95 0 0 22 Cindy Burke # 15.00 1 0 and another that contains this data: 5 40.0 15 42.0 16 40.0 17 41.5...

  • CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...

    CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT