public ActionResult ReporteLimpio(int id) { /*try * { * registro registro = db.registro.Find(id); * Session["reg_id"] = id; * ReportViewerViewModel model = new ReportViewerViewModel(); * string content = Url.Content("~/Reports/Viewer/ViewLimpio.aspx"); * model.ReportPath = content; * return View("ReportViewer", model); * } * catch (Exception ex) * { * ViewBag.mensaje = ex.Message; * //return View("Message"); * return RedirectToAction("Message", "Home", new { mensaje = ex.Message }); * }*/ try { registro registro = db.registro.Find(id); dsPruebaPaciente dsPrueba = new dsPruebaPaciente(); string conn = ConfigurationManager.AppSettings["conexion"]; string strConsulta = "Select * from view_prueba_paciente where reg_id=" + id + " order by exa_id"; SqlConnection sqlcon = new SqlConnection(conn); SqlDataAdapter daPrueba = new SqlDataAdapter(strConsulta, sqlcon); daPrueba.Fill(dsPrueba, "view_prueba_paciente"); RptLimpio rp = new RptLimpio(); string reportPath = Server.MapPath("~/Reports/RptLimpio.rpt"); rp.Load(reportPath); rp.SetDataSource(dsPrueba); var paciente = db.paciente.Where(p => p.pac_id == registro.reg_paciente).First(); //rp.SetParameterValue("paciente", paciente.pac_nombres + " " + paciente.pac_apellidos); rp.SetParameterValue("fecha", registro.reg_fecha); rp.SetParameterValue("edad", paciente.pac_edad); if (paciente.pac_genero != null) { rp.SetParameterValue("genero", paciente.pac_genero); } else { rp.SetParameterValue("genero", ""); } rp.SetParameterValue("orden", registro.reg_orden); Stream stream = rp.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); stream.Seek(0, SeekOrigin.Begin); return(File(stream, "application/pdf", id + ".pdf")); } catch (Exception ex) { ViewBag.mensaje = ex.Message; //return View("Message"); return(RedirectToAction("Message", "Home", new { mensaje = ex.Message })); } }
protected void Page_Load(object sender, EventArgs e) { if (this.reportDocument != null) { this.reportDocument.Close(); this.reportDocument.Dispose(); } int id = Convert.ToInt32(Session["reg_id"]); dsPruebaPaciente dsPrueba = new dsPruebaPaciente(); string conn = ConfigurationManager.AppSettings["conexion"]; string strConsulta = "Select * from view_prueba_paciente where reg_id=" + id + " order by exa_id"; registro registro = db.registro.Find(id); SqlConnection sqlcon = new SqlConnection(conn); SqlDataAdapter daQuimico = new SqlDataAdapter(strConsulta, sqlcon); daQuimico.Fill(dsPrueba, "view_prueba_paciente"); reportDocument = new ReportDocument(); string reportPath = Server.MapPath("~/Reports/RptLimpio.rpt"); reportDocument.Load(reportPath); reportDocument.SetDataSource(dsPrueba.Tables[0]); var paciente = db.paciente.Where(p => p.pac_id == registro.reg_paciente).First(); reportDocument.SetParameterValue("paciente", paciente.pac_nombres + " " + paciente.pac_apellidos); reportDocument.SetParameterValue("medico", ""); reportDocument.SetParameterValue("fecha", registro.reg_fecha); reportDocument.SetParameterValue("edad", paciente.pac_edad); if (paciente.pac_genero != null) { reportDocument.SetParameterValue("genero", paciente.pac_genero); } else { reportDocument.SetParameterValue("genero", ""); } reportDocument.SetParameterValue("hc", ""); reportDocument.SetParameterValue("orden", registro.reg_orden); crViewer.ReportSource = reportDocument; crViewer.DataBind(); }