-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate_Employee.cs
171 lines (147 loc) · 7.36 KB
/
Update_Employee.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
using System;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Walmart_OMS
{
public partial class Update_Employee : Form
{
public Update_Employee()
{
InitializeComponent();
}
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
private void Update_Employee_Load(object sender, EventArgs e)
{
try
{
txt_eid.Text = Admin_Panel.eid;
con = new SqlConnection("Data Source=HANSANA-3501;Initial Catalog=WalmartOMS_DB;Integrated Security=True");
con.Open();
cmd = new SqlCommand("SELECT * FROM All_Staff WHERE EID='" + txt_eid.Text + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
dr.Close();
cmd = new SqlCommand("SELECT First_Name FROM All_Staff WHERE EID='" + txt_eid.Text + "'", con);
string fname = cmd.ExecuteScalar().ToString();
cmd = new SqlCommand("SELECT Last_Name FROM All_Staff WHERE EID='" + txt_eid.Text + "'", con);
string lname = cmd.ExecuteScalar().ToString();
cmd = new SqlCommand("SELECT Contact_No FROM All_Staff WHERE EID='" + txt_eid.Text + "'", con);
int cno = Convert.ToInt32(cmd.ExecuteScalar());
txt_fname.Text = fname;
txt_lname.Text = lname;
txt_cno.Text = cno.ToString();
}
else
{
dr.Close();
this.Close();
MessageBox.Show("Employee Not Found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btn_update_Click(object sender, EventArgs e)
{
try
{
con.Open();
cmd = new SqlCommand("SELECT * FROM Staff WHERE EID='" + txt_eid.Text + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
dr.Close();
cmd = new SqlCommand("UPDATE Staff SET First_Name='" + txt_fname.Text + "',Last_Name='" + txt_lname.Text + "',Password='" + txt_password.Text + "',Contact_No='" + txt_cno.Text + "' WHERE EID='" + txt_eid.Text + "'", con);
cmd.ExecuteNonQuery();
cmd = new SqlCommand("UPDATE All_Staff SET First_Name=' " + txt_fname.Text + "',Last_Name='" + txt_lname.Text + "',Password='" + txt_password.Text + "',Contact_No='" + txt_cno.Text + "' WHERE EID= '" + txt_eid.Text + "'", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Employee update successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
dr.Close();
cmd = new SqlCommand("SELECT * FROM Admins WHERE EID='" + txt_eid.Text + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
dr.Close();
cmd = new SqlCommand("UPDATE Admins SET First_Name=' " + txt_fname.Text + "',Last_Name='" + txt_lname.Text + "',Password='" + txt_password.Text + "',Contact_No='" + txt_cno.Text + "' WHERE EID= '" + txt_eid.Text + "'", con);
cmd.ExecuteNonQuery();
cmd = new SqlCommand("UPDATE All_Staff SET First_Name=' " + txt_fname.Text + "',Last_Name='" + txt_lname.Text + "',Password='" + txt_password.Text + "',Contact_No='" + txt_cno.Text + "' WHERE EID= '" + txt_eid.Text + "'", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Employee Updated Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
dr.Close();
cmd = new SqlCommand("SELECT * FROM Super_Admins WHERE EID='" + txt_eid.Text + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
dr.Close();
cmd = new SqlCommand("SELECT * FROM Admins WHERE EID='" + Staff_Login.EID + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
dr.Close();
MessageBox.Show("You need elevated access to the system to update a SUPER ADMIN", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
dr.Close();
cmd = new SqlCommand("UPDATE Super_Admins SET First_Name=' " + txt_fname.Text + "',Last_Name='" + txt_lname.Text + "',Password='" + txt_password.Text + "',Contact_No='" + txt_cno.Text + "' WHERE EID= '" + txt_eid.Text + "'", con);
cmd.ExecuteNonQuery();
cmd = new SqlCommand("UPDATE All_Staff SET First_Name=' " + txt_fname.Text + "',Last_Name='" + txt_lname.Text + "',Password='" + txt_password.Text + "',Contact_No='" + txt_cno.Text + "' WHERE EID= '" + txt_eid.Text + "'", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Employee Updated Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
dr.Close();
MessageBox.Show("Employee not found in the server", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btn_exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btn_close_Click(object sender, EventArgs e)
{
this.Close();
}
private void btn_minimize_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
[DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
private extern static void ReleaseCapture();
[DllImport("user32.DLL", EntryPoint = "SendMessage")]
private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int lParam);
private void panel_control_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, 0x112, 0xf012, 0);
}
private void Update_Employee_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, 0x112, 0xf012, 0);
}
}
}