Exemplo n.º 1
0
        private void btnRel1_Click(object sender, EventArgs e)
        {
            CAMADAS.BLL.Itens bllItem = new CAMADAS.BLL.Itens();
            List<CAMADAS.MODEL.Itens> lstItens = new List<CAMADAS.MODEL.Itens>();
            lstItens = bllItem.Select();

            lstItens = lstItens.OrderBy(d => d.entrega).ToList();
            if (dtpInicio.Value != Convert.ToDateTime("01/01/1800"))
                lstItens = lstItens.Where(it => it.entrega >= dtpInicio.Value && it.entrega <= dtpFim.Value).OrderBy(d => d.entrega).ToList();
            if (txtEmprestimo.Text != "")
                lstItens = lstItens.Where(it => it.emprestimoID == Convert.ToInt32(txtEmprestimo.Text)).OrderBy(d => d.entrega).ToList();
            if (txtEmprestimo.Text != "" && dtpInicio.Value != Convert.ToDateTime("01/01/1800"))
                lstItens = lstItens.Where(it => it.entrega >= dtpInicio.Value && it.entrega <= dtpFim.Value && it.emprestimoID == Convert.ToInt32(txtEmprestimo.Text)).OrderBy(d => d.entrega).ToList();

            //if (txtEmprestimo.Text !="")
            //    lstItens = lstItens.Where(emp => emp.emprestimoID==Convert.ToInt32(txtEmprestimo.Text)).OrderBy(d => d.entrega).ToList();
            //else if (dtpInicio.Value!= Convert.ToDateTime("01/01/1800"))
            //    lstItens = lstItens.Where(it => it.entrega>=dtpInicio.Value && it.entrega<=dtpFim.Value).OrderBy(d => d.entrega).ToList();
            //else lstItens = lstItens.OrderBy(d => d.entrega).ToList();

            string pasta = Funcoes.deretorioPasta();
            string arquivo = pasta + @"\RelItens_" + DateTime.Now.ToShortDateString().Replace("/", "_") + "_" + DateTime.Now.ToLongTimeString().Replace(":", "_") + ".xlsx";
            string arquivoPDF = pasta + @"\RelItens_" + DateTime.Now.ToShortDateString().Replace("/", "_") + "_" + DateTime.Now.ToLongTimeString().Replace(":", "_") + ".pdf";

            FileInfo caminhoNomeArquivo = new FileInfo(arquivo);
            ExcelPackage arquivoExcel = new ExcelPackage(caminhoNomeArquivo);
            ExcelWorksheet planilha = arquivoExcel.Workbook.Worksheets.Add("Plan1");

            int col = 1;
            int lin = 1;
            planilha.Cells[lin, col].Value = "ID";
            planilha.Cells[lin, ++col].Value = "EMPRÉSTIMO";
            planilha.Cells[lin, ++col].Value = "TÍTULO";
            planilha.Cells[lin, ++col].Value = "ENTREGA";

            foreach (CAMADAS.MODEL.Itens item in lstItens)
            {
                col = 1;
                planilha.Cells[++lin, col].Value = item.id;
                planilha.Cells[lin, ++col].Value = item.emprestimoID;
                planilha.Cells[lin, ++col].Value = item.titulo;
                planilha.Cells[lin, ++col].Value = item.entrega;
                planilha.Cells[lin, col].Style.Numberformat.Format = "dd-MM-yyyy";

            }

            ExcelRange rng;

            using (rng = planilha.Cells["A1:D1"])
            {
                rng.Style.Font.Size = 15;
                rng.Style.Font.Name = "Arial";
                rng.Style.Font.Bold = true;
                rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
                rng.Style.Fill.BackgroundColor.SetColor(Color.Gray);
                rng.Style.Font.Color.SetColor(Color.White);

            }
            using (rng = planilha.Cells["A2:D"+lin.ToString()])
            {
                rng.Style.Font.Bold = false;
                rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
                rng.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                rng.Style.Font.Color.SetColor(Color.Black);

            }

            planilha.Cells.AutoFitColumns();

            planilha.Cells[++lin, 1].Value = "Gerado em " + DateTime.Now.ToString();
            arquivoExcel.Save();
            arquivoExcel.Dispose();

            Workbook workbook = new Workbook();
            //Load excel file
            workbook.LoadFromFile(arquivo);
            //Save excel file to pdf file.
            Worksheet worksheet = workbook.Worksheets[0];
            PageSetup setup = worksheet.PageSetup;
            setup.FitToPagesWide = 1;
            setup.FitToPagesTall = 1;
            workbook.SaveToFile(arquivoPDF, Spire.Xls.FileFormat.PDF);

            System.Diagnostics.Process.Start(arquivo);
        }
