public PDFDadosExame ConsultarDadosExamePreencherPDF(int idExame, int idConsulta) { try { MySqlConnection connection = new MySqlConnection(getStringConnection()); connection.Open(); var DALSQL = new PDFDALSQL(); MySqlCommand cmdDadosExame = new MySqlCommand(DALSQL.ConsultarDadosExamePreencherPDF(), connection); cmdDadosExame.Parameters.AddWithValue("@IDBASENOMEEXAME", idExame); cmdDadosExame.Parameters.AddWithValue("@IDCONSULTA", idConsulta); var teste = getGeneratedSql(cmdDadosExame); MySqlDataReader reader = cmdDadosExame.ExecuteReader(); PDFDadosExame dadosExame = new PDFDadosExame(); if (reader.HasRows) { while (reader.Read()) { dadosExame.nome = reader.GetString(0); dadosExame.rg = reader.GetString(1); dadosExame.dataNascimento = reader.GetDateTime(2); dadosExame.dataConsulta = reader.GetDateTime(3); dadosExame.baseNomeExame = reader.GetString(4); } reader.Close(); connection.Close(); } else { dadosExame = null; reader.Close(); connection.Close(); } return(dadosExame); } catch (Exception ex) { throw ex; } }
public IActionResult BaixarExamePDF(int id, string username) { try { ViewBag.MensagemBodyController = ""; ViewBag.MensagemBodyAction = ""; ViewBag.MensagemBody = ""; CarregarDadosUsuarioParaTela(); if ((ViewData["idUsuario"] != null) && ((int)ViewData["idUsuario"] != 0)) { if ((int)ViewData["flPacienteC"] != 0 && (int)ViewData["flExamesC"] != 0) { MemoryStream workStream = new MemoryStream(); DateTime dTime = DateTime.Now; Document doc = CriarDocumentoPDF(true); PdfWriter.GetInstance(doc, workStream).CloseStream = false; string strPDFFileName; if (id != 0 && username != null) { PDFBLL pdfBLL = new PDFBLL(); PDFDadosExame dadosExame = new PDFDadosExame(); dadosExame = pdfBLL.ConsultarDadosExamePreencherPDF(Convert.ToInt32(id), Convert.ToInt32(username)); strPDFFileName = string.Format("Solicitação Exame do Paciente " + dadosExame.nome + ".pdf"); if (dadosExame != null) { doc = LayoutPDFExame(doc, dadosExame); } else { HttpContext.Session.SetString("MensagemTitle", "Erro na consulta dos dados"); HttpContext.Session.SetString("MensagemBody", "Verifique os parametros passados!"); return(RedirectToAction("Index", "Home")); } } else { HttpContext.Session.SetString("MensagemTitle", "Erro na consulta dos dados"); HttpContext.Session.SetString("MensagemBody", "Verifique os parametros passados na URL!"); return(RedirectToAction("Index", "Home")); } byte[] byteInfo = workStream.ToArray(); workStream.Write(byteInfo, 0, byteInfo.Length); workStream.Position = 0; return(File(workStream, "application/pdf", strPDFFileName)); } else { HttpContext.Session.SetString("MensagemTitle", "Erro"); HttpContext.Session.SetString("MensagemBody", "O usuário " + ViewData["nome"] + " não tem acesso a página: 'Consulta/CadastrarConsulta'"); return(RedirectToAction("Index", "Home")); } } else { ViewData.Add("ReturnUrl", ((object[])this.ControllerContext.RouteData.Values.Values)[0] + "/" + ((object[])this.ControllerContext.RouteData.Values.Values)[1]); return(RedirectToAction("Signin", "Login", new { ReturnUrl = ViewData["ReturnUrl"] })); } } catch (Exception ex) { HttpContext.Session.SetString("MensagemTitle", "Erro"); HttpContext.Session.SetString("MensagemBody", "Exceção: " + ex.Message); return(RedirectToAction("Index", "Home")); } }
public Document LayoutPDFExame(Document doc, PDFDadosExame dadosExame) { doc.Open(); BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); Font font = new Font(bf, 11); BaseFont bfTitulo = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); Font fontTitulo = new Font(bfTitulo, 14); // CREANDO A TABLE PdfPTable table = new PdfPTable(3); table.HorizontalAlignment = 0; table.TotalWidth = 500f; table.LockedWidth = true; float[] widths = new float[] { 84f, 208f, 208f }; table.SetWidths(widths); // Celula LOGO Image myImage = Image.GetInstance("C:\\Users\\mselm\\source\\repos\\SGCM\\wwwroot\\images\\SGCM_logo.png"); PdfPCell cellImage = new PdfPCell(myImage); cellImage.PaddingTop = (float)2; cellImage.PaddingLeft = (float)2; cellImage.Rowspan = 3; cellImage.MinimumHeight = 40; table.AddCell(cellImage); // CELULA NOME SISTEMA PdfPCell cellSistemaNome = new PdfPCell(new Phrase("Sistema de Gerenciamento de Clínica Médica", fontTitulo)); cellSistemaNome.Colspan = 3; cellSistemaNome.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cellSistemaNome); // CELULA PACIENTE: NOME PdfPCell cellPacienteNome = new PdfPCell(new Phrase("Paciente: " + dadosExame.nome, font)); cellPacienteNome.PaddingBottom = (float)3; table.AddCell(cellPacienteNome); // CELULA CPF/RG: NÚMERO PdfPCell cellCpfRg = new PdfPCell(new Phrase("CPF/RG: " + dadosExame.rg, font)); cellCpfRg.PaddingBottom = (float)3; table.AddCell(cellCpfRg); var dataNascimento = dadosExame.dataNascimento; var hoje = DateTime.Now; var idade = hoje.Year - dataNascimento.Year; if (dataNascimento > hoje.AddYears(-idade)) { idade--; } // CELULA Idade: IDADE PdfPCell cellIdade = new PdfPCell(new Phrase("Idade: " + idade, font)); cellIdade.PaddingBottom = (float)3; table.AddCell(cellIdade); // CELULA Data Atendimento: DATA PdfPCell cellDataAtend = new PdfPCell(new Phrase("Data Atendimento: " + dadosExame.dataConsulta.ToShortDateString(), font)); cellDataAtend.PaddingBottom = (float)3; table.AddCell(cellDataAtend); doc.Add(table); //criando uma string vazia string dados = ""; //criando a variavel para paragrafo //Paragraph paragrafo = new Paragraph(dados, new Font(Font.NORMAL, 14)); Paragraph paragrafo = new Paragraph(dados, font); //etipulando o alinhamneto paragrafo.Alignment = Element.ALIGN_JUSTIFIED; //Alinhamento Justificado //adicioando texto paragrafo.Add("Solicito: " + dadosExame.baseNomeExame); //acidionado paragrafo ao documento doc.Add(paragrafo); doc.Close(); return(doc); }