web报表工具Stimulsoft Reports.Web在mvc项目中使用

Stimulsoft Reports.Web,是一款可以直接在Web中编辑报表的报表工具

web项目技术框架mvc4+easyui+knockoutjs

1.在项目中添加引用

Stimulsoft.Base.dll,

Stimulsoft.Report.dll,

Stimulsoft.Report.Web.dll,

Stimulsoft.Report.WebDesign.dll

2.定义模板文件:新建web窗体文件report.aspx

前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="report.aspx.cs" Inherits="PE.IEM.Web.report" %>
<%@ Register  Namespace="Stimulsoft.Report.Web" TagPrefix="cc1"  Assembly="Stimulsoft.Report.Web, Version=2012.3.1500.0, Culture=neutral, PublicKeyToken=096a9279a87304f1"%>
<%@ Register  Namespace="Stimulsoft.Report.Web" TagPrefix="cc2"  Assembly="Stimulsoft.Report.WebDesign, Version=2012.3.1500.0, Culture=neutral, PublicKeyToken=096a9279a87304f1"%>

<!doctype html>
<html>
    <head runat="server">
        <title></title>
    </head>
    <body style="background-color: #e8e8e8">
        <form id="form1" runat="server">
        <div style="width: 960px;margin: 0 auto;">
            <cc1:StiWebViewer ID="StiWebViewer1" runat="server"  GlobalizationFile="/Content/page/reports/Localization/zh-CHS.xml" ShowDesignButton="True"  onreportdesign="StiWebViewer1_ReportDesign" Theme="Office2010"  BackColor="#e8e8e8"/>
            <cc2:StiWebDesigner ID="StiWebDesigner1" runat="server" LocalizationDirectory="/Content/page/reports/Localization/" Localization="zh-CHS" onsavereport="StiWebDesigner1_SaveReport" />
        </div>
        </form>
    </body>
</html>

后台代码:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Stimulsoft.Report;

namespace PE.IEM.Web
{
    public partial class report : System.Web.UI.Page
    {
        /// <summary>
        /// 将获取的报表放在阅读器中显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            StiWebViewer1.Report = GetReport();
        }

        /// <summary>
        /// 编辑报表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void StiWebViewer1_ReportDesign(object sender, EventArgs e)
        {
            StiWebDesigner1.Design(GetReport());
        }

        /// <summary>
        /// 保存报表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void StiWebDesigner1_SaveReport(object sender, Stimulsoft.Report.Web.StiWebDesigner.StiSaveReportEventArgs e)
        {
            var report = e.Report;
            report.Save(GetReportPath());
        }

        /// <summary>
        /// 获取报表
        /// </summary>
        /// <returns></returns>
        private StiReport GetReport()
        {
            var report = new StiReport();
            //根据路径加载报表文件
            report.Load(GetReportPath());
            //动态改变数据库连接
            ChangeConnectString(report);
            //设置参数等
            report.Compile();
            SetReportParamaters(report);
           
            return report;
        }

        private void SetReportParamaters(StiReport report)
        {
            var dataSource = report.CompiledReport.DataSources;
            foreach (Stimulsoft.Report.Dictionary.StiDataSource ds in dataSource)
            {
                var param = Request.QueryString;
                foreach (string key in param.Keys)
                {
                    if (!ds.Parameters.Contains(key)) continue;
                    var p = ds.Parameters[key];
                    var v = param[key];
                    p.ParameterValue = v;
                }
            }
        }

        private string GetReportPath()
        {
            var path = String.Format("~/Areas/{0}/Reports/{1}.mrt",Request["area"], Request["rpt"]);
            path = Server.MapPath(path);
            if (!System.IO.File.Exists(path))
          //如果报表文件不存在,返回默认的报表文件 path
= Server.MapPath("~/Content/page/reports/helloworld.mrt"); return path; } private void ChangeConnectString(StiReport report) { foreach (Stimulsoft.Report.Dictionary.StiSqlDatabase item in report.Dictionary.Databases) { var prefix = item.Name.Split('_')[0]; item.ConnectionString = ConfigurationManager.ConnectionStrings["sqlConnection"].ConnectionString; } } } }

 

就是把阅读器和编辑器放在模板中

3.注册路由:在App_Start文件夹的RouteConfig中注册报表模板访问路径

routes.MapPageRoute("Report", "report", "~/Content/page/report.aspx");

4.js调用:调用报表模板访问路径并传递2个参数,根据传递的参数去查找并加载指定报表文件

this.printClick = function () {
   parent.wrapper.addTab.apply(this,{
'打印报表', '/report?area=XX&rpt=helloworld', 'icon-printer_color'});
};

5.效果展示

转载于:https://www.cnblogs.com/mora1988/p/5714817.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Stimulsoft Reports.Web ——适用于Web的报表生成器。Stimulsoft Reports.Web是一个报表工具,其设计的目的在于通过Web浏览器创建和渲染报表。您可以创建报表,显示报表,打印报表,导出报表。 Stimulsoft Reports.Web将提供完整的报表创建周期,从报表模板开始到在浏览器显示报表为止。这一过程可在web浏览器未被关闭时完成。 Stimulsoft Reports.Web是第一款可以让您直接在Web编辑报表的报表工具。在您的客户端的机器里不需要安装.Net框架、ActiveX控件或其他特殊 插件。所有你需要的只是一个带有Flash Player 9的Web浏览器。 这是首次一个报表生成器能让您在web浏览器的窗口编辑您的报表。唯一的需求是一个web浏览器和Flash Player 9。Stimulsoft Reports.Web能具有最高程度、带状界面、可视化控件开发程序、剪贴板、点击查看大图表格编辑、缩放以及其他多种功能,可以方便快捷的进行报表编辑。 您可以在浏览器的窗口查看报表。您可以打印一份报表。您可以导出一份报表,其导出格式超过了20种:PDF、XPS、Excel、Word、HTML、 RTF以及XML等格式。这一切能在基于Ajax的报表Web浏览器完成,也能直接通过Web应用程序的一段代码来完成。 Stimulsoft Reports.Web支持多种类型的.Net数据,DataSet、DataTable、DataView以及DataRelation等。所有数据输出都要考虑在 DataSet的数据的分级结构。所有的数据都是典型数据。其次,另外还支持Ado.Net不同类型的商业对象。您也可以直接从MS SQL、Oracle、ODBC、OleDB、FirebirdSQL、PostgeSQL、SQLCE与SQLite等数据库获取数据。获取XML文 件的数据也没有问题。除此之外,还可以进行分类、过滤、分组、合并以及汇总。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值