Exemplo n.º 2
0
        public static void relLivros()
        {
            CAMADAS.BLL.Livros          bllLivro  = new CAMADAS.BLL.Livros();
            List <CAMADAS.MODEL.Livros> lstLivros = new List <CAMADAS.MODEL.Livros>();

            lstLivros = bllLivro.Select().OrderByDescending(o => o.situacao).ThenBy(e => e.editora.ToLower()).ThenByDescending(t => t.titulo).ToList();

            string       pasta   = Funcoes.deretorioPasta();
            string       arquivo = pasta + @"\RelLivros.html";
            string       arqpdf  = pasta + @"\RelLivros.pdf";
            StreamWriter sw      = new StreamWriter(arquivo);

            using (sw) {
                sw.WriteLine("<html>");
                sw.WriteLine("<head>");
                sw.WriteLine("<meta http-equiv = 'Content-Type' " +
                             "content='text/html; charset=utf-8'/>");
                sw.WriteLine("<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css' integrity='sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T' crossorigin='anonymous'>");

                sw.WriteLine("</head>");
                sw.WriteLine("<body>");
                sw.WriteLine("<h1> Relatório de Livros</h1>");
                sw.WriteLine("<hr align='left' border:'5px' />");
                sw.WriteLine("</br>");
                sw.WriteLine("<table class='table table-striped'>");
                sw.WriteLine("<thead>");

                sw.WriteLine("<tr align='right'>");
                sw.WriteLine("<th  align='right' width='40px'>");
                sw.WriteLine("ID");
                sw.WriteLine("</th>");
                sw.WriteLine("<th  align='right' width='250px'>");
                sw.WriteLine("TÍTULO");
                sw.WriteLine("</th>");
                sw.WriteLine("<th  align='right' width='200px'>");
                sw.WriteLine("EDITORA");
                sw.WriteLine("</th>");
                sw.WriteLine("<th  align='right' width='250px'>");
                sw.WriteLine("AUTOR");
                sw.WriteLine("</th>");
                sw.WriteLine("<th  align='right' width='150px'>");
                sw.WriteLine("VALOR");
                sw.WriteLine("</th>");
                sw.WriteLine("<th align='right' width='60px'>");
                sw.WriteLine("SITUAÇÃO");
                sw.WriteLine("</th>");
                sw.WriteLine("</tr>");
                sw.WriteLine("</thead>");

                int   cont  = 0;
                float total = 0;
                sw.WriteLine("<tbody>");
                foreach (CAMADAS.MODEL.Livros livro in lstLivros)
                {
                    sw.WriteLine("<tr>");
                    sw.WriteLine("<td  align='right' width='40px'>");
                    sw.WriteLine(livro.id);
                    sw.WriteLine("</td>");
                    sw.WriteLine("<td  align='right' width='250px'>");
                    sw.WriteLine(livro.titulo);
                    sw.WriteLine("</td>");
                    sw.WriteLine("<td  align='right' width='200px'>");
                    sw.WriteLine(livro.editora);
                    sw.WriteLine("</td>");
                    sw.WriteLine("<td align='right' width='250px'>");
                    sw.WriteLine(livro.autor);
                    sw.WriteLine("</td>");
                    sw.WriteLine("<td  align='right' width='150px'>");
                    sw.WriteLine(string.Format("{0:C2}", livro.valor));
                    sw.WriteLine("</td>");
                    sw.WriteLine("<td align='right' width='60px'>");
                    sw.WriteLine(livro.situacao);
                    sw.WriteLine("</td>");
                    sw.WriteLine("</tr>");
                    total = total + livro.valor;
                    cont++;
                }
                sw.WriteLine("<tbody>");
                sw.WriteLine("</table> ");
                sw.WriteLine("<hr align='left' border:'5px' />");
                sw.WriteLine("<h2>Foram impressos {0} livros", cont);
                sw.WriteLine("<h2>Valor dos livros impresssos: " + string.Format("{0:R$ #,#.00}", total));
                sw.WriteLine("");

                sw.WriteLine("</body>");
                sw.WriteLine("</html>");
            }

            System.Diagnostics.Process.Start(arquivo);

            var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();

            htmlToPdf.CustomWkHtmlArgs = "--dpi 300";
            htmlToPdf.GeneratePdfFromFile(arquivo, null, arqpdf);
        }
