<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Reportes.aspx.cs" Inherits="AfiSystem.Reporte.Reportes" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" Height="100%" Width="100%" />
</form>
</body>
</html>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace AfiSystem.Reporte
{
public partial class Reportes : System.Web.UI.Page
{
CrystalDecisions.CrystalReports.Engine.ReportDocument reporte = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
reporte.Load("~/Templates/" + Session["NombreReporte"].ToString()));
DataTable dtDatos = (DataTable)Session["dtLlevar"];
reporte.SetDataSource(dtDatos);
CrystalReportViewer1.ReportSource = reporte;
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
CrystalReportViewer1.DataBind();
CrystalReportViewer1.RefreshReport();
}
}
}
Load with masterpage:
<%@ Page Title="" Language="C#" MasterPageFile="~/Reporte/Reportes.Master" AutoEventWireup="true" CodeBehind="CargarReporte.aspx.cs" Inherits="AfiSystem.Reporte.CargarReporte" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.btnLeft .x-btn-mc {
text-align : left;
}
.btnLeft .x-btn-mc em {
padding-left : 5px;
}
.x-btn-default-large .x-btn-icon
{
height: 120px;
}
.x-btn-default-large .x-btn-inner {
line-height: 260px !important;
}
#Panel1_Content {
height: 100%;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<ext:Viewport ID="ViewPort1" runat="server" Layout="Fit">
<Items>
<ext:Panel ID="Panel1" runat="server" Header="false">
<TopBar>
<ext:Toolbar ID="Toolbar1" runat="server" Dock="Top">
<Items>
<ext:Button ID="Button4" runat="server" Icon="Printer" ToolTip="Imprimir">
<DirectEvents>
<Click OnEvent="Imprimir" IsUpload="true">
<EventMask ShowMask="true" Msg="Imprimiendo..." />
</Click>
</DirectEvents>
</ext:Button>
<ext:ComboBox runat="server" ID="comboExportFormat" Cls="comboExportFormat" Editable="false"
ForceSelection="true" SelectedIndex="0">
<Items>
<ext:ListItem Text="PDF" Value="PDF" />
<ext:ListItem Text="Excel" Value="Excel" />
<ext:ListItem Text="Word" Value="Word" />
<ext:ListItem Text="RTF" Value="RTF" />
</Items>
</ext:ComboBox>
<ext:Button ID="Button5" runat="server" Icon="DiskDownload" ToolTip="Exportar al formato seleccionado">
<DirectEvents>
<Click OnEvent="Exportar" IsUpload="true">
<EventMask ShowMask="true" Msg="Exportarndo..." />
</Click>
</DirectEvents>
</ext:Button>
<ext:ToolbarFill ID="ToolbarFill1" runat="server" />
<ext:Button ID="Button3" runat="server" Text="<b>Cerrar" ToolTip="Cierra el reporte"
Icon="Decline" IconCls="x-btn-default-large .x-btn-icon">
<DirectEvents>
<Click OnEvent="CerrarReporte">
<EventMask ShowMask="true" Msg="Cerrando..." />
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:TabPanel ID="tabRMA" runat="server" Header="false" Border="false" Plain="true"
TabMenuHidden="true">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>
<ext:Panel ID="tabLast" runat="server" Border="false" Header="false" Height="700">
<Loader ID="Loader1" runat="server" Mode="Frame" Url="Reportes.aspx">
<LoadMask Msg="Cargando..." ShowMask="true" />
</Loader>
</ext:Panel>
</Items>
</ext:TabPanel>
</Items>
</ext:Panel>
</Items>
</ext:Viewport>
</asp:Content>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
namespace AfiSystem.Reporte
{
public partial class CargarReporte : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
Session["returnUrl"] = Request.UrlReferrer.ToString();
}
catch (Exception)
{
Session["returnUrl"] = null;
}
this.comboExportFormat.SelectedItem.Index = 0;
}
}
protected void Imprimir(object sender, DirectEventArgs e)
{
ReportDocument rep = new ReportDocument();
rep.Load(Server.MapPath("~/Templates/" + Session["NombreReporte"].ToString()));
DataTable dtDatos = (DataTable)Session["dtLlevar"];
rep.SetDataSource(dtDatos);
string NombreReporte = System.IO.Path.GetFileNameWithoutExtension(Session["NombreReporte"].ToString());
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
rep.PrintToPrinter(1, false, 0, 0);
}
protected void Exportar(object sender, DirectEventArgs e)
{
ReportDocument rep = new ReportDocument();
rep.Load(Server.MapPath("~/Templates/" + Session["NombreReporte"].ToString()));
DataTable dtDatos = (DataTable)Session["dtLlevar"];
rep.SetDataSource(dtDatos);
string NombreReporte = System.IO.Path.GetFileNameWithoutExtension(Session["NombreReporte"].ToString());
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
switch (comboExportFormat.SelectedItem.Value.ToUpper())
{
case "PDF":
rep.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, NombreReporte);
break;
case "EXCEL":
rep.ExportToHttpResponse(ExportFormatType.Excel, Response, true, NombreReporte);
break;
case "WORD":
rep.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, true, NombreReporte);
break;
case "RTF":
rep.ExportToHttpResponse(ExportFormatType.EditableRTF, Response, true, NombreReporte);
break;
}
}
protected void CerrarReporte(object sender, DirectEventArgs e)
{
Session["NombreReporte"] = null;
Session["dtLlevar"] = null;
if(Session["returnUrl"] != null)
{
string ultimaPagina = Session["returnUrl"].ToString();
Session["returnUrl"] = null;
X.Redirect(ultimaPagina, "Volviendo a la última página.");
}
else
{
Response.Redirect("~/Default.aspx");
}
}
}
}
Call report:
Session["dtLlevar"] = dsDatos.Tables[0];
Session["NombreReporte"] = "rptMovimiento.rpt";
X.Redirect("~/Reporte/CargarReporte.aspx", "Abriendo reporte...");