Ejemplo n.º 1
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        selectedProduct = new Product();
        this.selectedProduct.Course_id = course_id.ToString();

        if (Page.IsValid)
        {
            CartItemList cart = CartItemList.GetCart();
            int locCount = cart.Count;
            locCount = locCount + 1;
            this.selectedProduct.assignmentNumber = locCount.ToString();
            this.selectedProduct.aGUID = Guid.NewGuid().ToString();
            this.selectedProduct.Num_Assignment = locCount;
            CartItem cartItem = new CartItem();

            int Num_Assignments=0;
            int assignment = 1; //will be produced from loop according to Num_Assignments
            cart = CartItemList.GetCart();
            cartItem = cart[selectedProduct.Course_id];

            if (cartItem == null)
            {
                cart.AddItem(selectedProduct, Num_Assignments,assignment);
            }
            else
            {
                cart.AddItem(selectedProduct, Num_Assignments, assignment);
                cartItem.AddQuantity(1);
            }
            this.DisplayCart();

        }
    }
Ejemplo n.º 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            var         closeLink     = (Control)sender;
            GridViewRow row           = (GridViewRow)closeLink.NamingContainer;
            string      firstCellText = row.Cells[2].Text;
            Items       item          = new Items();
            string      output        = firstCellText.ToLower().Replace(" desert", "_desert");

            for (int i = 0; i < desertList.Count; i++)
            {
                if (desertList[i].item_name.ToLower().Replace(" desert", "_desert") == output)
                {
                    item.item_id          = desertList[i].item_id;
                    item.item_name        = desertList[i].item_name;
                    item.item_price       = desertList[i].item_price;
                    item.item_description = desertList[i].item_description;
                    item.image            = desertList[i].image;
                }
            }
            CartItemList cart     = CartItemList.GetCart();
            ItemList     cartItem = cart[item.item_name];
            int          quantity = 1;

            if (cartItem == null)
            {
                cart.AddItem(item, quantity);
            }
            else
            {
                cartItem.AddQuantity(quantity);
            }
            Response.Redirect("~/cart.aspx");
        }
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string id = GridView1.SelectedRow.Cells[1].Text;

            selectedPackage = PackagesDB.GetPackage(Convert.ToInt16(id));

            Page.Validate();
            // Next add them to the cart which is a session variable and thus global to
            // all the web forms
            if (Page.IsValid)
            {
                CartItemList cart     = CartItemList.GetCart();
                CartItem     cartItem = cart[selectedPackage.PackageId];

                //if item isn’t in cart, add it; otherwise, increase its quantity
                if (cartItem == null)
                {
                    cart.AddItem(selectedPackage, 1);
                }
                else
                {
                    cartItem.AddQuantity(1);
                }
            }
        }
Ejemplo n.º 4
0
    /* private Product GetSelectedProduct()
     * {
     *   //get row from SqlDataSource based on value in dropdownlist
     *   DataView productsTable = (DataView)
     *       SqlDataSource.Select(DataSourceSelectArguments.Empty);
     *   productsTable.RowFilter = string.Format("ProductID = '{0}'",
     *       ddlProducts.SelectedValue);
     *   DataRowView row = (DataRowView)productsTable[0];
     *
     *   //create a new product object and load with data from row
     *   Product p = new Product();
     *   p.ProductID = row["ProductID"].ToString();
     *   p.Name = row["Name"].ToString();
     *   p.ShortDescription = row["ShortDescription"].ToString();
     *   p.LongDescription = row["LongDescription"].ToString();
     *   p.UnitPrice = (decimal)row["UnitPrice"];
     *   p.ImageFile = row["ImageFile"].ToString();
     *   return p;
     * }*/

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string itemID;
            Button clickedButton = (Button)sender;
            itemID = clickedButton.Attributes["ItemID"];
            //get cart from session and selected item from cart
            CartItemList cart     = CartItemList.GetCart();
            CartItem     cartItem = cart[itemID];

            //if item isn’t in cart, add it; otherwise, increase its quantity
            if (cartItem == null)
            {
                SqlConnection conn = new SqlConnection(connstring);
                conn.Open();
                int           id        = Convert.ToInt32(itemID);
                SqlCommand    sqlcmd    = new SqlCommand("SELECT * FROM MenuItem where Id =" + id, conn);
                SqlDataReader theReader = sqlcmd.ExecuteReader();

                theReader.Read();
                MenuItem m = readerToMenuItem(theReader);
                cart.AddItem(m, 1);
            }
            else
            {
                cartItem.AddQuantity(1);
            }
            Response.Redirect("Cart.aspx");
        }
    }
