Vous êtes sur la page 1sur 5

Important Namespaces Used

---------------------------

using System.Data;
using System.Data.SqlClient;

-------------------------------

Static Variable Declaration


-----------------------------

static int seatbookno = -1;

------------------------------

Page Load Coding


----------------------------

if (!IsPostBack)
{
seatstatus();
}

---------------------------

User Defined Method


--------------------------

private void seatstatus()


{
String mycon = "Data Source=HP-PC\\SQLEXPRESS; Initial
Catalog=TicketBooking; Integrated Security=True";
String myquery = "Select * from Seatstatus";
SqlConnection con = new SqlConnection(mycon);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = myquery;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
int rows = ds.Tables[0].Rows.Count;
int i = 0;
while (i<rows)
{
String status;
status = ds.Tables[0].Rows[i]["status"].ToString();
if(status=="A")
{
if(i==0 && seatbookno-1!=i)
{
Button1.BackColor = System.Drawing.Color.Gray;
}
if (i == 1 && seatbookno - 1 != i)
{
Button2.BackColor = System.Drawing.Color.Gray;
}
if (i == 2 && seatbookno-1!= i)
{
Button3.BackColor = System.Drawing.Color.Gray;
}
if (i == 3 && seatbookno - 1 != i)
{
Button4.BackColor = System.Drawing.Color.Gray;
}
if (i == 4 && seatbookno - 1 != i)
{
Button5.BackColor = System.Drawing.Color.Gray;
}
if (i == 5 && seatbookno - 1 != i)
{
Button6.BackColor = System.Drawing.Color.Gray;
}
if (i == 6 && seatbookno - 1 != i)
{
Button7.BackColor = System.Drawing.Color.Gray;
}
if (i == 7 && seatbookno - 1 != i)
{
Button8.BackColor = System.Drawing.Color.Gray;
}
if (i == 8 && seatbookno - 1 != i)
{
Button9.BackColor = System.Drawing.Color.Gray;
}
if (i == 9 && seatbookno - 1 != i)
{
Button10.BackColor = System.Drawing.Color.Gray;
}
if (i == 10 && seatbookno - 1 != i)
{
Button11.BackColor = System.Drawing.Color.Gray;
}
if (i == 11 && seatbookno - 1 != i)
{
Button12.BackColor = System.Drawing.Color.Gray;
}
if (i == 12 && seatbookno - 1 != i)
{
Button13.BackColor = System.Drawing.Color.Gray;
}
if (i == 13 && seatbookno - 1 != i)
{
Button14.BackColor = System.Drawing.Color.Gray;

}
if (i == 14 && seatbookno - 1 != i)
{
Button15.BackColor = System.Drawing.Color.Gray;

}
if (i == 15 && seatbookno - 1 != i)
{

Button16.BackColor = System.Drawing.Color.Gray;
}
}
if (status == "B")
{
if (i == 0)
{
Button1.BackColor = System.Drawing.Color.Red;
Button1.Enabled = false;
}
if (i == 1)
{
Button2.BackColor = System.Drawing.Color.Red;
Button2.Enabled = false;
}
if (i == 2)
{
Button3.BackColor = System.Drawing.Color.Red;
Button3.Enabled = false;
}
if (i == 3)
{
Button4.BackColor = System.Drawing.Color.Red;
Button4.Enabled = false;
}
if (i == 4)
{
Button5.BackColor = System.Drawing.Color.Red;
Button5.Enabled = false;
}
if (i == 5)
{
Button6.BackColor = System.Drawing.Color.Red;
Button6.Enabled = false;
}
if (i == 6)
{
Button7.BackColor = System.Drawing.Color.Red;
Button7.Enabled = false;
}
if (i == 7)
{
Button8.BackColor = System.Drawing.Color.Red;
Button8.Enabled = false;
}
if (i == 8)
{
Button9.BackColor = System.Drawing.Color.Red;
Button9.Enabled = false;
}
if (i == 9)
{
Button10.BackColor = System.Drawing.Color.Red;
Button10.Enabled = false;
}
if (i == 10)
{
Button11.BackColor = System.Drawing.Color.Red;
Button11.Enabled = false;
}
if (i == 11)
{
Button12.BackColor = System.Drawing.Color.Red;
Button12.Enabled = false;
}
if (i == 12)
{
Button13.BackColor = System.Drawing.Color.Red;
Button13.Enabled = false;
}
if (i == 13)
{
Button14.BackColor = System.Drawing.Color.Red;
Button14.Enabled = false;

}
if (i == 14)
{
Button15.BackColor = System.Drawing.Color.Red;
Button15.Enabled = false;

}
if (i == 15)
{

Button16.BackColor = System.Drawing.Color.Red;
Button16.Enabled = false;
}

i = i + 1;
}

---------------------------------

Book Now Button Click Event Coding


----------------------------------

String mycon = "Data Source=HP-PC\\SQLEXPRESS; Initial Catalog=TicketBooking;


Integrated Security=True";
String updatedata = "Update SeatStatus set status='B' where seatno=" +
seatbookno;
SqlConnection con = new SqlConnection(mycon);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = updatedata;
cmd.Connection = con;
cmd.ExecuteNonQuery();
Response.Redirect("Thanks.aspx?seatno="+seatbookno);

-----------------------------------

Coding for Every Seat Number Button Click Event


------------------------------------------------
seatbookno = 1;
Button1.BackColor = System.Drawing.Color.Green;
seatstatus();

-----------------------------------------------

Vous aimerez peut-être aussi