Esempio n. 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (comp2007Entities db = new comp2007Entities())
            {
                Room objC = new Room();

                if (!String.IsNullOrEmpty(Request.QueryString["RoomID"]))
                {
                    Int32 RoomID = Convert.ToInt32(Request.QueryString["RoomID"]);
                    objC = (from r in db.Rooms
                            where r.RoomID == RoomID
                            select r).FirstOrDefault();
                }

                Booking objD = new Booking();

                //populate the booking entry from the input form and room info
                objD.RoomID = objC.RoomID;
                objD.LastName = txtLastName.Text;
                objD.FirstName = txtFirstName.Text;
                objD.DaysStaying = Convert.ToInt32(txtDaysStaying.Text);
                objD.BookDate = DateTime.Today;

                //Decimal TotalCost = objC.CostPerDay * objD.DaysStaying;

                    //add
                    db.Bookings.Add(objD);

                //save and redirect
                db.SaveChanges();
                Response.Redirect("bookings.aspx");
            }
        }
Esempio n. 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (comp2007Entities db = new comp2007Entities())
            {
                Room objC = new Room();

                if (!String.IsNullOrEmpty(Request.QueryString["RoomID"]))
                {
                    Int32 RoomID = Convert.ToInt32(Request.QueryString["RoomID"]);
                    objC = (from r in db.Rooms
                            where r.RoomID == RoomID
                            select r).FirstOrDefault();
                }

                //populate the room from the input form
                objC.Size = ddlRoomSize.Text;
                objC.CostPerDay = Convert.ToDecimal(txtCostPerDay.Text);
                objC.Availability = "y";

                if (String.IsNullOrEmpty(Request.QueryString["RoomID"]))
                {
                    //add
                    db.Rooms.Add(objC);
                }

                //save and redirect
                db.SaveChanges();
                Response.Redirect("rooms.aspx");
            }
        }
Esempio n. 3
0
        protected void GetRooms()
        {
            using (comp2007Entities db = new comp2007Entities())
            {
                String SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                var Rooms = from r in db.Rooms
                              select new { r.RoomID, r.Size, r.CostPerDay, r.Availability };

                grdRooms.DataSource = Rooms.AsQueryable().OrderBy(SortString).ToList();
                grdRooms.DataBind();
            }
        }
Esempio n. 4
0
        //show booking list
        protected void GetBookings()
        {
            using (comp2007Entities db = new comp2007Entities())
            {
                String SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                var Bookings = from b in db.Bookings
                            select new { b.BookingID, b.RoomID, b.LastName, b.FirstName, b.DaysStaying, b.BookDate };

                grdBookings.DataSource = Bookings.AsQueryable().OrderBy(SortString).ToList();
                grdBookings.DataBind();
            }
        }
Esempio n. 5
0
        protected void CheckOut()
        {
            //get selected room number
            Int32 RoomID = Convert.ToInt32(Request.QueryString["RoomID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                //get selected room
                Room objC = (from r in db.Rooms
                             where r.RoomID == RoomID
                             select r).FirstOrDefault();

                //populate the room
                objC.Size = objC.Size;
                objC.CostPerDay = objC.CostPerDay;
                objC.Availability = objC.Availability;

                //set room to available
                if (objC.Availability == "n")
                {
                    objC.Availability = "y";

                    if (String.IsNullOrEmpty(Request.QueryString["RoomID"]))
                    {
                        //add
                        db.Rooms.Add(objC);

                        //save and redirect
                        db.SaveChanges();
                    }
                }
                else
                {
                    //a customer is already checked into this room
                    Response.Redirect("rooms.aspx");
                }

                Booking objD = (from b in db.Bookings
                             where b.RoomID == RoomID
                             select b).FirstOrDefault();

                //remove customer's entry from the bookings db
                db.Bookings.Remove(objD);

                db.SaveChanges();

                //Redirect
                Response.Redirect("bookings.aspx");
            }
        }
Esempio n. 6
0
        protected void GetRoom()
        {
            //populate the existing room for editing
            using (comp2007Entities db = new comp2007Entities())
            {
                Int32 RoomID = Convert.ToInt32(Request.QueryString["RoomID"]);

                Room objC = (from r in db.Rooms
                               where r.RoomID == RoomID
                               select r).FirstOrDefault();

                //populate the form
                ddlRoomSize.Text = objC.Size;
                txtCostPerDay.Text = objC.CostPerDay.ToString();
            }
        }
Esempio n. 7
0
        protected void grdRooms_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //get selected room number
            Int32 RoomID = Convert.ToInt32(grdRooms.DataKeys[e.RowIndex].Values["RoomID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                //get selected room
                Room objC = (from r in db.Rooms
                               where r.RoomID == RoomID
                               select r).FirstOrDefault();

                //delete
                db.Rooms.Remove(objC);
                db.SaveChanges();

                //refresh grid
                GetRooms();
            }
        }
Esempio n. 8
0
        protected void CheckIn()
        {
            //populate the existing room for editing
            using (comp2007Entities db = new comp2007Entities())
            {
                Room objC = new Room();

                if (!String.IsNullOrEmpty(Request.QueryString["RoomID"]))
                {
                    Int32 RoomID = Convert.ToInt32(Request.QueryString["RoomID"]);
                    objC = (from r in db.Rooms
                            where r.RoomID == RoomID
                            select r).FirstOrDefault();
                }

                //populate the room from the input form
                objC.Size = objC.Size;
                objC.CostPerDay = objC.CostPerDay;
                objC.Availability = objC.Availability;

                //set availability to no
                if (objC.Availability == "y")
                {
                    objC.Availability = "n";

                    if (String.IsNullOrEmpty(Request.QueryString["RoomID"]))
                    {
                        //add
                        db.Rooms.Add(objC);
                    }
                    //save
                    db.SaveChanges();
                }
                //room not currently available
                else
                {
                    //redirect
                    Response.Redirect("rooms.aspx");
                }
            }
        }