diff options
author | | 1970-01-01 00:00:00 +0000 |
---|---|---|
committer | | 2025-01-08 04:46:10 +0000 |
commit | 1ac90768665c89d64a59f6e9935242fba1514bb9 (patch) | |
tree | 271671c7724a2d4f26e85f08df745b8163d6a811 /invoice_total4/InvoiceTotal/frmInvoiceTotal.cs | |
parent | invoice total 3 (diff) | |
download | cs-1ac90768665c89d64a59f6e9935242fba1514bb9.tar cs-1ac90768665c89d64a59f6e9935242fba1514bb9.tar.gz cs-1ac90768665c89d64a59f6e9935242fba1514bb9.tar.bz2 cs-1ac90768665c89d64a59f6e9935242fba1514bb9.tar.xz cs-1ac90768665c89d64a59f6e9935242fba1514bb9.zip |
invoice total 4
Diffstat (limited to 'invoice_total4/InvoiceTotal/frmInvoiceTotal.cs')
-rw-r--r-- | invoice_total4/InvoiceTotal/frmInvoiceTotal.cs | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/invoice_total4/InvoiceTotal/frmInvoiceTotal.cs b/invoice_total4/InvoiceTotal/frmInvoiceTotal.cs new file mode 100644 index 0000000..0f0448f --- /dev/null +++ b/invoice_total4/InvoiceTotal/frmInvoiceTotal.cs @@ -0,0 +1,99 @@ +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(); + } + + // DONE: declare class variables for array and list here + decimal[] rayInvoices = new decimal[5]; + int invoice = 0; + List<decimal> listInvoices = new List<decimal>(5); + + private void btnCalculate_Click(object sender, EventArgs e) + { + try { + if (txtSubtotal.Text == "") { + MessageBox.Show( + "Subtotal is a required field.", "Entry Error"); + } + else { + decimal subtotal = Decimal.Parse(txtSubtotal.Text); + if (subtotal > 0 && subtotal < 10000) { + decimal discountPercent = 0m; + if (subtotal >= 500) + discountPercent = .2m; + else if (subtotal >= 250 & subtotal < 500) + discountPercent = .15m; + else if (subtotal >= 100 & subtotal < 250) + discountPercent = .1m; + decimal discountAmount = subtotal * discountPercent; + decimal invoiceTotal = subtotal - discountAmount; + + discountAmount = Math.Round(discountAmount, 2); + invoiceTotal = Math.Round(invoiceTotal, 2); + + rayInvoices[invoice] = invoiceTotal; + invoice++; + listInvoices.Add(invoiceTotal); + + txtDiscountPercent.Text = discountPercent.ToString("p1"); + txtDiscountAmount.Text = discountAmount.ToString(); + txtTotal.Text = invoiceTotal.ToString(); + } + else { + MessageBox.Show( + "Subtotal must be greater than 0 and less than 10,000.", + "Entry Error"); + } + } + } + catch (FormatException) { + MessageBox.Show( + "Please enter a valid number for the Subtotal field.", + "Entry Error"); + } + catch (IndexOutOfRangeException) { + MessageBox.Show( + "You have already reached the maximum amount of invoices", + "Out of Range Error"); + } + txtSubtotal.Focus(); + } + + private void btnExit_Click(object sender, EventArgs e) + { + // DONE: add code that displays dialog boxes here + if (invoice > 0) { + string msg = ""; + + Array.Sort(rayInvoices); + foreach (decimal i in rayInvoices) + if (i != 0) + msg += i.ToString("c") + "\n"; + MessageBox.Show(msg, "Order Totals - Array"); + + msg = ""; + listInvoices.Sort(); + foreach (decimal i in listInvoices) + if (i != 0) + msg += i.ToString("c") + "\n"; + MessageBox.Show(msg, "Order Totals - List"); + } + this.Close(); + } + + } +} |