protected void DeleteRooms(object sender, EventArgs e) { Button btn = (Button)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; string name = gvr.Cells[1].Text; HotelInfo hf = new HotelInfo(); hf = bookContext.HotelInfos.Single(y => y.HotelName == name); bookContext.HotelInfos.DeleteOnSubmit(hf); bookContext.SubmitChanges(); GridView1.DataBind(); }
protected void BookRooms(object sender, EventArgs e) { Button btn = (Button)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; string name = gvr.Cells[1].Text; int availableRooms = Convert.ToInt32(gvr.Cells[3].Text); int bookedRooms = Convert.ToInt32(gvr.Cells[4].Text); gvr.Cells[3].Text = (availableRooms - 1).ToString(); gvr.Cells[4].Text = (bookedRooms + 1).ToString(); HotelInfo hf = new HotelInfo(); hf = bookContext.HotelInfos.Single(y => y.HotelName == name); hf.AvailableRooms = Convert.ToInt32(gvr.Cells[3].Text); hf.NoOfBookedRooms = Convert.ToInt32(gvr.Cells[4].Text); bookContext.SubmitChanges(); if (Convert.ToInt32(gvr.Cells[3].Text) == 0) { btn.Visible = false; btn.Parent.Controls[3].Visible = true; } }
protected void AddHotel_Click(object sender, EventArgs e) { try { using (BookHotelDataContext dataContext = new BookHotelDataContext()) { HotelInfo htlInf = new HotelInfo(); htlInf.HotelName = nameTxt.Text; htlInf.PricePerNight = Convert.ToDecimal(priceTxt.Text); htlInf.AvailableRooms = Convert.ToInt32(availableTxt.Text); htlInf.NoOfBookedRooms = Convert.ToInt32(bookedTxt.Text); dataContext.HotelInfos.InsertOnSubmit(htlInf); dataContext.SubmitChanges(); } Response.Redirect("BookHotel.aspx"); } catch (Exception ex) { Response.Write(ex); } }
partial void DeleteHotelInfo(HotelInfo instance);
partial void UpdateHotelInfo(HotelInfo instance);
partial void InsertHotelInfo(HotelInfo instance);