-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
115 lines (92 loc) · 3.09 KB
/
Form1.cs
File metadata and controls
115 lines (92 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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 Calculate_Invoice
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void calculateTotal()
{
if(txt_subTotal.Text != "")
{
// get the subtotal amount from the subtotal text box
decimal subTotal = Convert.ToDecimal(txt_subTotal.Text);
// set the discountPercent variable based on the value of the subtotal variable
decimal discountPercent = 0m; //the m indicate a decimal value
if (subTotal >= 500)
{
discountPercent = .2m;
}
else if (subTotal >= 250 && subTotal < 500)
{
discountPercent = .15m;
}
else if (subTotal >= 100 && subTotal < 250)
{
discountPercent = .1m;
}
// calculate and assign the values for the discountAmount and invoiceTotal variable
decimal discountAmount = subTotal * discountPercent;
decimal invoiceTotal = subTotal - discountAmount;
// format the values and display them in their text boxes
txtDiscountPercent.Text = discountPercent.ToString("p1"); // p1 = percent format with 1 decimal place
txtDiscountAmount.Text = discountAmount.ToString("c"); // c = currenct format
txtTotal.Text = invoiceTotal.ToString("c");
// move the focus to the subTotal text box
txt_subTotal.Focus();
}
else
{
MessageBox.Show("Sub Total Can Empty Field");
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void txt_subTotal_TextChanged(object sender, EventArgs e)
{
}
private void btn_exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyData == Keys.Escape)
{
this.Close();
}
else if (e.KeyData == Keys.Enter)
{
calculateTotal();
}
}
private void btn_cal_Click(object sender, EventArgs e)
{
calculateTotal();
}
private void txtNumberOnly(object sender, KeyPressEventArgs e)
{
if(!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)){
e.Handled = true;
MessageBox.Show("Sub Total Can Be Char");
}
}
}
}