public IEnumerable <Cliente> GetClientes(ReporteFilter filtro) { try { connection = new SqlServerConnection(); var parametros = new Dictionary <string, object> { { "@nombre", filtro.nombre }, { "@apellido", filtro.apellido }, { "@idPlan", filtro.idPlan }, { "@fechaDesde", filtro.fechaDesde }, { "@fechaHasta", filtro.fechaHasta } //{"@periodo", filtro.periodo } }; if (filtro.estadoCuenta != "0") { parametros.Add("@estadoCuenta", filtro.estadoCuenta); } var resultado = connection.GetArray <Cliente>("spGetClientes", parametros, System.Data.CommandType.StoredProcedure); return(resultado); } catch (Exception ex) { throw; } finally { connection.Close(); connection = null; } }
public IEnumerable <ReporteEventos> GetReporte(ReporteFilter filter) { try { connection = new SqlServerConnection(); var parametros = new Dictionary <string, object> { { "@idTipoEvento", filter.idTipoEvento }, { "@fechaDesde", filter.fechaDesde }, { "@fechaHasta", filter.fechaHasta }, { "@codigoCampo", filter.codigoCampo }, { "@periodo", filter.periodo } }; if (filter.numCaravana != 0) { parametros.Add("@numCaravana", filter.numCaravana); } var lista = connection.GetArray <ReporteEventos>("spObtenerDatosReporteEventos", parametros, System.Data.CommandType.StoredProcedure); DateTime fechaAnterior, fechaSiguiente; for (int i = 0; i < lista.Count(); i++) { parametros = new Dictionary <string, object>() { { "@idEvento", lista.ElementAt(i).idEvento } }; var caravanas = connection.GetArray <Caravana>("spGetBovinosXEvento", parametros, System.Data.CommandType.StoredProcedure).Select(x => Convert.ToString(x.caravana.ToString())).ToArray(); lista.ElementAt(i).caravanas = string.Join(", ", caravanas); if (lista.ElementAt(i).tipoEvento != "Vacunación") { for (int j = i + 1; j < lista.Count(); j++) { if (lista.ElementAt(j).tipoEvento == lista.ElementAt(i).tipoEvento) { fechaSiguiente = new DateTime(int.Parse(lista.ElementAt(i).fechaHora.Split('/')[2].Substring(0, 4)), int.Parse(lista.ElementAt(i).fechaHora.Split('/')[1]), int.Parse(lista.ElementAt(i).fechaHora.Split('/')[0])); fechaAnterior = new DateTime(int.Parse(lista.ElementAt(j).fechaHora.Split('/')[2].Substring(0, 4)), int.Parse(lista.ElementAt(j).fechaHora.Split('/')[1]), int.Parse(lista.ElementAt(j).fechaHora.Split('/')[0])); lista.ElementAt(i).duracion = (fechaSiguiente - fechaAnterior).Days; break; } } } else { lista.ElementAt(i).duracion = 1; } } return(lista.ToList()); } catch (Exception ex) { throw; } finally { connection.Close(); connection = null; } }
public Documento ClientesExportarExcel(ReporteFilter filter) { SLExcelData data = new SLExcelData(); try { data.HeadersFiltro = new List <string>(); data.HeadersFiltro.Add("Apellido"); data.HeadersFiltro.Add("Nombre"); data.HeadersFiltro.Add("Estado Cuenta"); data.HeadersFiltro.Add("Plan"); data.HeadersFiltro.Add("Fecha Desde"); data.HeadersFiltro.Add("Fecha Hasta"); List <string> rowFiltro = new List <string>(); if (filter.apellido != null) { rowFiltro.Add(filter.apellido); } else { rowFiltro.Add("Sin datos"); } if (filter.nombre != null) { rowFiltro.Add(filter.nombre); } else { rowFiltro.Add("Sin datos"); } if (filter.estadoCuenta != "0") { rowFiltro.Add(filter.estadoCuenta); } else { rowFiltro.Add("Sin datos"); } switch (filter.idPlan) { case 1: rowFiltro.Add("Plan pequeño"); break; case 2: rowFiltro.Add("Plan mediano"); break; case 3: rowFiltro.Add("Plan grande"); break; case 4: rowFiltro.Add("Plan super"); break; default: rowFiltro.Add("Sin datos"); break; } 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 = GetClientes(filter); data.Headers.Add("Apellido"); data.Headers.Add("Nombre"); data.Headers.Add("Fecha Alta"); data.Headers.Add("Plan Contratado"); data.Headers.Add("Administradores"); data.Headers.Add("Usuarios"); data.Headers.Add("Campos"); data.Headers.Add("Bovinos"); data.Headers.Add("Estado Cuenta"); foreach (var item in lista) { List <string> row = new List <string>(); row.Add(item.apellido); row.Add(item.nombre); row.Add(item.fechaAlta); if (item.idPlan == 1) { row.Add("Plan Pequeño"); } else if (item.idPlan == 2) { row.Add("Plan Mediano"); } else if (item.idPlan == 3) { row.Add("Plan Grande"); } else { row.Add("Plan Super"); } row.Add(item.cantidadAdministradores.ToString()); row.Add(item.cantidadUsuarios.ToString()); row.Add(item.cantidadCampos.ToString()); row.Add(item.cantidadBovinos.ToString()); row.Add(item.estadoCuenta); data.DataRows.Add(row); } var archivo = StaticFunctions.GenerateExcel(data, "Clientes", filter.campo, filter.usuario, filter.periodo); return(new Documento() { nombre = archivo }); } catch (Exception ex) { throw ex; } finally { } }
public Documento ClientesExportarPDF(ReporteFilter 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-yyyy"); // Nombre del archivo string fileName = string.Format("{0}-{1}.pdf", "Clientes", 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 = GetClientes(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 = ""; html = @" <html><head></head><body> <table> <tr><td><b>Clientes</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 nombre, apellido, plan; if (filter.nombre == null) { nombre = "Sin datos"; } else { nombre = filter.nombre; } if (filter.apellido == null) { apellido = "Sin datos"; } else { apellido = filter.apellido; } switch (filter.idPlan) { case 1: plan = "Plan pequeño"; break; case 2: plan = "Plan mediano"; break; case 3: plan = "Plan grande"; break; case 4: plan = "Plan super"; break; default: plan = "Sin datos"; break; } html = @" <html><head></head><body> <table> <tr><td><b>Filtro Aplicado</b></td><td></td><td></td><td></td><td></td><td></td></tr> </table> <table border='1'> <thead> <tr> <th>Nombre</th> <th>Apellido</th> <th>Estado Cuenta</th> <th>Plan</th> <th>Fecha Desde</th> <th>Fecha Hasta</th>"; html += @"</tr> </thead> <tbody> <tr><td>" + nombre + @"</td><td>" + apellido + @"</td><td>" + (filter.estadoCuenta != "0" ? filter.estadoCuenta : "Sin datos") + @"</td><td>" + plan + @"</td><td>" + (filter.fechaDesde != null ? filter.fechaDesde : "Sin datos") + @"</td><td>" + (filter.fechaHasta != null ? filter.fechaHasta : "Sin datos") + @"</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).16 * pageWidth, (float).16 * pageWidth, (float).16 * pageWidth, (float).16 * pageWidth, (float).16 * pageWidth, (float).16 * pageWidth }, rect); } doc.Add(element); } doc.Add(new Paragraph(" ")); html = @" <html><head></head><body> <table border='1'> <thead> <tr> <th>Apellido</th> <th>Nombre</th> <th>Fecha Alta</th> <th>Plan Contratado</th> <th>Administradores</th> <th>Usuarios</th> <th>Campos</th> <th>Bovinos</th> <th>Estado cuenta</th> </tr> </thead> <tbody>"; foreach (var item in lista) { html += @"<tr><td>" + item.apellido + @"</td><td>" + item.nombre + @"</td><td>" + item.fechaAlta + @"</td><td>" + item.nombrePlan + @"</td><td>" + item.cantidadAdministradores + @"</td><td>" + item.cantidadUsuarios + @"</td><td>" + item.cantidadCampos + @"</td><td>" + item.cantidadBovinos + @"</td><td>" + item.estadoCuenta + @"</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).1 * pageWidth, (float).1 * pageWidth, (float).1 * pageWidth, (float).1 * pageWidth, (float).1 * pageWidth, (float).1 * pageWidth, (float).1 * pageWidth, (float).1 * pageWidth, (float).1 * 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; } }
public Documento ReporteEventosExportarExcel(ReporteFilter filter) { SLExcelData data = new SLExcelData(); try { data.HeadersFiltro = new List <string>(); data.HeadersFiltro.Add("Caravana"); data.HeadersFiltro.Add("Tipo Evento"); data.HeadersFiltro.Add("Fecha Desde"); data.HeadersFiltro.Add("Fecha Hasta"); List <string> rowFiltro = new List <string>(); if (filter.numCaravana != 0) { rowFiltro.Add(filter.numCaravana.ToString()); } else { rowFiltro.Add("Sin datos"); } switch (filter.idTipoEvento) { case 1: rowFiltro.Add("Vacunación"); break; case 2: rowFiltro.Add("Antibiótico"); break; case 3: rowFiltro.Add("Manejo"); break; case 4: rowFiltro.Add("Alimenticio"); break; default: rowFiltro.Add("Sin filtro"); break; } 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 = GetReporte(filter); data.Headers.Add("Orden"); data.Headers.Add("Tipo Evento"); data.Headers.Add("Fecha"); data.Headers.Add("Duración (Días)"); data.Headers.Add("Descripción"); data.Headers.Add("Caravana de animales que participaron"); foreach (var item in lista) { List <string> row = new List <string>() { item.nroOrden.ToString(), item.tipoEvento, item.fechaHora, item.duracion.ToString(), item.descripcion, item.caravanas }; data.DataRows.Add(row); } var archivo = StaticFunctions.GenerateExcel(data, "ReportesEventos", filter.campo, filter.usuario, filter.periodo); return(new Documento() { nombre = archivo }); } catch (Exception ex) { throw ex; } finally { } }
public Documento ReporteEventosExportarPDF(ReporteFilter 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", "ReporteEventos", 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 = GetReporte(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; fecha = DateTime.Now.ToString("dd-MM-yyyy HH:mm"); string html = ""; html = @" <html><head></head><body> <table> <tr><td><b>Reporte Eventos</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> <tr><td>Período: <b>" + filter.periodo + @"</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 caravana, tipoEvento; if (filter.numCaravana == 0) { caravana = "Sin filtro"; } else { caravana = filter.numCaravana.ToString(); } switch (filter.idTipoEvento) { case 1: tipoEvento = "Vacunación"; break; case 2: tipoEvento = "Antibiótico"; break; case 3: tipoEvento = "Manejo"; break; case 4: tipoEvento = "Alimenticio"; break; default: tipoEvento = "Sin filtro"; break; } 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>Caravana</th> <th>Tipo Evento</th> <th>Fecha desde</th> <th>Fecha hasta</th>"; html += @"</tr> </thead> <tbody> <tr><td>" + caravana + @"</td><td>" + tipoEvento + @"</td><td>" + (filter.fechaDesde == null ? "Sin filtro" : filter.fechaDesde) + @"</td><td>" + (filter.fechaHasta == null ? "Sin filtro" : filter.fechaHasta) + @"</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).25 * pageWidth, (float).25 * pageWidth, (float).25 * pageWidth, (float).25 * pageWidth }, rect); } doc.Add(element); } doc.Add(new Paragraph(" ")); html = @" <html><head></head><body> <table border='1'> <thead> <tr> <th>Orden</th> <th>Tipo Evento</th> <th>Fecha</th> <th>Duración (Días)</th> <th>Descripción</th> <th>Caravanas que participaron</th> </tr> </thead> <tbody>"; foreach (var item in lista) { html += @"<tr><td>" + item.nroOrden + @"</td><td>" + item.tipoEvento + @"</td><td>" + item.fechaHora + @"</td><td>" + item.duracion + @"</td><td>" + item.descripcion + @"</td><td>" + item.caravanas + @"</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).08 * pageWidth, (float).15 * pageWidth, (float).2 * pageWidth, (float).12 * pageWidth, (float).2 * pageWidth, (float).15 * 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; } }