原創(chuàng)|使用教程|編輯:王香|2018-07-09 10:07:08.000|閱讀 683 次
概述:如何在ASP .Net Core中輕松,簡單地使用Online Designer
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
FastReport .Net 2018的一個新穎之處是將OnlineDesigner改編為.Net Core框架。 一般來說,OnlineDesigner并沒有改變。今天將在ASP.Net Core項目中使用它的一些功能。 首先需要在Web設計器中構建OnlineDesigner。 在OnlineDesigner的web designer中,應該選擇必須存在的組件,樣式,插件等。請注意“配置”部分。需要在此處設置API URLs。選擇FastReport.Web for Core:
組裝完Designer后,即可下載存檔。 創(chuàng)建一個ASP.Net Core Web Application:
選擇Web Application(Model-View-Controller):
需要將FastReport.Web庫添加到項目中??梢允褂肕anage Nuget Packages執(zhí)行此操作。在解決方案資源管理器中右鍵單擊項目的根目錄,然后選擇Manage Nuget Packages:
在包管理器中選擇Local package source:
需要在文件夾上配置它:С:\ Program Files(x86)\ FastReports \ FastReport.Net \ Nugets。請單擊齒輪圖標:
之后,將看到FastReport包。安裝FastReport.Web:
開始創(chuàng)建程序。 需要將文件夾WebReportDesigner放在wwwroot中下載的檔案中。 將兩個文件夾添加到wwwroot:Reports和DesignedReports。 在第一個文件夾中,將放置Simple List.frx報告模板和nwind.xml數(shù)據(jù)庫。這兩個文件都可以在文件夾C:\ Program Files(x86)\ FastReports \ FastReport.Net \ Demos \ Reports中獲取。將報告從OnlineDesigner保存到DesignedReports文件夾。 打開控制器HomeController.cs。添加庫來使用:
using FRCoreOnlineDesigner.Models; using FastReport.Web; using System.IO; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Hosting;
在HomeController構造函數(shù)中,獲取了hostingEnvironment對象,從中學習了wwwroot文件夾的絕對路徑。
public HomeController(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment; }
編輯Index方法:
public IActionResult Index() { WebReport WebReport = new WebReport(); // Create a Web Report Object WebReport.Width = "1000"; // Set the width of the report WebReport.Height = "1000"; // Set the height of the report string webRootPath = _hostingEnvironment.WebRootPath; // Get the path to wwwroot folder //string contentRootPath = _hostingEnvironment.ContentRootPath; WebReport.Report.Load(webRootPath + "/reports/Simple List.frx"); // Load the report into a WebReport object System.Data.DataSet dataSet = new System.Data.DataSet(); // Create a data source dataSet.ReadXml(webRootPath + "/reports/nwind.xml"); // Open the xml database WebReport.Report.RegisterData(dataSet, "NorthWind"); //Register the data source in the report WebReport.Mode = WebReportMode.Designer; // Set the mode of the web report object - display of the designer WebReport.DesignerPath = "/WebReportDesigner/index.html"; // Specify the URL of the online designer WebReport.DesignerSaveCallBack = "/Home/SaveDesignedReport"; // Set the view URL for the report save method ViewBag.WebReport = WebReport; // pass report to View return View(); }
再添加一個方法-SaveDesignedReport方法:
[HttpPost] // call-back for save the designed report public ActionResult SaveDesignedReport(string reportID, string reportUUID) { string webRootPath = _hostingEnvironment.WebRootPath; // Get the path to wwwroot folder ViewBag.Message = String.Format("Confirmed {0} {1}", reportID, reportUUID); // Set a message for view Stream reportForSave = Request.Body; // Write the result of the Post query to the stream string pathToSave = webRootPath + "/DesignedReports/TestReport.frx"; // get the path to save the file using (FileStream file = new FileStream(pathToSave, FileMode.Create)) // Create a file stream { reportForSave.CopyTo(file); // Save the result of the query to a file } return View(); }
對于此Web方法,需要再添加一個Views。對于文件夾Views-> Home,調用上下文菜單并選擇Add-> New item。接下來,選擇MVC View Page模板和SaveDesignedReport。
頁面代碼非常簡單:
<h2>@ViewBag.Message</h2>
編輯view index.cshtml:
@{ ViewData["Title"] = "Home Page"; } @await ViewBag.WebReport.Render()
await語句指示對異步報告處理方法的調用。 現(xiàn)在打開Startup.cs類。 在Configure方法中,最開始添加以下行:
app.UseFastReport();
現(xiàn)在應用程序將使用FRCore庫。 啟動Web Application。
保存報表:
保存完成后,檢查DesignedReports文件夾:
該報告已成功保存,總結一下。FastReport .Net 2018已完成其Web組件對ASP .Net Core框架的全局調整。與此同時,開發(fā)人員試圖盡可能地保持使用其組件的機制,類似于它們在ASP .Net MVC中的使用。
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn