コード例 #1
0
        protected void Button_FinCompra(object sender, EventArgs e)
        {
            HttpCookie cookie = Request.Cookies["damncookie"];

            if (check_caducidad())
            {
                ENUser user = new ENUser(0, "", "", cookie["username"], new DateTime(), "", "", "");

                if (user.ReadID())
                {
                    ENCart    cart  = new ENCart(0, user.userID, 0.0F, 0);
                    DataTable table = cart.ReadCart();
                    ENOrder   order = new ENOrder(user.userID, "Preparando", paga, DateTime.Now);
                    if (order.CreateOrder())
                    {
                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            ENProduct p = new ENProduct(Convert.ToInt32(table.Rows[i][0].ToString()), "", 0.0F, 0, "", "", "", "");
                            if (p.ReadProductFromCatalog())
                            {
                                p.stock -= Convert.ToInt32(table.Rows[i][3].ToString());
                            }
                            p.UpdateProduct();
                        }

                        cart.DeleteCart();
                    }
                }



                Response.Redirect("Default.aspx");
            }
        }
コード例 #2
0
        }//end page load

        protected void AddCartButton_Click(object sender, EventArgs e)
        {
            HttpCookie cookie = Request.Cookies["damncookie"];

            if (cookie != null)
            {
                ENProduct producto = new ENProduct(0, "", 0.0F, 0, "", "", "", "");
                ENUser    usuario  = new ENUser(0, "", "", cookie["username"], new DateTime(), "", "", "");

                producto.id = Convert.ToInt32(Request.QueryString["id"]);
                usuario.ReadID();

                if (producto.ReadProductFromCatalog())
                {
                    ENCart carrito = new ENCart(producto.id, usuario.userID, producto.price, Convert.ToInt32(ProdAmount.Text));

                    if (carrito.CreateCart())
                    {
                        ProductAddedLabel.Visible = true;
                    }
                }
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
コード例 #3
0
        protected void addProductBT_Click(object sender, EventArgs e)
        {
            ENProduct newProduct = new ENProduct(0, "", 0.00F, 0, "", "", "", "");
            float     bottleGrade = 0.0F, bottleVolume = 0.0F;
            string    bottleType = "";
            int       productCod = 0;

            //para la url de la imagen
            HttpPostedFile file = pictureUpload.PostedFile;
            string         url  = "";

            //check file was submitted
            if (file != null && file.ContentLength > 0)
            {
                string fname = Path.GetFileName(file.FileName);
                url = Path.Combine("~/Imagenes/", fname);
                file.SaveAs(Server.MapPath(url));
            }
            else
            {
                url = "~/Imagenes/fotoPerfil.jpg";
            }

            try {
                //Get product properties
                newProduct.price = float.Parse(NewProdPriceTB.Text); //Puede dar excepcion
                newProduct.name  = NewProdNameTB.Text;
                newProduct.brand = NewProdBrandTB.Text;
                newProduct.stock = Convert.ToInt32(NewProdStockTB.Text);
                newProduct.url   = url;

                //Item[0] -> Botella Alcohol, Item[1] -> Miscelanea
                if (ProdTypeDropDown.Items[0].Selected)
                {
                    newProduct.type = "botella";
                }
                else if (ProdTypeDropDown.Items[1].Selected)
                {
                    newProduct.type = "miscelanea";
                }
                else if (ProdTypeDropDown.Items[2].Selected)
                {
                    newProduct.type = "pack";
                }

                //In case the description is not empty
                if (NewProdDescriptionTB.Text != "")
                {
                    newProduct.description = NewProdDescriptionTB.Text;
                }
                else
                {
                    newProduct.description = "Este producto aún tiene una descripción";
                }


                //When the product type is "miscelanea" or "pack"
                if (ProdTypeDropDown.Items[1].Selected || ProdTypeDropDown.Items[2].Selected)
                {
                    if (ProdTypeDropDown.Items[2].Selected)
                    {
                        ENPack pack = new ENPack(newProduct.name, newProduct.price, newProduct.description, newProduct.url, newProduct.stock, newProduct.brand);

                        if (pack.createPack())
                        {
                            ProductCreatedLabel.Visible = true;
                        }
                        else
                        {
                            ErrorCreatingProductLabel.Visible = true;
                        }
                    }
                    else
                    {
                        if (newProduct.CreateProduct())
                        {
                            ProductCreatedLabel.Visible = true;
                        }
                        else
                        {
                            ErrorCreatingProductLabel.Visible = true;
                        }
                    }

                    //product type is "botella"
                }
                else if (ProdTypeDropDown.Items[0].Selected)
                {
                    //Los parse pueden dar excepciones
                    bottleGrade  = float.Parse(NewProdGradeTB.Text);
                    bottleVolume = float.Parse(NewProdVolumeTB.Text);
                    bottleType   = AlcoholicTypeDropDown.Text;

                    if (newProduct.CreateProduct())  //Create base product

                    {
                        if (newProduct.ReadProductName())
                        {
                            productCod = newProduct.id;
                            ENBottle newBottle = new ENBottle(productCod, bottleGrade, bottleVolume, bottleType);

                            if (newBottle.CreateBottle())  //Create bottle

                            {
                                ProductCreatedLabel.Visible       = true;
                                ErrorCreatingProductLabel.Visible = false;
                            }
                        }
                        else
                        {
                            ErrorCreatingProductLabel.Visible = true;
                            ProductCreatedLabel.Visible       = false;
                        }
                    }
                }
                else
                {
                    ErrorCreatingProductLabel.Visible = true;
                    ProductCreatedLabel.Visible       = true;
                }
            }catch (Exception Ex) {
                Console.WriteLine("Se ha introducido texto en un campo destinao a ser númerico. ", Ex.Message);

                if (ProdTypeDropDown.Items[1].Selected)
                {
                    ConvertErrorLabel.Visible  = true;
                    NewProdPriceTB.BorderColor = System.Drawing.Color.Red;
                }
                else if (ProdTypeDropDown.Items[0].Selected)
                {
                    ConvertErrorLabel.Visible   = true;
                    NewProdPriceTB.BorderColor  = System.Drawing.Color.Red;
                    NewProdGradeTB.BorderColor  = System.Drawing.Color.Red;
                    NewProdVolumeTB.BorderColor = System.Drawing.Color.Red;
                }
            }
        }
コード例 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie cookie = Request.Cookies["damncookie"];

            if (cookie == null)
            {
                //Rating
                RatingLabel.Visible  = false;
                UpdatePanel1.Visible = false;

                //Comments
                CommentLabel.Visible   = false;
                CommentTextBox.Visible = false;

                //Boton send Rating
                SendRating.Visible = false;
            }

            ENProduct product = new ENProduct(0, "", 0.0F, 0, "", "", "", "");
            ENBottle  bottle  = new ENBottle();

            product.id = Convert.ToInt32(Request.QueryString["id"]);
            ENLootCrate loot = new ENLootCrate(0, "", 0.0F, "", "", "");

            loot.id = Convert.ToInt32(Request.QueryString["lootid"]);

            if (product.ReadProductFromCatalog() && loot.id == 0)
            {
                //Limt the amount to buy to the product stock
                AmountRV.MaximumValue = Convert.ToString(product.stock);
                AmountRV.MinimumValue = "1";

                //Image url
                ProductImage.ImageUrl = product.url;
                //Product Name
                ProductNameLabel.Text = product.name;
                //Product price
                ProductPriceLabel.Text = product.price.ToString() + "€";
                //Brand
                ProductBrandLabel.Text = product.brand;
                //Descripción
                DescriptionTextLabel.Text = product.description;

                if (product.type == "botella")
                {
                    bottle.id = product.id;

                    if (bottle.ReadBottle())
                    {
                        //Volume
                        VolumenLabel.Visible       = true;
                        ProductVolumeLabel.Visible = true;
                        ProductVolumeLabel.Text    = bottle.volume.ToString() + " mL";

                        //Gradde
                        GradoLabel.Visible        = true;
                        ProductGradeLabel.Visible = true;
                        ProductGradeLabel.Text    = bottle.grade.ToString() + " %";

                        //Alcoholic Type
                        TipoDeAlcoholLabel.Visible   = true;
                        ProdAlcoholTypeLabel.Visible = true;
                        ProdAlcoholTypeLabel.Text    = bottle.alcoholicType;
                    }
                }
            }
            else
            {
                if (loot.readLootCrateID())
                {
                    AmountRV.MinimumValue = "0";
                    AmountRV.MaximumValue = "1";
                    AmountRV.Enabled      = false;

                    //Hide Marca
                    MarcaLabel.Visible        = false;
                    ProductBrandLabel.Visible = false;

                    //Hide choose amount
                    ProdAmount.Visible    = false;
                    CantidadLabel.Visible = false;

                    //hide add to cart
                    AddCartButton.Visible = false;

                    //Show Image
                    ProductImage.ImageUrl = loot.url;

                    //Show name
                    ProductNameLabel.Text = loot.nameLootCrate;

                    //Show price
                    ProductPriceLabel.Text = Convert.ToString(loot.price);

                    //Show description
                    DescriptionTextLabel.Text = loot.descriptionLootCrate;
                }
            }
        }//end page load
コード例 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ENProduct prod = new ENProduct(0, "", 0.00F, 0, "", "", "", "");


            if (Request.QueryString["cat"] == "bottle")
            {
                DataTable t    = prod.ReadProductBot();
                int       cont = 0;
                int       obj  = t.Rows.Count;
                for (int i = -1; i < (t.Rows.Count / 4); i++)
                {
                    TableRow row = new TableRow();
                    if (obj >= 4)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            TableCell cell = new TableCell();
                            HyperLink hy   = new HyperLink();
                            Image     im   = new Image();
                            im.ImageUrl    = t.Rows[cont][7].ToString();
                            im.Height      = 400;
                            im.Width       = 220;
                            hy.ID          = t.Rows[cont][0].ToString();
                            hy.CssClass    = "card";
                            hy.Text        = t.Rows[cont][1].ToString();
                            hy.NavigateUrl = "Product.aspx?id=" + hy.ID.ToString();
                            hy.Controls.Add(im);
                            cell.Controls.Add(hy);
                            row.Cells.Add(cell);
                            cont++;
                            obj--;
                        }
                    }
                    else
                    {
                        for (int j = 0; j < obj; j++)
                        {
                            TableCell cell = new TableCell();
                            HyperLink hy   = new HyperLink();
                            Image     im   = new Image();
                            im.ImageUrl    = t.Rows[cont][7].ToString();
                            im.Height      = 400;
                            im.Width       = 220;
                            hy.ID          = t.Rows[cont][0].ToString();
                            hy.CssClass    = "card";
                            hy.Text        = t.Rows[cont][1].ToString();
                            hy.NavigateUrl = "Product.aspx?id=" + hy.ID.ToString();
                            hy.Controls.Add(im);
                            cell.Controls.Add(hy);
                            row.Cells.Add(cell);
                            cont++;
                        }
                    }
                    cat.Rows.Add(row);
                }
            }
            else if (Request.QueryString["cat"] == "packs")
            {
                DataTable t    = prod.ReadProductPack();
                int       cont = 0;
                int       obj  = t.Rows.Count;
                for (int i = -1; i < (t.Rows.Count / 4); i++)
                {
                    TableRow row = new TableRow();
                    if (obj >= 4)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            TableCell cell = new TableCell();
                            HyperLink hy   = new HyperLink();
                            Image     im   = new Image();
                            im.ImageUrl    = t.Rows[cont][7].ToString();
                            im.Height      = 400;
                            im.Width       = 220;
                            hy.ID          = t.Rows[cont][0].ToString();
                            hy.CssClass    = "card";
                            hy.Text        = t.Rows[cont][1].ToString();
                            hy.NavigateUrl = "Product.aspx?id=" + hy.ID.ToString();
                            hy.Controls.Add(im);
                            cell.Controls.Add(hy);
                            row.Cells.Add(cell);
                            cont++;
                            obj--;
                        }
                    }
                    else
                    {
                        for (int j = 0; j < obj; j++)
                        {
                            TableCell cell = new TableCell();
                            HyperLink hy   = new HyperLink();
                            Image     im   = new Image();
                            im.ImageUrl    = t.Rows[cont][7].ToString();
                            im.Height      = 400;
                            im.Width       = 220;
                            hy.ID          = t.Rows[cont][0].ToString();
                            hy.CssClass    = "card";
                            hy.Text        = t.Rows[cont][1].ToString();
                            hy.NavigateUrl = "Product.aspx?id=" + hy.ID.ToString();
                            hy.Controls.Add(im);
                            cell.Controls.Add(hy);
                            row.Cells.Add(cell);
                            cont++;
                        }
                    }
                    cat.Rows.Add(row);
                }
            }
            else if (Request.QueryString["cat"] == "misc")
            {
                DataTable t    = prod.ReadProductMisc();
                int       cont = 0;
                int       obj  = t.Rows.Count;
                for (int i = -1; i < (t.Rows.Count / 4); i++)
                {
                    TableRow row = new TableRow();
                    if (obj >= 4)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            TableCell cell = new TableCell();
                            HyperLink hy   = new HyperLink();
                            Image     im   = new Image();
                            im.ImageUrl    = t.Rows[cont][7].ToString();
                            im.Height      = 400;
                            im.Width       = 220;
                            hy.ID          = t.Rows[cont][0].ToString();
                            hy.CssClass    = "card";
                            hy.Text        = t.Rows[cont][1].ToString();
                            hy.NavigateUrl = "Product.aspx?id=" + hy.ID.ToString();
                            hy.Controls.Add(im);
                            cell.Controls.Add(hy);
                            row.Cells.Add(cell);
                            cont++;
                            obj--;
                        }
                    }
                    else
                    {
                        for (int j = 0; j < obj; j++)
                        {
                            TableCell cell = new TableCell();
                            HyperLink hy   = new HyperLink();
                            Image     im   = new Image();
                            im.ImageUrl    = t.Rows[cont][7].ToString();
                            im.Height      = 400;
                            im.Width       = 220;
                            hy.ID          = t.Rows[cont][0].ToString();
                            hy.CssClass    = "card";
                            hy.Text        = t.Rows[cont][1].ToString();
                            hy.NavigateUrl = "Product.aspx?id=" + hy.ID.ToString();
                            hy.Controls.Add(im);
                            cell.Controls.Add(hy);
                            row.Cells.Add(cell);
                            cont++;
                        }
                    }
                    cat.Rows.Add(row);
                }
            }
            else
            {
                DataTable t    = prod.ReadProductCat();
                int       cont = 0;
                int       obj  = t.Rows.Count;
                for (int i = -1; i < (t.Rows.Count / 4); i++)
                {
                    TableRow row = new TableRow();
                    if (obj >= 4)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            TableCell cell = new TableCell();
                            HyperLink hy   = new HyperLink();
                            Image     im   = new Image();
                            im.ImageUrl    = t.Rows[cont][7].ToString();
                            im.Height      = 400;
                            im.Width       = 220;
                            hy.ID          = t.Rows[cont][0].ToString();
                            hy.CssClass    = "card";
                            hy.Text        = t.Rows[cont][1].ToString();
                            hy.NavigateUrl = "Product.aspx?id=" + hy.ID.ToString();
                            hy.Controls.Add(im);
                            cell.Controls.Add(hy);
                            row.Cells.Add(cell);
                            cont++;
                            obj--;
                        }
                    }
                    else
                    {
                        for (int j = 0; j < obj; j++)
                        {
                            TableCell cell = new TableCell();
                            HyperLink hy   = new HyperLink();
                            Image     im   = new Image();
                            im.ImageUrl    = t.Rows[cont][7].ToString();
                            im.Height      = 400;
                            im.Width       = 220;
                            hy.ID          = t.Rows[cont][0].ToString();
                            hy.CssClass    = "card";
                            hy.Text        = t.Rows[cont][1].ToString();
                            hy.NavigateUrl = "Product.aspx?id=" + hy.ID.ToString();
                            hy.Controls.Add(im);
                            cell.Controls.Add(hy);
                            row.Cells.Add(cell);
                            cont++;
                        }
                    }
                    cat.Rows.Add(row);
                }
            }
        }