protected void btnSubmit_Click(object sender, EventArgs e) { //retrieve the attraction session Attraction a = (Attraction)Session["userAttraction"]; //declare random number generator Random rnd = new Random(); //initialize the random number generator int rId = rnd.Next(30, 1000); TicketType t = new TicketType() { TicketID = rId, Type = tbxType.Text, Description = tbxDesc.Text, Price = Convert.ToDouble(tbxPrice.Text), Attraction = a }; int id = TicketTypeDB.insertTicket(t); //to insert ticket into database lblOutput.Text = "Successfully added!"; //to show the message tbxType.Text = ""; tbxPrice.Text = ""; tbxDesc.Text = ""; gvBind(); }
void gvBind() { //to show the ticket type into the gridview List <TicketType> ticketTypes = TicketTypeDB.getTicketByOwner(Convert.ToInt32(Session["attractionID"])); gvTicket.DataSource = ticketTypes; gvTicket.DataBind(); }
protected void gvTicket_RowDeleting(object sender, GridViewDeleteEventArgs e) { //to delete a row from database List <TicketType> ticketTypes = TicketTypeDB.getTicketByOwner(Convert.ToInt32(Session["attractionID"])); TicketType t = ticketTypes[e.RowIndex]; TicketTypeDB.deleteTicket(t.TicketID); ticketTypes.Remove(t); DataBind(); gvBind(); }
protected void btnBook_Click(object sender, EventArgs e) //to book the ticket of attraction { bool exist = false; TicketType t = TicketTypeDB.getTicket(Convert.ToInt32(Session["ticketID"])); //get the ticket details from database //to add the cart item classes for ticket details CartItem c = new CartItem(t, Convert.ToInt32(Session["ticketID"]), t.Type, t.Description, Convert.ToDouble(t.Price), tbxDate.Text, Convert.ToInt32(tbxNoOfGuests.Text), t.Price); ShoppingCart sc = (ShoppingCart)Session["cart"]; //retrieve the shopping cart session if (sc == null) //check the shopping cart is null { sc = new ShoppingCart(); sc.TicketAdd(c); //add into the cart item classes lblOutput.Text = "Ticket added to the Shopping Cart"; //show the messages when user add into cart item } else { List <CartItem> ci = sc.TicketCI; foreach (CartItem citm in ci) //use foreach to check the data is already added into cart item { if (citm.TICketID == t.TicketID) { exist = true; } } if (exist == false) { sc.TicketAdd(c); lblOutput.Text = "Ticket added to the shopping cart"; //show the messages when user add into cart item } else { lblOutput.Text = "You have already added this Ticket to the shopping cart"; //show the messages when user already add into cart item } } Session["cart"] = sc; //brings session into cart session }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { lblNoOfTicket.Visible = false; List <TicketType> ticketTypes = TicketTypeDB.getTicketByOwner(Convert.ToInt32(Session["attraction"])); //get data from database //to check whether the data is not null if (ticketTypes.Count != 0) { List <TicketType> ticAvail = new List <TicketType>(); Session["ticket"] = ticAvail; //create ticket session lvTicket.DataSource = ticketTypes; lvTicket.DataBind(); } else { lblNoOfTicket.Visible = true; //show the message if the data is null } pnlDetail.Visible = false; pnlBook.Visible = false; tbxDate.Attributes["min"] = DateTime.Now.ToString("yyyy-MM-dd"); //users are not allowed to select past date } }