Ejemplo n.º 1
0
        private void ExportToPdf(DataGrid grid)
        {
            try
            {
                PdfPTable table       = new PdfPTable(grid.Columns.Count);
                Document  pdfcommande = new Document(iTextSharp.text.PageSize.A4.Rotate(), 6, 3, 3, 3);
                string    Directorio  = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                PdfWriter writer      = PdfWriter.GetInstance(pdfcommande, new FileStream(Directorio + "\\Informe.pdf", FileMode.Create));
                pdfcommande.Open();
                iTextSharp.text.Paragraph firstpara  = new iTextSharp.text.Paragraph("Informe de Prescripciones");
                iTextSharp.text.Paragraph firstpara2 = new iTextSharp.text.Paragraph(" ");
                foreach (DataGridColumn column in grid.Columns)
                {
                    table.AddCell(new Phrase(column.Header.ToString()));
                }
                table.HeaderRows = 1;
                IEnumerable itemsSource = grid.ItemsSource as IEnumerable;
                if (itemsSource != null)
                {
                    foreach (var item in itemsSource)
                    {
                        Entidades.PrescripcionPersonalizada ps = new Entidades.PrescripcionPersonalizada();
                        ps = (Entidades.PrescripcionPersonalizada)item;
                        if (ps != null)
                        {
                            table.AddCell(new Phrase(ps.idPrescripcion.ToString()));
                            table.AddCell(new Phrase(ps.rutPersona));
                            table.AddCell(new Phrase(ps.nomPersona));
                            table.AddCell(new Phrase(ps.diagnostico));
                            table.AddCell(new Phrase(ps.fechaPres.ToString()));
                            table.AddCell(new Phrase(ps.rutMedico));
                            table.AddCell(new Phrase(ps.nomMedico));
                            table.AddCell(new Phrase(ps.nomMedicamento));
                            table.AddCell(new Phrase(ps.formaFarmaceutica));
                            table.AddCell(new Phrase(ps.cantidad.ToString()));
                            table.AddCell(new Phrase(ps.estado));

                            /*float[] widths = new float[] { 150f, 150f, 150f, 160f, 160f, 160f, 160f, 160f, 160f, 160f, 160f };
                             * table.SetWidths(widths);*/
                        }
                    }
                    pdfcommande.Add(firstpara);
                    pdfcommande.Add(firstpara2);
                    pdfcommande.Add(table);
                    pdfcommande.Close();
                    writer.Close();
                    MessageBox.Show("Informe creado y enviado a escritorio en formato pdf");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("No se pudo Crear el informe");
            }
        }
Ejemplo n.º 2
0
 public List <Entidades.PrescripcionPersonalizada> obtenerPresTodas()
 {
     try
     {
         string        sqlSelect = "SELECT PR.ID_PS, PE.RUT AS RUT_RETIRA, PE.NOMBRES ||' '|| PE.APELLIDOS AS NOMBRE_COMPLETO, PR.DIAGNOSTICO, PR.FECHA_PRES, PR.CANTIDAD, M.RUT AS RUT_MEDICO, M.NOMBRES || ' ' || M.AP_PATERNO AS NOMBRE_MEDICO, ME.NOMBRE_COMERCIAL, ME.FORMA_FARMACEUTICA, PR.ESTADO FROM PRESCRIPCION PR JOIN PERSONA PE ON (PR.PERSONA_ID = PE.RUT) JOIN MEDICO M ON (PR.MEDICO_ID = M.RUT) JOIN MEDICAMENTO ME ON (PR.MEDICAMENTO_ID = ME.ID_MCTOS)";
         OracleCommand cmd       = Datos.Conexion.conectar().CreateCommand();
         cmd.CommandText = sqlSelect;
         cmd.CommandType = CommandType.Text;
         OracleDataReader dr = cmd.ExecuteReader();
         List <Entidades.PrescripcionPersonalizada> ppList = new List <Entidades.PrescripcionPersonalizada>();
         while (dr.Read())
         {
             Entidades.PrescripcionPersonalizada pp = new Entidades.PrescripcionPersonalizada();
             pp.idPrescripcion = Convert.ToDecimal(dr["ID_PS"]);
             pp.rutPersona     = dr["RUT_RETIRA"].ToString();
             pp.nomPersona     = dr["NOMBRE_COMPLETO"].ToString();
             pp.diagnostico    = dr["DIAGNOSTICO"].ToString();
             try
             {
                 pp.fechaPres = Convert.ToDateTime(dr["FECHA_PRES"].ToString());
             }
             catch (Exception)
             {
                 pp.fechaPres = null;
             }
             pp.cantidad          = Convert.ToDecimal(dr["CANTIDAD"]);
             pp.rutMedico         = dr["RUT_MEDICO"].ToString();
             pp.nomMedico         = dr["NOMBRE_MEDICO"].ToString();
             pp.nomMedicamento    = dr["NOMBRE_COMERCIAL"].ToString();
             pp.formaFarmaceutica = dr["FORMA_FARMACEUTICA"].ToString();
             pp.estado            = dr["ESTADO"].ToString();
             ppList.Add(pp);
         }
         return(ppList);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 3
0
        private void btnListarPres_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Negocio.PrescripcionN pn = new Negocio.PrescripcionN();
                Entidades.PrescripcionPersonalizada pp = new Entidades.PrescripcionPersonalizada();
                ComboBoxItem typeItem = (ComboBoxItem)cboListarPres.SelectedItem;
                string       valorCbo = typeItem.Content.ToString();
                switch (valorCbo)
                {
                case "Todas":
                    dgLisPres.ItemsSource = pn.listarPres(" ");
                    break;

                case "Emitido":
                    dgLisPres.ItemsSource = pn.listarPres("Emitido");
                    break;

                case "Completado":
                    dgLisPres.ItemsSource = pn.listarPres("Completado");
                    break;

                case "Reservar":
                    dgLisPres.ItemsSource = pn.listarPres("Reservar");
                    break;

                case "Cancelar":
                    dgLisPres.ItemsSource = pn.listarPres("Cancelar");
                    break;

                default:
                    break;
                }
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 4
0
 private void btnGuardarPres_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Entidades.PrescripcionPersonalizada pr = new Entidades.PrescripcionPersonalizada();
         Negocio.PrescripcionN  pn = new Negocio.PrescripcionN();
         Entidades.Prescripcion p  = new Entidades.Prescripcion();
         Negocio.MedicamentoN   mn = new Negocio.MedicamentoN();
         Entidades.Medicamento  m  = new Entidades.Medicamento();
         pr       = (Entidades.PrescripcionPersonalizada)dgPrescrip.SelectedItem;
         p        = pn.obtenerPres(pr.idPrescripcion);
         p.estado = valorDgCboEstado;
         if (p != null && p.estado != "Emitido" && valorDgCboEstado.Trim() != string.Empty)
         {
             if (p.estado == "Completado")
             {
                 m = mn.obtenerMedicamento(p.idMedicamento);
                 if (m.stock >= p.cantidad)
                 {
                     if (pn.modificarPres(p))
                     {
                         decimal cantidad = m.stock - pr.cantidad;
                         m.stock = cantidad;
                         if (mn.modificarMedicamento(m) == true)
                         {
                             MessageBox.Show("Exito al Completar");
                             valorDgCboEstado = "";
                             llenarGrid();
                         }
                     }
                 }
                 else
                 {
                     MessageBox.Show("No se puede completar porque el medicamento no tiene la cantidad requerida, recomiende reservar");
                     valorDgCboEstado = "";
                     llenarGrid();
                 }
             }
             else if (p.estado == "Reservar")
             {
                 if (pn.modificarPres(p))
                 {
                     MessageBox.Show("Exito al reservar");
                     valorDgCboEstado = "";
                     llenarGrid();
                 }
             }
             else if (p.estado == "Cancelar")
             {
                 if (pn.modificarPres(p))
                 {
                     MessageBox.Show("Exito al Cancelar");
                     valorDgCboEstado = "";
                     llenarGrid();
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }