Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. this is the class i'm working with
  2.  
  3. public partial class MainShoppingPage : System.Web.UI.Page
  4. {
  5. List<CartObject> cart = new List<CartObject>();
  6. List<Product> allProducts = new List<Product>();
  7. List<Product> bookList = new List<Product>();
  8. List<Product> dvdList = new List<Product>();
  9. protected void Page_Load(object sender, EventArgs e)
  10. {
  11. BuildProducts bp = new BuildProducts();
  12. allProducts = (List<Product>)Session["AllProducts"];
  13.  
  14. if (!IsPostBack)
  15. {
  16. foreach (var i in allProducts)
  17. {
  18. if (i.ProductType == "Book")
  19. {
  20. BooksDropDown.Items.Add(i.Title);
  21. BooksDropDown.SelectedIndex = 0;
  22. bookList.Add(i);
  23. int selectedBook = BooksDropDown.SelectedIndex;
  24. BookPriceValueLabel.Text = bookList[selectedBook].Price.ToString("c");
  25. }
  26. else
  27. {
  28. DvdDropDown.Items.Add(i.Title);
  29. DvdDropDown.SelectedIndex = 0;
  30. dvdList.Add(i);
  31. int selectedDvd = DvdDropDown.SelectedIndex;
  32. DVDPriceValueLabel.Text = dvdList[selectedDvd].Price.ToString("c");
  33. }
  34. }
  35. }
  36. }
  37.  
  38. //Exit Button
  39. protected void ExitButton_Click(object sender, EventArgs e)
  40. {
  41. Response.Redirect("ExitScreen.aspx");
  42. }
  43.  
  44. // this is the button that i'm having trouble with
  45. protected void AddButton_Click(object sender, EventArgs e)
  46. {
  47. string bookQuantity = BookQuantityTB.Text;
  48. string dvdQuantity = DvdQuantityTB.Text;
  49. Product selectedBook = allProducts[BooksDropDown.SelectedIndex];
  50. Product selectedDvd = allProducts[DvdDropDown.SelectedIndex + 5];
  51.  
  52. MessageLabel.Text = "";
  53.  
  54. if(Session["CartObjs"] == null)
  55. {
  56. if(bookQuantity != "" && dvdQuantity == "")
  57. {
  58. CartObject book = new CartObject(int.Parse(bookQuantity), selectedBook);
  59. cart.Add(book);
  60. HttpContext.Current.Session["CartObjs"] = cart;
  61. }
  62. else if(dvdQuantity != "" && bookQuantity == "")
  63. {
  64. CartObject dvd = new CartObject(int.Parse(dvdQuantity), selectedDvd);
  65. cart.Add(dvd);
  66. HttpContext.Current.Session["CartObjs"] = cart;
  67. }
  68. else if( dvdQuantity != "" && bookQuantity != "")
  69. {
  70. CartObject book = new CartObject(int.Parse(bookQuantity), selectedBook);
  71. CartObject dvd = new CartObject(int.Parse(dvdQuantity), selectedDvd);
  72. cart.Add(book);
  73. cart.Add(dvd);
  74. HttpContext.Current.Session["CartObjs"] = cart;
  75. }
  76. else
  77. {
  78. MessageLabel.Text = "One of the quantities must be more than 0. Otherwise Please Click Exit.";
  79. }
  80. }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement