Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this is the class i'm working with
- public partial class MainShoppingPage : System.Web.UI.Page
- {
- List<CartObject> cart = new List<CartObject>();
- List<Product> allProducts = new List<Product>();
- List<Product> bookList = new List<Product>();
- List<Product> dvdList = new List<Product>();
- protected void Page_Load(object sender, EventArgs e)
- {
- BuildProducts bp = new BuildProducts();
- allProducts = (List<Product>)Session["AllProducts"];
- if (!IsPostBack)
- {
- foreach (var i in allProducts)
- {
- if (i.ProductType == "Book")
- {
- BooksDropDown.Items.Add(i.Title);
- BooksDropDown.SelectedIndex = 0;
- bookList.Add(i);
- int selectedBook = BooksDropDown.SelectedIndex;
- BookPriceValueLabel.Text = bookList[selectedBook].Price.ToString("c");
- }
- else
- {
- DvdDropDown.Items.Add(i.Title);
- DvdDropDown.SelectedIndex = 0;
- dvdList.Add(i);
- int selectedDvd = DvdDropDown.SelectedIndex;
- DVDPriceValueLabel.Text = dvdList[selectedDvd].Price.ToString("c");
- }
- }
- }
- }
- //Exit Button
- protected void ExitButton_Click(object sender, EventArgs e)
- {
- Response.Redirect("ExitScreen.aspx");
- }
- // this is the button that i'm having trouble with
- protected void AddButton_Click(object sender, EventArgs e)
- {
- string bookQuantity = BookQuantityTB.Text;
- string dvdQuantity = DvdQuantityTB.Text;
- Product selectedBook = allProducts[BooksDropDown.SelectedIndex];
- Product selectedDvd = allProducts[DvdDropDown.SelectedIndex + 5];
- MessageLabel.Text = "";
- if(Session["CartObjs"] == null)
- {
- if(bookQuantity != "" && dvdQuantity == "")
- {
- CartObject book = new CartObject(int.Parse(bookQuantity), selectedBook);
- cart.Add(book);
- HttpContext.Current.Session["CartObjs"] = cart;
- }
- else if(dvdQuantity != "" && bookQuantity == "")
- {
- CartObject dvd = new CartObject(int.Parse(dvdQuantity), selectedDvd);
- cart.Add(dvd);
- HttpContext.Current.Session["CartObjs"] = cart;
- }
- else if( dvdQuantity != "" && bookQuantity != "")
- {
- CartObject book = new CartObject(int.Parse(bookQuantity), selectedBook);
- CartObject dvd = new CartObject(int.Parse(dvdQuantity), selectedDvd);
- cart.Add(book);
- cart.Add(dvd);
- HttpContext.Current.Session["CartObjs"] = cart;
- }
- else
- {
- MessageLabel.Text = "One of the quantities must be more than 0. Otherwise Please Click Exit.";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement