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 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;
                }
            }
        }
    }