-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathEmployeeInformationSystem
77 lines (71 loc) · 3.08 KB
/
EmployeeInformationSystem
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
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;
using MySql.Data.MySqlClient;
namespace EmployeeInformation
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnAdd_Click(object sender, EventArgs e)
{
string connection = "server=localhost;user id=root;password=;database=employeerecord";
string query = "INSERT INTO tbl_employee(FIRSTNAME,MI,LASTNAME,GENDER,POSITION)VALUES('"+ this.FIRSTNAME.Text + "','" + this.MI.Text + "','" + this.LASTNAME.Text + "','" + this.GENDER.Text + "','" + this.POSITION.Text + "')";
MySqlConnection conn = new MySqlConnection(connection);
MySqlCommand cmd = new MySqlCommand(query, conn);
MySqlDataReader dr;
conn.Open();
dr = cmd.ExecuteReader();
MessageBox.Show("Successfully saved");
conn.Close();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
string connection = "server=localhost;user id=root;password=;database=employeerecord";
string query = "UPDATE tbl_employee SET FIRSTNAME='" + this.FIRSTNAME.Text + "',MI='" + this.MI.Text + "',LASTNAME='" + this.LASTNAME.Text + "',GENDER='" + this.GENDER.Text + "',POSITION='" + this.POSITION.Text + "' WHERE EMPID='"+ this.EMPID.Text + "'";
MySqlConnection conn = new MySqlConnection(connection);
MySqlCommand cmd = new MySqlCommand(query, conn);
MySqlDataReader dr;
conn.Open();
dr = cmd.ExecuteReader();
MessageBox.Show("Record has been updated successfully");
conn.Close();
}
private void btnDelete_Click(object sender, EventArgs e)
{
string connection = "server=localhost;user id=root;password=;database=employeerecord";
string query = "DELETE FROM tbl_employee WHERE EMPID='"+ this.EMPID.Text + "'";
MySqlConnection conn = new MySqlConnection(connection);
MySqlCommand cmd = new MySqlCommand(query, conn);
MySqlDataReader dr;
conn.Open();
dr = cmd.ExecuteReader();
MessageBox.Show("Data has been succesfully deleted!!");
conn.Close();
}
private void btnLoadData_Click(object sender, EventArgs e)
{
string connection = "server=localhost;user id=root;password=;database=apsystem";
string query = "SELECT * FROM tbl_employee";
MySqlConnection conn = new MySqlConnection(connection);
MySqlCommand cmd = new MySqlCommand(query, conn);
MySqlDataAdapter da = new MySqlDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}