public ActionResult Reporte(int id) { //declarar el objeto de la clase LocalReport LocalReport localReport = new LocalReport(); //localReport.ReportPath = Server.MapPath("~/Content/Reports/Report1.rdlc"); localReport.ReportPath = Server.MapPath("~/Content/Reports/Reporte.rdlc"); List<Alertas> listReport = new AlertasRepository().GetAllAlertasReporte(id).ToList(); List<Alertas_detalle> ListDetalle = new Alertas_detalleRepository().GetAllAlertas_detalle(id).ToList(); string test = ListDetalle[0].EtiquetaUnidades; List<EAN> ListDetalleEAN = new EANRepository().GetListEANByAlerta(id).ToList(); ReportDataSource reportDataSource = new ReportDataSource("ReporteAlertas", listReport); ReportDataSource reportDataSource2 = new ReportDataSource("Detalle", ListDetalle); ReportDataSource reportDataSource3 = new ReportDataSource("DetalleEAN", ListDetalleEAN); localReport.DataSources.Add(reportDataSource); localReport.DataSources.Add(reportDataSource2); localReport.DataSources.Add(reportDataSource3); string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/'); //string uriImage = Request.Url.Authority.Replace(Request.Url.Authority, "") + // baseUrl + @dirLogos + listReport.FirstOrDefault().NombreLogo; //ReportParameter[] param = new ReportParameter[1]; //param[0] = new ReportParameter("Path", uriImage); //localReport.EnableExternalImages = true; //localReport.SetParameters(param); //Ahora pasamos los datos al reporte //declaramos las variables de configuración para el reporte string reportType = "PDF"; string mimeType; string encoding; string fileNameExtension; //En la configuración del reporte debe especificarse para el tipo de reporte //consulte el sitio para más información //http://msdn2.microsoft.com/en-us/library/ms155397.aspx Warning[] warnings; string[] streams; byte[] renderedBytes; //Transformar el reporte a bytes para transferirlo como flujo renderedBytes = localReport.Render(reportType, null, out mimeType, out encoding, out fileNameExtension, out streams, out warnings); //enviar el archivo al cliente (navegador) return File(renderedBytes, mimeType); }
public ActionResult Index(FormCollection par) { if (!BioTecnal.Models.ApplicationModelRepositoy.validateOptionByRole(User.Identity.Name, "Alertas")) { TempData["ErrorMessage"] = string.Format("Acceso denegado a {0}", "Alertas"); return RedirectToAction("Error", "Shared"); } string user = this.User.Identity.Name; string estado = string.Empty; List<Alertas> listAlertas = null; DateTime fechaIni; DateTime fechafin; if (string.IsNullOrEmpty(par["RepFechaIni"]) != true && string.IsNullOrEmpty(par["RepFechaFin"]) != true) { fechaIni = Convert.ToDateTime(par["RepFechaIni"]); fechafin = Convert.ToDateTime(par["RepFechaFin"]); listAlertas = new AlertasRepository().GetListAlertasByEstadoFecha(par["estado"], fechaIni, fechafin, user).ToList(); } if (string.IsNullOrEmpty(par["RepFechaIni"]) != true && string.IsNullOrEmpty(par["RepFechaFin"]) == true) { fechaIni = Convert.ToDateTime(par["RepFechaIni"]); fechafin = Convert.ToDateTime(par["RepFechaIni"]); listAlertas = new AlertasRepository().GetListAlertasByEstadoFecha(par["estado"], fechaIni, fechafin, user).ToList(); } if (string.IsNullOrEmpty(par["RepFechaIni"]) == true && string.IsNullOrEmpty(par["RepFechaFin"]) != true) { fechaIni = Convert.ToDateTime(par["RepFechaFin"]); fechafin = Convert.ToDateTime(par["RepFechaFin"]); listAlertas = new AlertasRepository().GetListAlertasByEstadoFecha(par["estado"], fechaIni, fechafin, user).ToList(); } if (par["estado"] != string.Empty && string.IsNullOrEmpty(par["RepFechaIni"]) == true && string.IsNullOrEmpty(par["RepFechaFin"]) == true) { listAlertas = new AlertasRepository().GetListAlertasByEstado(par["estado"]).ToList(); } if (par["estado"] == string.Empty && string.IsNullOrEmpty(par["RepFechaIni"]) == true && string.IsNullOrEmpty(par["RepFechaFin"]) == true) { listAlertas = new AlertasRepository().GetAllAlertas(user).ToList(); } return PartialView("_Index", listAlertas.OrderByDescending(e=>e.Fecha_alerta)); }