Exemplo n.º 3
0
        public static void relLivro()
        {
            CAMADAS.BLL.Livros          bllLivro  = new CAMADAS.BLL.Livros();
            List <CAMADAS.MODEL.Livros> lstLivros = new List <CAMADAS.MODEL.Livros>();

            lstLivros = bllLivro.Select();

            string pasta      = Funcoes.deretorioPasta();
            string arquivo    = pasta + @"\RelLivros_" + DateTime.Now.ToShortDateString().Replace("/", "_") + "_" + DateTime.Now.ToLongTimeString().Replace(":", "_") + ".html";
            string arquivoPDF = pasta + @"\RelLivros_" + DateTime.Now.ToShortDateString().Replace("/", "_") + "_" + DateTime.Now.ToLongTimeString().Replace(":", "_") + ".pdf";


            StreamWriter sw = new StreamWriter(arquivo);

            using (sw)
            {
                sw.WriteLine("<html>");
                sw.WriteLine("<head>");
                sw.WriteLine("<meta http-equiv='Content-Type' " +
                             "content='text/html; charset=utf-8'/>");
                sw.WriteLine("<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css' integrity='sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T' crossorigin='anonymous'>");

                sw.WriteLine("</head>");

                sw.WriteLine("<body>");
                sw.WriteLine("<h1>Relatório de Livros</h1>");
                sw.WriteLine("<hr align='left' border:'5px' />");

                sw.WriteLine("<table class='table table-striped'>");
                //Cabeçalho da tabela

                sw.WriteLine("<tr align='right'>");
                sw.WriteLine("<th align='right' width='30px'>");
                sw.WriteLine("ID");
                sw.WriteLine("</th>");
                sw.WriteLine("<th align='right' width='250px'>");
                sw.WriteLine("TITULO");
                sw.WriteLine("</th>");
                sw.WriteLine("<th align='right' width='150px'>");
                sw.WriteLine("EDITORA");
                sw.WriteLine("</th>");
                sw.WriteLine("<th  align='right' width='150px'>");
                sw.WriteLine("AUTOR");
                sw.WriteLine("</th>");
                sw.WriteLine("<th  align='right' width='150px'>");
                sw.WriteLine("VALOR");
                sw.WriteLine("</th>");
                sw.WriteLine("<th align='right' width='60px'>");
                sw.WriteLine("SITUAÇÃO");
                sw.WriteLine("</th>");
                sw.WriteLine("</tr>");

                int   cont = 0;
                float soma = 0;
                foreach (CAMADAS.MODEL.Livros livro in lstLivros.OrderBy(o => o.situacao).ThenBy(t => t.autor).ThenBy(w => w.titulo))
                {
                    sw.WriteLine("<tr>");
                    sw.WriteLine("<td align='right' width='30px'>");
                    sw.WriteLine(livro.id);
                    sw.WriteLine("</td>");
                    sw.WriteLine("<td align='right' width='250px'>");
                    sw.WriteLine(livro.titulo);
                    sw.WriteLine("</td>");
                    sw.WriteLine("<td align='right' width='150px'>");
                    sw.WriteLine(livro.editora);
                    sw.WriteLine("</td>");
                    sw.WriteLine("<td  align='right' width='150px'>");
                    sw.WriteLine(livro.autor);
                    sw.WriteLine("</td>");
                    sw.WriteLine("<td  align='right' width='150px'>");
                    sw.WriteLine(string.Format("{0:C2}", livro.valor));
                    sw.WriteLine("</td>");
                    sw.WriteLine("<td align='right' width='60px'>");
                    sw.WriteLine(livro.situacao);
                    sw.WriteLine("</td>");
                    sw.WriteLine("</tr>");
                    soma = soma + livro.valor;
                    cont++;
                }



                sw.WriteLine("");
                sw.WriteLine("");
                sw.WriteLine("</table>");
                sw.WriteLine("<hr align='left' border:'5px' />");
                sw.WriteLine("<h2>");
                sw.WriteLine("Total de Registros Impressos: " + cont.ToString());
                sw.WriteLine("</br>");
                sw.WriteLine("Valor total dos Livros R$: " + string.Format("{0:#.#,00}", soma));
                sw.WriteLine("</body>");
                sw.WriteLine("</h2>");
                sw.WriteLine("</html>");
            }
            System.Diagnostics.Process.Start(arquivo);

            var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();

            htmlToPdf.CustomWkHtmlArgs = "--dpi 300";
            htmlToPdf.GeneratePdfFromFile(arquivo, null, arquivoPDF);
        }