Exemplo n.º 1
0
        private void VendaView_Load(object sender, EventArgs e)
        {
            VendaBLL vendaBLL = new VendaBLL();

            dgvVendas.DataSource = "";
            dgvVendas.DataSource = vendaBLL.Select();
        }
Exemplo n.º 2
0
        private void Vender(object sender, EventArgs e)
        {
            ProdutoBLL produtoBLL = new ProdutoBLL();
            VendaBLL   vendaBLL   = new VendaBLL();
            Produto    produto    = new Produto();
            Venda      venda      = new Venda();
            string     quantidade = "";

            quantidade = dgvProdutos.SelectedRows[0].Cells["quantidade"].Value.ToString();
            if (Int32.Parse(qtdtxt.Text) > Int32.Parse(quantidade))
            {
                MessageBox.Show("Quantidade inválida");
            }
            else
            {
                if (Int32.Parse(dgvProdutos.SelectedRows[0].Cells["id"].Value.ToString()) == 0 &&
                    Int32.Parse(dgvClientes.SelectedRows[0].Cells["id"].Value.ToString()) == 0)
                {
                    MessageBox.Show("Cliente ou Produto não Selecionado");
                }
                else
                {
                    produto            = produtoBLL.SelectById(Int32.Parse(dgvProdutos.SelectedRows[0].Cells["id"].Value.ToString()));
                    produto.Quantidade = produto.Quantidade - Int32.Parse(qtdtxt.Text);
                    produtoBLL.Update(produto);

                    venda.idcliente   = Int32.Parse(dgvClientes.SelectedRows[0].Cells["id"].Value.ToString());
                    venda.idproduto   = Int32.Parse(dgvProdutos.SelectedRows[0].Cells["id"].Value.ToString());
                    venda.NomeCliente = dgvClientes.SelectedRows[0].Cells["nome"].Value.ToString();
                    venda.NomeProduto = dgvProdutos.SelectedRows[0].Cells["nome"].Value.ToString();
                    venda.Quantidade  = Int32.Parse(qtdtxt.Text);

                    vendaBLL.Insert(venda);
                    dgvVendas.DataSource = vendaBLL.Select();
                }
            }
        }