Ejemplo n.º 5
0
    private void AddToBasket(int ProductId)
    {
        CartItemList cart = CartItemList.GetCart();
        //Create Product From Id
        // create a new product object and load with data from row
        Product p = new Product();

        Session["Basket"] = true;

        //Read Info From DB For Product

        SqlConnection conn = new SqlConnection();

        conn.ConnectionString = "Data Source = (LocalDB)\\MSSQLLocalDB;" +

                                "AttachDbFilename = C:\\Users\\Matte\\Downloads\\Ex09Cart\\Ex09Cart\\App_Data\\MyRestaurant.mdf;" +
                                "Integrated Security = True";

        SqlCommand command = new SqlCommand("SELECT* FROM [Product] Where Id = @Id");

        command.Parameters.AddWithValue("@Id", ProductId);


        command.Connection = conn;
        conn.Open();

        DataSet        ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(command);

        da.Fill(ds);
        conn.Close();
        if (ds.Tables.Count > 0)
        {
            p.ProductID = ds.Tables[0].Rows[0].Field <int>("Id").ToString();

            p.Name      = ds.Tables[0].Rows[0].Field <string>("name");
            p.UnitPrice = ds.Tables[0].Rows[0].Field <decimal>("cost");
            p.ImageFile = "Images/Products/" + ds.Tables[0].Rows[0].Field <string>("image");

            //if item isn’t in cart, add it; otherwise, increase its quantity
            cart = CartItemList.GetCart();
            CartItem cartItem = cart[p.ProductID];
            if (cartItem == null)
            {
                cart.AddItem(p, 1);
            }
            else
            {
                cartItem.AddQuantity(1);
            }

            Response.Redirect("Cart.aspx");
        }
        //Response.Redirect("login.aspx");
    }
        protected void Page_Load(object sender, EventArgs e)
        {
            Item i = new Item();

            i.ItemID = 1; i.Name = "apples"; i.Price = 1;

            CartItemList a = new CartItemList();

            a.AddItem(i, 1);
            Session["Cart"] = a;
        }
Ejemplo n.º 7
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                Product      selectedProduct = GetSelectedProduct();
                CartItemList cart            = CartItemList.GetCart();
                CartItem     cartItem        = cart[selectedProduct.productID];

                if (cartItem == null)
                {
                    cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text));
                }
                ;
            }
        }
Ejemplo n.º 8
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         CartItemList cart     = CartItemList.GetCart();
         CartItem     cartItem = cart[selectedProduct.Name];
         if (cartItem == null)
         {
             cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text));
         }
         else
         {
             cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
         }
         Response.Redirect("Cart.aspx");
     }
 }
    protected void addButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            CartItemList cart     = CartItemList.GetCart();
            CartItem     cartItem = cart[selectedProduct.ProductID];

            if (cartItem == null)
            {
                cart.AddItem(selectedProduct, Convert.ToInt32(quantityTextBox.Text));
            }
            else
            {
                cartItem.AddQuantity(Convert.ToInt32(quantityTextBox.Text));
            }
            Response.Redirect("~/ShoppingPages/Cart.aspx");
        }
    }
Ejemplo n.º 10
0
    protected void AddToCart(int itemID)
    {
        Item         selectedProduct = this.GetSelectedProduct(itemID);
        CartItemList cart            = CartItemList.GetCart();
        CartItem     cartItem        = cart[selectedProduct.ItemID];

        if (cartItem == null)
        {
            cart.AddItem(selectedProduct, 1);
            Console.WriteLine(selectedProduct.ItemName);
        }
        else
        {
            cartItem.AddQuantity(1);
        }
        resetCartSize();
        Session["sessionCart"] = cart;
    }
Ejemplo n.º 11
0
 protected void btnAdd_Click1(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         selectedProduct = this.GetSelectedProduct();
         CartItemList cart     = CartItemList.GetCart();
         CartItem     cartItem = cart[selectedProduct.ProductID];
         if (cartItem.Product != selectedProduct)
         {
             cart.AddItem(selectedProduct, 1);
         }
         else
         {
             cartItem.AddQuantity(1);
         }
         Console.WriteLine("PageLoad");
         Response.Redirect("Cart.aspx", false);
     }
 }
Ejemplo n.º 12
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //get cart from session state and selected item from cart
            CartItemList cart     = CartItemList.GetCart();
            CartItem     cartItem = cart[selectedProduct.ProductID];

            //if item is nt in cart, add it; else increase its quantity
            if (cartItem == null)
            {
                cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text));
            }
            else
            {
                cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
            }
            Response.Redirect("Cart.aspx");
        }
    }
Ejemplo n.º 13
0
        protected void btnAddToCart_Click(object sender, EventArgs e)
        {
            Product redpepper = new Product();

            redpepper.name        = "Redpepper";
            redpepper.description = "These cases are great quality protective cases. They have ip68 water and dust resistance which means you can drop them in the pool and not worry!";
            redpepper.unitPrice   = 70;
            redpepper.type        = dropPhone.Text;


            CartItemList cart     = CartItemList.GetCart();
            CartItem     cartItem = cart[0];

            if (cartItem == null)
            {
                cart.AddItem(redpepper, Convert.ToInt32(dropQuantity.Text));
            }

            Response.Redirect("~/Cart.aspx");
        }
Ejemplo n.º 14
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                CartItemList cart     = CartItemList.GetCart();
                CartItem     cartItem = cart[selectedProduct.ProductID];

                //if item isn't in cart, add it;
                //otherwise, increase its quantity
                if (cartItem == null)
                {
                    cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text));
                }
                else
                {
                    cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
                }
                Response.Redirect("~/Cart.aspx");
            }
        }
