-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
74 lines (71 loc) · 3.29 KB
/
Form1.cs
File metadata and controls
74 lines (71 loc) · 3.29 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
namespace StudentSystem
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
toolTip1.IsBalloon = true;
toolTip1.ToolTipTitle = "Input rule";
toolTip1.ToolTipIcon = ToolTipIcon.Info;
toolTip1.SetToolTip(maskedTextBox1, "Only numbers from 1 to 10 are allowed");
toolTip1.SetToolTip(maskedTextBox6, "Only numbers from 1 to 10 are allowed");
toolTip1.SetToolTip(maskedTextBox3, "Only numbers from 1 to 50 are allowed");
toolTip1.SetToolTip(maskedTextBox4, "Only numbers from 1 to 20 are allowed");
toolTip1.SetToolTip(maskedTextBox5, "Only numbers from 1 to 10 are allowed");
}
private void button1_Click(object sender, EventArgs e)
{
if (maskedTextBox1.Text == "" || maskedTextBox3.Text == "" || maskedTextBox4.Text == "" ||
maskedTextBox5.Text == "" || maskedTextBox6.Text == "" ||
Convert.ToInt16(maskedTextBox1.Text) < 1 || Convert.ToInt16(maskedTextBox1.Text) > 10 ||
Convert.ToInt16(maskedTextBox6.Text) < 1 || Convert.ToInt16(maskedTextBox6.Text) > 10 ||
Convert.ToInt16(maskedTextBox3.Text) < 1 || Convert.ToInt16(maskedTextBox3.Text) > 50 ||
Convert.ToInt16(maskedTextBox4.Text) < 1 || Convert.ToInt16(maskedTextBox4.Text) > 20 ||
Convert.ToInt16(maskedTextBox5.Text) < 1 || Convert.ToInt16(maskedTextBox5.Text) > 10)
{
MessageBox.Show("Please enter valid values according to the input rules.", "Invalid Input",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (textBox1.Text == "" || maskedTextBox2.Text == "" || maskedTextBox2.Text.Length != 9 ||
!textBox1.Text.All(c => char.IsLetter(c) || char.IsWhiteSpace(c)))
{
errorProvider1.SetError(textBox1, "Please input name and surname");
errorProvider2.SetError(maskedTextBox2, "Please input valid student number");
}
else
{
int result =
Convert.ToInt16(maskedTextBox1.Text) +
Convert.ToInt16(maskedTextBox6.Text) +
Convert.ToInt16(maskedTextBox3.Text) +
Convert.ToInt16(maskedTextBox4.Text) +
Convert.ToInt16(maskedTextBox5.Text);
string grade = result switch
{
>= 91 and <= 100 => "A",
>= 81 and <= 90 => "B",
>= 71 and <= 80 => "C",
>= 61 and <= 70 => "D",
>= 51 and <= 60 => "E",
_ => "F",
};
dataGridView1.Rows.Add(textBox1.Text, maskedTextBox2.Text, result + " - " + grade);
}
}
private void button2_Click(object sender, EventArgs e)
{
maskedTextBox1.Clear();
maskedTextBox3.Clear();
maskedTextBox4.Clear();
maskedTextBox5.Clear();
maskedTextBox6.Clear();
textBox1.Clear();
maskedTextBox2.Clear();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
}
}