-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerification-Form.aspx.cs
More file actions
394 lines (349 loc) · 16.4 KB
/
Verification-Form.aspx.cs
File metadata and controls
394 lines (349 loc) · 16.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
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
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Z_Wallet
{
public partial class Verification : Page
{
string connectionString = ConfigurationManager.ConnectionStrings["Z-WalletConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["AccountNumber"] == null)
{
Response.Redirect("Default.aspx"); // Redirect to the login page
}
else
{
if (!IsPostBack)
{
PopulateCountries();
int accountNumber;
if (int.TryParse(Session["AccountNumber"].ToString(), out accountNumber))
{
// Load the user's verification information if available
LoadVerificationInfo(accountNumber);
}
else
{
// Handle invalid account number in session
Response.Redirect("~/Default.aspx");
}
}
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
// Validate the form fields
if (ValidateForm())
{
// Get the account number from the session
int accountNumber = Convert.ToInt32(Session["AccountNumber"]);
// Check if the account is already verified
if (IsAccountVerified(accountNumber))
{
// Display message that the account is already verified
lblErrorMessage.Text = "Account is already verified.";
lblErrorMessage.Visible = true;
lblSuccessMessage.Visible = false;
}
else
{
// Check if both front and back ID pictures are chosen
if (fileUpload1.HasFile && fileUpload2.HasFile)
{
// Check file extensions
string fileExtension1 = Path.GetExtension(fileUpload1.FileName).ToLower();
string fileExtension2 = Path.GetExtension(fileUpload2.FileName).ToLower();
if (IsImageExtension(fileExtension1) && IsImageExtension(fileExtension2))
{
// Prepare the database query to save or update the verification information
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand("IF EXISTS (SELECT * FROM [User-Verification] WHERE AccountNumber = @AccountNumber) " +
"UPDATE [User-Verification] SET " +
"FrontIDPicture = @FrontIDPicture, BackIDPicture = @BackIDPicture " +
"WHERE AccountNumber = @AccountNumber " +
"ELSE " +
"INSERT INTO [User-Verification] (AccountNumber, FrontIDPicture, BackIDPicture) " +
"VALUES (@AccountNumber, @FrontIDPicture, @BackIDPicture)", connection);
command.Parameters.AddWithValue("@AccountNumber", accountNumber);
// Save the front ID picture
byte[] imageData1 = fileUpload1.FileBytes;
command.Parameters.AddWithValue("@FrontIDPicture", imageData1);
// Save the back ID picture
byte[] imageData2 = fileUpload2.FileBytes;
command.Parameters.AddWithValue("@BackIDPicture", imageData2);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
// Update the account status in the Users table to "Pending"
UpdateAccountStatus(accountNumber, "Pending");
// Display success message or perform other actions
lblSuccessMessage.Visible = true;
lblSuccessMessage.Text = "Form submitted successfully!";
lblErrorMessage.Visible = false;
}
}
else
{
// Display error message for invalid file extensions
lblErrorMessage.Text = "Please choose image files only.";
lblErrorMessage.Visible = true;
lblSuccessMessage.Visible = false;
}
}
else
{
// Display error message for not choosing both front and back ID pictures
lblErrorMessage.Text = "Please choose both front and back ID pictures.";
lblErrorMessage.Visible = true;
lblSuccessMessage.Visible = false;
}
}
}
}
private bool IsImageExtension(string fileExtension)
{
// Define the allowed image file extensions
string[] allowedExtensions = { ".jpg", ".jpeg", ".png" };
// Check if the file extension is in the allowed extensions list
return allowedExtensions.Contains(fileExtension);
}
private void UpdateAccountStatus(int accountNumber, string status)
{
// Update the account status in the Users table
string query = "UPDATE [Users] SET [AccountStatus] = @AccountStatus WHERE [AccountNumber] = @AccountNumber";
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Parameters.AddWithValue("@AccountStatus", status);
command.Parameters.AddWithValue("@AccountNumber", accountNumber);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}
}
}
private bool IsAccountVerified(int accountNumber)
{
// Check if the account is already verified in the database
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand("SELECT AccountStatus FROM Users WHERE AccountNumber = @AccountNumber", connection);
command.Parameters.AddWithValue("@AccountNumber", accountNumber);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
string verificationStatus = reader["AccountStatus"].ToString();
if (verificationStatus == "Verified")
{
reader.Close();
connection.Close();
return true;
}
}
reader.Close();
connection.Close();
}
return false;
}
protected void btnCancel_Click(object sender, EventArgs e)
{
// Clear the form fields and redirect the user
ClearForm();
Response.Redirect("~/Dashboard.aspx");
}
private void PopulateCountries()
{
// Clear existing items in the countries dropdown list
ddlCountries.Items.Clear();
// Add a default 'Select Country' option to the countries dropdown list
ddlCountries.Items.Add(new ListItem("Select Country", ""));
// Get a list of RegionInfo objects representing all the specific cultures
var countries = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures)
.Select(x => new System.Globalization.RegionInfo(x.LCID))
.Distinct()
.OrderBy(x => x.DisplayName);
// Loop through the countries list and add each country to the countries dropdown list
foreach (var country in countries)
{
ddlCountries.Items.Add(new ListItem(country.DisplayName, country.EnglishName));
}
}
private void LoadVerificationInfo(int accountNumber)
{
// Prepare the database query to load the user's verification information
using (SqlConnection connection = new SqlConnection(connectionString))
{
// Load the verification information from the User-Verification table
SqlCommand command = new SqlCommand("SELECT * FROM [User-Verification] WHERE AccountNumber = @AccountNumber", connection);
command.Parameters.AddWithValue("@AccountNumber", accountNumber);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
txtFirstName.Text = reader["FirstName"].ToString();
txtLastName.Text = reader["LastName"].ToString();
txtMiddleName.Text = reader["MiddleName"].ToString();
txtBirthDate.Text = Convert.ToDateTime(reader["Birthdate"]).ToString("yyyy-MM-dd");
ddlGender.SelectedValue = reader["Gender"].ToString();
txtNationality.Text = reader["Nationality"].ToString();
txtPlaceOfBirth.Text = reader["PlaceOfBirth"].ToString();
txtAddressLine1.Text = reader["AddressLineOne"].ToString();
txtAddressLine2.Text = reader["AddressLineTwo"].ToString();
txtCityAddress.Text = reader["City"].ToString();
ProvinceAddress.Text = reader["Province"].ToString();
txtPostalCode.Text = reader["PostalCode"].ToString();
ddlCountries.SelectedValue = reader["Country"].ToString();
ddlIDType.SelectedValue = reader["IDType"].ToString();
}
reader.Close();
// Load the verification status from the Users table
command = new SqlCommand("SELECT AccountStatus FROM [Users] WHERE AccountNumber = @AccountNumber", connection);
command.Parameters.AddWithValue("@AccountNumber", accountNumber);
SqlDataReader statusReader = command.ExecuteReader();
if (statusReader.Read())
{
string accountStatus = statusReader["AccountStatus"].ToString();
lblAccountStatus.Text = accountStatus;
lblAccountStatus.CssClass = "status-badge " + GetStatusBadgeClass(accountStatus);
if (accountStatus == "Pending" || accountStatus == "Unverified" || accountStatus == "Denied")
{
cardfileUpload1.Visible = true; // Show front ID picture file upload
cardfileUpload2.Visible = true; // Show back ID picture file upload
}
else if (accountStatus == "Verified")
{
cardfileUpload1.Visible = false; // Hide front ID picture file upload
cardfileUpload2.Visible = false; // Hide back ID picture file upload
}
}
statusReader.Close();
connection.Close();
}
}
protected string GetStatusBadgeClass(string status)
{
switch (status)
{
case "Verified":
return "bg-success";
case "Pending":
return "bg-info";
case "Denied":
return "bg-danger";
case "Suspended":
return "bg-warning";
case "Unverified":
return "bg-secondary";
default:
return "bg-secondary";
}
}
private bool ValidateForm()
{
// Perform validation for the required fields
if (string.IsNullOrEmpty(txtFirstName.Text))
{
lblErrorMessage.Text = "First name is required.";
lblErrorMessage.Visible = true;
return false;
}
if (string.IsNullOrEmpty(txtLastName.Text))
{
lblErrorMessage.Text = "Last name is required.";
lblErrorMessage.Visible = true;
return false;
}
if (ddlIDType.SelectedIndex == 0)
{
lblErrorMessage.Text = "ID type is required.";
lblErrorMessage.Visible = true;
return false;
}
if (string.IsNullOrEmpty(txtBirthDate.Text))
{
lblErrorMessage.Text = "Birth date is required.";
lblErrorMessage.Visible = true;
return false;
}
if (ddlGender.SelectedIndex == -1)
{
lblErrorMessage.Text = "Gender is required.";
lblErrorMessage.Visible = true;
return false;
}
if (string.IsNullOrEmpty(txtNationality.Text))
{
lblErrorMessage.Text = "Nationality is required.";
lblErrorMessage.Visible = true;
return false;
}
if (string.IsNullOrEmpty(txtPlaceOfBirth.Text))
{
lblErrorMessage.Text = "Place of birth is required.";
lblErrorMessage.Visible = true;
return false;
}
if (string.IsNullOrEmpty(txtAddressLine1.Text))
{
lblErrorMessage.Text = "Address Line 1 is required.";
lblErrorMessage.Visible = true;
return false;
}
if (string.IsNullOrEmpty(txtCityAddress.Text))
{
lblErrorMessage.Text = "City is required.";
lblErrorMessage.Visible = true;
return false;
}
if (string.IsNullOrEmpty(ProvinceAddress.Text))
{
lblErrorMessage.Text = "Province is required.";
lblErrorMessage.Visible = true;
return false;
}
if (string.IsNullOrEmpty(txtPostalCode.Text))
{
lblErrorMessage.Text = "Postal code is required.";
lblErrorMessage.Visible = true;
return false;
}
if (ddlCountries.SelectedIndex == 0)
{
lblErrorMessage.Text = "Country is required.";
lblErrorMessage.Visible = true;
return false;
}
lblErrorMessage.Visible = false;
return true;
}
private void ClearForm()
{
txtFirstName.Text = string.Empty;
txtLastName.Text = string.Empty;
txtMiddleName.Text = string.Empty;
txtBirthDate.Text = string.Empty;
ddlGender.SelectedIndex = -1;
txtNationality.Text = string.Empty;
txtPlaceOfBirth.Text = string.Empty;
txtAddressLine1.Text = string.Empty;
txtAddressLine2.Text = string.Empty;
txtCityAddress.Text = string.Empty;
ProvinceAddress.Text = string.Empty;
txtPostalCode.Text = string.Empty;
ddlCountries.SelectedIndex = 0;
ddlIDType.SelectedIndex = 0;
lblErrorMessage.Visible = false;
lblSuccessMessage.Visible = false;
}
}
}