protected void gvHistory_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     lbladded.Visible    = false;
     gvRoom.Visible      = false;
     pnlFeedback.Visible = false;
     //show the full details of selected role
     if (e.CommandName == "Select")
     {
         List <Booking> bookingList = (List <Booking>)Session["History"];
         Booking        book        = bookingList[gvHistory.PageIndex * gvHistory.PageSize + Convert.ToInt32(e.CommandArgument)];
         //Checking room item booking to display
         List <ItemBooking> itemList = ItemBookingDB.getAllRoomItemBooking();
         List <ItemBooking> item     = new List <ItemBooking>();
         //Showing each item that is under the selected booking
         foreach (ItemBooking it in itemList)
         {
             if (it.BookingID.BookingID.ToString() == book.BookingID.ToString())
             {
                 gvRoom.Visible = true;
                 ItemBooking room = it;
                 item.Add(room);
             }
         }
         //Not showing rooms when there's no rooms under selected booking
         if (item.Count > 0)
         {
             gvRoom.DataSource = item;
             gvRoom.DataBind();
             Session["OldRoom"] = item;
         }
         List <ItemBooking> tList   = ItemBookingDB.getAllTicketItemBooking();
         List <ItemBooking> tickets = new List <ItemBooking>();
         foreach (ItemBooking it in tList)
         {
             if (it.BookingID.BookingID.ToString() == book.BookingID.ToString())
             {
                 dlTicket.Visible = true;
                 ItemBooking ticket = it;
                 tickets.Add(ticket);
                 gvTicket.DataSource = tickets;
                 gvTicket.DataBind();
                 Session["OldTicket"] = tickets;
             }
         }
         List <ItemBooking> rList       = ItemBookingDB.getAllRestaurantItemBooking();
         List <ItemBooking> restaurants = new List <ItemBooking>();
         foreach (ItemBooking it in rList)
         {
             if (it.BookingID.BookingID.ToString() == book.BookingID.ToString())
             {
                 dlRestaurant.Visible = true;
                 ItemBooking restaurant = it;
                 restaurants.Add(restaurant);
                 gvRestaurant.DataSource = restaurants;
                 gvRestaurant.DataBind();
                 Session["OldRestaurant"] = restaurants;
             }
         }
     }
 }
    protected void gvUpcoming_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Allowing access to service provider to update booking status
        lblCustomer.Visible = false;
        dlCustomer.Visible  = false;
        List <ItemBooking> itemList = (List <ItemBooking>)Session["Upcoming"];
        ItemBooking        item     = itemList[Convert.ToInt32(gvUpcoming.PageSize * gvUpcoming.PageIndex + e.RowIndex)];

        //Checking pending bookings to update status
        if (item.ItemBookingStatus == "Pending")
        {
            if (e.NewValues["ItemBookingStatus"].ToString() == "Pending" || e.NewValues["ItemBookingStatus"].ToString() == "Approved" || e.NewValues["ItemBookingStatus"].ToString() == "Rejected")
            {
                lblNoResult.Text     = "";
                gvUpcoming.EditIndex = -1;
                //Sending email with company email
                SmtpClient client = new SmtpClient("smtp.gmail.com");
                client.EnableSsl   = true;
                client.Credentials = new NetworkCredential("*****@*****.**", "smart-travel1005");
                MailMessage msg = new MailMessage("*****@*****.**", item.BookingID.CID.CustEmail);
                if (e.NewValues["ItemBookingStatus"].ToString() == "Approved")
                {
                    //Informing customer about approve booking
                    try
                    {
                        msg.Subject = "Your Booking has been confirmed";
                        msg.Body    = "Your reservation booking at " + item.RestaurantID.Name + " has been confirmed. Check out the updated status on our website. Your booking ID is " + item.BookingID.BookingID + "\r\n";
                        msg.Body   += "Thanks you for choosing SmartTravel";
                        client.Send(msg);
                        item.ItemBookingStatus = Convert.ToString(e.NewValues["ItemBookingStatus"]);
                        //updating item booking status into database
                        int add = ItemBookingDB.UpdateItemBooking(item);
                        bind();
                    }
                    //If email cannot be sent
                    catch (Exception er)
                    {
                        lblNoResult.Text = "Internet connection required: " + er.ToString();
                    }
                }
                //Informing customer about approve booking
                else if (e.NewValues["ItemBookingStatus"].ToString() == "Rejected")
                {
                    msg.Subject = "Your Booking has been rejected";
                    msg.Body    = "We're sorry to inform you that your reservation booking at " + item.RestaurantID.Name + " has been rejected. Check out the updated status on our website. Your booking ID is " + item.BookingID.BookingID + "\r\n";
                    msg.Body   += "Thanks you for choosing SmartTravel";
                    client.Send(msg);
                }
            }
            else
            {
                lblNoResult.Text = "Status can only be Pending, Approved or Rejected!";
            }
        }
        else
        {
            lblNoResult.Text = "Status can be changed only for the Pending Booking";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //if user hotel is null
        if (Session["userHotel"] == null)
        {
            Response.Redirect("LoginForm.aspx"); //brings to the loginform page
        }
        lblNoResult.Text    = "";
        lblFeedback.Visible = false;

        if (!IsPostBack)
        {
            //Displaying upcoming and past bookings
            lblCustomer.Visible = false;
            dlCustomer.Visible  = false;
            gvFeedback.Visible  = false;
            lblTitle.Text       = "Upcoming Booking";
            gvHistory.Visible   = false;
            //Getting current signed in user
            Hotel hotel = (Hotel)Session["userHotel"];
            //Getting booked rooms from database and display them
            List <ItemBooking> itemList = ItemBookingDB.getAllRoomItemBooking();
            List <ItemBooking> upcoming = new List <ItemBooking>();
            List <ItemBooking> history  = new List <ItemBooking>();
            foreach (ItemBooking it in itemList)
            {
                //Checking the date to show only the upcoming events
                if (it.RoomID.Hotel.OrgEmail == hotel.OrgEmail)
                {
                    if (it.StartDate > DateTime.Now && it.ItemBookingStatus != "Canceled")
                    {
                        ItemBooking item = it;
                        upcoming.Add(item);
                        gvUpcoming.DataSource = upcoming;
                        gvUpcoming.DataBind();
                        //Keep the list of upcoming bookings in a session for further use
                        Session["upcoming"] = upcoming;
                    }
                    //Displaying the past bookings
                    else
                    {
                        ItemBooking item = it;
                        history.Add(item);
                        gvHistory.DataSource = history;
                        gvHistory.DataBind();
                        //Keep the list of past bookings in a session for further use
                        Session["history"] = history;
                    }
                }
            }
            Hotel acc = (Hotel)Session["userHotel"];
            //Getting feedback from database and display them
            List <Review> feedbackList = ReviewDB.getAllHotelReviewByID(acc.HotelID);
            gvFeedback.DataSource = feedbackList;
            gvFeedback.DataBind();
            Session["Feedback"] = feedbackList;
        }
    }
 protected void gvRoom_ItemCommand(object source, DataListCommandEventArgs e)
 {
     //Allowing access to show the feedback panel to give feedback
     lbladded.Visible = false;
     if (e.CommandName == "feedback")
     {
         //Retrieving the selected item details
         List <ItemBooking> itemList = (List <ItemBooking>)Session["OldRoom"];
         ItemBooking        item     = ItemBookingDB.getAllItemBookingbyID(e.CommandArgument.ToString());
         //Showing feedback panel to allow giving feedbacks
         lblTitle.Text        = item.RoomID.Hotel.Name;
         pnlFeedback.Visible  = true;
         pnlFeedback0.Visible = false;
         pnlFeedback1.Visible = false;
         gvRoom.Visible       = true;
         Session["retrieve"]  = item;
     }
 }
 protected void gvRestaurant_ItemCommand(object source, DataListCommandEventArgs e)
 {
     //Allowing access to show the feedback panel to give feedback
     lbladded.Visible = false;
     if (e.CommandName == "feedback")
     {
         //Retrieving the selected item details to show respective feedback panel
         List <ItemBooking> itemList = (List <ItemBooking>)Session["OldRestaurant"];
         ItemBooking        item     = ItemBookingDB.getAllItemBookingbyID(e.CommandArgument.ToString());
         lblTitle1.Text = "Restaurant Name: " + item.RestaurantID.Name;
         //Showing feedback panel to allow giving feedbacks
         pnlFeedback1.Visible = true;
         pnlFeedback0.Visible = false;
         pnlFeedback.Visible  = false;
         dlRestaurant.Visible = true;
         Session["retrieve"]  = item;
         gvRoom.Visible       = false;
         dlTicket.Visible     = false;
     }
 }
