private SaleCartItem Displayitem(GridViewRow row) { var id = row.FindControl("ProductIDLabel") as Label; var name = row.FindControl("ProductLabel") as Label; var qty = row.FindControl("QuantityTextBox") as TextBox; var price = row.FindControl("PriceLabel") as Label; var result = new SaleCartItem { ProductID = int.Parse(id.Text), ProductName = name.Text, Quantity = int.Parse(qty.Text), Price = decimal.Parse(price.Text), Amount = decimal.Parse(price.Text) * int.Parse(qty.Text) }; return(result); }
protected void AddButton_Click(object sender, EventArgs e) { var controller = new SalesController(); var qty = int.Parse(QtyTextBox.Text); var existing = SaleCartItemsGridView.TemplateControl.FindControl("ProductLabel") as Label; if (CategoryList.SelectedIndex == 0) { MessageUserControl.ShowInfo("please select a product"); } else { if (qty <= 0) { var product = controller.GetProduct(int.Parse(productList.SelectedValue)); QtyTextBox.Text = 1.ToString(); if (existing == null) { var item = new SaleCartItem { ProductID = product.ProductID, ProductName = product.ItemName, Quantity = int.Parse(QtyTextBox.Text), Price = product.ItemPrice, Amount = product.ItemPrice * int.Parse(QtyTextBox.Text), }; var salecart = Loopform(); salecart.Add(item); SaleCartItemsGridView.DataSource = salecart; SaleCartItemsGridView.DataBind(); MessageUserControl.ShowInfo("Add item to cart success "); MoneyTotal(); } else { MessageUserControl.ShowInfo("item already in cart "); } } else { var product = controller.GetProduct(int.Parse(productList.SelectedValue)); var item = new SaleCartItem { ProductID = product.ProductID, ProductName = product.ItemName, Quantity = qty, Price = product.ItemPrice, Amount = product.ItemPrice * qty, }; var salecart = Loopform(); salecart.Add(item); SaleCartItemsGridView.DataSource = salecart; SaleCartItemsGridView.DataBind(); MessageUserControl.ShowInfo("Add item to cart success "); MoneyTotal(); } } }