public IEnumerable <Inconsistencia> GetList(InconsistenciaFilter filter) { try { connection = new SqlServerConnection(); var parametros = new Dictionary <string, object> { { "@tipo", filter.tipo }, { "@estado", filter.estado }, { "@fechaDesde", filter.fechaDesde }, { "@fechaHasta", filter.fechaHasta }, { "@codigoCampo", filter.codigoCampo }, { "@periodo", filter.periodo } }; var lista = connection.GetArray <Inconsistencia>("spObtenerListaInconsistencias", parametros, System.Data.CommandType.StoredProcedure); return(lista.ToList()); } catch (Exception ex) { throw; } finally { connection.Close(); connection = null; } }
public Documento InconsistenciasExportarExcel(InconsistenciaFilter filter) { SLExcelData data = new SLExcelData(); try { data.HeadersFiltro = new List <string>(); data.HeadersFiltro.Add("Tipo de Conflicto"); data.HeadersFiltro.Add("Estado"); data.HeadersFiltro.Add("Fecha desde"); data.HeadersFiltro.Add("Fecha hasta"); List <string> rowFiltro = new List <string>(); if (filter.tipo == 1) { rowFiltro.Add("Tacto"); } else if (filter.tipo == 2) { rowFiltro.Add("Inseminación"); } else { rowFiltro.Add("Sin datos"); } if (filter.estado == 1) { rowFiltro.Add("Solucionado"); } else if (filter.estado == 2) { rowFiltro.Add("Pendiente"); } else { rowFiltro.Add("Sin datos"); } if (filter.fechaDesde != null) { rowFiltro.Add(filter.fechaDesde); } else { rowFiltro.Add("Sin datos"); } if (filter.fechaHasta != null) { rowFiltro.Add(filter.fechaHasta); } else { rowFiltro.Add("Sin datos"); } data.DataRowsFiltro = new List <List <string> >(); data.DataRowsFiltro.Add(rowFiltro); var lista = GetList(filter); data.Headers.Add("Tipo Conflicto"); data.Headers.Add("Fecha"); data.Headers.Add("Estado"); foreach (var item in lista) { List <string> row = new List <string>() { item.tipo, item.fecha, item.estado }; data.DataRows.Add(row); } var archivo = StaticFunctions.GenerateExcel(data, "Conflictos", filter.campo, filter.usuario, filter.periodo); return(new Documento() { nombre = archivo }); } catch (Exception ex) { throw ex; } finally { } }
public Documento InconsistenciasExportarPDF(InconsistenciaFilter filter) { FileStream fs; Document doc = null; PdfWriter writer; try { doc = new Document(); // Verifico el directorio string filePath = System.IO.Path.Combine(HttpRuntime.AppDomainAppPath, "Archivos\\"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } var fecha = DateTime.Now.ToString("dd-MM-yyyyHHmm"); // Nombre del archivo string fileName = string.Format("{0}-{1}-{2}.pdf", "Conflictos", filter.campo, fecha); // Generación del PDF fs = new FileStream(System.IO.Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write, FileShare.None); writer = PdfWriter.GetInstance(doc, fs); doc.Open(); string pathImg1 = System.IO.Path.Combine(HttpRuntime.AppDomainAppPath, "Archivos\\logo_farmix.jpg"); Image image1; if (Image.GetInstance(pathImg1) != null) { image1 = Image.GetInstance(pathImg1); image1.ScalePercent(24F); image1.Alignment = Element.ALIGN_CENTER; doc.Add(image1); } //añadimos linea negra abajo de las imagenes para separar. doc.Add(new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(2.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)))); doc.Add(new Paragraph(" ")); //Inicio datos var lista = GetList(filter); Font fuente1 = new Font(FontFamily.TIMES_ROMAN, 12.0f, Font.BOLD, BaseColor.BLACK); Font fuente2 = new Font(FontFamily.TIMES_ROMAN, 14.0f, Font.BOLD, BaseColor.BLACK); Rectangle rect = PageSize.LETTER; List <IElement> ie; float pageWidth = rect.Width; string html = ""; fecha = DateTime.Now.ToString("dd-MM-yyyy HH:mm"); html = @" <html><head></head><body> <table> <tr><td><b>Inconsistencias</b></td></tr> <tr><td>Campo: <b>" + filter.campo + @"</b></td></tr> <tr><td>Generado por: <b>" + filter.usuario + @"</b></td></tr> <tr><td>Fecha: <b>" + fecha + @"</b></td></tr> </table> </body></html>"; ie = HTMLWorker.ParseToList(new StringReader(html), null); foreach (IElement element in ie) { PdfPTable table1 = element as PdfPTable; if (table1 != null) { table1.SetWidthPercentage(new float[] { (float)1 * pageWidth }, rect); } doc.Add(element); } doc.Add(new Paragraph(" ")); if (lista.Count() > 0) { string tipoConflicto, estado; if (filter.tipo == 0) { tipoConflicto = "Sin filtro"; } else { tipoConflicto = filter.tipo.ToString(); } if (filter.estado == 0) { estado = "Sin filtro"; } else if (filter.estado == 2) { estado = "Pendiente"; } else { estado = filter.estado.ToString(); } html = @" <html><head></head><body> <table> <tr><td><b>Filtro Aplicado</b></td><td></td><td></td><td></td></tr> </table> <table border='1'> <thead> <tr> <th>Tipo Conflicto</th> <th>Estado</th> <th>Fecha Desde</th> <th>Fecha Hasta</th> </tr> </thead> <tbody> <tr><td>" + tipoConflicto + @"</td><td>" + estado + @"</td><td>" + (filter.fechaDesde == null ? "Sin filtro" : filter.fechaDesde) + @"</td><td>" + (filter.fechaHasta == null ? "Sin filtro" : filter.fechaHasta) + @"</td><td></tr> </tbody></table></body></html>"; ie = HTMLWorker.ParseToList(new StringReader(html), null); foreach (IElement element in ie) { PdfPTable table = element as PdfPTable; if (table != null) { table.SetWidthPercentage(new float[] { (float).2 * pageWidth, (float).2 * pageWidth, (float).2 * pageWidth, (float).2 * pageWidth }, rect); } doc.Add(element); } doc.Add(new Paragraph(" ")); html = @" <html><head></head><body> <table border='1'> <thead> <tr> <th>Tipo Conflicto</th> <th>Fecha</th> <th>Estado</th> </tr> </thead> <tbody>"; foreach (var item in lista) { html += @"<tr><td>" + item.tipo + @"</td><td>" + item.fecha + @"</td><td>" + item.estado + @"</td></tr>"; } html += @"</tbody></table> </body></html> "; ie = HTMLWorker.ParseToList(new StringReader(html), null); foreach (IElement element in ie) { PdfPTable table = element as PdfPTable; if (table != null) { table.SetWidthPercentage(new float[] { (float).3 * pageWidth, (float).3 * pageWidth, (float).3 * pageWidth }, rect); } doc.Add(element); } } doc.Close(); return(new Documento() { nombre = fileName }); } catch (Exception ex) { doc.Close(); throw ex; } finally { fs = null; doc = null; writer = null; } }