示例#1
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);
            }
        }
示例#2
0
        // Ação para efetuar a venda
        private void BtnOk_Click(object sender, EventArgs e)
        {
            try
            {
                int var = 0;

                for (int i = 0; i <= Convert.ToInt32(txtRow.Text) - 1; i++)
                {
                    var += 1;

                    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);

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

                        ItemDeVenda ivenda = new ItemDeVenda();
                        ivenda.IdVenda = venda.Codigo;
                        ivenda.Qtd     = Convert.ToInt32(dataGridView1.Rows[i].Cells[5].Value);

                        if (Convert.ToString(dataGridView1.Rows[i].Cells[4].Value) != "Produto da casa")
                        {
                            ivenda.IdProduto = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);

                            if (ivenda.Inserir() == 1)
                            {
                                Produto produto = new Produto();

                                //atualizando a quantidade em estoque dos produtos
                                produto.Codigo = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);

                                if (Convert.ToString(dataGridView1.Rows[i].Cells[4].Value) != "Produto da casa")
                                {
                                    produto.NovaQtd(Convert.ToInt32(dataGridView1.Rows[i].Cells[5].Value));
                                }
                            }
                            else
                            {
                                MessageBox.Show("Erro ao concluir venda.", "Erro",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            ivenda.IdProdCasa = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);


                            if (ivenda.Inserir2() == 1)
                            {
                                Produto produto = new Produto();

                                //atualizando a quantidade em estoque dos produtos
                                produto.Codigo = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);

                                if (Convert.ToString(dataGridView1.Rows[i].Cells[4].Value) != "Produto da casa")
                                {
                                    produto.NovaQtd(Convert.ToInt32(dataGridView1.Rows[i].Cells[5].Value));
                                }
                            }
                            else
                            {
                                MessageBox.Show("Erro ao concluir venda.", "Erro",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }

                    if (i == Convert.ToInt32(txtRow.Text) - 1 && var > 0)
                    {
                        MessageBox.Show("Venda realizada com sucesso.");

                        Close();

                        FrmNovaVenda tela = new FrmNovaVenda();
                        tela.Show();
                    }
                }

                if (var == 0)
                {
                    MessageBox.Show("A fila está vazia.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }