Ejemplo n.º 1
0
        private void InserirLinha(Document doc, float[] TamanhoColunas, int Borda, List <int> AlinhamentoCelula, Font Fonte, List <string> Textos)
        {
            PdfPTable pdfTable = new PdfPTable(TamanhoColunas);

            pdfTable.WidthPercentage    = 100f;
            pdfTable.DefaultCell.Border = Borda;
            int cont = 0;

            foreach (string item in Textos)
            {
                Pdf.AddCelula(AlinhamentoCelula[cont], Borda, Fonte, pdfTable, item);
                cont++;
            }

            doc.Add(pdfTable);
        }
Ejemplo n.º 2
0
        private void GeraReltatorioComprador()
        {
            string pasta = Diretorio.CaminhoSalva("Aquivos pdf|*.pdf", "", "RolComprador");

            using (var doc = new Document(iTextSharp.text.PageSize.A4, 40, 40, 50, 50))
            {
                PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(pasta, FileMode.CreateNew));
                doc.Open();

                PdfPTable pdfTable = new PdfPTable(new float[] { 100f });
                pdfTable.WidthPercentage = 100f;
                Pdf.AddCelula(1, 0, FontTitulo, pdfTable, $"Relatorio Gastros por Compradores\n\n");
                doc.Add(pdfTable);



                List <string> lista = new List <string>();
                lista = EntradaController.GetLista("Comprador");
                lista.Sort();

                double        total      = 0;
                List <string> listaTotal = new List <string>();



                if (lista.Count > 0)
                {
                    foreach (string item in lista)
                    {
                        PdfPTable pdfTable3 = new PdfPTable(new float[] { 100f });
                        pdfTable3.WidthPercentage = 100f;
                        Pdf.AddCelula(Element.ALIGN_CENTER, Rectangle.LEFT_BORDER, FontSubTitulo, pdfTable3, item);
                        doc.Add(pdfTable3);

                        PdfPTable pdfTable2 = new PdfPTable(new float[] { 20f, 60f, 20f });
                        pdfTable2.WidthPercentage = 100f;
                        Pdf.AddCelula(Element.ALIGN_CENTER, Rectangle.NO_BORDER, FontSubTitulo, pdfTable2, "DATA");
                        Pdf.AddCelula(Element.ALIGN_CENTER, Rectangle.NO_BORDER, FontSubTitulo, pdfTable2, "PRODUTO");
                        Pdf.AddCelula(Element.ALIGN_CENTER, Rectangle.NO_BORDER, FontSubTitulo, pdfTable2, "SUBTOTAL");
                        doc.Add(pdfTable2);

                        double    valor   = 0;
                        DataTable valores = EntradaController.GetSqlEntradas($"SELECT DATAENTRADA, PRODUTOID,Total FROM Entradas WHERE Comprador = '{item}' ORDER BY DATAENTRADA DESC ");


                        if (valores.Rows.Count > 0)
                        {
                            foreach (DataRow dr in valores.Rows)
                            {
                                string produto = ProdutosController.GetStringProduto(int.Parse(dr["ProdutoId"].ToString()));
                                string data    = DateTime.Parse(dr["DataEntrada"].ToString()).ToString("dd/MM/yyyy");

                                if (dr["Total"].ToString().Length > 0)
                                {
                                    valor += Convert.ToDouble(dr["Total"].ToString());
                                }

                                PdfPTable tab = new PdfPTable(new float[] { 15f, 65f, 20f });
                                tab.WidthPercentage = 100f;
                                Pdf.AddCelula(Element.ALIGN_LEFT, Rectangle.LEFT_BORDER, FontLinhas, tab, data);
                                Pdf.AddCelula(Element.ALIGN_LEFT, Rectangle.LEFT_BORDER, FontLinhas, tab, produto);
                                Pdf.AddCelula(Element.ALIGN_RIGHT, Rectangle.LEFT_BORDER, FontLinhas, tab, dr["Total"].ToString());
                                doc.Add(tab);
                            }
                        }

                        listaTotal.Add($"{item};{valor.ToString("N2")}");

                        doc.Add(Pdf.addParagrafoCentro("\n\n", Element.ALIGN_CENTER, FontTitulo));
                    }
                }


                if (listaTotal.Count > 0)
                {
                    foreach (string item in listaTotal)
                    {
                        string[] vetor = item.Split(';');

                        PdfPTable tab3 = new PdfPTable(new float[] { 80f, 20f });
                        tab3.WidthPercentage    = 100f;
                        tab3.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                        Pdf.AddCelula(Element.ALIGN_RIGHT, 0, FontLinhas, tab3, vetor[0] + ": ");
                        Pdf.AddCelula(Element.ALIGN_RIGHT, 0, FontTotais, tab3, $"R$ {vetor[1]}");
                        doc.Add(tab3);

                        total += double.Parse(vetor[1]);
                    }
                }

                PdfPTable pdfTable4 = new PdfPTable(new float[] { 70f, 30f });
                pdfTable4.WidthPercentage    = 100f;
                pdfTable4.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                Pdf.AddCelula(Element.ALIGN_RIGHT, 0, FontLinhas, pdfTable4, "");
                Pdf.AddCelula(Element.ALIGN_RIGHT, 0, FontTotais, pdfTable4, $"Total: {total.ToString("N2")}");
                doc.Add(pdfTable4);


                //doc.Add(Pdf.addParagrafoCentro("Relatório\n\n", Element.ALIGN_CENTER, FontTitulo));


                doc.Close();
                System.Diagnostics.Process.Start(pasta);
            }
        }
