private void ExportToPdfControl(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 Control de Stock.pdf", FileMode.Create)); pdfcommande.Open(); iTextSharp.text.Paragraph firstpara = new iTextSharp.text.Paragraph("Informe de Controles de Stock"); 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.ControlStockInforme c = new Entidades.ControlStockInforme(); c = (Entidades.ControlStockInforme)item; if (c != null) { table.AddCell(new Phrase(c.idControl.ToString())); table.AddCell(new Phrase(c.nombre)); table.AddCell(new Phrase(c.descrip)); table.AddCell(new Phrase(c.fecha.ToString())); table.AddCell(new Phrase(c.cantidad.ToString())); table.AddCell(new Phrase(c.rutFar)); table.AddCell(new Phrase(c.nombres)); table.AddCell(new Phrase(c.idMedica.ToString())); table.AddCell(new Phrase(c.nombreMed)); } } 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"); } }
public List <Entidades.ControlStockInforme> obtenerControles() { try { string sqlSelect = "SELECT C.ID_CS, C.NOMBRE, C.DESCRIPCION, C.FECHA, C.CANTIDAD, C.USUARIO_ID, U.NOMBRES ||' '|| U.AP_PATERNO AS NOMBRE_FAR, C.ID_MEDICAMENTO, M.NOMBRE_COMERCIAL FROM CONTROLSTOCK C JOIN MEDICAMENTO M ON (C.ID_MEDICAMENTO = M.ID_MCTOS) JOIN USUARIO U ON (C.USUARIO_ID = U.RUT)"; OracleCommand cmd = Datos.Conexion.conectar().CreateCommand(); cmd.CommandText = sqlSelect; cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); List <Entidades.ControlStockInforme> csList = new List <Entidades.ControlStockInforme>(); while (dr.Read()) { Entidades.ControlStockInforme cs = new Entidades.ControlStockInforme(); cs.idControl = Convert.ToDecimal(dr["ID_CS"]); cs.nombre = dr["NOMBRE"].ToString(); cs.descrip = dr["DESCRIPCION"].ToString(); try { cs.fecha = Convert.ToDateTime(dr["FECHA"].ToString()); } catch (Exception) { cs.fecha = null; } cs.cantidad = Convert.ToDecimal(dr["CANTIDAD"]); cs.rutFar = dr["USUARIO_ID"].ToString(); cs.nombres = dr["NOMBRE_FAR"].ToString(); cs.idMedica = Convert.ToDecimal(dr["ID_MEDICAMENTO"]); cs.nombreMed = dr["NOMBRE_COMERCIAL"].ToString(); csList.Add(cs); } return(csList); } catch (Exception) { return(null); } }