public void CarregarDadosGrid()
        {
            try
            {
                BLL.Venda forn = new BLL.Venda();
                dataGridView1.DataSource = forn.ListarVendas(String.Empty).Tables[0];
                // textBox1.Focus();
                //a propriedade DATASOURCE do datagrid é a fonte de dados. Esta propriedade recebe (=) do objeto USU o método LISTAR usando como parametro o texto TEXT.TRIM().TOUPPER() digitado no TEXTBOX1. Esse DATASOURCE usará a tabela zero TABLES[0] do método LISTAR

                if (dataGridView1.Rows.Count == 0)
                {
                    btnAlterar.Enabled   = false;
                    btnConsultar.Enabled = false;
                    btnAtivar.Enabled    = false;
                    btnDesativar.Enabled = false;
                }
                else
                {
                    btnAlterar.Enabled   = true;
                    btnConsultar.Enabled = true;
                    btnAtivar.Enabled    = true;
                    btnDesativar.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //throw;
            }
        }
Beispiel #2
0
        public void FinalizarVenda(object o, EventArgs e)
        {
            try
            {
                BLL.Venda v = new BLL.Venda();
                v.CodigoCliente = CodigoCliente;

                v.DataVenda = DateTime.Today;



                foreach (DataGridViewRow row in dataGridView1.Rows.Cast <DataGridViewRow>()
                         .Where(t => !string.IsNullOrEmpty(t.Cells["ValorTot"].Value?.ToString())))
                {
                    totalVenda += Convert.ToDecimal(row.Cells["ValorTot"].Value);
                }

                v.ValorTotal = Convert.ToDecimal(totalVenda);
                v.IncluirComParametro();
                SalvarProdutos();
                AtualizarEstoque();
                MessageBox.Show("Venda finalizada com sucesso");

                Close();
            }
            catch (Exception ex)

            {
                throw ex;
            }
        }
        private void SalvarParcelas()
        {
            if (gbParcela.Visible == true)
            {
                try
                {
                    BLL.Venda v = new BLL.Venda();
                    DAO.ClasseParaManipularBancoDeDados c = new DAO.ClasseParaManipularBancoDeDados();

                    string comando;

                    SqlParameter[] listaComParametros =
                    {
                        new SqlParameter("@CodigoVenda", SqlDbType.Int)
                        {
                            Value = v.RetornarVenda()
                        },
                        new SqlParameter("@NumeroParcelas", SqlDbType.Int)
                        {
                            Value = Convert.ToInt32(cbParcela.SelectedItem)
                        }
                    };

                    comando = "INSERT INTO tbParcelamentoVenda(CodigoVenda,NumeroParcelas)VALUES(@CodigoVenda,@NumeroParcelas)";
                    c.ExecutarComandoParametro(comando, listaComParametros);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
 public void MostrarNumeroDeParcelas()
 {
     System.Data.SqlClient.SqlDataReader ddr;
     BLL.Venda v = new BLL.Venda();
     ddr = v.MostrarParcela();
     ddr.Read();
     if (ddr.HasRows)
     {
         lblNumeroParcelasVenda.Text    = Convert.ToString(ddr[2]) + "Vezes";
         lblParceladoEm.Visible         = true;
         lblNumeroParcelasVenda.Visible = true;
     }
 }
 public void CarregarDadosGrid()
 {
     try
     {
         BLL.Venda ven = new BLL.Venda();
         dataGridView1.DataSource = ven.ListarVendas(textBox1.Text.Trim().ToUpper()).Tables[0];
         textBox1.Focus();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         //throw;
     }
 }
        public void FinalizarVenda(object o, EventArgs e)
        {
            try
            {
                BLL.Venda v = new BLL.Venda();
                v.CodigoCliente  = Convert.ToInt32(cbCliente.SelectedValue);
                v.CodigoVendedor = Convert.ToInt32(cbVendedor.SelectedValue);
                v.DataVenda      = DateTime.Today;

                BLL.Cupom cup = new BLL.Cupom();


                v.ValorTotal = Convert.ToDouble(totalVenda);


                v.Pagamento = Convert.ToString(cbForma.SelectedItem);
                if (chkDuasFormas.Checked == true)
                {
                    v.IncluirComParametroDuasFormas();
                    v.Pagamento2 = Convert.ToString(cbForma2.SelectedItem);
                }
                else
                {
                    v.IncluirComParametro();
                }

                SalvarProdutos();
                AtualizarEstoque();
                SalvarParcelas();
                if (txtCupom.Text.Length == 0)
                {
                    MessageBox.Show("Venda finalizada com sucesso");
                }
                if (pictureBox1.ImageLocation == "c.png")
                {
                    MessageBox.Show("Venda finalizada com sucesso.O cupom " + txtCupom.Text.ToUpper() + " foi adicionado a venda gerando um desconto de " + cup.RetornarValorCupom(txtCupom.Text) + " á compra");
                }

                Close();
            }
            catch (Exception ex)

            {
                throw ex;
            }
        }
Beispiel #7
0
        private void SalvarProdutos()
        {
            BLL.Venda v = new BLL.Venda();
            int       CodigoUltimaVenda = v.RetornarVenda();
            int       CodigoProdutoGrid = 0;
            int       QuantidadeGrid    = 0;

            //foreachzinho para pegar linha por linha e depois ir inserindo na tabela linha por linha
            foreach (DataGridViewRow row in dataGridView1.Rows.Cast <DataGridViewRow>()
                     .Where(t => !string.IsNullOrEmpty(t.Cells["CodProd"].Value?.ToString())))
            {
                try
                {
                    CodigoProdutoGrid = Convert.ToInt32(row.Cells["CodProd"].Value);
                    QuantidadeGrid    = Convert.ToInt32(row.Cells["QuantProd"].Value);
                    DAO.ClasseParaManipularBancoDeDados c = new DAO.ClasseParaManipularBancoDeDados();

                    string comando;

                    SqlParameter[] listaComParametros =
                    {
                        new SqlParameter("@CodigoVenda", SqlDbType.Int)
                        {
                            Value = CodigoUltimaVenda
                        },
                        new SqlParameter("@CodigoProduto", SqlDbType.Int)
                        {
                            Value = CodigoProdutoGrid
                        },
                        new SqlParameter("@Quantidade", SqlDbType.Int)
                        {
                            Value = QuantidadeGrid
                        },
                    };

                    comando = "INSERT INTO tbItem_Venda(CodigoVenda,CodigoProduto,Quantidade) Values (@CodigoVenda,@CodigoProduto,@Quantidade)";
                    c.ExecutarComandoParametro(comando, listaComParametros);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConsultar_Click(object sender, EventArgs e)
        {
            Telas.Vender.FrmVender f = new FrmVender();
            f.button2.Visible = false;
            f.Text            = "Consultando Venda";

            f.button1.Visible = false;

            f.lblProd.Visible       = false;
            f.lblQuant.Visible      = false;
            f.lblValor.Visible      = false;
            f.label4.Visible        = false;
            f.cbForma.Visible       = false;
            f.cbProduto.Visible     = false;
            f.txtQuantidade.Visible = false;
            f.txtValor.Visible      = false;
            f.CarregarCombo(sender, e);
            f.lblCli.Text         = Convert.ToString(dataGridView1.CurrentRow.Cells[2].Value);
            f.lblVendedor.Text    = Convert.ToString(dataGridView1.CurrentRow.Cells[4].Value);
            f.lblVendedor.Visible = true;
            f.lblCli.Visible      = true;
            BLL.Venda v = new BLL.Venda();

            f.dataGridView1.Columns["CodProd"].Visible   = false;
            f.dataGridView1.Columns["NomeProd"].Visible  = false;
            f.dataGridView1.Columns["QuantProd"].Visible = false;
            f.dataGridView1.Columns["ValorTot"].Visible  = false;


            f.dataGridView1.DataSource   = v.ListarItensVenda(Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value)).Tables[0];
            f.cbCliente.Visible          = false;
            f.cbVendedor.Visible         = false;
            f.lblFormaPagamento2.Visible = true;
            f.lblValorTotal.Text         = Convert.ToString(dataGridView1.CurrentRow.Cells[5].Value);
            f.lblFormapgto2.Text         = "Cartão";
            f.lblFormapgto2.Visible      = true;



            f.MostrarNumeroDeParcelas();
            f.ShowDialog();
        }
        private void btnConsultar_Click(object sender, EventArgs e)
        {
            Venda.FrmVenda f = new Venda.FrmVenda();
            f.btnFechar.Visible = false;
            f.Text = "Consultando Venda";


            f.label1.Visible        = true;
            f.txtCliente.Visible    = false;
            f.pictureBox1.Visible   = false;
            f.pictureBox2.Visible   = false;
            f.label2.Visible        = false;
            f.cbProduto.Visible     = false;
            f.label3.Visible        = false;
            f.txtQuantidade.Visible = false;
            f.txtUnit.Visible       = false;
            f.groupBox1.Visible     = true;

            f.label4.Visible = false;


            BLL.Venda v = new BLL.Venda();

            f.dataGridView1.Columns["CodProd"].Visible   = false;
            f.dataGridView1.Columns["NomeProd"].Visible  = false;
            f.dataGridView1.Columns["QuantProd"].Visible = false;
            f.dataGridView1.Columns["ValorTot"].Visible  = false;


            f.dataGridView1.DataSource = v.ListarItensVenda(Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value)).Tables[0];

            f.lblTotal.Text              = Convert.ToString(dataGridView1.CurrentRow.Cells[1].Value);
            f.lblDataVenda.Text          = Convert.ToString(dataGridView1.CurrentRow.Cells[2].Value);
            f.lblClienteConsulta.Visible = true;
            f.label5.Text = Convert.ToString(dataGridView1.CurrentRow.Cells[4].Value);
            f.lblClienteConsulta.Visible = true;



            f.ShowDialog();
        }
Beispiel #10
0
        public void Cadastrar(BLL.Venda v)
        {
            //Cadastro do cabeçalho da venda
            int        chaveGerada;
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = con.Conectar();
            cmd.CommandText = @"INSERT INTO Venda       
                                    (CodCli, DataVenda)
                                VALUES 
                                    (@codCli, getdate());
                                
                                SELECT SCOPE_IDENTITY();";
            cmd.Parameters.AddWithValue("@codCli", v.CodCliente);
            chaveGerada = Convert.ToInt16(cmd.ExecuteScalar());

            SqlCommand cmdItens = new SqlCommand();

            cmdItens.Connection  = con.Conectar();
            cmdItens.CommandText = @"INSERT INTO VendaItens
                                        (CodVenda, CodProd, Qtd, ValorUnit)
                                    VALUES
                                        (@codVenda, @codProd, @qtd, @valorUnit)";
            cmdItens.Parameters.Add("@codVenda", SqlDbType.Int);
            cmdItens.Parameters.Add("@codProd", SqlDbType.Int);
            cmdItens.Parameters.Add("@qtd", SqlDbType.Int);
            cmdItens.Parameters.Add("@valorUnit", SqlDbType.Money);

            //Cadastro dos Itens da Venda
            foreach (BLL.VendaItens item in v.ListaDeItens)
            {
                cmdItens.Parameters["@codVenda"].Value  = chaveGerada;
                cmdItens.Parameters["@codProd"].Value   = item.CodProduto;
                cmdItens.Parameters["@qtd"].Value       = item.Qtd;
                cmdItens.Parameters["@valorUnit"].Value = item.ValorUnit;
                cmdItens.ExecuteNonQuery(); //Cadastrar o Item
            }

            con.Desconectar();
        }
        private void GerarPDF3(object o, EventArgs e)
        {
            //Cria O documento
            Document  doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 10, 35);
            PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("Venda.pdf", FileMode.Create));

            doc.Open();
            //Adiciona o logo
            iTextSharp.text.Image PNG = iTextSharp.text.Image.GetInstance("Logo.png");
            PNG.ScalePercent(85f);
            doc.Add(PNG);
            //Titulo
            Paragraph header = new Paragraph("Informações da venda ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 14f, iTextSharp.text.Font.BOLD, BaseColor.BLACK));

            header.Alignment = Element.ALIGN_LEFT;
            doc.Add(header);


            //Info sobre venda
            var blackListTextFont = FontFactory.GetFont("Calibri_BOLD", 14, BaseColor.BLACK);
            var redListTextFont   = FontFactory.GetFont("Calibri", 12, BaseColor.BLACK);

            //Cli:

            iTextSharp.text.Image cliente = iTextSharp.text.Image.GetInstance("User_32px.png");
            cliente.ScaleToFit(20f, 20f);
            Chunk imageCliente = new Chunk(cliente, 0, -4);

            var titleChunk       = new Chunk("  Cliente: ", blackListTextFont);
            var descriptionChunk = new Chunk(Convert.ToString(dataGridView1.CurrentRow.Cells[4].Value) + "\n", redListTextFont);
            var phrase           = new Phrase(imageCliente);

            phrase.Add(titleChunk);
            phrase.Add(descriptionChunk);
            doc.Add(phrase);



            //Funcionario
            iTextSharp.text.Image image3 = iTextSharp.text.Image.GetInstance("User_32px.png");
            image3.ScaleToFit(20f, 20f);
            Chunk imageChunk3 = new Chunk(image3, 0, -4);

            var FuncionarioChunk     = new Chunk("  Funcionário Responsavel: ", blackListTextFont);
            var nomeFuncionarioChunk = new Chunk(Convert.ToString(dataGridView1.CurrentRow.Cells[6].Value) + "\n", redListTextFont);
            var phraseFuncionario    = new Phrase(imageChunk3);

            phraseFuncionario.Add(FuncionarioChunk);
            phraseFuncionario.Add(nomeFuncionarioChunk);
            doc.Add(phraseFuncionario);


            //ValorDaVenda

            iTextSharp.text.Image image2 = iTextSharp.text.Image.GetInstance("Duration Finance_50px.png");
            image2.ScaleToFit(20f, 20f);
            Chunk imageChunk2       = new Chunk(image2, 0, -4);
            var   titleChunk2       = new Chunk("  Valor da Venda: ", blackListTextFont);
            var   descriptionChunk2 = new Chunk(Convert.ToString(dataGridView1.CurrentRow.Cells[1].Value) + "\n", redListTextFont);
            var   phrase2           = new Phrase(imageChunk2);

            phrase2.Add(titleChunk2);
            phrase2.Add(descriptionChunk2);
            doc.Add(phrase2);

            //DataVenda

            iTextSharp.text.Image imagemData = iTextSharp.text.Image.GetInstance("Schedule_50px.png");
            imagemData.ScaleToFit(20f, 20f);
            Chunk imagemChunkData   = new Chunk(imagemData, 0, -4);
            var   titleChunk3       = new Chunk("  Data da Venda: ", blackListTextFont);
            var   descriptionChunk3 = new Chunk(Convert.ToString(dataGridView1.CurrentRow.Cells[2].Value) + "\n", redListTextFont);
            var   phrase3           = new Phrase(imagemChunkData);

            phrase3.Add(titleChunk3);
            phrase3.Add(descriptionChunk3);
            doc.Add(phrase3);


            BLL.Venda v = new BLL.Venda();


            System.Data.SqlClient.SqlDataReader ddr;
            ddr = v.RetornarForma(Convert.ToInt16(dataGridView1.CurrentRow.Cells[0].Value));
            ddr.Read();
            if (ddr.HasRows)
            {
                //Frma
                iTextSharp.text.Image imagemPgto = iTextSharp.text.Image.GetInstance("Bank Cards_48px.png");
                imagemPgto.ScaleToFit(20f, 20f);
                Chunk imagemChunkPgto   = new Chunk(imagemPgto, 0, -6);
                var   titleChunk4       = new Chunk("  Forma de pagamento: ", blackListTextFont);
                var   descriptionChunk4 = new Chunk(ddr["Nome"] + "\n", redListTextFont);
                var   phrase4           = new Phrase(imagemChunkPgto);
                phrase4.Add(titleChunk4);
                phrase4.Add(descriptionChunk4);
                doc.Add(phrase4);
            }



            //Titulo2
            Paragraph paragraph = new Paragraph("Produtos da Venda \n              ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20f, iTextSharp.text.Font.BOLD, BaseColor.BLACK));

            paragraph.Alignment = Element.ALIGN_CENTER;
            doc.Add(paragraph);
            int CodigoVenda = 0;

            CodigoVenda = Convert.ToInt16(dataGridView1.CurrentRow.Cells[0].Value);
            ;
            dgImpressao.DataSource = v.ListarItensVenda(CodigoVenda).Tables[0];

            PdfPTable table = new PdfPTable(dgImpressao.Columns.Count);



            //table.AddCell(cell);

            for (int i = 0; i < dgImpressao.Columns.Count; i++)
            {
                table.AddCell(new Phrase(dgImpressao.Columns[i].HeaderText, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 9f, iTextSharp.text.Font.BOLD, BaseColor.BLACK)));
            }
            table.HeaderRows = 1;
            for (int i = 0; i < dgImpressao.Rows.Count; i++)
            {
                for (int k = 0; k < dgImpressao.Columns.Count; k++)
                {
                    if (dgImpressao[k, i].Value != null)
                    {
                        table.AddCell(new Phrase(dgImpressao[k, i].Value.ToString(), new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 8f, iTextSharp.text.Font.NORMAL, BaseColor.BLACK)));
                    }
                }
            }

            doc.Add(table);
            //Finaliza o pdf
            doc.Close();

            //Abre o Pdf Gerado
            System.Diagnostics.Process.Start("Venda.pdf");
        }
        private void SalvarPagamentoVenda()
        {
            try
            {
                BLL.Venda v = new BLL.Venda();
                int       CodigoUltimaVenda = v.RetornarVenda();
                if (checkBox1.Checked)
                {
                    TCC_Inf2Dm.ClasseParaManipularBancoDeDados c = new TCC_Inf2Dm.ClasseParaManipularBancoDeDados();
                    string         comando;
                    SqlParameter[] listaComParametros =
                    {
                        new SqlParameter("@CodigoVenda", SqlDbType.Int)
                        {
                            Value = CodigoUltimaVenda
                        },
                        new SqlParameter("@CodigoFormaPgto", SqlDbType.Int)
                        {
                            Value = Convert.ToInt32(comboBox1.SelectedValue)
                        },
                        new SqlParameter("@Valor", SqlDbType.Decimal)
                        {
                            Value = totalVenda / 2
                        }
                    };
                    comando = "INSERT INTO tbPgto_Venda(CodigoVenda,CodigoFormaPgto,ValorForma) Values (@CodigoVenda,@CodigoFormaPgto,@Valor)";
                    c.ExecutarComandoParametro(comando, listaComParametros);

                    SqlParameter[] listaComParametros2 =
                    {
                        new SqlParameter("@CodigoVenda", SqlDbType.Int)
                        {
                            Value = CodigoUltimaVenda
                        },
                        new SqlParameter("@CodigoFormaPgto2", SqlDbType.Int)
                        {
                            Value = Convert.ToInt32(comboBox2.SelectedValue)
                        },
                        new SqlParameter("@Valor", SqlDbType.Decimal)
                        {
                            Value = totalVenda / 2
                        }
                    };
                    comando = "INSERT INTO tbPgto_Venda(CodigoVenda,CodigoFormaPgto,ValorForma) Values (@CodigoVenda,@CodigoFormaPgto2,@Valor)";
                    c.ExecutarComandoParametro(comando, listaComParametros2);
                }
                else
                {
                    TCC_Inf2Dm.ClasseParaManipularBancoDeDados c = new TCC_Inf2Dm.ClasseParaManipularBancoDeDados();
                    string         comando;
                    SqlParameter[] listaComParametros =
                    {
                        new SqlParameter("@CodigoVenda", SqlDbType.Int)
                        {
                            Value = CodigoUltimaVenda
                        },
                        new SqlParameter("@CodigoFormaPgto", SqlDbType.Int)
                        {
                            Value = Convert.ToInt32(comboBox1.SelectedValue)
                        },
                        new SqlParameter("@Valor", SqlDbType.Decimal)
                        {
                            Value = totalVenda
                        }
                    };
                    comando = "INSERT INTO tbPgto_Venda(CodigoVenda,CodigoFormaPgto,ValorForma) Values (@CodigoVenda,@CodigoFormaPgto,@Valor)";
                    c.ExecutarComandoParametro(comando, listaComParametros);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw ex;
            }
        }