-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form3.cs
406 lines (322 loc) · 13 KB
/
Form3.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace KoforiduaPolyBiometric_Attendance
{
public partial class Form3 : Form
{
Bitmap img;
//SqlConnection cn = new SqlConnection(@"Data Source=localhost;Initial Catalog=Login;Integrated Security=True");
// SqlCommand cmd = new SqlCommand();
// SqlDataReader dr;
public Form3()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Form frm = new Form4();
frm.Show();
this.Visible = true;
this.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
Form frm = new Form6();
frm.Show();
this.Visible = true;
this.Hide();
}
private void button5_Click(object sender, EventArgs e)
{
Form frm = new Form5();
frm.Show();
this.Visible = true;
this.Hide();
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void Form3_Load(object sender, EventArgs e)
{
}
private void label9_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
//f1
}
private void button4_Click(object sender, EventArgs e)
{
//f2
}
private void button9_Click(object sender, EventArgs e)
{
// Uploading a picture from a file
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files (*.jpg; *.jpeg; *.gif; *.bmp) | *.jpg; *.jpeg; *.gif; *.bmp";
if
(open.ShowDialog() == DialogResult.OK)
{
img = new Bitmap(open.FileName);
pictureBox2.Image = img;
}
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
//Calculation of Age
int age = 0;
int year = dateTimePicker1.Value.Year;
int month = dateTimePicker1.Value.Day;
age = DateTime.Today.Year - year;
txtAge.Text = age.ToString();
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void label10_Click(object sender, EventArgs e)
{
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
ToolTip toolTip1 = new ToolTip();
toolTip1.AutomaticDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(this.txtLastName, "Please Enter Last Name ");
Char ch = e.KeyChar;
if (!char.IsLetter(e.KeyChar) && !char.IsControl(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))
{
e.Handled = true;
}
if (this.txtLastName.Text == "")
{
errorProvider1.SetError(this.txtLastName, "Please fill the required field");
}
}
private void button8_Click(object sender, EventArgs e)
{
Form frm = new Form3();
frm.Show();
this.Visible = true;
this.Hide();
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (this.txtFirstName.Text == "")
{
ToolTip toolTip1 = new ToolTip();
toolTip1.AutomaticDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(this.txtFirstName, "Please Enter First Name");
Char ch = e.KeyChar;
if (!char.IsLetter(e.KeyChar) && !char.IsControl(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))
{
e.Handled = true;
}
if (txtFirstName.Text == "")
{
errorProvider1.SetError(txtFirstName, "Please fill the required field");
}
}
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
if (this.txtIndexNum.Text == "")
{
ToolTip toolTip1 = new ToolTip();
toolTip1.AutomaticDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(this.txtIndexNum, "Please Enter Index Number");
}
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
////Disable combobox
cmbProgramme.DropDownStyle = ComboBoxStyle.DropDownList;
//////
}
private void button10_Click(object sender, EventArgs e)
{
Form frm = new Main_Form();
frm.Show();
this.Visible = true;
this.Hide();
}
/////Student Enrollment
private void btnEnroll_Click(object sender, EventArgs e)
{
try
{
GetInit cn = new GetInit();
MySqlConnection connection = cn.Initialize();
//SqlConnection connection = new SqlConnection("Data Source=JUSTWILLIAMS/STEV;Initial Catalog=Login;Integrated Security=True")
MySqlCommand checker = new MySqlCommand("SELECT * FROM enrollment_table WHERE Index_Number=@Index_Number", connection);
checker.Connection = connection;
checker.Parameters.AddWithValue("@Index_Number", this.txtIndexNum.Text.Trim());
connection.Open();
checker.ExecuteNonQuery();
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(checker);
if (this.txtIndexNum.Text == "")
{
errorProvider1.SetError(this.txtIndexNum, "Please fill the required field");
}
else if (this.txtFirstName.Text == "")
{
errorProvider1.SetError(this.txtFirstName, "Please fill the required field");
}
else if (this.txtAge.Text == "")
{
errorProvider1.SetError(this.txtAge, "Please fill the required field");
}
else if (this.cmbGender.Text == "")
{
errorProvider1.SetError(this.cmbGender, "Please fill the required field");
}
else if (this.cmbProgramme.Text == "")
{
errorProvider1.SetError(this.cmbCourse, "Please fill the required field");
}
else if (this.txtLastName.Text == "")
{
errorProvider1.SetError(this.txtLastName, "Please fill the required field");
}
else if (this.cmbProgramme.Text == "")
{
errorProvider1.SetError(this.cmbProgramme, "Please fill the required field");
}
else if (IsEmpty(img))
{
MessageBox.Show("Profile Passport Photograph Required");
}
else
{
da.Fill(dt);
var i = dt.Rows.Count;
if (i > 0)
{
MessageBox.Show("Already Registered");
}
else
{
//MySqlCommand cmd = new MySqlCommand();
MySqlCommand cmd = new MySqlCommand("INSERT INTO Enrollment_Table (Index_Number, Last_Name, First_Name, Other_Name, Date_of_Birth, Age, Gender, Programme_Offered, Course_Offered, Level, Image) VALUES (@Index_Number, @Last_Name, @First_Name, @Other_Name, @Date_of_Birth, @Age, @Gender, @Programme_Offered, @Course_Offered, @Level, @Image)");
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@Index_Number", txtIndexNum.Text);
cmd.Parameters.AddWithValue("@Last_Name", txtLastName.Text);
cmd.Parameters.AddWithValue("@First_Name", txtFirstName.Text);
cmd.Parameters.AddWithValue("@Other_Name", txtOtherName.Text);
cmd.Parameters.AddWithValue("@Date_of_Birth", dateTimePicker1.Value);
cmd.Parameters.AddWithValue("@Age", txtAge.Text);
cmd.Parameters.AddWithValue("@Gender", cmbGender.Text);
cmd.Parameters.AddWithValue("@Programme_Offered", cmbProgramme.Text);
cmd.Parameters.AddWithValue("@Course_Offered", cmbCourse.Text);
cmd.Parameters.AddWithValue("@Level", cmbLevel.Text);
cmd.Parameters.AddWithValue("@Image", img);
cmd.ExecuteNonQuery();
MessageBox.Show("Enrolled Successfully");
txtAge.Clear();
txtFirstName.Clear();
txtIndexNum.Clear();
txtOtherName.Clear();
txtLastName.Clear();
cmbLevel.Text = "";
cmbProgramme.Text = "";
cmbCourse.Text = "";
}
}
connection.Close();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
bool IsEmpty(Bitmap image)
{
return (image == null);
}
private void cmbCourse_SelectedIndexChanged(object sender, EventArgs e)
{
/////disable combobox
cmbCourse.DropDownStyle = ComboBoxStyle.DropDownList;
//////
cmbCourse.Enabled = false;
}
private void txtIndexNum_TextChanged(object sender, EventArgs e)
{
if (this.txtIndexNum.Text == "")
{
ToolTip toolTip1 = new ToolTip();
toolTip1.AutomaticDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(this.txtIndexNum, "Please Enter Index Number");
}
}
private void txtOtherName_KeyPress(object sender, KeyPressEventArgs e)
{
if (this.txtOtherName.Text == "")
{
ToolTip toolTip1 = new ToolTip();
toolTip1.AutomaticDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(this.txtOtherName, "Please Enter Other Name");
Char ch = e.KeyChar;
if (!char.IsLetter(e.KeyChar) && !char.IsControl(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))
{
e.Handled = true;
txtOtherName.Clear();
}
}
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
}
private void cmbGender_SelectedIndexChanged(object sender, EventArgs e)
{
////Disable combobox
cmbGender.DropDownStyle = ComboBoxStyle.DropDownList;
///////
}
private void button3_Click_1(object sender, EventArgs e)
{
MessageBox.Show("Kindly Ensure you have Enrolled Student Before Capturing");
Suprema.UFE30_DatabaseDemo newfrm = new Suprema.UFE30_DatabaseDemo(txtIndexNum.Text);
newfrm.Text = txtIndexNum.Text;
newfrm.ShowDialog();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void txtLastName_TextChanged(object sender, EventArgs e)
{
}
}
}