public FileResult ExportPdf() { Stream stream = null; var nombreArchivo = ""; int IdMovimiento = 1313; try { object objetos = new object(); EntitiesProveduria db = new EntitiesProveduria(); SqlConnectionStringBuilder builderOrden = new SqlConnectionStringBuilder(db.Database.Connection.ConnectionString); SP_INGRESO_BODEGATableAdapter tableAdapter = new SP_INGRESO_BODEGATableAdapter(); DataTable dataTable = tableAdapter.GetData(IdMovimiento, out objetos); String pathReport = Path.Combine(HttpRuntime.AppDomainAppPath, "Reports\\Cr_Ingreso_Bodega1.rpt"); ReportDocument reportDocument = new ReportDocument(); reportDocument.Load(pathReport); reportDocument.SetDataSource(dataTable); reportDocument.SetDatabaseLogon(builderOrden.UserID, builderOrden.Password); stream = reportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); stream.Seek(0, SeekOrigin.Begin); nombreArchivo = "INGRESO_BODEGA.pdf"; } catch (Exception ex) { logger.Error(ex, ex.Message); } return(File(stream, "application/pdf", nombreArchivo)); }
public FileResult ViewPDF(int?id) { Stream stream = null; var nombreArchivo = ""; ReportDocument reportDocument = new ReportDocument(); byte[] pdfByte = null; try { EPRTA_MOVIMIENTO solicitud = unitOfWork.MovimientoRepository.GetById(id); EntitiesProveduria db = new EntitiesProveduria(); SqlConnectionStringBuilder builderVenta = new SqlConnectionStringBuilder(db.Database.Connection.ConnectionString); String pathReport = ""; if (solicitud.ID_TIPO_MOVIMIENTO == 2) { SP_EGRESO_BODEGATableAdapter tableAdapter = new SP_EGRESO_BODEGATableAdapter(); object objetos = new object(); DataTable dataTable = tableAdapter.GetData(id, out objetos); pathReport = Path.Combine(HttpRuntime.AppDomainAppPath, "Reports\\Cr_Egreso_Bodega.rpt"); reportDocument.Load(pathReport); reportDocument.SetDataSource(dataTable); } else if (solicitud.ID_TIPO_MOVIMIENTO == 4) { SP_INGRESO_BODEGATableAdapter tableAdapter = new SP_INGRESO_BODEGATableAdapter(); object objetos = new object(); DataTable dataTable = tableAdapter.GetData(id, out objetos); pathReport = Path.Combine(HttpRuntime.AppDomainAppPath, "Reports\\Cr_Ingreso_Bodega.rpt"); reportDocument.Load(pathReport); reportDocument.SetDataSource(dataTable); } else if (solicitud.ID_TIPO_MOVIMIENTO == 10 || solicitud.ID_TIPO_MOVIMIENTO == 11) { SP_AJUSTE_BODEGATableAdapter tableAdapter = new SP_AJUSTE_BODEGATableAdapter(); object objetos = new object(); DataTable dataTable = tableAdapter.GetData(id, out objetos); pathReport = Path.Combine(HttpRuntime.AppDomainAppPath, "Reports\\Cr_Ajuste_Bodega.rpt"); reportDocument.Load(pathReport); reportDocument.SetDataSource(dataTable); } reportDocument.SetDatabaseLogon(builderVenta.UserID, builderVenta.Password); stream = reportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); pdfByte = ReadFully(stream); nombreArchivo = "Movimiento_bodega"; Response.AddHeader("content-disposition", "inline; title='';" + "filename=" + nombreArchivo + ".pdf"); } catch (Exception ex) { logger.Error(ex, ex.Message); } finally { if (reportDocument != null) { if (reportDocument.IsLoaded) { reportDocument.Close(); reportDocument.Dispose(); } } } return(File(pdfByte, MediaTypeNames.Application.Pdf)); }