Dear All,
How to manage the booking slots
I have a table EventData and EventBookingslot.
In Event data table i have 30 slots. From eventbookingslots table i want to receive only 30 booking, but i am receiving more than 30 booking.
Sometime i have receive the same Ticket Id 2 or 3 times.
How can i limit the booking?
public partial class TicketBooking : System.Web.UI.Page
{
//SqlDataReader sdr = null;
DataTable dtable = new DataTable();
//SqlConnection con = null;
SqlCommand cmd = null;
DataTable dt = new DataTable();
String cs = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindAvailSlot();
BindBookedSlot();
autoincrement();
auto();
}
}
private void BindAvailSlot()
{
SqlConnection con = new SqlConnection(cs);
con.Open();
string str = "SELECT * from EventData where Event_CatID=9 and Status=1";
cmd = new SqlCommand(str, con);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
txt_avslot.Text = reader["Event_slot"].ToString();
reader.Close();
con.Close();
con.Open();
SqlDataReader reader1 = cmd.ExecuteReader();
reader1.Read();
txtSlot_price.Text = reader1["Event_Slot_Price"].ToString();
reader1.Close();
con.Close();
con.Open();
SqlDataReader reader2 = cmd.ExecuteReader();
reader2.Read();
txtEventDate.Text = reader2["Event_Date"].ToString();
reader2.Close();
con.Close();
con.Open();
SqlDataReader reader3 = cmd.ExecuteReader();
reader3.Read();
txtEventTime.Text = reader3["Event_Time"].ToString();
reader2.Close();
con.Close();
con.Open();
SqlDataReader reader4 = cmd.ExecuteReader();
reader4.Read();
txt_MovieID.Text = reader4["EventID"].ToString();
reader4.Close();
con.Close();
con.Open();
SqlDataReader reader5 = cmd.ExecuteReader();
reader5.Read();
txt_MovieName.Text = reader5["Event_Name"].ToString();
reader5.Close();
con.Close();
}
private void BindBookedSlot()
{
SqlConnection con = new SqlConnection(cs);
con.Open();
//string str = "Select Sum(Booked_slots)As TotalBSlot from EventBookingslots";
string str = "Select Count(*) As TotalSlot from EventBookingslots where EventID='19'";
cmd = new SqlCommand(str, con);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
txtBookedQty.Text = reader["TotalSlot"].ToString();
reader.Close();
con.Close();
con.Open();
}
protected void btnBooking_Click(object sender, EventArgs e)
{
int val5 = 0;
int val6 = 0;
int val7 = 0;
int.TryParse(txt_avslot.Text, out val5);
int.TryParse(txtBookedQty.Text, out val6);
int.TryParse(ddltickets.SelectedItem.Value, out val7);
int Q = (val5 - val6);
int val3 = 0;
int val4 = 0;
int.TryParse(txt_avslot.Text, out val3);
int.TryParse(txtBookedQty.Text, out val4);
if (val3 > val4)
{
if (txtFullName.Value == "" && txtTelephone.Value == "")
{
lblAvailSlot.Visible = true;
lblAvailSlot.Text = "Please fill the data";
//ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please fill the data');", true);
return;
}
if (Save() > 0)
{
BindAvailSlot();
BindBookedSlot();
//Response.Redirect("Success.aspx?TicketNo="+txtticketID.Text+"& Name="+txtFullName.Value+" & Slot="+ddltickets.SelectedItem.Value+" & Amount="+txtamount.Text+"");
Response.Redirect("Success.aspx?TicketNo=" + txtticketID.Text + "&EDate="+txtEventDate.Text+"&ETime="+txtEventTime.Text+"");
//Bookingpnl.Visible = false;
//successpnl.Visible = true;
ClearForm();
}
}
else
{
lblAvailSlot.Visible = true;
lblAvailSlot.Text = "Slots Not Available";
return;
}
}
private int Save()
{
EventBookingslot Evet = new EventBookingslot
{
TicketNo=txtticketID.Text,
Cus_Name = txtFullName.Value,
Cus_Mobile = Convert.ToInt32(txtTelephone.Value),
Cus_Email = txtEmail.Value,
Cus_Vehicletype=ddlvechicletype.SelectedItem.Value,
Cus_VehicleColor=txtCarColor.Value,
EventID=Convert.ToInt32(txt_MovieID.Text),
Event_Name=txt_MovieName.Text.Trim(),
Event_Date = DateTime.Parse(txtEventDate.Text),
Event_Time = txtEventTime.Text,
NoofPerson = Convert.ToInt32(ddltickets.SelectedItem.Value),
Amount = Convert.ToDecimal(txtamount.Text),
Status=false
};
return new EBookingSlotDAL().Save(Evet);
}
private void autoincrement()
{
int count;
SqlConnection con = new SqlConnection(cs);
string str = "SELECT count(*) from EventBookingslots";
cmd = new SqlCommand(str, con);
con.Open();
count = Convert.ToInt16(cmd.ExecuteScalar()) + 1;
//txtticketID.Text = "DIM-7300" + count;
con.Close();
}
private void auto()
{
txtticketID.Text = "DIM-" + GetUniqueKey(4);
}
public static string GetUniqueKey(int maxSize)
{
char[] chars = new char[62];
chars = "123456789".ToCharArray();
byte[] data = new byte[1];
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
crypto.GetNonZeroBytes(data);
data = new byte[maxSize];
crypto.GetNonZeroBytes(data);
StringBuilder result = new StringBuilder(maxSize);
foreach (byte b in data)
{
result.Append(chars[b % (chars.Length)]);
}
return result.ToString();
}
}