標籤:
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中的應用