-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfirm.aspx.cs
More file actions
69 lines (60 loc) · 2.6 KB
/
Confirm.aspx.cs
File metadata and controls
69 lines (60 loc) · 2.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
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string conn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["bus"].ConnectionString;
if (!IsPostBack) {
string busID = Request.QueryString["BusID"];
string seatsLeft = Request.QueryString["seatsLeft"];
string seats = Request.QueryString["seats"];
int s1, s2;
int.TryParse(seatsLeft, out s1);
int.TryParse(seats, out s2);
if (s2 <= s1)
{
using (SqlConnection con = new SqlConnection(conn))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandText = "Update Buses set Seats = @Seats where BusID = @BusID";
cmd.Parameters.AddWithValue("@Seats", (s1 - s2).ToString());
cmd.Parameters.AddWithValue("@BusID", busID);
con.Open();
cmd.ExecuteNonQuery();
}
}
string user = (string)Session["user"];
if(user == null)
{
user = "Anonymous Buyer";
}
using (SqlConnection con = new SqlConnection(conn))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandText = "Insert into Bookings values (@user,@bus,@time,@seats)";
cmd.Parameters.AddWithValue("@user", user);
cmd.Parameters.AddWithValue("@bus", busID);
cmd.Parameters.AddWithValue("@time", DateTime.Now.ToString());
cmd.Parameters.AddWithValue("@seats", s2.ToString());
con.Open();
cmd.ExecuteNonQuery();
}
}
label1.Text = seats + " seats have been booked in bus with Bus ID as " + busID + ".<br/>Booking confirmed! Check your past trips for more details";
}else
{
label1.Text = "Enough seats are not available. Booking failed.";
}
}
}
}