-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManageStudentForm.cs
118 lines (103 loc) · 3.85 KB
/
ManageStudentForm.cs
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
116
117
118
using MySql.Data.MySqlClient;
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 SMS_Server
{
public partial class ManageStudentForm : Form
{
StudentClass student = new StudentClass();
public ManageStudentForm()
{
InitializeComponent();
}
public void showTable()
{
dataGridStudenti.DataSource = student.getStudentList(new MySqlCommand("SELECT * FROM `student`"));
}
private void ManageStudentForm_Load(object sender, EventArgs e)
{
showTable();
}
private void dataGridStudenti_Click(object sender, EventArgs e)
{
txtBoxId.Text = dataGridStudenti.CurrentRow.Cells[0].Value.ToString();
txtBoxFN.Text = dataGridStudenti.CurrentRow.Cells[1].Value.ToString();
txtBoxlast_name.Text = dataGridStudenti.CurrentRow.Cells[2].Value.ToString();
dateTimeDB.Value = (DateTime)dataGridStudenti.CurrentRow.Cells[3].Value;
if (dataGridStudenti.CurrentRow.Cells[4].Value.ToString() == "M")
rBttnGenderM.Checked = true;
else
rBttnGenderF.Checked = true;
}
private void btnClear_Click(object sender, EventArgs e)
{
txtBoxFN.Clear();
txtBoxlast_name.Clear();
}
private void btnSearch_Click(object sender, EventArgs e)
{
dataGridStudenti.DataSource = student.searchStudent(txtBoxSearchStd.Text);
}
bool verify()
{
if ((txtBoxFN.Text == "") || (txtBoxlast_name.Text == ""))
{
return false;
}
else { return true; }
}
private void btnUpdate_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(txtBoxId.Text);
string first_name = txtBoxFN.Text;
string last_name = txtBoxlast_name.Text;
DateTime DB = dateTimeDB.Value;
string gender = rBttnGenderM.Checked ? "Male" : "Female";
int born_year = dateTimeDB.Value.Year;
int this_year = DateTime.Now.Year;
if ((this_year - born_year < 7 || this_year - born_year > 26))
{
MessageBox.Show("The age must be between 7 and 26 years old", "Invalid age", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (verify())
{
try
{
if (student.updateStudent(id, first_name, last_name, DB, gender))
{
showTable();
MessageBox.Show("Succesfully updated", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show("Empty text box", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(txtBoxId.Text);
if (MessageBox.Show("Do you really want to delete it", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
if (student.deleteStudent(id))
{
showTable();
MessageBox.Show("Deleted", "Success", MessageBoxButtons.OK, MessageBoxIcon.Warning);
btnClear.PerformClick();
}
}
}
}
}