Exemplo n.º 1
0
        protected void AddToCartBtn_Click(object sender, EventArgs e)
        {
            if (GV.user == null)
            {
                Response.Redirect("~/Account/Login.aspx");
                return;
            }
            System.Web.UI.WebControls.Button btn = (System.Web.UI.WebControls.Button)sender;
            Product prod = new Product();

            DefaultConnectionTableAdapters.CatsTableAdapter cta = new DefaultConnectionTableAdapters.CatsTableAdapter();
            var table = cta.GetCats();


            for (int i = 0; i < table.Count; i++)
            {
                if (Int32.Parse(hiddenValue.Value) == i)
                {
                    prod.Name        = table[i].Name;
                    prod.Price       = table[i].Price;
                    prod.Quantity    = int.Parse(hiddenQuantity.Value);
                    prod.Description = table[i].Description;
                    prod.Img         = table[i].ImageSource;
                    prod.Category    = table[i].Category;
                }
            }

            DefaultConnectionTableAdapters.ProductsTableAdapter pta = new DefaultConnectionTableAdapters.ProductsTableAdapter();
            var tableowner = pta.GetDataByOwnerId(GV.user.Id);

            for (int i = 0; i < tableowner.Count; i++)
            {
                var row = tableowner[i];
                if (row.Name == prod.Name)
                {
                    pta.UpdateProductCount(row.Quantity + prod.Quantity, GV.user.Id, row.Id);
                    return;
                }
            }
            pta.Insert(Guid.NewGuid().ToString(),
                       prod.Name,
                       prod.Price,
                       prod.Quantity,
                       DateTime.Now,
                       prod.Category,
                       prod.Img,
                       prod.Description,
                       GV.user.Id, true);

            Response.Redirect("/ProductPage.aspx");
        }
Exemplo n.º 2
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            System.Web.UI.WebControls.Button btn = (System.Web.UI.WebControls.Button)sender;
            Product prod = new Product();

            if (GV.user == null)
            {
                Response.Redirect("~/Account/Login.aspx");
                return;
            }


            if (btn.ID.Equals(p1_submit.ID))
            {
                prod.Name        = "cat one";
                prod.Price       = 400;
                prod.Quantity    = int.Parse(hidden_prod_one.Value.ToString());
                prod.Description = "Cyber cat! this cat has the power to control the tv without the remote!";
                prod.Category    = 1;
                prod.Img         = "/images/cat1.png";
            }

            if (btn.ID.Equals(p2_submit.ID))
            {
                prod.Name        = "cat two";
                prod.Price       = 400;
                prod.Quantity    = int.Parse(hidden_prod_two.Value.ToString());
                prod.Description = "Ninja cat! this cat has the power to stealthly remove food from the fridge!";
                prod.Category    = 2;
                prod.Img         = "/images/cat2.png";
            }

            if (btn.ID.Equals(p3_submit.ID))
            {
                prod.Name        = "cat three";
                prod.Price       = 400;
                prod.Quantity    = int.Parse(hidden_prod_three.Value.ToString());
                prod.Description = "Vacu-cat! this cat is said to be the cat of vald the impailer himself!";
                prod.Category    = 3;
                prod.Img         = "/images/cat3.png";
            }

            DefaultConnectionTableAdapters.ProductsTableAdapter pta = new DefaultConnectionTableAdapters.ProductsTableAdapter();
            var table = pta.GetDataByOwnerId(GV.user.Id);

            for (int i = 0; i < table.Count; i++)
            {
                var row = table[i];
                if (row.Name == prod.Name)
                {
                    pta.UpdateProductCount(row.Quantity + prod.Quantity, GV.user.Id, row.Id);
                    return;
                }
            }
            pta.Insert(Guid.NewGuid().ToString(),
                       prod.Name,
                       prod.Price,
                       prod.Quantity,
                       DateTime.Now,
                       prod.Category,
                       prod.Img,
                       prod.Description,
                       GV.user.Id, true);
        }