protected void gridProdutos_RowCommand(object sender, GridViewCommandEventArgs e) { Produto produto = ProdutoBS.Read(Convert.ToInt32(e.CommandArgument)); switch (e.CommandName) { case "EditProduto": txtNome.Text = produto.Nome; txtValor.Text = produto.Valor.ToString(); try { list_fornecedor.SelectedValue = produto.IdFornecedor.ToString(); } catch (Exception) { } SetEditMode(produto.Id); break; case "DeleteProduto": ProdutoBS.Delete(produto); SetEditMode(-1); ReloadGrid(); break; } ClearLabel(); }
private void RenderItensTable() { DataTable dt = new DataTable(); dt.Clear(); dt.Columns.Add("ID", typeof(int)); dt.Columns.Add("Produto", typeof(String)); dt.Columns.Add("Quantidade", typeof(int)); dt.Columns.Add("Valor", typeof(float)); List <Itens> carrinho = Session["carrinhoCompras"] as List <Itens>; if (carrinho == null) { carrinho = new List <Itens>(); } foreach (var item in carrinho) { DataRow row = dt.NewRow(); row["ID"] = item.IdProduto; row["Produto"] = ProdutoBS.Read(item.IdProduto).Nome; row["Quantidade"] = item.Quantidade; row["Valor"] = item.Valor; dt.Rows.Add(row); } gridCarrinho.DataSource = dt; gridCarrinho.DataBind(); RenderFinishTransaction(); }
protected void gridProdutos_RowCommand(object sender, GridViewCommandEventArgs e) { Produto produto = ProdutoBS.Read(Convert.ToInt32(e.CommandArgument)); switch (e.CommandName) { case "SelectProduto": txtNomeProduto.Text = produto.Nome; txtPrecoProduto.Text = string.Format("{0:C}", produto.Valor); txtIdProduto.Text = produto.Id.ToString(); txtQuantidade.Text = "1"; break; } }
protected void btnCadastro_Click(object sender, EventArgs e) { if (!ValidateFields()) { lblResultado.Text = "<div class=\"alert alert-danger\" role=\"alert\">Dados Inválidos, os campos não podem ser vazios!!</div>"; return; } if (!ValidateNumber()) { lblResultado.Text = "<div class=\"alert alert-danger\" role=\"alert\">Valor inválido, verifique e tente novamente!</div>"; return; } if (editMode == -1) { try { ProdutoBS.Create(new Produto(txtNome.Text, float.Parse(txtValor.Text), Convert.ToInt32(list_fornecedor.SelectedValue))); lblResultado.Text = "<div class=\"alert alert-success\" role=\"alert\">Produto cadastrado com sucesso!</div>"; } catch (Exception) { lblResultado.Text = "<div class=\"alert alert-danger\" role=\"alert\">Produto já cadastrado!</div>"; } } else { try { ProdutoBS.Update(new Produto(txtNome.Text, float.Parse(txtValor.Text), Convert.ToInt32(list_fornecedor.SelectedValue)) { Id = editMode }); lblResultado.Text = "<div class=\"alert alert-success\" role=\"alert\">Produto alterado com sucesso!</div>"; } catch (Exception) { lblResultado.Text = "<div class=\"alert alert-danger\" role=\"alert\">Produto já cadastrado!</div>"; } } SetEditMode(-1); ReloadGrid(); ClearFields(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["carrinhoCompras"] != null) { carrinho = Session["carrinhoCompras"] as List <Itens>; } gridProdutos.DataSource = ProdutoBS.getAll(); gridProdutos.DataBind(); if (!IsPostBack) { list_clientes.DataSource = ClienteBS.GetAll(); list_clientes.DataTextField = "cpfCliente"; list_clientes.DataValueField = "idCliente"; list_clientes.DataBind(); } RenderItensTable(); RenderFinishTransaction(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["VendaDetalhes"] != null) { Venda venda = VendaBS.Read(Convert.ToInt32(Session["VendaDetalhes"])); Cliente cliente = ClienteBS.Read(venda.IdCliente); table_div.InnerHtml += "<table class=\"table\">"; table_div.InnerHtml += $"<tr> <td>ID da Venda</td ><td>{venda.Id}</td > </tr>"; table_div.InnerHtml += $"<tr> <td>CPF do Cliente</td ><td>{cliente.CPF}</td > </tr>"; table_div.InnerHtml += $"<tr> <td>Nome do Cliente</td ><td>{cliente.Nome}</td > </tr>"; table_div.InnerHtml += $"<tr> <td>Data da Venda</td ><td>{venda.Data}</td > </tr>"; table_div.InnerHtml += $"<tr> <td>Valor total</td ><td>{string.Format("{0:C}", venda.ValorTotal)}</td > </tr>"; table_div.InnerHtml += "</table>"; List <Itens> itens = VendaBS.GetAllItensVenda(venda.Id); table_itens_div.InnerHtml += "<table class=\"table view-table\">"; table_itens_div.InnerHtml += "<tr> <th>Produto</th> <th>Quantidade</th> <th>Valor Total</th> </tr>"; foreach (var item in itens) { table_itens_div.InnerHtml += $"<tr> <td>{ProdutoBS.Read(item.IdProduto).Nome} </td> <td>{item.Quantidade} </td> <td>{string.Format("{0:C}", item.Valor)}</td> </tr>"; } table_div.InnerHtml += "</table>"; } }
public ProdutoService() { produtoBS = new ProdutoBS(); }
private void ReloadGrid() { gridProdutos.DataSource = ProdutoBS.getAll(); gridProdutos.DataBind(); }