码迷,mamicode.com
首页 > Web开发 > 详细

FastReport.Net在Rozor中的应用

时间:2016-08-21 15:09:31      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:

Webconfig中配置

IIS6.0 <system.web> <httpHandlers> 下增加

<httpHandlers>  
     <add path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport"/>  
</httpHandlers>  

IIS7.0后  <system.webServer>  <handlers>

 <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
      <remove name="FastReportHandler"/> 
      <add name="FastReportHandler" path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport" />
    </handlers>
   
    <staticContent>
        <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
        <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" />
    </staticContent>
    
  </system.webServer>

 

<system.web.webPages.razor>中增加节点

<add namespace="FastReport" />
<add namespace="FastReport.Web" />

 

 

在Rozor中代码

@{
    ViewBag.Title = "Index";
}
@FastReport.Web.WebReportGlobals.ScriptsWOjQuery()
@FastReport.Web.WebReportGlobals.StylesWOjQuery()
<style >
    .frtoolbar{
        height:40px !important;
    }
</style>
<div style="overflow:scroll;height:100%">
    @ViewBag.WebReport.GetHtml()
</div>

 

 

Action代码

 public ActionResult Index()
        {
            SetReport();
            webReport.Width = Unit.Percentage(100); // 
            webReport.Height = Unit.Percentage(100);// ; 
            webReport.ToolbarIconsStyle = ToolbarIconsStyle.Red;
            webReport.ToolbarStyle = ToolbarStyle.Small;
            webReport.ShowExports = true;
            webReport.ShowToolbar = true;
            webReport.ShowZoomButton = true;
            webReport.ShowPrint = true;
            webReport.AutoHeight = true;
            ViewBag.WebReport = webReport;
            return View();
        }
        private void SetReport()
        {
            string report_path = GetReportPath();
            var user = (User)HttpContext.Session[Common.Constants.USER_KEY];
            webReport.Report.Load(report_path + "test2.frx");
            webReport.Report.Parameters.FindByName("工号").Value = user.SysOperator.LoginName;
            webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black;
            webReport.ShowExports = true;
            webReport.ShowPrint = true;
            ViewBag.WebReport = webReport;
        }
        private string GetReportPath()
        {
            string report_path = Config.ApplicationFolder;
            using (XmlDocument xml = new XmlDocument())
            {
                xml.Load(@Server.MapPath("../../App_Data/fastReport.config"));
                foreach (XmlItem item in xml.Root.Items)
                    if (item.Name == "Config")
                        foreach (XmlItem configitem in item.Items)
                            if (configitem.Name == "Reports")
                                report_path += configitem.GetProp("Path");
            }
            return report_path;
        }

fastReport.config

<?xml version="1.0" encoding="utf-8" ?>
<Test>
         <Config>
                    <Reports Path="\App_Data\report\"/>
         </Config>
</Test>

FastReport设计

因为这里的数据源是存储过程并且用到了临时表,所有存储过程中需要增加

IF 1=0 BEGIN  
    SET FMTONLY OFF  
END  

否则提示#temp无效

 

这里是通过程序后台传递参数,所以要注意一下

1.

技术分享

2.

技术分享

3.

技术分享

 

PS:还有一点需要强调,FastReport数据源可以直接加载,不需要后台传递DataSet也是可以加载的,但要保证存储过程的正确性

附上FastReport可用版本http://download.csdn.net/detail/anbylau2130/9608832

FastReport.Net在Rozor中的应用

标签:

原文地址:http://www.cnblogs.com/anbylau2130/p/5792689.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!