Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        CrystalDecisions.Enterprise.SessionMgr        boSessionMgr = new CrystalDecisions.Enterprise.SessionMgr();
        CrystalDecisions.Enterprise.InfoStore         boInfoStore;
        CrystalDecisions.Enterprise.EnterpriseService boEnterpriseService;
        CrystalDecisions.Enterprise.InfoObjects       boInfoObjects;
        string boReportName;
        string boQuery;

        CrystalDecisions.ReportAppServer.ClientDoc.ReportAppFactory boReportAppFactory;
        CrystalDecisions.ReportAppServer.Utilities.Conversion       boConversion = new CrystalDecisions.ReportAppServer.Utilities.Conversion();

        if (ViewState["boEnterpriseSession"] != null)
        {
            boEnterpriseSession = boSessionMgr.GetSession(ViewState["boEnterpriseSession"].ToString());
        }
        else
        {
            //Log on to the Enterprise CMS
            boEnterpriseSession = boSessionMgr.Logon(Request.QueryString["username"], Request.QueryString["password"], Request.QueryString["cms"], Request.QueryString["authtype"]);
            ViewState.Add("boEnterpriseSession", boEnterpriseSession);
        }

        //get report object from session or create a new report object
        if (ViewState["boSerializedReport"] != null)
        {
            //Reconstruct the serialized ReportClientDocument
            string boSerializedReport = ViewState["boSerializedReport"].ToString();
            boReportClientDocument = (ReportClientDocument)boConversion.ToReportClientDocument(boSerializedReport);
        }
        else
        {
            boEnterpriseService = boEnterpriseSession.GetService("", "InfoStore");
            boInfoStore         = new CrystalDecisions.Enterprise.InfoStore(boEnterpriseService);

            boReportName = "World Sales Report";

            //Retrieve the report object from the InfoStore, only need the SI_ID for RAS
            boQuery = "Select SI_ID From CI_INFOOBJECTS Where SI_NAME = '" + boReportName +
                      "' AND SI_Instance=0";
            boInfoObjects = boInfoStore.Query(boQuery);
            boInfoObject  = boInfoObjects[1];

            boEnterpriseService = null;

            //Retrieve the RASReportFactory
            boEnterpriseService = boEnterpriseSession.GetService("RASReportFactory");
            boReportAppFactory  = (CrystalDecisions.ReportAppServer.ClientDoc.ReportAppFactory)boEnterpriseService.Interface;
            //Open the report from Enterprise
            boReportClientDocument = boReportAppFactory.OpenDocument(boInfoObject.ID, 0);

            //Serialize the ReportClientDocument
            string boSerializedReport = boConversion.ToString(boReportClientDocument);
            //Add the reportClientDocument to session
            ViewState.Add("boSerializedReport", boSerializedReport);
        }

        //Set the ReportSource of the viewer to the report in Session
        boCrystalReportViewer.ReportSource = boReportClientDocument;
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        CrystalDecisions.Enterprise.SessionMgr        boSessionMgr;
        CrystalDecisions.Enterprise.InfoStore         boInfoStore;
        CrystalDecisions.Enterprise.EnterpriseService boEnterpriseService;
        CrystalDecisions.Enterprise.InfoObjects       boInfoObjects;
        string boReportName;
        string boQuery;

        CrystalDecisions.ReportAppServer.ClientDoc.ReportAppFactory boReportAppFactory;

        //Log on to the Enterprise CMS
        boSessionMgr        = new CrystalDecisions.Enterprise.SessionMgr();
        boEnterpriseSession = boSessionMgr.Logon(Request.QueryString["username"], Request.QueryString["password"], Request.QueryString["cms"], Request.QueryString["authtype"]);
        Session.Add("boEnterpriseSession", boEnterpriseSession);
        boEnterpriseService = boEnterpriseSession.GetService("", "InfoStore");
        boInfoStore         = new CrystalDecisions.Enterprise.InfoStore(boEnterpriseService);

        boReportName = "World Sales Report";

        //Retrieve the report object from the InfoStore, only need the SI_ID for RAS
        boQuery = "Select SI_ID From CI_INFOOBJECTS Where SI_NAME = '" + boReportName +
                  "' AND SI_Instance=0";
        boInfoObjects = boInfoStore.Query(boQuery);
        boInfoObject  = boInfoObjects[1];

        boEnterpriseService = null;

        //Retrieve the RASReportFactory
        boEnterpriseService = boEnterpriseSession.GetService("RASReportFactory");
        boReportAppFactory  = (CrystalDecisions.ReportAppServer.ClientDoc.ReportAppFactory)boEnterpriseService.Interface;
        //Open the report from Enterprise
        boReportClientDocument = boReportAppFactory.OpenDocument(boInfoObject.ID, 0);

        /**
         * This exports the report to a byte() that we will stream out using the default options for the enum
         * The available enums are:
         * CrReportExportFormatEnum.crReportExportFormatCharacterSeparatedValues
         * CrReportExportFormatEnum.crReportExportFormatCrystalReports
         * CrReportExportFormatEnum.crReportExportFormatEditableRTF
         * CrReportExportFormatEnum.crReportExportFormatHTML
         * CrReportExportFormatEnum.crReportExportFormatMSExcel
         * CrReportExportFormatEnum.crReportExportFormatMSWord
         * CrReportExportFormatEnum.crReportExportFormatPDF
         * CrReportExportFormatEnum.crReportExportFormatRecordToMSExcel
         * CrReportExportFormatEnum.crReportExportFormatRTF
         * CrReportExportFormatEnum.crReportExportFormatTabSeparatedText
         * CrReportExportFormatEnum.crReportExportFormatText
         * CrReportExportFormatEnum.crReportExportFormatXML
         */
        Byte[] oByte = (Byte[])boReportClientDocument.PrintOutputController.Export(CrReportExportFormatEnum.crReportExportFormatPDF, 1).ByteArray;

        Response.ClearContent();
        Response.ClearHeaders();
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-disposition", "filename=MyReport.pdf");
        Response.BinaryWrite(oByte);
        Response.End();

        boReportClientDocument.Close();
        boEnterpriseSession.Logoff();
    }
Ejemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        CrystalDecisions.Enterprise.SessionMgr        boSessionMgr;
        CrystalDecisions.Enterprise.InfoStore         boInfoStore;
        CrystalDecisions.Enterprise.EnterpriseService boEnterpriseService;
        CrystalDecisions.Enterprise.InfoObjects       boInfoObjects;
        string boReportName;
        string boQuery;

        CrystalDecisions.ReportAppServer.ClientDoc.ReportAppFactory boReportAppFactory;

        //Log on to the Enterprise CMS
        boSessionMgr        = new CrystalDecisions.Enterprise.SessionMgr();
        boEnterpriseSession = boSessionMgr.Logon(Request.QueryString["username"], Request.QueryString["password"], Request.QueryString["cms"], Request.QueryString["authtype"]);
        Session.Add("boEnterpriseSession", boEnterpriseSession);
        boEnterpriseService = boEnterpriseSession.GetService("", "InfoStore");
        boInfoStore         = new CrystalDecisions.Enterprise.InfoStore(boEnterpriseService);

        boReportName = "World Sales Report";

        //Retrieve the report object from the InfoStore, only need the SI_ID for RAS
        boQuery = "Select SI_ID From CI_INFOOBJECTS Where SI_NAME = '" + boReportName +
                  "' AND SI_Instance=0";
        boInfoObjects = boInfoStore.Query(boQuery);
        boInfoObject  = boInfoObjects[1];

        boEnterpriseService = null;

        //Retrieve the RASReportFactory
        boEnterpriseService = boEnterpriseSession.GetService("RASReportFactory");
        boReportAppFactory  = (CrystalDecisions.ReportAppServer.ClientDoc.ReportAppFactory)boEnterpriseService.Interface;
        //Open the report from Enterprise
        boReportClientDocument = boReportAppFactory.OpenDocument(boInfoObject.ID, 0);

        ExportOptions exportOptions = new ExportOptions();

        //This sets which format we will export to.
        exportOptions.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatMSExcel;
        //Create the FormatOptions class for PDF.
        ExcelExportFormatOptions ExcelexportOptions = new ExcelExportFormatOptions();

        ExcelexportOptions.BaseAreaGroupNumber            = 1;
        ExcelexportOptions.BaseAreaType                   = CrAreaSectionKindEnum.crAreaSectionKindReportHeader;
        ExcelexportOptions.ConstantColWidth               = 20;
        ExcelexportOptions.ConvertDatesToStrings          = true;
        ExcelexportOptions.StartPageNumber                = 1;
        ExcelexportOptions.EndPageNumber                  = 5;
        ExcelexportOptions.ExcelTabHasColumnHeadings      = true;
        ExcelexportOptions.ExportPageAreaPairType         = CrExportPageAreaKindEnum.crExportPageAreaKindForEachPage;
        ExcelexportOptions.ExportPageBreaks               = true;
        ExcelexportOptions.MaintainRelativeObjectPosition = true;
        ExcelexportOptions.ShowGridlines                  = false;
        ExcelexportOptions.UseConstantColWidth            = true;

        //Set the export format options with the page range we just set.
        exportOptions.FormatOptions = ExcelexportOptions;

        //This exports the report to a byte() that we will stream out.
        Byte[] oByte = (Byte[])boReportClientDocument.PrintOutputController.ExportEx(exportOptions).ByteArray;

        Response.ClearContent();
        Response.ClearHeaders();
        Response.ContentType = "application/vnd.ms-excel";
        Response.AddHeader("Content-disposition", "filename=MyReport.xls");
        Response.BinaryWrite(oByte);
        Response.End();

        boReportClientDocument.Close();
        boEnterpriseSession.Logoff();
    }