-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewStudent.cs
90 lines (78 loc) · 2.65 KB
/
NewStudent.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
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 NewStudent : Form
{
StudentClass student = new StudentClass();
readonly string csvimportpath = "C\\";
public NewStudent()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
string first_name = txtBoxfirst_name.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 > 19))
{
MessageBox.Show("Věk musí byt mezi 7 a 19", "Neplatný věk", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (verify())
{
try
{
if (student.insertStudent(first_name, last_name, DB, gender))
{
showTable();
MessageBox.Show("Nový student přidan", "Přidat studenta", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}catch(Exception ex)
{
MessageBox.Show(ex.Message, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show("PrazDBý řadek", "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
bool verify()
{
if((txtBoxfirst_name.Text == "") || (txtBoxlast_name.Text == ""))
{
return false;
}
else { return true; }
}
private void RegForm_Load(object sender, EventArgs e)
{
showTable();
}
public void showTable()
{
dataGridStudenti.DataSource = student.getStudentList(new MySqlCommand("SELECT * FROM `student`"));
}
private void btnClear_Click(object sender, EventArgs e)
{
txtBoxfirst_name.Clear();
txtBoxlast_name.Clear();
}
private void bttnImportCSV_Click(object sender, EventArgs e)
{
student.importStudentCSV(csvimportpath);
}
}
}