-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm9.cs
More file actions
105 lines (81 loc) · 4.2 KB
/
Copy pathForm9.cs
File metadata and controls
105 lines (81 loc) · 4.2 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
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 FlightReservation
{
public partial class Form9 : Form
{
public Form9()
{
InitializeComponent();
button1.Click += button1_Click;
button2.Click += button2_Click;
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "yyyy-MM-dd HH:mm:ss";
// Set initial value
dateTimePicker1.Value = new DateTime(2024, 5, 15, 8, 0, 0);
}
private void button2_Click(object sender, EventArgs e)
{
string connString = "Server=Eng-SHAHD; Database=FlightReservation; Integrated Security=True;";
using (SqlConnection conn = new SqlConnection(connString))
{
try
{
conn.Open();
Console.WriteLine("Connected");
MessageBox.Show("Connection Successful...");
string sqlQueryInsert1 = "INSERT INTO Reservaration (ReservarationNo,UserID,Flight_ID,FlightClassId,SeatNo , TicketNo,ISCancle , DateTime) " +
" VALUES (@ReservarationNo,@UserID,@Flight_ID,@FlightClassId,@SeatNo,@TicketNo,@ISCancle,@DateTime)";
string sqlQueryInsert2 = "INSERT INTO FlightClass (FlightClassId, FirstClass, Business, Economy , Premium,TicketNo,SeatNo)" +
" VALUES (@FlightClassId, @FirstClass, @Business, @Economy,@Premium,@TicketNo,@SeatNo)";
SqlCommand command = new SqlCommand(sqlQueryInsert1, conn);
SqlCommand command2 = new SqlCommand(sqlQueryInsert2, conn);
command.Parameters.AddWithValue("@ReservarationNo", Convert.ToInt32(textBox3.Text));
command.Parameters.AddWithValue("@UserID", Convert.ToInt32(textBox4.Text));
command.Parameters.AddWithValue("@Flight_ID", Convert.ToInt32(textBox5.Text)); // Assuming textBox1 contains the flight ID
command.Parameters.AddWithValue("@FlightClassId", Convert.ToInt32(textBox9.Text));
command.Parameters.AddWithValue("@SeatNo", Convert.ToInt32(textBox6.Text));
command.Parameters.AddWithValue("@TicketNo", Convert.ToInt32(textBox7.Text));
command.Parameters.AddWithValue("@ISCancle",checkBox1.Checked ? "1" : "0");
command.Parameters.AddWithValue("@DateTime", dateTimePicker1.Value);
command2.Parameters.AddWithValue("@FlightClassId", Convert.ToInt32(textBox8.Text));
command2.Parameters.AddWithValue("@TicketNo", Convert.ToInt32(textBox7.Text));
command2.Parameters.AddWithValue("@SeatNo", Convert.ToInt32(textBox6.Text));
command2.Parameters.AddWithValue("@FirstClass", radioButton1.Checked ? "1" : "0");
command2.Parameters.AddWithValue("@Business", radioButton2.Checked ? "1" : "0");
command2.Parameters.AddWithValue("@Premium", radioButton3.Checked ? "1" : "0");
command2.Parameters.AddWithValue("@Economy", radioButton4.Checked ? "1" : "0");
MessageBox.Show("Executing Query...");
int rowsAffected = command.ExecuteNonQuery();
int rowAffected = command2.ExecuteNonQuery();
if (rowsAffected > 0)
{
MessageBox.Show("Reservation Successfully!");
}
else
{
MessageBox.Show("Not Book a Flight!");
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Form13 form13 = new Form13();
form13.Show();
this.Hide();
}
}
}