Ejemplo n.º 3
0
        private void GeraReltatorio()
        {
            string pasta = Diretorio.CaminhoSalva("Aquivos pdf|*.pdf", "", "");

            using (var doc = new Document(iTextSharp.text.PageSize.A4, 40, 40, 50, 50))
            {
                PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(pasta, FileMode.CreateNew));
                doc.Open();

                PdfPTable pdfTable = new PdfPTable(new float[] { 100f });
                pdfTable.WidthPercentage = 100f;
                Pdf.AddCelula(1, 0, FontTitulo, pdfTable, $"Relatorio Gastros por Fornecedores\n\n");
                doc.Add(pdfTable);

                PdfPTable pdfTable2 = new PdfPTable(new float[] { 70f, 30f });
                pdfTable2.WidthPercentage = 100f;
                Pdf.AddCelula(Element.ALIGN_CENTER, Rectangle.NO_BORDER, FontSubTitulo, pdfTable2, "FORNECEDOR");
                Pdf.AddCelula(Element.ALIGN_CENTER, Rectangle.NO_BORDER, FontSubTitulo, pdfTable2, "SUBTOTAL");
                doc.Add(pdfTable2);

                List <string> lista = new List <string>();
                lista = EntradaController.GetLista("FornecedorId");

                double    total = 0;
                DataTable dt    = new DataTable();
                dt.Columns.Add("Fornecedor");
                dt.Columns.Add("Valor");

                if (lista.Count > 0)
                {
                    foreach (string item in lista)
                    {
                        double    valor      = 0;
                        DataTable valores    = EntradaController.GetSqlEntradas($"SELECT Total FROM Entradas WHERE FornecedorId = '{item}' ORDER BY FornecedorId ");
                        string    fornecedor = EntradaController.GetString($"SELECT NomeFantasia FROM Fornecedores where Id ='{item}'", "NomeFantasia");


                        if (valores.Rows.Count > 0)
                        {
                            foreach (DataRow dr in valores.Rows)
                            {
                                if (dr["Total"].ToString().Length > 0)
                                {
                                    valor += Convert.ToDouble(dr["Total"].ToString());
                                }
                            }
                        }



                        dt.Rows.Add(fornecedor, valor.ToString("N2"));

                        total += valor;
                    }
                }

                dt.DefaultView.Sort = "Fornecedor ASC";
                dt = dt.DefaultView.ToTable();

                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        PdfPTable pdfTable3 = new PdfPTable(new float[] { 70f, 30f });
                        pdfTable3.WidthPercentage = 100f;
                        Pdf.AddCelula(Element.ALIGN_LEFT, Rectangle.LEFT_BORDER, FontLinhas, pdfTable3, dr["Fornecedor"].ToString());
                        Pdf.AddCelula(Element.ALIGN_RIGHT, Rectangle.LEFT_BORDER, FontLinhas, pdfTable3, dr["Valor"].ToString());
                        doc.Add(pdfTable3);
                    }
                }

                PdfPTable pdfTable4 = new PdfPTable(new float[] { 70f, 30f });
                pdfTable4.WidthPercentage    = 100f;
                pdfTable4.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                Pdf.AddCelula(Element.ALIGN_RIGHT, 0, FontLinhas, pdfTable4, "");
                Pdf.AddCelula(Element.ALIGN_RIGHT, 0, FontTotais, pdfTable4, $"Total: {total.ToString("N2")}");
                doc.Add(pdfTable4);


                //doc.Add(Pdf.addParagrafoCentro("Relatório\n\n", Element.ALIGN_CENTER, FontTitulo));


                doc.Close();
                System.Diagnostics.Process.Start(pasta);
            }
        }