protected void Page_Load(object sender, EventArgs e)
 {
     //Stops page from repopulating with previous data
     if (!IsPostBack)
     {
         //Request product value from viewProduct page depending on which product is selected
         string product   = Request.QueryString["product"];
         int    productID = 0;
         try
         {
             productID = Convert.ToInt32(product);
         }
         catch { }
         p = QueryClass.GetProduct(productID);
         //Change textbox text to equal product values of item selected
         productUpdateName.Text        = p.Name;
         productUpdateCategory.Text    = p.Category;
         productUpdateStock.Text       = p.Stock.ToString();
         productUpdateDescription.Text = p.Description;
         productUpdatePrice.Text       = p.Price.ToString("F");
         productUpdateQuantity.Text    = p.Quantity.ToString();
         pID.Text      = p.ID.ToString();
         fileName.Text = "Filename before the change: " + p.Image;
     }
 }
        protected void updateConfirmBtn_Clicked(object sender, System.EventArgs e)
        {
            int productID = 0;

            try
            {
                productID = Convert.ToInt32(pID.Text);
            }
            catch { }
            p = QueryClass.GetProduct(productID);
            //Store updated values in variables
            string updateCategory    = productUpdateCategory.Text;
            string updateName        = productUpdateName.Text;
            int    updateStock       = Convert.ToInt32(productUpdateStock.Text);
            string updateDescription = productUpdateDescription.Text;
            double updatePrice       = Convert.ToDouble(productUpdatePrice.Text);
            int    updateQuantity    = Convert.ToInt32(productUpdateQuantity.Text);
            string InsertImage;

            if (updateFileUploadImg.HasFile)
            {
                InsertImage = "../img/" + Convert.ToString(updateFileUploadImg.FileName);
            }
            else
            {
                InsertImage = p.Image;
            }
            //Checks to see if all the inputs are valid
            if (IsValid)
            {
                if (updateFileUploadImg.HasFile)
                {
                    //Checks to see if file type is an image
                    if (updateFileUploadImg.PostedFile.ContentType == "image/jpeg" || updateFileUploadImg.PostedFile.ContentType == "image/png" || updateFileUploadImg.PostedFile.ContentType == "image/jpg")
                    {
                        //Make error message invisible if file type is correct
                        updateImageFileError.Visible = false;
                        //Save image to project
                        updateFileUploadImg.SaveAs(Server.MapPath("~/img/" + updateFileUploadImg.FileName));
                    }
                    else
                    {
                        //make error message visbile
                        updateImageFileError.Visible = true;
                    }
                }
                if (!updateImageFileError.Visible)
                {
                    p.Category    = updateCategory;
                    p.Name        = updateName;
                    p.Stock       = updateStock;
                    p.Description = updateDescription;
                    p.Price       = updatePrice;
                    p.Quantity    = updateQuantity;
                    p.Image       = InsertImage;
                    QueryClass.UpdateProduct(p);
                    Response.Redirect("ManageProducts.aspx");
                }
            }
        }
Ejemplo n.º 3
0
        protected void btnAddToCart_Click(object sender, EventArgs e)
        {
            //Checks to see if product which will be the number to get an item from a list is not null
            int productIndex = Convert.ToInt32(productID);

            List <Product> cart      = new List <Product>();
            bool           isCartNew = false;

            //gets the cart or sets a new one
            if (Session["cart"] == null)
            {
                isCartNew = true;
            }
            else
            {
                cart = (List <Product>)Session["cart"];
            }

            Product p = QueryClass.GetProduct(productIndex);;

            if (isCartNew)
            {
                cart.Add(p);
                Session.Add("cart", cart);
            }
            else
            {
                int positionIndex = -1;
                //find said product in the cart
                for (int i = 0; i < cart.Count; i++)
                {
                    if (cart[i].Name.Equals(p.Name))
                    {
                        positionIndex = i;
                    }
                }
                if (positionIndex == -1)
                {
                    cart.Add(p);
                }
                //if found, only adds item if there is enought stock
                else if (p.Stock > cart[positionIndex].Quantity)
                {
                    cart[positionIndex].Quantity += 1;
                }
                Session["cart"] = cart;
            }
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Receive variable value from another page which is Products where products equals index of list products
            String productID = Request.QueryString["PassingValue"];
            int    id        = 0;

            try
            {
                id = Convert.ToInt32(productID);
            }
            catch { }
            p = QueryClass.GetProduct(id);

            //Change the information purchase product to equal the product at a certain index using 'product' variable
            productViewName.Text        = p.Name;
            productViewPrice.Text       = "Price: $" + p.Price.ToString("F");
            productViewDescription.Text = p.Description;
            productViewImage.ImageUrl   = p.Image;
        }