Beispiel #6
0
 protected void gvBooking_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "Item") //if admin selected on the specific booking id
     {
         dlRestaurant.Visible = false;
         dlRoom.Visible       = false;
         dlTicket.Visible     = false;
         List <Booking>     bookingList = (List <Booking>)Session["Booking"];    //retrieve the booking session
         List <ItemBooking> itemList    = ItemBookingDB.getAllRoomItemBooking(); //get the data from database for room details
         List <ItemBooking> item        = new List <ItemBooking>();              //add new list into itembooking
         foreach (ItemBooking it in itemList)                                    //use foreach to check with the itembookinglist
         {
             for (int n = 0; n < bookingList.Count; n++)                         //use for loop to check how many rows are there inside of the database
             {
                 //to check whether booking is available in database
                 if (it.BookingID.BookingID.ToString() == bookingList[n].BookingID.ToString() && bookingList[n].BookingID.ToString() == e.CommandArgument.ToString())
                 {
                     //to show the room details into datalist
                     ItemBooking room = it;
                     item.Add(room);
                     dlRoom.DataSource = item;
                     dlRoom.DataBind();
                     Session["room"] = item;
                 }
             }
         }
         //retrieve the booking session
         //get the ticket item booking from database
         //add new list from itembooking classes
         List <Booking>     tList          = (List <Booking>)Session["Booking"];
         List <ItemBooking> itemTicketList = ItemBookingDB.getAllTicketItemBooking();
         List <ItemBooking> itemT          = new List <ItemBooking>();
         foreach (ItemBooking it in itemTicketList)      //use foreach to check the itembooking
         {
             for (int n = 0; n < bookingList.Count; n++) //use for loop to check how many rows are there inside of the database
             {
                 //check with the booking id, if the data is available in database
                 if (it.BookingID.BookingID.ToString() == bookingList[n].BookingID.ToString() && bookingList[n].BookingID.ToString() == e.CommandArgument.ToString())
                 {
                     //to show the ticket into datalist
                     ItemBooking ticket = it;
                     itemT.Add(ticket);
                     dlTicket.DataSource = itemT;
                     dlTicket.DataBind();
                     Session["ticket"] = it.ItemBookingID;
                 }
             }
         }
         //retrieve the booking session
         //get the restaurant item booking from database
         //add new list from itembooking classes
         List <Booking>     rList     = (List <Booking>)Session["Booking"];
         List <ItemBooking> itemRlist = ItemBookingDB.getAllRestaurantItemBooking();
         List <ItemBooking> itemR     = new List <ItemBooking>();
         foreach (ItemBooking it in itemRlist)           //use foreach to check the itembooking
         {
             for (int n = 0; n < bookingList.Count; n++) //use for loop to check how many rows are there inside of the database
             {
                 //check with the booking id, if the data is available in database
                 if (it.BookingID.BookingID.ToString() == bookingList[n].BookingID.ToString() && bookingList[n].BookingID.ToString() == e.CommandArgument.ToString())
                 {
                     //to show the restaurant details into datalist
                     ItemBooking restaurant = it;
                     itemR.Add(restaurant);
                     dlRestaurant.DataSource = itemR;
                     dlRestaurant.DataBind();
                     Session["restaurant"] = itemR;
                 }
             }
         }
         //to check the item is more than zero -- ticket, hotel room and resturant
         if (itemT.Count > 0)
         {
             dlTicket.Visible = true;
         }
         if (itemR.Count > 0)
         {
             dlRestaurant.Visible = true;
         }
         if (item.Count > 0)
         {
             dlRoom.Visible = true;
         }
     }
 }
    protected void dlRestaurant_ItemCommand(object source, DataListCommandEventArgs e)
    {
        //When user clicked a booking to cancel, server will send the notification email
        if (e.CommandName == "cancel")
        {
            ItemBooking item = ItemBookingDB.getAllItemBookingbyID(e.CommandArgument.ToString());
            //Sending email to both customer and service provider to inform about service cancellation
            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.EnableSsl   = true;
            client.Credentials = new NetworkCredential("*****@*****.**", "smart-travel1005");
            try
            {
                MailMessage msg = new MailMessage("*****@*****.**", item.RestaurantID.OrgEmail.ToString());
                msg.Subject = "Booking cancellation";
                msg.Body    = "Your arranged booking " + item.BookingID.BookingID + " has been cancelled";
                client.Send(msg);
            }
            //When email server is not accessible
            catch (Exception er)
            {
                lblNoResult.Visible = true;
                lblNoResult.Text    = "Internet connection required";
            }
            try
            {
                //Sending email to Customer
                MailMessage msg1 = new MailMessage("*****@*****.**", item.BookingID.CID.CustEmail.ToString());
                msg1.Subject = "Booking cancellation";
                msg1.Body    = "Your booking " + item.BookingID.BookingID + " has been cancelled";
                if (item.ItemBookingStatus != "Canceled")
                {
                    client.Send(msg1);
                }
            }
            //When email server is not accessible
            catch (Exception er)
            {
                lblNoResult.Visible = true;
                lblNoResult.Text    = "Internet connection required ";
            }

            //Booking cancellation text displayed
            lblNoResult.Visible = true;
            lblNoResult.Text    = "Your booking has been cancelled";

            //Updating booking status
            item.ItemBookingStatus = "Canceled";
            int update = ItemBookingDB.UpdateItemBooking(item);

            List <ItemBooking> itemList = ItemBookingDB.getAllRestaurantItemBooking();
            List <ItemBooking> items    = new List <ItemBooking>();
            //Reloading data to show the updated booking status
            Booking book = item.BookingID;
            foreach (ItemBooking it in itemList)
            {
                if (it.BookingID.BookingID.ToString() == book.BookingID.ToString())
                {
                    dlRoom.Visible = true;
                    ItemBooking room = it;
                    items.Add(room);
                    dlRestaurant.DataSource = items;
                    dlRestaurant.DataBind();
                    Session["RestaurantItem"] = items;
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Response.Redirect("LoginForm.aspx"); //redirect to the login form, if the user is null
        }
        gvUpcoming.Visible = true;
        if (!IsPostBack)
        {
            //retrieve the user session
            Customer customer = (Customer)Session["user"];
            //get the data from booking database
            List <Booking> bookingList = BookingDB.getAllBookingByCID(customer);
            //add the new list for upcoming booking
            List <Booking> upcoming = new List <Booking>();
            foreach (Booking it in bookingList) //use foreach to get the itembooking details
            {
                List <ItemBooking> itemBookings = ItemBookingDB.getAllItemBookingbyBookingID(it.BookingID);

                ItemBooking itemBookingId = itemBookings[0]; //set an array for itembooking -- start from zero

                //use for loop to count how many itembookings
                for (int i = 0; i < itemBookings.Count - 1; i++)
                {
                    //use if statement, to check with the startdate
                    if (itemBookingId.StartDate < itemBookings[i + 1].StartDate)
                    {
                        //get the itembooking details and increase an array by one
                        itemBookingId = itemBookings[i + 1];
                    }
                }
                //check the start date from datetime.now functions
                if (itemBookingId.StartDate > DateTime.Now)
                {
                    //add the booking item into item list
                    Booking item = it;
                    upcoming.Add(item);
                    //show the upcoming item into gridview
                    gvUpcoming.DataSource = upcoming;
                    gvUpcoming.DataBind();
                }
            }
            Session["Upcoming"] = upcoming; //create upcoming session
            //create a new list for history booking
            List <Booking> history = new List <Booking>();
            //use foreach to check the bookinglist
            foreach (Booking it in bookingList)
            {
                //check the date with datetime.now functions
                if (it.Date < DateTime.Now)
                {
                    //show the history booking
                    Booking item = it;
                    history.Add(item);
                    gvHistory.DataSource = history;
                    gvHistory.DataBind();
                }
            }
            Session["History"] = history; //create a history session
        }
    }
 protected void gvUpcoming_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     lblNoResult.Visible = false;
     lblNoResult.Visible = false;
     if (e.CommandName == "Select") //if user select the upcoming bookinglist
     {
         dlRoom.Visible       = false;
         dlTicket.Visible     = false;
         dlRestaurant.Visible = false;
         List <Booking>     bookingList = (List <Booking>)Session["Upcoming"]; //retrieve the upcoming session
         Booking            book        = bookingList[gvUpcoming.PageIndex * gvUpcoming.PageSize + Convert.ToInt32(e.CommandArgument)];
         List <ItemBooking> itemList    = ItemBookingDB.getAllRoomItemBooking();
         List <ItemBooking> item        = new List <ItemBooking>();
         foreach (ItemBooking it in itemList) //use foreach to check with itembooking database
         {
             //check with the booking
             if (it.BookingID.BookingID.ToString() == book.BookingID.ToString())
             {
                 dlRoom.Visible = true;
                 ItemBooking room = it;
                 item.Add(room);
                 //show the room details into datalist
                 dlRoom.DataSource = item;
                 dlRoom.DataBind();
                 Session["RoomItem"] = item; //create a session for room item
             }
         }
         //get the itembooking ticket details from database
         List <ItemBooking> tList = ItemBookingDB.getAllTicketItemBooking();
         //add the new list to itembooking
         List <ItemBooking> tickets = new List <ItemBooking>();
         //use foreach to check with itembooking database
         foreach (ItemBooking it in tList)
         {
             if (it.BookingID.BookingID.ToString() == book.BookingID.ToString())
             {
                 dlTicket.Visible = true;
                 ItemBooking ticket = it;
                 tickets.Add(ticket);
                 //show the ticket details into datalist
                 dlTicket.DataSource = tickets;
                 dlTicket.DataBind();
                 Session["TicketItem"] = tickets; //create a session for ticket item
             }
         }
         //get the itembooking restaurant details from database
         List <ItemBooking> rList = ItemBookingDB.getAllRestaurantItemBooking();
         //add the new list to itembooking
         List <ItemBooking> restaurants = new List <ItemBooking>();
         //use foreach to check with itembooking database
         foreach (ItemBooking it in rList)
         {
             if (it.BookingID.BookingID.ToString() == book.BookingID.ToString())
             {
                 dlRestaurant.Visible = true;
                 ItemBooking restaurant = it;
                 restaurants.Add(restaurant);
                 //show the restaurant details into datalist
                 dlRestaurant.DataSource = restaurants;
                 dlRestaurant.DataBind();
                 Session["RestaurantItem"] = restaurants; //create a restaurant item into datalist
             }
         }
     }
 }