//meotodo que vou chamar no botão finalizar venda public void Atualizar(VendasDTO vendas) { try { con = new ConexaoDAL(); con.Conectar(); SqlCommand commando = new SqlCommand(); commando.Connection = con.Conexao; commando.CommandText = "UPDATE VENDAS SET CLI_CPF = @CLI_CPF,VEND_ID = @VEND_ID,VEN_DTEMISSAO = @VEN_DTEMISSAO,VEN_VALOR = @VEN_VALOR,VEN_DESCONTO = @VEN_DESCONTO,VEN_VALORPAGO = @VEN_VALORPAGO WHERE CLI_CPF = @CLI_CPF"; commando.Parameters.Add("@CLI_CPF", SqlDbType.VarChar, 15); commando.Parameters["@CLI_CPF"].Value = vendas.CLI_CPF; commando.Parameters.Add("@VEND_ID", SqlDbType.Int); commando.Parameters["@VEND_ID"].Value = vendas.VEND_ID; commando.Parameters.Add("@VEN_DTEMISSAO", SqlDbType.Date); commando.Parameters["@VEN_DTEMISSAO"].Value = vendas.VEN_DTEMISSAO; commando.Parameters.Add("@VEN_VALOR", SqlDbType.Money); commando.Parameters["@VEN_VALOR"].Value = vendas.VEN_VALOR; commando.Parameters.Add("@VEN_DESCONTO", SqlDbType.Money); commando.Parameters["@VEN_DESCONTO"].Value = vendas.VEN_DESCONTO; commando.Parameters.Add("@VEN_VALORPAGO", SqlDbType.Money); commando.Parameters["@VEN_VALORPAGO"].Value = vendas.VEN_VALORPAGO; commando.ExecuteNonQuery(); con.Desconectar(); } catch (Exception erro) { MessageBox.Show(erro.Message); } }
private void btnNovaVenda_Click(object sender, EventArgs e) { if(cBClienteVenda.Text == "") { MessageBox.Show("Selecione um Cliente para prosseguir!"); }else { VendasDTO dto = new VendasDTO(); dto.CLI_CPF = cBClienteVenda.SelectedValue.ToString(); bll.SalvarVendas(dto); gBNovaVenda.Enabled = true; btnNovaVenda.Enabled = false; cBClienteVenda.Enabled = false; btnFinalizaPedido.Enabled = true; btnNovoItem.Enabled = true; cBProdutoItem.Enabled = true; txtQuantidadeItem.Enabled = true; GerarNumero(); } }
private void btnFinalizarVenda_Click(object sender, EventArgs e) { if (txtDescontoVenda.Text == "") { MessageBox.Show("Selecione o desconto se houve para finalizar a venda!"); } else { VendasDTO dto = new VendasDTO(); dto.CLI_CPF = cBClienteVenda.SelectedValue.ToString(); dto.VEND_ID = Convert.ToInt32(cBCodVendedorVenda.SelectedValue); dto.VEN_DTEMISSAO = DateTime.Parse(dTPDataEmissaoVenda.Text); dto.VEN_VALOR = Convert.ToDecimal(txtValorVenda.Text); dto.VEN_DESCONTO = Convert.ToDecimal(txtDescontoVenda.Text); dto.VEN_VALORPAGO = Convert.ToDecimal(txtValorPagoVenda.Text); bll.Atualizar(dto); MessageBox.Show("Venda Finalizada com sucesso!"); btnNovaVenda.Enabled = true; gBNovaVenda.Enabled = true; btnFinalizaPedido.Enabled = true; btnFinalizarVenda.Enabled = false; cBClienteVenda.Enabled = true; btnDetalhe.Enabled = true; dGVendasItens.DataSource = null; //LimpaControles(); } }
//metodo que vou chamar no botão Nova Venda public void SalvarVendas(VendasDTO vendas) { try { con = new ConexaoDAL(); con.Conectar(); SqlCommand commando = new SqlCommand(); commando.Connection = con.Conexao; commando.CommandText = "INSERT INTO VENDAS(CLI_CPF)VALUES (@CLI_CPF)"; commando.Parameters.Add("@CLI_CPF", SqlDbType.VarChar, 15); commando.Parameters["@CLI_CPF"].Value = vendas.CLI_CPF; commando.ExecuteNonQuery(); con.Desconectar(); } catch (Exception erro) { MessageBox.Show(erro.Message); } }