-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm8.cs
More file actions
593 lines (521 loc) · 23.6 KB
/
Copy pathForm8.cs
File metadata and controls
593 lines (521 loc) · 23.6 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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace H1
{
public partial class Form8 : Form
{
private string connectionString = @"Data Source=ABDULSABOOR190\SQLEXPRESS;Initial Catalog=sabbbb;Integrated Security=True;Encrypt=False";
private int currentUserId = 7; // In a real application, this would come from login authentication
private Timer dateTimeTimer;
public Form8()
{
InitializeComponent();
InitializeNavPanel();
SetActiveButton(btnDashboard);
}
private void InitializeNavPanel()
{
// Remove border from buttons in the navigation panel
foreach (Control control in navPanel.Controls)
{
if (control is Button button)
{
button.FlatAppearance.BorderSize = 0;
}
}
}
private void Form8_Load(object sender, EventArgs e)
{
// Update the date/time display
lblDateTime.Text = DateTime.Now.ToString("MMMM dd, yyyy | h:mm tt");
// Create timer to update date/time
dateTimeTimer = new Timer();
dateTimeTimer.Interval = 60000; // Update every minute
dateTimeTimer.Tick += (s, args) => { lblDateTime.Text = DateTime.Now.ToString("MMMM dd, yyyy | h:mm tt"); };
dateTimeTimer.Start();
RefreshDashboard();
}
private void RefreshDashboard()
{
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
LoadUserProfile(conn);
LoadNextTrip(conn);
LoadTravelStatus(conn);
}
}
catch (Exception ex)
{
MessageBox.Show("Error loading dashboard data: " + ex.Message,
"Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadUserProfile(SqlConnection conn)
{
string query = @"
SELECT u.email, tp.first_name, tp.last_name, tp.phone
FROM AppUser u
JOIN TravelerProfile tp ON u.user_id = tp.user_id
WHERE u.user_id = @userId";
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.AddWithValue("@userId", currentUserId);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
string firstName = reader["first_name"].ToString();
string lastName = reader["last_name"].ToString();
lblWelcome.Text = $"Welcome, {firstName} {lastName}";
}
else
{
lblWelcome.Text = "Welcome, Guest";
}
}
}
}
private void LoadNextTrip(SqlConnection conn)
{
// Updated query to match the database schema provided
string query = @"
SELECT TOP 1
t.title,
t.destination,
FORMAT(t.start_date, 'MMMM dd, yyyy') + ' - ' +
FORMAT(t.end_date, 'MMMM dd, yyyy') AS travel_date,
h.name AS hotel_name,
b.status
FROM Booking b
JOIN Trip t ON b.trip_id = t.trip_id
LEFT JOIN Assignment a ON b.booking_id = a.booking_id
LEFT JOIN Service s ON a.service_id = s.service_id
LEFT JOIN Hotel h ON s.provider_id = h.provider_id
WHERE b.traveler_id = @userId
AND t.start_date >= GETDATE()
ORDER BY t.start_date ASC";
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.AddWithValue("@userId", currentUserId);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
txtDestination.Text = reader["destination"].ToString();
txtDate.Text = reader["travel_date"].ToString();
txtHotel.Text = reader["hotel_name"] != DBNull.Value ?
reader["hotel_name"].ToString() : "Not assigned";
txtStatus.Text = reader["status"].ToString();
}
else
{
txtDestination.Text = "No upcoming trips";
txtDate.Text = "-";
txtHotel.Text = "-";
txtStatus.Text = "-";
}
}
}
}
private void LoadTravelStatus(SqlConnection conn)
{
// Load digital passes status
string passQuery = @"
SELECT COUNT(*) AS active_passes
FROM DigitalPass dp
JOIN Booking b ON dp.booking_id = b.booking_id
WHERE b.traveler_id = @userId
AND dp.valid_to >= GETDATE()";
using (SqlCommand cmd = new SqlCommand(passQuery, conn))
{
cmd.Parameters.AddWithValue("@userId", currentUserId);
int activePasses = Convert.ToInt32(cmd.ExecuteScalar());
textBox3.Text = $"{activePasses} active pass{(activePasses != 1 ? "es" : "")}";
}
// Load payments status
string paymentQuery = @"
SELECT COUNT(*) AS completed_payments
FROM Payment p
JOIN Booking b ON p.booking_id = b.booking_id
WHERE b.traveler_id = @userId
AND p.status = 'completed'";
using (SqlCommand cmd = new SqlCommand(paymentQuery, conn))
{
cmd.Parameters.AddWithValue("@userId", currentUserId);
int completedPayments = Convert.ToInt32(cmd.ExecuteScalar());
textBox2.Text = $"{completedPayments} completed payment{(completedPayments != 1 ? "s" : "")}";
}
// Added an alternative approach since Visas table is not in the provided schema
// This checks for special requests that might be related to visas
string visaQuery = @"
SELECT COUNT(*)
FROM Booking b
WHERE b.traveler_id = @userId
AND b.special_requests LIKE '%visa%'";
try
{
using (SqlCommand cmd = new SqlCommand(visaQuery, conn))
{
cmd.Parameters.AddWithValue("@userId", currentUserId);
int visaRequests = Convert.ToInt32(cmd.ExecuteScalar());
textBox1.Text = $"{visaRequests} visa request{(visaRequests != 1 ? "s" : "")}";
}
}
catch (Exception)
{
// If the query fails, it might be because the Visas table actually exists but wasn't in the provided schema
// Fall back to hardcoded data
textBox1.Text = "Visa status unavailable";
}
}
private void SetActiveButton(Button activeButton)
{
// Reset all navigation buttons to default color
Color defaultColor = Color.FromArgb(52, 73, 94);
Color activeColor = Color.FromArgb(41, 128, 185);
foreach (Control control in navPanel.Controls)
{
if (control is Button button)
{
button.BackColor = defaultColor;
}
}
// Set the active button to highlight color
activeButton.BackColor = activeColor;
}
#region Navigation Button Click Events
private void btnDashboard_Click(object sender, EventArgs e)
{
SetActiveButton(btnDashboard);
RefreshDashboard();
}
private void btnRegistration_Click(object sender, EventArgs e)
{
SetActiveButton(btnRegistration);
// Implementation for registration form
ShowNotImplementedMessage("Registration");
}
private void btnSearchBooking_Click(object sender, EventArgs e)
{
SetActiveButton(btnSearchBooking);
// Implementation for search booking functionality
ShowTripSearchDialog();
}
private void ShowTripSearchDialog()
{
// This would be better implemented as a separate form
// For now, show a simple dialog with trip search capabilities
Form searchForm = new Form();
searchForm.Text = "Search Trips";
searchForm.Size = new Size(600, 400);
searchForm.StartPosition = FormStartPosition.CenterParent;
// Add controls to the form
DataGridView dgvTrips = new DataGridView();
dgvTrips.Dock = DockStyle.Fill;
searchForm.Controls.Add(dgvTrips);
// Load trips data
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
string query = @"
SELECT t.trip_id, t.title, t.destination,
t.start_date, t.end_date, t.price, t.difficulty_level,
op.company_name as operator
FROM Trip t
JOIN TourOperatorProfile op ON t.operator_id = op.user_id
WHERE t.is_active = 1
AND t.start_date >= GETDATE()
ORDER BY t.start_date";
SqlDataAdapter adapter = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
adapter.Fill(dt);
dgvTrips.DataSource = dt;
}
}
catch (Exception ex)
{
MessageBox.Show("Error loading trips: " + ex.Message,
"Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
searchForm.ShowDialog();
}
private void btnViewBooking_Click(object sender, EventArgs e)
{
SetActiveButton(btnViewBooking);
DisplayUserBookings();
}
private void DisplayUserBookings()
{
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
string query = @"
SELECT t.title, t.destination,
FORMAT(t.start_date, 'MMMM dd, yyyy') AS start_date,
FORMAT(t.end_date, 'MMMM dd, yyyy') AS end_date,
b.status, b.total_amount, b.participants
FROM Booking b
JOIN Trip t ON b.trip_id = t.trip_id
WHERE b.traveler_id = @userId
ORDER BY t.start_date DESC";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@userId", currentUserId);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
if (dt.Rows.Count > 0)
{
// Create a more visually pleasing booking display form
Form bookingsForm = new Form();
bookingsForm.Text = "Your Bookings";
bookingsForm.Size = new Size(800, 500);
bookingsForm.StartPosition = FormStartPosition.CenterParent;
DataGridView dgvBookings = new DataGridView();
dgvBookings.Dock = DockStyle.Fill;
dgvBookings.ReadOnly = true;
dgvBookings.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dgvBookings.DataSource = dt;
bookingsForm.Controls.Add(dgvBookings);
bookingsForm.ShowDialog();
}
else
{
MessageBox.Show("You don't have any bookings yet.",
"Bookings", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error loading bookings: " + ex.Message,
"Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnViewPass_Click(object sender, EventArgs e)
{
SetActiveButton(btnViewPass);
DisplayDigitalPasses();
}
private void DisplayDigitalPasses()
{
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
string query = @"
SELECT dp.type, dp.qr_code,
t.title as trip_title, t.destination,
FORMAT(dp.valid_from, 'MMMM dd, yyyy') AS valid_from,
FORMAT(dp.valid_to, 'MMMM dd, yyyy') AS valid_to,
dp.access_code
FROM DigitalPass dp
JOIN Booking b ON dp.booking_id = b.booking_id
JOIN Trip t ON b.trip_id = t.trip_id
WHERE b.traveler_id = @userId
AND dp.valid_to >= GETDATE()";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@userId", currentUserId);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
if (dt.Rows.Count > 0)
{
// Create a more visually pleasing digital pass display form
Form passesForm = new Form();
passesForm.Text = "Your Digital Passes";
passesForm.Size = new Size(700, 500);
passesForm.StartPosition = FormStartPosition.CenterParent;
DataGridView dgvPasses = new DataGridView();
dgvPasses.Dock = DockStyle.Fill;
dgvPasses.ReadOnly = true;
dgvPasses.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dgvPasses.DataSource = dt;
passesForm.Controls.Add(dgvPasses);
passesForm.ShowDialog();
}
else
{
MessageBox.Show("You don't have any active digital passes.",
"Digital Passes", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error loading digital passes: " + ex.Message,
"Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnDigitalPass_Click(object sender, EventArgs e)
{
SetActiveButton(btnDigitalPass);
DisplayDigitalPasses(); // Reuse the same display method
}
private void btnReviews_Click(object sender, EventArgs e)
{
SetActiveButton(btnReviews);
DisplayUserReviews();
}
private void DisplayUserReviews()
{
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
string query = @"
SELECT t.title, t.destination,
r.rating, r.comment, r.status,
FORMAT(r.created_at, 'MMMM dd, yyyy') AS review_date
FROM Review r
JOIN Booking b ON r.booking_id = b.booking_id
JOIN Trip t ON b.trip_id = t.trip_id
WHERE b.traveler_id = @userId
ORDER BY r.created_at DESC";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@userId", currentUserId);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
if (dt.Rows.Count > 0)
{
// Create a review display form
Form reviewsForm = new Form();
reviewsForm.Text = "Your Reviews";
reviewsForm.Size = new Size(800, 500);
reviewsForm.StartPosition = FormStartPosition.CenterParent;
DataGridView dgvReviews = new DataGridView();
dgvReviews.Dock = DockStyle.Fill;
dgvReviews.ReadOnly = true;
dgvReviews.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dgvReviews.DataSource = dt;
reviewsForm.Controls.Add(dgvReviews);
reviewsForm.ShowDialog();
}
else
{
MessageBox.Show("You haven't submitted any reviews yet.",
"Reviews", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error loading reviews: " + ex.Message,
"Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnProfile_Click(object sender, EventArgs e)
{
SetActiveButton(btnProfile);
DisplayUserProfile();
}
private void DisplayUserProfile()
{
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
string query = @"
SELECT u.email, tp.first_name, tp.last_name, tp.phone,
tp.date_of_birth, tp.nationality, tp.profile_picture
FROM AppUser u
JOIN TravelerProfile tp ON u.user_id = tp.user_id
WHERE u.user_id = @userId";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@userId", currentUserId);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
// Create a simple profile display form
Form profileForm = new Form();
profileForm.Text = "Your Profile";
profileForm.Size = new Size(500, 400);
profileForm.StartPosition = FormStartPosition.CenterParent;
profileForm.FormBorderStyle = FormBorderStyle.FixedDialog;
profileForm.MaximizeBox = false;
profileForm.MinimizeBox = false;
TableLayoutPanel layout = new TableLayoutPanel();
layout.Dock = DockStyle.Fill;
layout.ColumnCount = 2;
layout.RowCount = 6;
layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F));
layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 70F));
// Add profile information fields
AddProfileField(layout, "Email:", reader["email"].ToString(), 0);
AddProfileField(layout, "First Name:", reader["first_name"].ToString(), 1);
AddProfileField(layout, "Last Name:", reader["last_name"].ToString(), 2);
AddProfileField(layout, "Phone:", reader["phone"].ToString(), 3);
string dob = reader["date_of_birth"] != DBNull.Value ?
Convert.ToDateTime(reader["date_of_birth"]).ToString("MMMM dd, yyyy") : "Not specified";
AddProfileField(layout, "Date of Birth:", dob, 4);
string nationality = reader["nationality"] != DBNull.Value ?
reader["nationality"].ToString() : "Not specified";
AddProfileField(layout, "Nationality:", nationality, 5);
// Add edit button
Button btnEdit = new Button();
btnEdit.Text = "Edit Profile";
btnEdit.Dock = DockStyle.Bottom;
btnEdit.Click += (s, args) => { ShowNotImplementedMessage("Profile editing"); };
profileForm.Controls.Add(layout);
profileForm.Controls.Add(btnEdit);
layout.Location = new Point(0, 0);
layout.Size = new Size(profileForm.ClientSize.Width, profileForm.ClientSize.Height - btnEdit.Height);
btnEdit.Location = new Point(0, profileForm.ClientSize.Height - btnEdit.Height);
btnEdit.Size = new Size(profileForm.ClientSize.Width, btnEdit.Height);
profileForm.ShowDialog();
}
else
{
MessageBox.Show("Profile information not found.",
"Profile", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error loading profile: " + ex.Message,
"Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AddProfileField(TableLayoutPanel layout, string label, string value, int row)
{
Label lblField = new Label();
lblField.Text = label;
lblField.Dock = DockStyle.Fill;
lblField.TextAlign = ContentAlignment.MiddleRight;
lblField.Font = new Font(lblField.Font, FontStyle.Bold);
TextBox txtValue = new TextBox();
txtValue.Text = value;
txtValue.Dock = DockStyle.Fill;
txtValue.ReadOnly = true;
txtValue.BorderStyle = BorderStyle.None;
txtValue.BackColor = SystemColors.Window;
layout.Controls.Add(lblField, 0, row);
layout.Controls.Add(txtValue, 1, row);
}
private void ShowNotImplementedMessage(string feature)
{
MessageBox.Show($"The {feature} feature is not implemented yet.",
"Feature Not Available", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#endregion
}
}