Beispiel #1
0
        public PDFDadosMedicamento ConsultarDadosMedicamentoPreencherPDF(int idMedicamento, int idConsulta)
        {
            try {
                MySqlConnection connection = new MySqlConnection(getStringConnection());
                connection.Open();

                var          DALSQL = new PDFDALSQL();
                MySqlCommand cmdDadosMedicamento = new MySqlCommand(DALSQL.ConsultarDadosMedicamentoPreencherPDF(), connection);
                cmdDadosMedicamento.Parameters.AddWithValue("@IDMEDICAMENTOCONSULTA_MEDICAMENTO", idMedicamento);
                cmdDadosMedicamento.Parameters.AddWithValue("@IDCONSULTA", idConsulta);

                //var teste = getGeneratedSql(cmdDadosMedicamento);

                MySqlDataReader     reader           = cmdDadosMedicamento.ExecuteReader();
                PDFDadosMedicamento dadosMedicamento = new PDFDadosMedicamento();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        dadosMedicamento.nome           = reader.GetString(0);
                        dadosMedicamento.rg             = reader.GetString(1);
                        dadosMedicamento.dataNascimento = reader.GetDateTime(2);
                        dadosMedicamento.dataConsulta   = reader.GetDateTime(3);
                        dadosMedicamento.nomeGenerico   = reader.GetString(4);
                        dadosMedicamento.nomeFabrica    = reader.GetString(5);
                    }
                    reader.Close();
                    connection.Close();
                }
                else
                {
                    dadosMedicamento = null;
                    reader.Close();
                    connection.Close();
                }

                return(dadosMedicamento);
            } catch (Exception ex) {
                throw ex;
            }
        }
Beispiel #2
0
        public Document LayoutPDFMedicamento(Document doc, PDFDadosMedicamento dadosMedicamento)
        {
            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: " + dadosMedicamento.nome, font));

            cellPacienteNome.PaddingBottom = (float)3;
            table.AddCell(cellPacienteNome);

            // CELULA CPF/RG: NÚMERO
            PdfPCell cellCpfRg = new PdfPCell(new Phrase("CPF/RG: " + dadosMedicamento.rg, font));

            cellCpfRg.PaddingBottom = (float)3;
            table.AddCell(cellCpfRg);

            var dataNascimento = dadosMedicamento.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: " + dadosMedicamento.dataConsulta.ToShortDateString(), font));

            cellDataAtend.PaddingBottom = (float)3;
            table.AddCell(cellDataAtend);

            doc.Add(table);

            string    dados         = "";
            Paragraph paragrafoFixo = new Paragraph(dados, font);

            paragrafoFixo.Alignment = Element.ALIGN_JUSTIFIED;
            paragrafoFixo.Add("Uso oral: ");
            doc.Add(paragrafoFixo);

            string    dadosVariavel     = "";
            Paragraph paragrafoVariavel = new Paragraph(dadosVariavel, font);

            paragrafoVariavel.Alignment = Element.ALIGN_JUSTIFIED;
            paragrafoVariavel.Add("                 " + dadosMedicamento.nomeGenerico + "_______________________________________________");
            doc.Add(paragrafoVariavel);

            doc.Close();
            return(doc);
        }
Beispiel #3
0
        public IActionResult BaixarPDFMedicamento(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();
                            PDFDadosMedicamento dadosMedicamento = new PDFDadosMedicamento();
                            dadosMedicamento = pdfBLL.ConsultarDadosMedicamentoPreencherPDF(Convert.ToInt32(id), Convert.ToInt32(username));

                            strPDFFileName = string.Format("Receita Medicamento do Paciente " + dadosMedicamento.nome + ".pdf");

                            if (dadosMedicamento != null)
                            {
                                doc = LayoutPDFMedicamento(doc, dadosMedicamento);
                            }
                            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"));
            }
        }