예제 #1
0
 private void btnTotals_Click(object sender, EventArgs e)
 {
     ProgNumInv     = 0;
     ProgTotInv     = 0;
     ProgAvg        = 0;
     txtNumInv.Text = ProgNumInv.ToString();
     txtTotInv.Text = ProgTotInv.ToString("c");
     txtInvAvg.Text = ProgAvg.ToString("c");
 }
예제 #2
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            decimal invoiceSubtotal = Convert.ToDecimal(txtEntSub.Text); //string to decimal
            decimal discountPercent = 0m;

            if (invoiceSubtotal >= 500)
            {
                discountPercent = .2m;
            }
            else if (invoiceSubtotal >= 250 && invoiceSubtotal < 500)
            {
                discountPercent = .15m;
            }
            else if (invoiceSubtotal >= 100 && invoiceSubtotal < 250)
            {
                discountPercent = .1m;
            }

            decimal discountAmount = invoiceSubtotal * discountPercent;
            decimal invoiceTotal   = invoiceSubtotal - discountAmount;

            ProgNumInv++;
            txtNumInv.Text = ProgNumInv.ToString();

            ProgTotInv    += invoiceTotal;
            txtTotInv.Text = ProgTotInv.ToString("c");

            ProgAvg        = ProgTotInv / ProgNumInv;
            txtInvAvg.Text = ProgAvg.ToString("c");

            txtDisPer.Text = discountPercent.ToString("p1"); //decimal to string as percent w/ 1 dec place
            txtDisAmo.Text = discountAmount.ToString("c");   //decimal to string as currency
            txtTotal.Text  = invoiceTotal.ToString("c");     //decimal to string as currency
            txtSub.Text    = invoiceSubtotal.ToString("C");

            txtEntSub.Focus();
        }