HI,
I have make a bus seat panel, in that image button is showing submit query.
please help me regarding that and i also attached the .aspx and .aspx.cs code
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Khargesh RajputPosted Jan 24, 2015, 1:27 AM
or
right click in browser and inspect elements and vview in html whether image are loaded or not
rinku baruahPosted Jan 24, 2015, 1:01 AM
it is a Aspx code of seat.
and image display on C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
//using System.Transactions;
using System.Data;
using System.Windows.Forms;
using System.Collections.Specialized;
public partial class NON_AC_32 : System.Web.UI.Page
{
//CommittableTransaction transactions = new CommittableTransaction();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
SqlCommand cmd = null;
SqlDataReader dr = null;
int number_of_seats = 32;
int pnr;
string[] s;
string bus_id = "";
string bus_type = "";
string choosed_Destination = "";
string Bus_Name, Dep_Time, Arr_Time, Bus_type, Seat_Arrangements, start, destination;
int Seat_Count, available_seats, booked_seats, bus_ref;
Double Fare;
DateTime journey_date;
protected void Page_Load(object sender, EventArgs e)
{
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
con.Open();
bus_id = Request.QueryString["bus"];
bus_type = Request.QueryString["type"];
choosed_Destination = Request.QueryString["dest"];
get_Bus_Detail();
if (!IsPostBack)
{
load_seats();
set_defaults();
}
}
protected void set_defaults()
{
set_validation_false_for_seats();
Fare_Label.Text = "0";
from.Text = start;
B_Name.Text = Bus_Name;
Destination.Text = choosed_Destination;
Journey_Date.Text = journey_date.ToString("dd-MMM-yyyy [dddd]");
Load_Boarding_Points();
}
//loading the seats and Displaying in Bus Format
protected void load_seats()
{
try
{
cmd = new SqlCommand("select * from seats_layout where bus_sno='" + bus_id + "' ", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
for (int i = 1; i <= number_of_seats; i++)
{
string s = "s" + i.ToString();
if (dr[s].ToString() == "0")
{
ImageButton img = (ImageButton)Seat_Panel.FindControl(s);
img.ImageUrl = "Images/booked.jpg";
img.Enabled = false;
}
if (dr[s].ToString() == "b")
{
ImageButton img = (ImageButton)Seat_Panel.FindControl(s);
img.ImageUrl = "Images/booked.jpg";
img.Enabled = false;
}
else if (dr[s].ToString() == "1")
{
ImageButton img = (ImageButton)Seat_Panel.FindControl(s);
img.ImageUrl = "Images/selectable.jpg";
img.Enabled = true;
}
}
}
}
catch (SqlException sqlex)
{
Response.Write("");
Load_data l = new Load_data();
Response.Redirect(l.home_page);
}
}
protected double get_Fare(string bus_id, string destination)
{
cmd = new SqlCommand("SELECT Destination.Fare FROM Bus_Detail INNER JOIN Destination ON Bus_Detail.Bus_Ref = Destination.Bus_ref where bus_detail.bus_sno ='" + bus_id + "' and Destination.destination ='" + destination + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
return Convert.ToDouble(dr[0]);
}
else
{
return 0.00;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (terms.Checked == false)
{
Response.Write("");
}
else if (Mobile_No.Text.Length != 10)
{
Response.Write("");
}
else
{
if (Selected_Seats.Text != "")
{
bool error = false;
generate_pnr();
s = Selected_Seats.Text.Split(',');
for (int i = 1; i < s.Length; i++)
{
if (!confirm_avaliablity(s[i].ToString()))
{
no_longer_available(s[i].ToString());
}
else
{
// form1.Action = "http://192.168.3.27/Pay/pay.aspx";
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
con.Open();
//check_cart(s[i].ToString());
try
{
SqlCommand cmd1 = new SqlCommand("insert_into_orders", con);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add("seatDetails", SqlDbType.VarChar).Value = bus_id + s[i].ToString();
cmd1.Parameters.Add("BusDetail", SqlDbType.VarChar).Value = bus_id.ToString();
cmd1.Parameters.Add("Passengername", SqlDbType.VarChar).Value = name.Text;
cmd1.Parameters.Add("Bookdate", SqlDbType.DateTime).Value = DateTime.Now;
cmd1.Parameters.Add("Bustype", SqlDbType.VarChar).Value = bus_type;
cmd1.Parameters.Add("PassangerAddress", SqlDbType.VarChar).Value = Address1.Text + " " + Address2.Text + " " + city.Text + " " + state.Text + " " + Pincode.Text;
cmd1.Parameters.Add("BoaringPoint", SqlDbType.VarChar).Value = Boarding_Points.SelectedItem.Text;
cmd1.Parameters.Add("DeptTime", SqlDbType.Time).Value = Dep_Time;
cmd1.Parameters.Add("ArrivalTime", SqlDbType.Time).Value = Arr_Time;
cmd1.Parameters.Add("StartPlace", SqlDbType.VarChar).Value = start;
cmd1.Parameters.Add("Destination", SqlDbType.VarChar).Value = Destination.Text;
cmd1.Parameters.Add("Fare", SqlDbType.Money).Value = Fare;
cmd1.Parameters.Add("Contact", SqlDbType.BigInt).Value = Convert.ToInt64(Mobile_No.Text);
cmd1.Parameters.Add("Email", SqlDbType.VarChar).Value = email.Text;
cmd1.Parameters.Add("Age", SqlDbType.Int).Value = Convert.ToInt64(Age.Text);
cmd1.Parameters.Add("Gender", SqlDbType.VarChar).Value = Gender.SelectedItem.Text;
cmd1.Parameters.Add("seat", SqlDbType.VarChar).Value = s[i];
cmd1.Parameters.Add("pnr", SqlDbType.Int).Value = pnr;
cmd1.Parameters.Add("bookedtype", SqlDbType.VarChar).Value = "CUSTOMER";
cmd1.ExecuteNonQuery();
// Response.Write("");
// Response.Redirect("http://google.com");
}
catch (SqlException sqlex)
{
if (sqlex.Number == 2627)
{
Response.Write("");
ImageButton img = (ImageButton)Seat_Panel.FindControl(s[i].ToString());
img.ImageUrl = "Images/booked.jpg";
img.Enabled = false;
remove(s[i].ToString(), Fare);
Selected_Seats.Text = Selected_Seats.Text.Replace("," + s[i].ToString(), "");
rollback_pnr(pnr);
error = true;
break;
}
else
{
cmd = new SqlCommand("SELECT description FROM master.dbo.sysmessages where error='" + sqlex.Number + "' and msglangid='1033' ", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Write("");
}
remove(s[i].ToString(), Fare);
rollback_pnr(pnr);
error = true;
break;
//ImageButton img = (ImageButton)Seat_Panel.FindControl(s[i].ToString());
// img.ImageUrl = "Images/booked.jpg";
// img.Enabled = false;
// Selected_Seats.Text = Selected_Seats.Text.Replace("," + s[i].ToString(), "");
}
}
}
}
if (error != true)
{
insert_into_orderdetails();
}
}
else
{
Response.Write("");
}
}
}
//confirm the availabity after clicking the submit button
protected bool confirm_avaliablity(string seat)
{
try
{
cmd = new SqlCommand("select " + seat + " from seats_layout where Bus_Sno = '" + bus_id + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
if (dr[0].ToString() == "1")
{
return true;
}
else if ((dr[0].ToString() == "0") || (dr[0].ToString() == "b"))
{
return false;
}
else
{
return false;
}
}
else
{
return false;
}
}
catch (SqlException ex)
{
Response.Write("");
return false;
}
}
//Gets all details about the bus
protected void get_Bus_Detail()
{
cmd = new SqlCommand("select bus_sno,Bus_Name,CONVERT(VARCHAR(8),Dep_Time,108) as Departure,CONVERT(VARCHAR(8),Arr_Time,108) as Arrival,Seat_Details,Fare,Bus_Type,Seat_Arrangement,start,Destination ,journey_date,Available_Seats,booked_seats,Bus_Ref from Bus_Detail where Bus_Sno = '" + bus_id + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
Bus_Name = dr[1].ToString();
Dep_Time = dr[2].ToString();
Arr_Time = dr[3].ToString();
Seat_Count = dr.GetInt32(4);
Bus_type = dr[6].ToString();
Seat_Arrangements = dr[7].ToString();
start = dr[8].ToString();
destination = dr[9].ToString();
journey_date = dr.GetDateTime(10);
available_seats = dr.GetInt32(11);
booked_seats = dr.GetInt32(12);
bus_ref = Convert.ToInt32(dr[13]);
Fare = get_Fare(bus_id, choosed_Destination);
}
}
//Adding Which Seats are selecled currently
protected void add(string seat, double fares)
{
double f = Convert.ToDouble(Fare_Label.Text);
Fare_Label.Text = Convert.ToString(f + fares);
Application["Fare"] = f + fares;
add_to_seat_cart(seat);
//Response.Write("");
}
protected void remove(string seat, double fares)
{
double f = Convert.ToDouble(Fare_Label.Text);
Fare_Label.Text = Convert.ToString(f - fares);
Application["Fare"] = f - fares;
remove_from_seat_cart(seat);
//Response.Write("");
}
//Removing Seat from Seat_cart table
protected void remove_from_seat_cart(string seat)
{
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
con.Open();
cmd = new SqlCommand("delete from seat_cart where seat='" + seat + "' and ip='" + Request.ServerVariables["REMOTE_ADDR"] + "'", con);
cmd.ExecuteNonQuery();
}
//Adding Seat to seat_cart table
protected void add_to_seat_cart(string seat)
{
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
con.Open();
cmd = new SqlCommand("insert into seat_cart values('" + seat + "','" + DateTime.Now + "','" + bus_id + "','" + Request.ServerVariables["REMOTE_ADDR"] + "')", con);
cmd.ExecuteNonQuery();
}
//selecting on an available seat
protected void add_seat(string seat)
{
ImageButton img = (ImageButton)Seat_Panel.FindControl(seat);
img.ImageUrl = "Images/selected.jpg";
//update_to_b(s1.ID.ToString());
add(seat, Fare);
Selected_Seats.Text = Selected_Seats.Text.ToString() + "," + img.ID.ToString();
}
//Deselecting the selected Seat
protected void remove_seat(string seat)
{
ImageButton img = (ImageButton)Seat_Panel.FindControl(seat);
img.ImageUrl = "Images/selectable.jpg";
//update_to_one(s1.ID.ToString());
remove(seat, Fare);
Selected_Seats.Text = Selected_Seats.Text.Replace("," + seat, "");
}
// Seat Selection and deselection Function
protected void Click(object sender, ImageClickEventArgs e)
{
ImageButton img = (ImageButton)sender;
// img = (ImageButton)Seat_Panel.FindControl(img);
if (img.ImageUrl == "Images/selectable.jpg")
{
add_seat(img.ID.ToString());
}
else if (img.ImageUrl == "Images/selected.jpg")
{
remove_seat(img.ID.ToString());
}
}
// Just Setting Validation Property to false and giving alternate text to all the Seats
protected void set_validation_false_for_seats()
{
for (int i = 1; i <= number_of_seats; i++)
{
string s = "s" + i.ToString();
ImageButton img = (ImageButton)Seat_Panel.FindControl(s);
img.ToolTip = img.ID.ToString();
img.CausesValidation = false;
img.PostBackUrl = "#";
}
}
//load boarding Points
protected void Load_Boarding_Points()
{
cmd = new SqlCommand("select Boarding_Points from Boarding_Points where Bus_Sno ='" + bus_ref.ToString() + "'", con);
dr = cmd.ExecuteReader();
Boarding_Points.DataSource = dr;
Boarding_Points.DataTextField = "Boarding_Points";
Boarding_Points.DataValueField = "Boarding_Points";
Boarding_Points.DataBind();
}
protected void check_cart(string Seat)
{
cmd = new SqlCommand("select seats from cart where bus_sno='" + bus_id + "'", con);
SqlDataReader dr1 = cmd.ExecuteReader();
if (dr1.Read())
{
dr1.Close();
dr = cmd.ExecuteReader();
while (dr.Read())
{
string[] s = dr[0].ToString().Split(',');
for (int i = 0; i < s.Length; i++)
{
if (s[i] == Seat)
{
Response.Write("");
// return false;
}
else
{
// return true;
}
}
}
}
else
{
//return false;
}
}
protected void no_longer_available(string seat)
{
Response.Write("");
ImageButton img = (ImageButton)Seat_Panel.FindControl(seat);
img.ImageUrl = "Images/booked.jpg";
img.Enabled = false;
Selected_Seats.Text = Selected_Seats.Text.Replace("," + seat, "");
}
protected void generate_pnr()
{
Check c = new Check();
pnr = c.generate_pnr();
}
protected void rollback_pnr(int pnr)
{
cmd = new SqlCommand("rollback_on_failure", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("pnr", SqlDbType.NVarChar).Value = pnr.ToString();
cmd.ExecuteNonQuery();
}
protected void insert_into_orderdetails()
{
string seatinfo = null;
s = Selected_Seats.Text.Split(',');
for (int i = 1; i < s.Length; i++)
{
seatinfo += s[i].ToString();
}
try
{
cmd = new SqlCommand("insert into OrderDetails values('" + seatinfo + "','" + Fare_Label.Text + "',getdate(),'" + pnr + "','" + email.Text + "','0')", con);
cmd.ExecuteNonQuery();
Assign_Values();
}
catch (SqlException sqlex)
{
rollback_pnr(pnr);
}
}
protected void Assign_Values()
{
Load_data load = new Load_data();
string Url = load.ebs_url;
string Method = "post";
string FormName = "form1";
NameValueCollection FormFields = new NameValueCollection();
FormFields.Add("account_id", load.ebs_account_id);
FormFields.Add("reference_no", pnr.ToString());
FormFields.Add("amount", Fare_Label.Text);
FormFields.Add("description", "yatra");
FormFields.Add("name", name.Text);
FormFields.Add("address", Address1.Text + " " + Address2.Text);
FormFields.Add("city", city.Text);
FormFields.Add("state", state.Text);
FormFields.Add("postal_code", Pincode.Text);
FormFields.Add("country", "IN");
FormFields.Add("email", email.Text);
FormFields.Add("phone", Mobile_No.Text);
FormFields.Add("ship_name", name.Text);
FormFields.Add("ship_address", Address1.Text + " " + Address2.Text);
FormFields.Add("ship_city", city.Text);
FormFields.Add("ship_state", state.Text);
FormFields.Add("ship_postal_code", Pincode.Text);
FormFields.Add("ship_country", "IN");
FormFields.Add("ship_phone", Mobile_No.Text);
FormFields.Add("return_url", load.ebs_return_url);
FormFields.Add("mode", load.ebs_mode);
Response.Clear();
Response.Write("
Please Wait, your order is being processed....!
You will be redirected to the payment page shortly
DO NOT REFRESH OR CLICK ON BACK BUTTON
Response.Write(string.Format("", FormName));
Response.Write(string.Format("");
Response.Write("");
Response.End();
/*reference_no.Value = pnr.ToString();
amount.Value = Fare_Label.Text;
description.Value = "My Bus Yatra";
address.Value = Address1.Text + " " + Address2.Text;
postal_code.Value = Pincode.Text;
country.Value = "IN";
phone.Value = Mobile_No.Text;
ship_address.Value = Address1.Text + " " + Address2.Text;
ship_state.Value = state.Text;
ship_postal_code.Value = Pincode.Text;
ship_country.Value = "IN";
ship_phone.Value = Mobile_No.Text;
return_url.Value = "http://192.168.3.200/book/pay/response.aspx?DR={DR}";
mode.Value = "TEST";
frmTransaction.Action="pay/pay.aspx";*/
}
protected void mobile_length(Object sender, ServerValidateEventArgs e)
{
if (Mobile_No.Text.Length != 10)
{
e.IsValid = false;
}
else
{
e.IsValid = true;
}
}
}
Khargesh RajputPosted Jan 23, 2015, 11:37 PM
set proper path to image url
Manish Kumar ChoudharyPosted Jan 23, 2015, 7:32 AM
Add this attribute to your button:
rinku baruahPosted Jan 23, 2015, 7:02 AM
Manish Kumar ChoudharyPosted Jan 23, 2015, 5:48 AM
What exactly you want to do when you click on image buttons ?