Ejemplo n.º 1
0
        private void realizarVendaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmNovaVenda tela = new frmNovaVenda();

            tela.Show();

            Close();
        }
Ejemplo n.º 2
0
        private void BtnOk_Click(object sender, EventArgs e)
        {
            Produto produto = new Produto();

            for (int i = 0; i <= Convert.ToInt32(txtRow.Text) - 1; i++)
            {
                //atualizando a quantidade em estoque dos produtos
                produto.Id = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);
                produto.NovaQtd(Convert.ToInt32(dataGridView1.Rows[i].Cells[5].Value));
            }

            Venda venda = new Venda();

            venda.Data  = DateTime.Now; //pega a data e hora em que foi realizado a venda
            venda.Valor = Convert.ToDouble(txtTotal.Text);

            try
            {
                if (venda.Inserir() == 1)
                {
                    venda.PegaId();

                    ItemDeVenda ivenda = new ItemDeVenda();
                    ivenda.IdVenda = venda.Codigo;

                    for (int i = 0; i <= Convert.ToInt32(txtRow.Text) - 1; i++)
                    {
                        if (Convert.ToString(dataGridView1.Rows[i].Cells[0].Value) != "X")
                        {
                            ivenda.IdProduto = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);
                            ivenda.Qtd       = Convert.ToInt32(dataGridView1.Rows[i].Cells[5].Value);
                            ivenda.Inserir();
                        }
                        else
                        {
                            MessageBox.Show("ok");
                        }
                    }

                    MessageBox.Show("Venda realizada com sucesso.");

                    Close();
                    frmNovaVenda tela = new frmNovaVenda();
                    tela.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }