-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm4.cs
More file actions
81 lines (66 loc) · 2.72 KB
/
Copy pathForm4.cs
File metadata and controls
81 lines (66 loc) · 2.72 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
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 Form4 : Form
{
public Form4()
{
InitializeComponent();
button1.Click += button1_Click;
button2.Click += button2_Click;
}
private void button1_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 AirPlane (PlanCode,PlanName) VALUES (@PlanCode,@PlanName)";
string sqlQueryInsert2 = "INSERT INTO AirPlaneType (MaxSeats, MadeIn, CompanyName, PlanCode) VALUES (@MaxSeats, @MadeIn, @CompanyName, @PlanCode)";
SqlCommand command = new SqlCommand(sqlQueryInsert1, conn);
SqlCommand command2 = new SqlCommand(sqlQueryInsert2, conn);
command.Parameters.AddWithValue("@PlanCode", textBox1.Text);
command.Parameters.AddWithValue("@PlanName", textBox2.Text);
command2.Parameters.AddWithValue("@MaxSeats", Convert.ToInt32(textBox3.Text)); // Assuming textBox1 contains the flight ID
command2.Parameters.AddWithValue("@MadeIn", textBox4.Text);
command2.Parameters.AddWithValue("@CompanyName", textBox5.Text);
command2.Parameters.AddWithValue("@PlanCode", textBox6.Text);
MessageBox.Show("Executing Query...");
int rowsAffected = command.ExecuteNonQuery();
int rowAffected = command2.ExecuteNonQuery();
if (rowsAffected > 0)
{
MessageBox.Show("Inserted Successfully!");
}
else
{
MessageBox.Show("No rows inserted!");
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
Form12 form12 = new Form12();
form12.Show();
this.Hide();
}
}
}