protected void OrderBtn_Click(object sender, EventArgs e) { if (GV.user == null) { Response.Redirect("~/CartV2.aspx"); } DefaultConnectionTableAdapters.OrdersTableAdapter ota = new DefaultConnectionTableAdapters.OrdersTableAdapter(); DefaultConnectionTableAdapters.ProductsTableAdapter pta = new DefaultConnectionTableAdapters.ProductsTableAdapter(); var productTable = pta.GetDataByOwnerId(GV.user.Id); var orderId = Guid.NewGuid().ToString(); //add to order table for (int i = 0; i < productTable.Count; i++) { var order = Orders.GenerateOrders(orderId); order.ProductId = productTable[i].Id; order.Quantity = productTable[i].Quantity; order.CustomerId = GV.user.Id; order.Subtotal = productTable[i].Quantity * productTable[i].Price; ota.Insert(order.OrderId, order.ProductId, order.CustomerId, order.Quantity, order.Subtotal, order.Purchased); } //change visibility from products table for (int i = 0; i < productTable.Count; i++) { pta.UpdateVisibility(false, productTable[i].Id); } Response.Redirect("~/OrdersPage.aspx"); }
public static List <Product> GetProducts() { if (GV.user == null) { return(new List <Product>()); } var id = GV.user.Id; List <Product> list = new List <Product>(); DefaultConnectionTableAdapters.ProductsTableAdapter pta = new DefaultConnectionTableAdapters.ProductsTableAdapter(); var tables = pta.GetDataByOwnerId(id); for (int i = 0; i < tables.Count; i++) { var row = tables[i]; Product p = new Product(); p.Description = row.Description; p.Name = row.Name; p.Price = row.Price; p.Quantity = row.Quantity; p.Img = row.Img; list.Add(p); } return(list); }
protected void GridView_Load(object sender, EventArgs e) { if (GV.user == null) { return; } var id = GV.user.Id; DefaultConnectionTableAdapters.ProductsTableAdapter pta = new DefaultConnectionTableAdapters.ProductsTableAdapter(); var tables = pta.GetDataByOwnerId(id); }
private void updateTotalTable() { if (GV.user == null) { return; } DefaultConnectionTableAdapters.ProductsTableAdapter pta = new DefaultConnectionTableAdapters.ProductsTableAdapter(); var td = pta.GetDataByOwnerId(GV.user.Id); GridView1.DataSource = td; GridView1.DataBind(); }
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"); }
public void UpdateItem(object sender, EventArgs e) { var senderBtn = (HiddenField)sender; //senderBtn.Visible = false DefaultConnectionTableAdapters.ProductsTableAdapter pta = new DefaultConnectionTableAdapters.ProductsTableAdapter(); //var parameters = ObjectDataSource1.Select(); var table = pta.GetDataByOwnerId(GV.user.Id); var rowNumber = int.Parse(senderBtn.ID.Split('_')[1]); var row = table[rowNumber]; if (int.Parse(senderBtn.Value) == 0) { pta.Delete(row.Id); } else { pta.UpdateProductCount(int.Parse(senderBtn.Value), row.Owner, row.Id); } Response.Redirect("~/CartV2.aspx"); }
protected void Create_Click(object sender, EventArgs e) { DefaultConnectionTableAdapters.ProductsTableAdapter ap = new DefaultConnectionTableAdapters.ProductsTableAdapter(); DefaultConnection.ProductsDataTable products = ap.GetData(); CatDataSetTableAdapters.CatsTableAdapter catsAdapter = new CatDataSetTableAdapters.CatsTableAdapter(); if (FileUploadCreate.HasFile) { try { if (FileUploadCreate.PostedFile.ContentType == "image/jpeg" || FileUploadCreate.PostedFile.ContentType == "image/png") { if (FileUploadCreate.PostedFile.ContentLength < 1024000) { var ext = Path.GetExtension(FileUploadCreate.FileName); FileUploadCreate.SaveAs(Server.MapPath("~/images/") + Img.Text + ext); } else { } } else { } } catch (Exception ex) { //StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } var price = int.Parse(Price.Text); var quantity = int.Parse(Quantity.Text); var cat = int.Parse(Category.Text); catsAdapter.Insert(Guid.NewGuid().ToString(), Name.Text, Img.Text, cat, quantity, price, Description.Text); GridView1.DataBind(); }
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); }
public int GetProductQuantity(string id) { DefaultConnectionTableAdapters.ProductsTableAdapter pta = new DefaultConnectionTableAdapters.ProductsTableAdapter(); return(pta.GetOneProductById(id)[0].Quantity); }