Exemple #1
0
        protected void btnDeleteReview_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < gvReviews.Rows.Count; i++)       //Input Validation to make sure one and only one checkbox is selected
            {
                CheckBox cb;
                cb = (CheckBox)gvReviews.Rows[i].FindControl("cbSelect");

                if (cb.Checked)
                {
                    amountchecked = amountchecked + 1;
                }
            }

            if (amountchecked < 1 || amountchecked > 1)
            {
                lblMessage.Text = "Please Select only one restaurant to work with at a time.";
            }
            else
            {
                for (int i = 0; i < gvReviews.Rows.Count; i++)                             //If all conditions are good pull the information from the one selected
                {
                    CheckBox cb;
                    cb = (CheckBox)gvReviews.Rows[i].FindControl("cbSelect");

                    if (!cb.Checked)
                    {
                        continue;
                    }
                    else
                    {
                        UserFunctions uf = new UserFunctions();

                        string restaurantname    = gvReviews.Rows[i].Cells[1].Text;
                        string restaurantaddress = gvReviews.Rows[i].Cells[2].Text;
                        string review            = gvReviews.Rows[i].Cells[5].Text;
                        int    restaurantID      = uf.GetRestaurantID(restaurantname, restaurantaddress);


                        UserObject user;
                        user = (UserObject)Session["User"];
                        string username = user.username;



                        if (uf.DeleteReviewDB(username, restaurantID, review) > 0)
                        {
                            lblMessage.Text = "Success. You have deleted that review";
                            DBConnect objDB  = new DBConnect();
                            String    strSQL = "SELECT Reviews.Review, Reviews.PriceRating, Reviews.QualityRating, Restaurant.Name, Restaurant.Address FROM Reviews JOIN Restaurant ON Reviews.RestaurantID=Restaurant.RestaurantID WHERE Username='******'";
                            DataSet   myDS   = objDB.GetDataSet(strSQL);

                            gvReviews.DataSource = myDS;
                            gvReviews.DataBind();
                        }
                        else
                        {
                            lblMessage.Text = "Error. Please try again.";
                        }
                    }
                }
            }
        }