FastReport.Net在Rozor中的應用

Webconfig中配置git

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

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

IIS7.0後  <system.webServer>  <handlers>api

 <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>中增長節點app

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

 

 

在Rozor中代碼less

@{
    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代碼spa

 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.net

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

FastReport設計設計

由於這裏的數據源是存儲過程而且用到了臨時表,全部存儲過程當中須要增長code

IF 1=0 BEGIN  
    SET FMTONLY OFF  
END  

不然提示#temp無效xml

 

這裏是經過程序後臺傳遞參數,因此要注意一下

1.

2.

3.

 

PS:還有一點須要強調,FastReport數據源能夠直接加載,不須要後臺傳遞DataSet也是能夠加載的,但要保證存儲過程的正確性

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

相關文章
相關標籤/搜索