Ejemplo n.º 15
0
    protected void ButtonCart_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //get cart from session and selected item from cart
            CartItemList cart     = CartItemList.GetCart();
            CartItem     cartItem = cart[selectedProduct.ProductID];

            //if item isn’t in cart, add it; otherwise, increase its quantity
            if (cartItem == null)
            {
                cart.AddItem(selectedProduct,
                             Convert.ToInt32(TextBoxQty.Text));
            }
            else
            {
                cartItem.AddQuantity(Convert.ToInt32(TextBoxQty.Text));
            }
            Response.Redirect("Cart.aspx", false);
        }
    }
Ejemplo n.º 16
0
        protected void btnAddToCart_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                //get cart from session state and selected item from cart
                CartItemList cart     = CartItemList.GetCart();
                CartItem     cartItem = cart[displayProduct.Product_id];
                //if item isn't in cart, add it; otherwise, increase its quantity
                if (cartItem == null)
                {
                    cart.AddItem(displayProduct, Convert.ToInt32(txtQuantity.Text));
                    //cart.AddItem(displayProduct);
                }
                else
                {
                    cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
                }

                Response.Redirect("~/MobileCart.aspx");
            }
        }
Ejemplo n.º 17
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                Button btn = (Button)sender;
                switch (btn.CommandName)
                {
                case "addCart":
                    Product      selectedProduct = GetSelectedProduct();
                    CartItemList cart            = CartItemList.GetCart();
                    CartItem     cartItem        = cart[selectedProduct.Id];

                    if (cartItem == null)
                    {
                        cart.AddItem(selectedProduct);
                    }
                    Response.Redirect("addtocart.aspx");
                    break;
                }
            }
        }
Ejemplo n.º 18
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //get selected product
                var product = GetSelectedProduct(ddlProducts.SelectedValue);

                //get cart from session and selected item from cart
                CartItemList cart     = CartItemList.GetCart();
                CartItem     cartItem = cart[product.ProductID];

                //if item isn’t in cart, add it; otherwise, increase its quantity
                if (cartItem == null)
                {
                    cart.AddItem(product, Convert.ToInt32(txtQuantity.Text));
                }
                else
                {
                    cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
                }
                var url = FriendlyUrl.Href("~/cart", "Cart");
                Response.Redirect(url);
            }
        }
Ejemplo n.º 19
0
    protected void btnAddtoCart_Click(object sender, EventArgs e)
    {
        int quantitySelected = 0;

        try{
            quantitySelected = Convert.ToInt16(txtQuantity.Text);

            if (Page.IsValid)
            {
                Cake         selectedProduct = this.GetSelectedProduct();
                CartItemList cart            = CartItemList.GetCart();
                CartItem     cartItem        = cart[selectedProduct.ProductId];


                int index         = 0;
                int alreadyInCart = 0;
                if (cart.Count > 0)
                {
                    while (index != -1)
                    {
                        if (cart.GetProdID(index) == selectedProduct.ProductId)
                        {
                            alreadyInCart = cart.GetQuantity(index);
                        }
                        index = cart.IndexAdvance(index);
                    }
                }
                // checking first to see if we have the amount selected currently on hand
                if (quantitySelected + alreadyInCart <= selectedProduct.OnHand)
                {
                    if (quantitySelected > 0)
                    {
                        // if we do, then we can add to cart and redirect to cart
                        //if item isn't in cart, add it; otherwise, increase its quantity
                        if (cartItem == null)
                        {
                            cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text));
                        }
                        else
                        {
                            cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
                        }
                        Response.Redirect("~/Cart/Cart.aspx");
                    }
                    else
                    {
                        lblQuan.Text = "Please enter a quantity greater than zero.";
                    }
                }
                else
                {
                    //ask them to order fewer
                    lblQuan.Text = "Sorry, we do not have that many on hand.";
                }
            }
        }
        catch (Exception ex)
        {
            lblQuan.Text = "That's not a valid number.";
        }
    }
Ejemplo n.º 20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        course_id = Request.QueryString["id"];
        User_ID = User.Identity.Name.ToString(); // Gets user that is logged in

        lstCart.Items.Clear();
        if (IsPostBack) // On Postback
        {
            cart = new CartItemList();
            newCart = new CartItemList();
            cart = CartItemList.GetCart();
            newCart = CartItemList.GetNewCart();
        }
        if (!IsPostBack) // Not postback, inital load
        {
            CartItemList.newCart();
            cart = new CartItemList();
            newCart = new CartItemList();
            cart = CartItemList.GetCart();
            List<AssignmentClass> productList = new List<AssignmentClass>();
            //productList = ProductDB.GetProduct();
            productList = AssignmentClassDB.GetProductCID(course_id);
            foreach (AssignmentClass p in productList)
            {
                cart.AddItem(p, Convert.ToInt32(p.Course_id), Convert.ToInt32(p.assignmentNumber));
            }

            this.DisplayCart(); // Make this load the course assignments
           // this.DisplayNewCart();
        }
    }