-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm10.cs
More file actions
195 lines (165 loc) · 7.1 KB
/
Copy pathForm10.cs
File metadata and controls
195 lines (165 loc) · 7.1 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
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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace FlightReservation
{
public partial class Form10 : Form
{
string connString = "Server=Eng-SHAHD; Database=FlightReservation; Integrated Security=True;";
public Form10()
{
InitializeComponent();
button1.Click += button1_Click;
button2.Click += button2_click;
button3.Click += button3_click;
button4.Click += button4_click;
}
private void button1_Click(object sender, EventArgs e)
{
Form13 form13 = new Form13();
form13.Show();
this.Hide();
}
private void LoadDataIntoDataGridView()
{
try
{
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
// Construct SQL query with joins
string sqlQuerySelect = @"
SELECT
R.ReservarationNo,
U.UserID,
U.Fname,
F.Source_Name,
F.Desctination_Name,
F.LeftTime,
F.ArriveTime,
FC.FlightClassId,
FC.FirstClass,
FC.Business,
FC.Economy,
FC.Premium,
S.SeatNo,
T.TicketNo,
T.Price,
R.ISCancle,
R.DateTime
FROM
Reservaration R
INNER JOIN
User_ U ON R.UserID = U.UserID
INNER JOIN
Flight F ON R.Flight_ID = F.Flight_ID
INNER JOIN
FlightClass FC ON R.FlightClassId = FC.FlightClassId
INNER JOIN
Seat S ON R.SeatNo = S.SeatNo
INNER JOIN
Tickets T ON R.TicketNo = T.TicketNo
WHERE
R.ISCancle = 1 AND
U.UserID = @UserID AND
(FC.FirstClass = 1 OR FC.Business = 1 OR FC.Economy = 1 OR FC.Premium = 1)"; // Example filter
using (SqlCommand cmd = new SqlCommand(sqlQuerySelect, conn))
{
cmd.Parameters.AddWithValue("@UserID", Convert.ToInt32(textBox2.Text));
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
if (dataTable.Rows.Count == 0)
{
MessageBox.Show("Sorry! There are no booked flights for you.", "No Reservations Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
dataGridView1.DataSource = dataTable;
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button2_click(object sender, EventArgs e)
{
LoadDataIntoDataGridView();
}
private void button3_click(object sender, EventArgs e)
{
try
{
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
string sqlQueryUpdate = "UPDATE FlightClass SET FirstClass = @FirstClass,Business = @Business,Economy = @Economy,Premium = @Premium WHERE FlightClassId = @FlightClassId";
using (SqlCommand cmd = new SqlCommand(sqlQueryUpdate, conn))
{
// Add parameters for update
cmd.Parameters.AddWithValue("@FirstClass", radioButton1.Checked ? "1" : "0");
cmd.Parameters.AddWithValue("@Business", radioButton2.Checked ? "1" : "0");
cmd.Parameters.AddWithValue("@Economy", radioButton3.Checked ? "1" : "0");
cmd.Parameters.AddWithValue("@Premium", radioButton4.Checked ? "1" : "0");
cmd.Parameters.AddWithValue("@FlightClassId", Convert.ToInt32(textBox4.Text));
int rowsAffected = cmd.ExecuteNonQuery();
if (rowsAffected > 0)
{
MessageBox.Show("Flight class Changed successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("No rows Changed. Please check the FlightClassId.", "No Class Changed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button4_click(object sender, EventArgs e)
{
try
{
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
string sqlQueryDelete = "DELETE FROM Reservaration WHERE ReservarationNo = @ReservarationNo";
using (SqlCommand cmd = new SqlCommand(sqlQueryDelete, conn))
{
// Add parameters for update
cmd.Parameters.AddWithValue("@ReservarationNo", Convert.ToInt32(textBox6.Text));
int rowsAffected = cmd.ExecuteNonQuery();
if (rowsAffected > 0)
{
MessageBox.Show("Reservation Cancelling successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Fail To Cancelling . Please check the ReservationNo.", "No Class Changed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}