예제 #1
0
        public void RelatorioLista()
        {
            byte[] bPDF = null;

            MemoryStream ms = new MemoryStream();
            TextReader txtReader = new StringReader("");

            // 1: create object of a itextsharp document class
            Document doc = new Document(PageSize.A4, 5, 5, 25, 70);

            // 2: we create a itextsharp pdfwriter that listens to the document and directs a XML-stream to a file
            PdfWriter oPdfWriter = PdfWriter.GetInstance(doc, ms);

            oPdfWriter.PageEvent = new Paginacao();

            // 3: we create a worker parse the document
            HTMLWorker htmlWorker = new HTMLWorker(doc);

            // 4: we open document and start the worker on the document
            doc.Open();

            //doc.NewPage();
            //doc.Add(new Paragraph("CAPA RELATORIO PROCESSOS");

            /*var paragrafo = new Paragraph("CAPA RELATORIO PROCESSOS", new Font(Font.NORMAL, 24));
            //etipulando o alinhamneto
            paragrafo.Alignment = Element.ALIGN_CENTER;
            paragrafo.Font = new Font(Font.FontFamily.HELVETICA);
            doc.Add(paragrafo);*/

            /*var paragrafo2 = new Paragraph(doc.PageNumber.ToString(), new Font(Font.NORMAL, 8));
            paragrafo2.Alignment = Element.ALIGN_CENTER;
            paragrafo2.Font = new Font(Font.FontFamily.HELVETICA);
            doc.Add(paragrafo2);*/

            //doc.NewPage();

            doc.Add(new Paginacao().Paragrafo("Gerenciamento Eletrônico de Documentos \n", 18f));

            doc.Add(new Paginacao().Paragrafo("Sesconti Servicos \n", 18f));

               /* var paragrafo = new Paragraph("RELATÓRIO LICITAÇÃO \n", new Font(Font.NORMAL, 24));
            paragrafo.Alignment = Element.ALIGN_CENTER;
            paragrafo.Font = new Font(Font.FontFamily.HELVETICA);
            doc.Add(paragrafo);*/

            var _flt = (Filtro)Session["Filtro"];

            /*var municipio = new Paragraph("Município: " + new Entidade().NomeEntidade()+"\n", new Font(Font.NORMAL, 10f));
            municipio.Alignment = Element.ALIGN_CENTER;
            municipio.Font = new Font(Font.FontFamily.HELVETICA);
            doc.Add(municipio);*/

            doc.Add(new Paginacao().Paragrafo("Município: " + new Entidade().NomeEntidade() + "\n", 10f));

            if (_flt.UnidadeGestora > 0)
            {
                doc.Add(new Paginacao().Paragrafo("Unidade Gestora: "+ _flt.CodigoNomeUnidadeGestora+"\n", 10f));
            }
            if (_flt.DataRefDoc!="")
            {
                doc.Add(new Paginacao().Paragrafo("Referente MESANO: " + new Funcoes().MMAAAA(_flt.DataRefDoc) + "\n", 10f));
            }
            if (_flt.DataInicio != "")
            {
                var periodo = new Paragraph("Período: " + new Funcoes().DDMMAAAA(_flt.DataInicio) + " à " + new Funcoes().DDMMAAAA(_flt.DataFim) + "\n", new Font(Font.NORMAL, 10f));
                periodo.Alignment = Element.ALIGN_CENTER;
                periodo.Font = new Font(Font.FontFamily.HELVETICA);
                doc.Add(periodo);
            }
            if (_flt.Tipo != 0)
            {
                doc.Add(new Paginacao().Paragrafo("Documentos: " + new Retorno().TipoDocumento(_flt.Tipo) + "\n", 10f));
            }

            doc.Add(new Paginacao().Paragrafo("___________________________________________________________________________________________ \n", 10f));

            PdfPTable tbl = new PdfPTable(6); //3 é quantidade de colunas
            float[] anchoDeColumnas = new float[] { 50f, 60f, 40f, 160f, 55f, 45f };
            tbl.SetWidths(anchoDeColumnas);
            tbl.DefaultCell.Border = Rectangle.NO_BORDER;

            /*tbl.AddCell("TESTE 1");
            tbl.AddCell("TESTE 2");
            tbl.AddCell("Grupo Teste da Silva Rodrigues LDTA");
            tbl.AddCell("TESTE 4");
            tbl.AddCell("TESTE 5");
            tbl.AddCell("TESTE 6");*/

            Filtro flt = (Filtro)Session["Filtro"];
            if (flt != null)
            {
               var lista = new DAO.Licitacao().ListaLicitacaoFiltro(flt);

               tbl.AddCell(new Paginacao().ColCabecalho("Num.Proc."));
               tbl.AddCell(new Paginacao().ColCabecalho("Modalidade"));
               tbl.AddCell(new Paginacao().ColCabecalho("Dt.Real"));
               tbl.AddCell(new Paginacao().ColCabecalho("Descrição do Objeto"));
               tbl.AddCell(new Paginacao().ColCabecalho("Unid.Gestora"));
               tbl.AddCell(new Paginacao().ColCabecalho("Quant.Doc"));
               int totDocs = 0;
               int reg = 0;
               foreach (var lst in lista)
               {
                   PdfPCell cell1 = new PdfPCell(new Phrase(lst.NUMPROC.ToString(), new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL)));
                   cell1.Border = 0;
                   tbl.AddCell(cell1);

                   PdfPCell cell2 = new PdfPCell(new Phrase(lst.MOLMODALIDADE.ToString(), new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL)));
                   cell2.Border = 0;
                   tbl.AddCell(cell2);

                   PdfPCell cell3 = new PdfPCell(new Phrase(lst.DTREAL.ToString(), new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL)));
                   cell3.Border = 0;
                   tbl.AddCell(cell3);

                   PdfPCell cell4 = new PdfPCell(new Phrase(lst.DESCOBJ.ToString(), new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL)));
                   cell4.Border = 0;
                   tbl.AddCell(cell4);

                   string ungs = new Licitacao().RetornaUnidadeGestora(lst.ID).ToString();
                   PdfPCell cell5 = new PdfPCell(new Phrase(ungs, new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL)));
                   cell5.Border = 0;
                   tbl.AddCell(cell5);

                   string qtdimg = lst.QTDIMG.ToString();
                   PdfPCell cell6 = new PdfPCell(new Phrase(qtdimg, new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL)));
                   cell6.Border = 0;
                   tbl.AddCell(cell6);

                   totDocs += int.Parse(qtdimg);
                   reg++;
                   //PdfPCell cell = new PdfPCell(new Phrase("TESTE 7", new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL, BaseColor.BLACK)));
                   //cell.Border = 0;
                   //tbl.AddCell(cell);
               }
               doc.Add(tbl);

               doc.Add(new Paginacao().Paragrafo("\n\n", 10f));
               doc.Add(new Paginacao().Paragrafo("___________________________________________________________________________________________ \n\n", 10f));
               doc.Add(new Paginacao().Paragrafo("Total de processos listados: " + reg.ToString() + "        Total Documentos: " + totDocs.ToString() + "\n", 10f));

               doc.NewPage();

               htmlWorker.StartDocument();

               // 5: parse the html into the document
               htmlWorker.Parse(txtReader);

               // 6: close the document and the worker
               htmlWorker.EndDocument();
               htmlWorker.Close();
               doc.Close();

               bPDF = ms.ToArray();

               Response.Clear();
               Response.ContentType = "application/pdf";
               Response.AddHeader("content-disposition", "attachment;filename=" + "RelLicitacao.pdf");
               Response.Cache.SetCacheability(HttpCacheability.NoCache);
               Response.BinaryWrite(bPDF);
               Response.End();
            }
            else
            {
                TempData["MsgErro"] = "Sem registros para listar em relatório...";
            }
            //return RedirectToAction("Index");
        }
