public ActionResult Descargar(int id) { try { dsRayos dsRayos = new dsRayos(); string conn = ConfigurationManager.AppSettings["conexion"]; int ray_id = id; string strRayos = "Select * from view_rayos where ray_id=" + ray_id; SqlConnection sqlcon = new SqlConnection(conn); SqlDataAdapter daRayos = new SqlDataAdapter(strRayos, sqlcon); daRayos.Fill(dsRayos, "view_rayos"); RptRayos_ rp = new RptRayos_(); string reportPath = Server.MapPath("~/Reports/RptRayos_.rpt"); rp.Load(reportPath); rp.SetDataSource(dsRayos); Stream stream = rp.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); stream.Seek(0, SeekOrigin.Begin); return(File(stream, "application/pdf", ray_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(); } dsRayos dsPrueba = new dsRayos(); string conn = ConfigurationManager.AppSettings["conexion"]; int id = Convert.ToInt32(Session["ray_id"]); rayos rayos = db.rayos.Find(id); //string fileName = medico.med_firma; //if (String.IsNullOrEmpty(fileName)) // fileName = "firma.png"; string strAudiometia = "Select * from rayos where ray_id=" + id; string strPaciente = "Select * from paciente where pac_id=" + rayos.ray_paciente; SqlConnection sqlcon = new SqlConnection(conn); SqlDataAdapter daAudiometria = new SqlDataAdapter(strAudiometia, sqlcon); SqlDataAdapter daPaciente = new SqlDataAdapter(strPaciente, sqlcon); daAudiometria.Fill(dsPrueba, "rayos"); daPaciente.Fill(dsPrueba, "paciente"); reportDocument = new ReportDocument(); //Report path string reportPath = Server.MapPath("~/Reports/RptRayos.rpt"); reportDocument.Load(reportPath); reportDocument.SetDataSource(dsPrueba); reportDocument.SetParameterValue("hc", ""); reportDocument.SetParameterValue("orden", ""); //string path01 = Path.Combine(Server.MapPath("~/Content/firmas"), fileName); //reportDocument.SetParameterValue("picturePath", path01); crViewer.ReportSource = reportDocument; crViewer.DataBind(); }