-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemployees.cs
618 lines (538 loc) · 21.5 KB
/
employees.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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace project_pos
{
public partial class frm_emp : Form
{
SqlConnection con = new SqlConnection(@"Data Source=RANDULA-MSI\SQLEXPRESS;Initial Catalog=se_db_pzdr;Integrated Security=True");
SqlCommand cmd;
SqlDataReader dr;
string imgLoc = "";
string status = "";
public frm_emp(string id_load)
{
InitializeComponent();
txt_id_load.Text = id_load;
try
{
con.Open();
String validate = "SELECT * FROM se_tbl_emp WHERE id = '" + txt_id_load.Text + "'";
cmd = new SqlCommand(validate, con);
dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
txt_id_load.Text = dr[0].ToString();
txt_pos_load.Text = dr[8].ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
if (txt_pos_load.Text == "admin")
{
status = "admin";
}
else if (txt_pos_load.Text == "sup")
{
status = "sup";
}
else if (txt_pos_load.Text == "chef")
{
status = "chef";
}
else
{
status = "cash";
}
panel_sup.Visible = false;
panel_admin.Visible = false;
panel_cash.Visible = false;
panel_chef.Visible = false;
if (status == "admin")
{
panel_admin.Visible = true;
lbl_admin.Text = "Logged in as an Administrator. FULL ACCESS GRANTED";
}
else if (status == "sup")
{
panel_sup.Visible = true;
lbl_sup.Text = "Logged in as a Supervisor. LIMITED ACCESS GRANTED";
btn_del.Visible = false;
}
else if (status == "chef")
{
panel_chef.Visible = true;
lbl_chef.Text = "Logged in as an Chef. LIMITED ACCESS GRANTED";
}
else
{
panel_cash.Visible = true;
lbl_cash.Text = "Logged in as a Cashier. LIMITED ACCESS GRANTED";
}
}
private void frm_emp_Load(object sender, EventArgs e)
{
lbl_date.Text = DateTime.Now.ToLongDateString();
lbl_time.Text = DateTime.Now.ToLongTimeString();
btn_add.Enabled = false;
btn_del.Enabled = false;
btn_edit.Enabled = false;
btn_brws.Enabled = false;
btn_save.Enabled = false;
if (txt_pos_load.Text == "sup")
{
txt_pw.Visible = false;
rb_admin.Visible = false;
rb_sup.Visible = false;
rb_chef.Visible = false;
rb_cash.Visible = false;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
lbl_date.Text = DateTime.Now.ToLongDateString();
lbl_time.Text = DateTime.Now.ToLongTimeString();
}
private void button1_Click(object sender, EventArgs e)
{
frm_menu fmm = new frm_menu(txt_id_load.Text);
fmm.Show();
this.Hide();
}
private void button1_Click_1(object sender, EventArgs e)
{
status = "edit";
txt_id.ReadOnly = false;
txt_fname.ReadOnly = false;
txt_lname.ReadOnly = false;
txt_age.ReadOnly = false;
txt_contact.ReadOnly = false;
txt_address.ReadOnly = false;
txt_pos.ReadOnly = false;
txt_pw.ReadOnly = false;
btn_edit.Enabled = false;
btn_save.Enabled = true;
btn_brws.Enabled = true;
}
private void btn_scan_Click(object sender, EventArgs e)
{
if (txt_id.Text == "")
{
MessageBox.Show("Enter an ID number!!", "No ID number.", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else {
try
{
con.Open();
String validate = "SELECT * FROM se_tbl_emp WHERE id = '" + txt_id.Text + "'";
if (con.State != ConnectionState.Open)
con.Open();
cmd = new SqlCommand(validate, con);
dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
txt_title.Text = dr[1].ToString();
txt_fname.Text = dr[2].ToString();
txt_lname.Text = dr[3].ToString();
txt_age.Text = dr[5].ToString();
txt_contact.Text = dr[6].ToString();
txt_address.Text = dr[7].ToString();
txt_pos.Text = dr[8].ToString();
txt_pw.Text = dr[9].ToString();
txt_id.Enabled = false;
btn_scan.Enabled = false;
btn_del.Enabled = true;
btn_edit.Enabled = true;
byte[] img = (byte[])(dr[4]);
if (img == null)
{
img_emp.Image = null;
}
else
{
MemoryStream ms = new MemoryStream(img);
img_emp.Image = Image.FromStream(ms);
}
con.Close();
}
else
{
MessageBox.Show("No Employee Record for the ID number " + txt_id.Text + ". A new Employee Record can be added if needed", "Empty ID Slot!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
btn_add.Enabled = true;
txt_id.Enabled = false;
btn_scan.Enabled = false;
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
con.Close();
}
}
}
private void btn_clear_Click(object sender, EventArgs e)
{
txt_id.Text = "";
txt_title.Text = "";
txt_fname.Text = "";
txt_lname.Text = "";
txt_age.Text = "";
txt_contact.Text = "";
txt_address.Text = "";
txt_pos.Text = "";
txt_pw.Text = "";
img_emp.Image = null;
txt_id.Enabled = true;
btn_scan.Enabled = true;
btn_add.Enabled = false;
btn_del.Enabled = false;
btn_edit.Enabled = false;
btn_brws.Enabled = false;
btn_save.Enabled = false;
txt_title.ReadOnly = true;
txt_fname.ReadOnly = true;
txt_lname.ReadOnly = true;
txt_age.ReadOnly = true;
txt_contact.ReadOnly = true;
txt_address.ReadOnly = true;
txt_pos.ReadOnly = true;
txt_pw.ReadOnly = true;
rb_mr.Checked = false;
rbmrs.Checked = false;
rbmiss.Checked = false;
if (txt_pos_load.Text == "sup")
{
txt_pw.Visible = false;
}
con.Close();
}
private void txt_id_KeyUp(object sender, KeyEventArgs e)
{
}
private void txt_id_KeyPress(object sender, KeyPressEventArgs e)
{
Char chr = e.KeyChar;
if (!Char.IsDigit(chr) && chr != 8)
{
e.Handled = true;
}
}
private void btn_add_Click(object sender, EventArgs e)
{
status = "add";
txt_fname.ReadOnly = false;
txt_lname.ReadOnly = false;
txt_age.ReadOnly = false;
txt_contact.ReadOnly = false;
txt_address.ReadOnly = false;
txt_pw.ReadOnly = false;
txt_title.Enabled = true;
txt_fname.Enabled = true;
txt_lname.Enabled = true;
txt_age.Enabled = true;
txt_contact.Enabled = true;
txt_address.Enabled = true;
txt_pos.Enabled = true;
txt_pw.Enabled = true;
btn_add.Enabled = false;
btn_brws.Enabled = true;
btn_save.Enabled = true;
txt_pw.Visible = true;
}
private void txt_age_KeyPress(object sender, KeyPressEventArgs e)
{
Char chr = e.KeyChar;
if (!Char.IsDigit(chr) && chr != 8)
{
e.Handled = true;
}
}
private void txt_contact_KeyPress(object sender, KeyPressEventArgs e)
{
}
private void button1_Click_2(object sender, EventArgs e)
{
try
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|All Files (*.*)|*.*";
dlg.Title = "Select Image";
if (dlg.ShowDialog() == DialogResult.OK)
{
imgLoc = dlg.FileName.ToString();
img_emp.ImageLocation = imgLoc;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btn_save_Click(object sender, EventArgs e)
{
if (txt_title.Text == "")
{
MessageBox.Show("Select the title!!", "Empty Details!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (txt_fname.Text == "")
{
MessageBox.Show("Enter First Name!!", "Empty Details!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (txt_lname.Text == "")
{
MessageBox.Show("Enter Last Name!!", "Empty Details!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (img_emp.Image == null)
{
MessageBox.Show("Select an Image!!", "Empty Details!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (txt_age.Text == "")
{
MessageBox.Show("Enter the Age!!", "Empty Details!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (txt_contact.Text == "")
{
MessageBox.Show("Enter the Contact Number!!", "Empty Details!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (txt_address.Text == "")
{
MessageBox.Show("Enter the Address!!", "Empty Details!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (txt_pos.Text == "")
{
MessageBox.Show("Select the Employee Position!!", "Empty Details!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (txt_pw.Text == "")
{
MessageBox.Show("Enter the Password!!", "Empty Details!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else {
{
if (status == "add")
{
try
{
byte[] img = null;
FileStream fs = new FileStream(imgLoc, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
img = br.ReadBytes((int)fs.Length);
string add = "INSERT INTO se_tbl_emp (id , title , f_name , l_name , img , age , contact , address , position , password) VALUES (" + txt_id.Text + ", '" + txt_title.Text + "' , '" + txt_fname.Text + "' , '" + txt_lname.Text + "' , @img , " + txt_age.Text + " , '" + txt_contact.Text + "' , '" + txt_address.Text + "' , '" + txt_pos.Text + "' , '" + txt_pw.Text + "')";
if (con.State != ConnectionState.Open)
con.Open();
cmd = new SqlCommand(add, con);
cmd.Parameters.Add(new SqlParameter("@img", img));
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("You inserted the data Successfully!!", "New Record Entered!", MessageBoxButtons.OK, MessageBoxIcon.Information);
txt_id.Text = "";
txt_title.Text = "";
txt_fname.Text = "";
txt_lname.Text = "";
txt_age.Text = "";
txt_contact.Text = "";
txt_address.Text = "";
txt_pos.Text = "";
txt_pw.Text = "";
img_emp.Image = null;
txt_id.Enabled = true;
btn_scan.Enabled = true;
btn_add.Enabled = false;
btn_del.Enabled = false;
btn_edit.Enabled = false;
btn_brws.Enabled = false;
btn_save.Enabled = false;
txt_title.ReadOnly = true;
txt_fname.ReadOnly = true;
txt_lname.ReadOnly = true;
txt_age.ReadOnly = true;
txt_contact.ReadOnly = true;
txt_address.ReadOnly = true;
txt_pos.ReadOnly = true;
txt_pw.ReadOnly = true;
if (txt_pos_load.Text == "sup")
{
txt_pw.Visible = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
}
else
{
try
{
con.Open();
MemoryStream ms = new MemoryStream();
img_emp.Image.Save(ms, img_emp.Image.RawFormat);
byte[] img = ms.ToArray();
string edit = "UPDATE se_tbl_emp SET title = '" + txt_title.Text + "', f_name = '" + txt_fname.Text + "', l_name = '" + txt_lname.Text + "' , img = @img , age = '" + txt_age.Text + "' , contact = '" + txt_contact.Text + "' , address = '" + txt_address.Text + "' , position = '" + txt_pos.Text + "' , password = '" + txt_pw.Text + "' WHERE id = '" + txt_id.Text + "' ";
cmd = new SqlCommand(edit, con);
cmd.Parameters.Add(new SqlParameter("@img", img));
cmd.ExecuteNonQuery();
MessageBox.Show("Data has been updated Successfully!!", "Record Updated!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
con.Close();
txt_id.Text = "";
txt_title.Text = "";
txt_fname.Text = "";
txt_lname.Text = "";
txt_age.Text = "";
txt_contact.Text = "";
txt_address.Text = "";
txt_pos.Text = "";
txt_pw.Text = "";
img_emp.Image = null;
txt_id.Enabled = true;
btn_scan.Enabled = true;
btn_add.Enabled = false;
btn_del.Enabled = false;
btn_edit.Enabled = false;
btn_brws.Enabled = false;
btn_save.Enabled = false;
txt_title.ReadOnly = true;
txt_fname.ReadOnly = true;
txt_lname.ReadOnly = true;
txt_age.ReadOnly = true;
txt_contact.ReadOnly = true;
txt_address.ReadOnly = true;
txt_pos.ReadOnly = true;
txt_pw.ReadOnly = true;
rb_mr.Checked = false;
rbmrs.Checked = false;
rbmiss.Checked = false;
if (txt_pos_load.Text == "sup")
{
txt_pw.Visible = false;
}
}
catch (Exception ex)
{
con.Close();
MessageBox.Show(ex.Message);
}
}
}
}
}
private void btn_del_Click(object sender, EventArgs e)
{
if(MessageBox.Show("Are you Sure?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
con.Open();
string del = "DELETE FROM se_tbl_emp WHERE id = '" + txt_id.Text + "' ";
cmd = new SqlCommand(del, con);
cmd.ExecuteNonQuery();
MessageBox.Show("Record Deleted!!", "Confirmed!!", MessageBoxButtons.OK, MessageBoxIcon.Information );
con.Close();
txt_id.Text = "";
txt_title.Text = "";
txt_fname.Text = "";
txt_lname.Text = "";
txt_age.Text = "";
txt_contact.Text = "";
txt_address.Text = "";
txt_pos.Text = "";
txt_pw.Text = "";
img_emp.Image = null;
txt_id.Enabled = true;
btn_scan.Enabled = true;
btn_add.Enabled = false;
btn_del.Enabled = false;
btn_edit.Enabled = false;
btn_brws.Enabled = false;
btn_save.Enabled = false;
txt_title.ReadOnly = true;
txt_fname.ReadOnly = true;
txt_lname.ReadOnly = true;
txt_age.ReadOnly = true;
txt_contact.ReadOnly = true;
txt_address.ReadOnly = true;
txt_pos.ReadOnly = true;
txt_pw.ReadOnly = true;
rb_mr.Checked = false;
rbmrs.Checked = false;
rbmiss.Checked = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void rb_mr_CheckedChanged(object sender, EventArgs e)
{
txt_title.Text = "Mr.";
rbmrs.Checked = false;
rbmiss.Checked = false;
}
private void rbmrs_CheckedChanged(object sender, EventArgs e)
{
txt_title.Text = "Mrs.";
rb_mr.Checked = false;
rbmiss.Checked = false;
}
private void rbmiss_CheckedChanged(object sender, EventArgs e)
{
txt_title.Text = "Miss.";
rb_mr.Checked = false;
rbmrs.Checked = false;
}
private void txt_pos_TextChanged(object sender, EventArgs e)
{
}
private void rb_admin_CheckedChanged(object sender, EventArgs e)
{
txt_pos.Text = "admin";
rb_sup.Checked = false;
rb_chef.Checked = false;
rb_cash.Checked = false;
}
private void rb_sup_CheckedChanged(object sender, EventArgs e)
{
txt_pos.Text = "sup";
rb_admin.Checked = false;
rb_chef.Checked = false;
rb_cash.Checked = false;
}
private void rb_chef_CheckedChanged(object sender, EventArgs e)
{
txt_pos.Text = "chef";
rb_admin.Checked = false;
rb_sup.Checked = false;
rb_cash.Checked = false;
}
private void rb_cash_CheckedChanged(object sender, EventArgs e)
{
txt_pos.Text = "cash";
rb_admin.Checked = false;
rb_sup.Checked = false;
rb_chef.Checked = false;
}
private void btn_view_Click(object sender, EventArgs e)
{
frm_emp_view fev = new frm_emp_view(txt_pos_load.Text);
fev.Show();
}
private void txt_id_TextChanged(object sender, EventArgs e)
{
}
}
}