예제 #2
0
        public ActionResult EnviarPDF(int? licID)
        {
            string pdfpath = "";
            string _nomearquivo = "";
            try
            {
                var docs = db.LICITACAODOCS.Where(d => d.DOC_LIC_ID == licID).ToList();
                string _arquivo = "";
                string path = HttpContext.Server.MapPath("~/DOCS/");
                var lic = new Licitacao(licID);
                string _numproc = lic.TLicitacao.NUMPROC.ToString(); //db.LICITACAO.FirstOrDefault(l => l.ID == licID).NUMPROC.ToString();
                string _diamesano = new DAO.Documento().DiaMesAnoAtual();
                pdfpath = HttpContext.Server.MapPath("~/PDF/") + SoNumeros(_numproc) +"_"+ _diamesano + ".pdf";
                _nomearquivo = SoNumeros(_numproc) + "_" + _diamesano + ".pdf";
                //string pdfpath = HttpContext.Server.MapPath("~/PDF/") + procID.ToString() + ".pdf";

                if (System.IO.File.Exists(pdfpath))
                {
                    System.IO.File.Delete(pdfpath);
                }

                using (var doc = new iTextSharp.text.Document())
                {
                    if (doc.IsOpen()) doc.Close();
                    iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream(pdfpath, FileMode.Create));
                    doc.Open();

                    //DADOS CAPA
                    doc.Add(new Paginacao().ParagrafoNegrito("ESTADO DO CEARÁ \n\n", 24f));
                    doc.Add(new Paginacao().ParagrafoNegrito(new Entidade().NomeEntidade() + "\n\n\n", 24f));
                    doc.Add(new Paginacao().ParagrafoNegrito("PROCESSO DE LICITATÓRIO \n\n", 24f));

                    doc.Add(new Paginacao().ParagrafoNegrito("Exercício:" + new Funcoes().MMAAAA(lic.TLicitacao.DTREFDOC.ToString()) + " \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", 24f));

                    Single _tamfont = 10f;
                    var fun = new Funcoes();

                    doc.Add(new Paginacao().Paragrafo("Modalidade: " + fun.NaoNull(lic.TLicitacao.MOLMODALIDADE.ToString()) + "", _tamfont, 1));
                    doc.Add(new Paginacao().Paragrafo("Data Realização: " + fun.NaoNull(lic.TLicitacao.DTREAL.ToString()) + "", _tamfont, 1));

                    doc.Add(new Paginacao().Paragrafo("Participantes: " + fun.NaoNull(lic.Participantes) + "", _tamfont, 1));

                    doc.Add(new Paginacao().Paragrafo("Descrição do Objeto: " + fun.NaoNull(lic.TLicitacao.DESCOBJ.ToString()) + "", _tamfont, 1));

                    doc.Add(new Paginacao().Paragrafo("\n\n\n\n\n\n\n\n", _tamfont, 1));
                    doc.Add(new Paginacao().Paragrafo("Ged SESCONTI", _tamfont, 0));
                    doc.Add(new Paginacao().Paragrafo("Emissão em " + Funcoes.DataAtual(), _tamfont, 0));

                    doc.NewPage();

                    foreach (var itm in docs)
                    {
                        _arquivo = path + itm.DOC_ARQUIVO;
                        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(_arquivo);

                        image.ScaleToFit(doc.PageSize.Width - 120, doc.PageSize.Height - 80);
                        image.ScaleAbsoluteHeight(doc.PageSize.Height - 80);
                        image.ScaleAbsoluteWidth(doc.PageSize.Width - 80);

                        doc.Add(image);
                    }

                }

                TempData["MsgFixa"] = "Documentos gravados em "+ pdfpath +" com sucesso.";
            }
            catch (Exception ex)
            {
                TempData["MsgErro"] = "Occoreu um erro: " + ex.Message;
            }

            return RedirectToAction("Edit", new { id = licID, arqpdf=_nomearquivo });
        }