-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8HRPage.aspx.cs
More file actions
244 lines (227 loc) · 10.4 KB
/
8HRPage.aspx.cs
File metadata and controls
244 lines (227 loc) · 10.4 KB
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
using System;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication06_eVisa
{
public partial class _8HRPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("uid=sa; password=manager@123; database=EVisa; server=7Y27QV3\\SQLEXPRESS");
try
{
SqlDataAdapter adapder = new SqlDataAdapter("select * from employees", con);
DataSet ds = new DataSet();
adapder.Fill(ds);
gvEmployees.DataSource = ds;
gvEmployees.DataBind();
SqlDataAdapter a = new SqlDataAdapter("select * from resultreport", con);
DataSet d = new DataSet();
a.Fill(d);
gvVisaReporting.DataSource = d;
gvVisaReporting.DataBind();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Error: {ex.Message}');", true);
}
finally
{
con.Close();
}
}
protected void BtnSubmitVisaRequest_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("uid=sa; password=manager@123; database=EVisa; server=7Y27QV3\\SQLEXPRESS");
try
{
con.Open();
string query = "INSERT INTO VISASTATUS (EmployeeId, VisaType, VisaExpiry, RenewalRequested) VALUES (@EmployeeId, @VisaType, @VisaExpiry, @RenewalRequested)";
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.AddWithValue("@EmployeeId", txtEmployeeId.Text);
cmd.Parameters.AddWithValue("@VisaType", txtVisaType.Text);
cmd.Parameters.AddWithValue("@VisaExpiry", txtExpiry.Text);
cmd.Parameters.AddWithValue("@RenewalRequested", txtRenewalRequest.Text);
cmd.ExecuteNonQuery();
}
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Visa Status is added for {txtEmployeeId.Text}');", true);
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Error: {ex.Message}');", true);
}
finally
{
con.Open();
txtEmployeeId.Text = string.Empty;
txtVisaType.Text = string.Empty;
txtExpiry.Text = string.Empty;
txtRenewalRequest.Text = string.Empty;
}
}
protected void BtnUpdateVisaRequest_Click(object sender, EventArgs e)
{
string connectionString = "uid=sa; password=manager@123; database=EVisa; server=7Y27QV3\\SQLEXPRESS";
using (SqlConnection con = new SqlConnection(connectionString))
{
try
{
con.Open();
string query = "UPDATE VISASTATUS SET RENEWALREQUESTED = @RenewalRequested WHERE VISAID = @VisaId";
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.AddWithValue("@RenewalRequested", txtFinalResult.Text);
cmd.Parameters.AddWithValue("@VisaId", int.Parse(txtVisaId.Text));
int rowsAffected = cmd.ExecuteNonQuery();
if (rowsAffected > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Visa Status is updated for {txtVisaId.Text}');", true);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('No record found for Visa ID {txtVisaId.Text}.');", true);
}
}
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Error: {ex.Message}');", true);
}
finally
{
con.Close();
txtFinalResult.Text = string.Empty;
txtVisaId.Text = string.Empty;
}
}
}
protected void BtnChangePassword_Click(object sender, EventArgs e)
{
string connectionString = "uid=sa; password=manager@123; database=EVisa; server=7Y27QV3\\SQLEXPRESS";
using (SqlConnection con = new SqlConnection(connectionString))
{
try
{
con.Open();
string fetchPasswordQuery = "SELECT PASSWORD FROM HR WHERE HRID = @HrID";
string currentPasswordFromDb = null;
using (SqlCommand fetchPasswordCmd = new SqlCommand(fetchPasswordQuery, con))
{
fetchPasswordCmd.Parameters.AddWithValue("@HrID", Request.QueryString["uid"]);
object result = fetchPasswordCmd.ExecuteScalar();
if (result != null)
{
currentPasswordFromDb = result.ToString();
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('No record found for Visa ID {txtVisaId.Text}.');", true);
return;
}
}
// Verify if the current password entered by the user matches the password in the database
if (txtCurrentPassword.Text == currentPasswordFromDb)
{
// Update the password
string updatePasswordQuery = "UPDATE HR SET PASSWORD = @NewPassword WHERE HRID = @HrID";
using (SqlCommand updatePasswordCmd = new SqlCommand(updatePasswordQuery, con))
{
updatePasswordCmd.Parameters.AddWithValue("@NewPassword", txtNewPassword.Text);
updatePasswordCmd.Parameters.AddWithValue("@HrID", Request.QueryString["uid"]);
int rowsAffected = updatePasswordCmd.ExecuteNonQuery();
if (rowsAffected > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('HR Password is updated successfully.');", true);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Failed to update the password.');", true);
}
}
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Current password is incorrect.');", true);
}
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Error: {ex.Message}');", true);
}
finally
{
con.Close();
}
}
}
protected void BtnSendFeedback_Click(object sender, EventArgs e)
{
string connectionString = "uid=sa; password=manager@123; database=EVisa; server=7Y27QV3\\SQLEXPRESS";
using (SqlConnection con = new SqlConnection(connectionString))
{
try
{
con.Open();
string query = "INSERT INTO FEEDBACK (EmployeeId, HrID, FeedbackDate, FeedbackText) VALUES (NULL, @HrID, CONVERT(DATE, GETDATE()), @FeedbackText)";
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.AddWithValue("@HrID", Request.QueryString["uid"]);
cmd.Parameters.AddWithValue("@FeedbackText", txtFeedback.Text);
cmd.ExecuteNonQuery();
}
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Feedback is added successfully.');", true);
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Error: {ex.Message}');", true);
}
finally
{
con.Close();
txtFeedback.Text = string.Empty;
}
}
}
protected void BtnEmpRefresh_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("uid=sa; password=manager@123; database=EVisa; server=7Y27QV3\\SQLEXPRESS");
try
{
SqlDataAdapter adapder = new SqlDataAdapter("select * from employees", con);
DataSet ds = new DataSet();
adapder.Fill(ds);
gvEmployees.DataSource = ds;
gvEmployees.DataBind();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Error: {ex.Message}');", true);
}
finally
{
con.Close();
}
}
protected void BtnReportRefresh_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("uid=sa; password=manager@123; database=EVisa; server=7Y27QV3\\SQLEXPRESS");
try
{
SqlDataAdapter adapder = new SqlDataAdapter("select * from resultreport", con);
DataSet ds = new DataSet();
adapder.Fill(ds);
gvVisaReporting.DataSource = ds;
gvVisaReporting.DataBind();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('Error: {ex.Message}');", true);
}
finally
{
con.Close();
}
}
}
}