using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebViewerFlashviewer.Reports;

namespace WebViewerFlashviewer
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@"Reports\RDL报表.rdlx")));
            this.WebViewer1.Report = rpt;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            var a = this.DropDownList1.SelectedIndex;
            if (a == 0)
            {
                GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@"Reports\RDL报表.rdlx")));
                this.WebViewer1.Report = rpt;
            }
            if (a == 1)
            {
                GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@"Reports\页面报表.rdlx")));
                this.WebViewer1.Report = rpt;
            }
            if (a == 2)
            {
                GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
                rpt.LoadLayout(Server.MapPath(@"Reports\区域报表.rpx"));
                this.WebViewer1.Report = rpt;
            }
            if (a == 3)
            {
                SectionReport1 rpt = new SectionReport1();
                this.WebViewer1.Report = rpt;
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            var a = this.DropDownList1.SelectedIndex;
            if (a == 0)
            {
                GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@"Reports\RDL报表.rdlx")));
                this.WebViewer1.Report = rpt;
                System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"D:\MyWord");
                outputDirectory.Create();
                //定义导出设置
                GrapeCity.ActiveReports.Export.Word.Page.Settings wordSetting = new GrapeCity.ActiveReports.Export.Word.Page.Settings();
                wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML;
                //创建渲染机制
                GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension wordRenderingExtension = new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
                //创建导出提供器
                GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
                //导出
                rpt.Document.Render(wordRenderingExtension, outputProvider, wordSetting);

                //Section Report
            }
            if (a == 1)
            {               
                GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@"Reports\页面报表.rdlx")));
                GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(rpt);

                // Provide settings for your rendering output.
                GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
                excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xlsx;
                GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;

                // Set the rendering extension and render the report.
                GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension excelRenderingExtension = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension();
                GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
                reportDocument.Render(excelRenderingExtension, outputProvider, setting.GetSettings());

                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("content-disposition", "inline;filename=MyExport.xls");
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
                Response.BinaryWrite(ms.ToArray());
                Response.End();

            }
            if (a == 2)
            {
             
                GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
                rpt.LoadLayout(Server.MapPath(@"Reports\区域报表.rpx"));
                this.WebViewer1.Report = rpt;
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
                // Set a file format of the exported excel file to Xlsx to support Microsoft Excel 2007 and newer versions.
                XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
                XlsExport1.Export(rpt.Document, ms);
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=区域报表.xlsx"));
                Response.BinaryWrite(ms.ToArray());
                Response.End();

            }
            if (a == 3)
            {              
                SectionReport1 rpt = new SectionReport1();
                this.WebViewer1.Report = rpt;
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
                // Set a file format of the exported excel file to Xlsx to support Microsoft Excel 2007 and newer versions.
                XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
                XlsExport1.Export(rpt.Document, ms);
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=区域报表基于代码.xlsx"));
                Response.BinaryWrite(ms.ToArray());
                Response.End();

            }

        }
    }
}