protected void btnAddReview_Click(object sender, EventArgs e) { UserFunctions uf = new UserFunctions(); if (txtReview.Text == "") { lblErrorMessage.Text = "Please say something about the restaurant."; } else { UserObject user = (UserObject)Session["User"]; string username = user.username; string RestaurantName = lblRestaurantName.Text; int RestID = uf.GetRestaurantID(rname, raddress); int qualityrating = int.Parse(ddlQualityRating.Text); int pricerating = 5; if (uf.AddNewReviewDB(username, RestID, txtReview.Text, pricerating, qualityrating) > 0) { uf.CalculateAverages(RestID); Response.Redirect("UserHome.aspx"); } else { lblErrorMessage.Text = "Error. Please try again."; } } }
protected void btnBookReservation_Click(object sender, EventArgs e) { string time = ddlResTime.Text; string partysizetext = ddlPartySize.Text; if ((ddlMonth.Text == "Month") || (ddlDay.Text == "Day") || (ddlYear.Text == "Year")) //Input Validation for Date { lblErrorMessage.Text = "Please select a valid date for your reservation."; } if (time == "") //Input validation for Time { lblErrorMessage.Text = "Please make sure you have selected a time for your reservation."; } if (partysizetext == "") //Input Validation for Party Size { lblErrorMessage.Text = "Please enter a valid size for your party."; } else { string month = ddlMonth.Text; string day = ddlDay.Text; string year = ddlYear.Text; String date = month + " " + day + " " + year; //Concatinates the parts of the date to create one date string int partysize = Convert.ToInt32(ddlPartySize.Text); UserObject user = (UserObject)Session["User"]; string username = user.username; UserFunctions uf = new UserFunctions(); int restaurantID = uf.GetRestaurantID(rname, raddress); //Gets Rest ID using the name and address if (uf.AddNewReservationDB(time, date, username, restaurantID, partysize) > 0) //Checks if database update works { Response.Redirect("ReservationConfirmation.aspx"); //If it works redirect to confirmation page } else { lblErrorMessage.Text = "Error. Please try again."; } } }
protected void Page_Load(object sender, EventArgs e) { String rname; String raddress; if (!IsPostBack) { UserFunctions uf = new UserFunctions(); rname = Session["Restaurant Name"].ToString(); raddress = Session["Restaurant Address"].ToString(); DBConnect objDB = new DBConnect(); int restid = uf.GetRestaurantID(rname, raddress); String strSQL = "SELECT * From Reviews WHERE RestaurantID = '" + restid + "'"; DataSet myDS = objDB.GetDataSet(strSQL); gvReviews.DataSource = myDS; gvReviews.DataBind(); } }
protected void btnCancelReservation_Click(object sender, EventArgs e) { for (int i = 0; i < gvReservations.Rows.Count; i++) //Input Validation to make sure one and only one checkbox is selected { CheckBox cb; cb = (CheckBox)gvReservations.Rows[i].FindControl("cbSelectCancel"); if (cb.Checked) { amountchecked = amountchecked + 1; } } if (amountchecked < 1 || amountchecked > 1) { lblErrorMessage.Text = "Please Select only one restaurant to work with at a time."; } else { for (int i = 0; i < gvReservations.Rows.Count; i++) //If all conditions are good pull the information from the one selected { CheckBox cb; cb = (CheckBox)gvReservations.Rows[i].FindControl("cbSelectCancel"); if (!cb.Checked) { continue; } else { UserFunctions uf = new UserFunctions(); string restaurantname = gvReservations.Rows[i].Cells[1].Text; string restaurantaddress = gvReservations.Rows[i].Cells[2].Text; string date = gvReservations.Rows[i].Cells[3].Text; string time = gvReservations.Rows[i].Cells[4].Text; int restaurantID = uf.GetRestaurantID(restaurantname, restaurantaddress); UserObject user; user = (UserObject)Session["User"]; string username = user.username; if (uf.DeleteReservationDB(username, date, time) > 0) { lblErrorMessage.Text = "Success. You have canceled your reservation."; DBConnect objDB = new DBConnect(); String strSQL = "SELECT Reservation.Time, Reservation.Date, Reservation.PartySize, Restaurant.Name, Restaurant.Address FROM Reservation JOIN Restaurant ON Reservation.RestaurantID=Restaurant.RestaurantID WHERE Username='******'"; //Pull all reservations where username is this DataSet myDS = objDB.GetDataSet(strSQL); gvReservations.DataSource = myDS; gvReservations.DataBind(); } else { lblErrorMessage.Text = "Error. Please try again."; } } } } }
protected void btnSubmit_Click(object sender, EventArgs e) { UserObject user; user = (UserObject)Session["User"]; string username = user.username; int amountchecked = 0; for (int i = 0; i < gvRestaurants.Rows.Count; i++) //Input Validation to make sure one and only one checkbox is selected { CheckBox cb; cb = (CheckBox)gvRestaurants.Rows[i].FindControl("cbSelect"); if (cb.Checked) { amountchecked = amountchecked + 1; } } if (amountchecked < 1 || amountchecked > 1) { lblErrorMessage.Text = "You can only select one restaurant of which to be a representative."; } else { for (int i = 0; i < gvRestaurants.Rows.Count; i++) //If all conditions are good pull the information from the one selected { CheckBox cb; cb = (CheckBox)gvRestaurants.Rows[i].FindControl("cbSelect"); if (!cb.Checked) { continue; } else { UserFunctions uf = new UserFunctions(); string restaurantname = gvRestaurants.Rows[i].Cells[1].Text; string restaurantaddress = gvRestaurants.Rows[i].Cells[2].Text; int restaurantID = uf.GetRestaurantID(restaurantname, restaurantaddress); UserObject user1; user1 = (UserObject)Session["User"]; string repUsername = user1.username; string sqlcheck = "SELECT * FROM RestaurantRepresentative WHERE Username ='******'"; DBConnect objDB = new DBConnect(); DataSet checkingDS = objDB.GetDataSet(sqlcheck); if (checkingDS.Tables[0].Rows.Count == 0) { if ((uf.DeclareRestaurantAssignmentDB(username, restaurantID)) > 0) { lblErrorMessage.Text = "Success. You have selected the restaurant of which you work."; String strSQL = "SELECT Reservation.Time, Reservation.Date, Reservation.PartySize, Restaurant.Name, Restaurant.Address FROM Reservation JOIN Restaurant ON Reservation.RestaurantID=Restaurant.RestaurantID WHERE Username='******'"; //Pull all reservations where username is this DataSet myDS = objDB.GetDataSet(strSQL); } else { lblErrorMessage.Text = "Error. Please try again."; } } else { lblErrorMessage.Text = "You already work someowhere else."; } } } } }
protected void btnConfirmEdit_Click(object sender, EventArgs e) //START WORKING HERE ON 3/11 -- work on updating an entry in the DB { UserFunctions uf = new UserFunctions(); UserObject user; user = (UserObject)Session["User"]; string username = user.username; string rname = lblRestaurantName.Text; string raddress = lblRestaurantAddress.Text; int restaurantID = uf.GetRestaurantID(rname, raddress); int reviewID = (int)Session["ReviewID"]; newpricerating = Convert.ToInt32(ddlPriceRating.Text); newqualityrating = Convert.ToInt32(ddlQualityRating.Text); newreviewcomments = txtNewComments.Text; //priceratinginitial = (int)Session["priceratinginitial"]; //qualityratinginitial = (int)Session["qualityratinginitial"]; //reviewcommentsinitial = Session["reviewcommentsinitial"].ToString(); //if (ddlPriceRating.Text == "") //{ // newpricerating = priceratinginitial; //} //else //{ // newpricerating = Convert.ToInt32(ddlPriceRating.Text); //} //if (ddlQualityRating.Text == "") //{ // newqualityrating = qualityratinginitial; //} //else //{ // newqualityrating = Convert.ToInt32(ddlQualityRating.Text); //} //if (txtNewComments.Text == "") //{ // newreviewcomments = reviewcommentsinitial; //} //else //{ // newreviewcomments = txtNewComments.Text; //} if (uf.ModifyReviewDB(reviewID, newreviewcomments, newpricerating, newqualityrating) > 0) { lblMessage.Text = "Success, You have edited your review."; HideEditFunctions(); 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 = "Please try again."; } }