原創|使用教程|編輯:鄭恭琳|2017-11-21 17:39:19.000|閱讀 829 次
概述:Online Designer是在Internet上創建報告的絕佳工具。 我們來看看這種情況。 您創建一個報告模板,保存它,然后......看到消息“沒有保存”。 但是,哪里出錯了呢? 您怎么知道錯誤是什么? 現在,web報告具有“調試”屬性,您可以使用該屬性在線報告設計器中“捕捉”錯誤。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Online Designer是在Internet上創建報告的絕佳工具。 我們來看看這種情況。 您創建一個報告模板,保存它,然后......看到消息“沒有保存”。 但是,哪里出錯了呢? 您怎么知道錯誤是什么? 現在,web報告具有“調試”屬性,您可以使用該屬性在線報告設計器中“捕捉”錯誤。
我們需要啟用WebReport.Debug屬性,并在保存報告的方法中創建一個錯誤處理程序。 當調用WebReport.DesignerSaveCallBack事件時,該錯誤將被傳遞給設計器。
讓我們看一下簡化的online designer保存報告的過程,然后就會發生這樣的情況:
我們來看一個例子。 創建一個ASP.Net MVC應用程序。
打開控制器HomeController.cs。 初步添加鏈接到鏈接中的FastReport和FastReport.Web庫。 “uses”部分將包含以下鏈接:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.UI; using System.Runtime.Caching; using System.Text; using System.IO; using FastReport; using FastReport.Web; using FastReport.Utils; using System.Web.UI.WebControls; using FastReport.Export.Html; using FastReport.Data; using System.Net.Http.Headers; using FastReport.Export.Image; using System.Net.Http;
在索引方法中,我們將創建一個空的報表并在在線設計器(OnlineDesigner)中打開它。 但是,事先您需要在該項目中添加一個online designer。 將下載的在線設計器解壓到解決方案根目錄下的WebReportDesigner文件夾中:
public ActionResult Index() { WebReport webReport = new WebReport(); // Create a new web report Report report = new Report(); // Create a new report ReportPage page = new ReportPage(); // Create a new report page report.Pages.Add(page); // Add a page to the report webReport.Width = Unit.Percentage(100); // Web Report Width 100% webReport.Height = Unit.Percentage(100);// Web Report Height 100% string report_path = this.Server.MapPath("~/App_Data/");// Report folder System.Data.DataSet dataSet = new System.Data.DataSet();//Create a data set dataSet.ReadXml(report_path + "nwind.xml");// load the database into it webReport.Report = report; // Assign a blank report to the report in the program webReport.RegisterData(dataSet, "NorthWind");// Register the data source in the report webReport.DesignReport = true; // Enable report design mode webReport.DesignerPath = "~/WebReportDesigner/index.html";// Set the path to the designer webReport.DesignerSaveCallBack = "~/Home/SaveDesignedReport";// Set the view to save the reports, which we will create a little later webReport.ID = "DesignReport"; //Report id webReport.Debug = true; ViewBag.WebReport = webReport; return View(); }
現在我們需要一個在線設計器中保存報告的方法:
[HttpPost] public ActionResult SaveDesignedReport(string reportID, string reportUUID) { ViewBag.Message = String.Format("Confirmed {0} {1}", reportID, reportUUID); if (reportID == "DesignReport") { try { Stream reportForSave = Request.InputStream; string pathToSave = Server.MapPath("~/App_Data/DesignedReports/test.frx"); using (FileStream file = new FileStream(pathToSave, FileMode.CreateNew)) { reportForSave.CopyTo(file); } } catch (Exception e) { throw new Exception(e.Message); } } return View(); }
在這里,我們添加錯誤處理。 要將錯誤返回給在線設計器,您需要拋出一個異常:
throw new Exception(e.Message);
對于這個動作,我們創建一個名為SaveDesignedReport.cshtml的單獨視圖和下面的代碼:
@ViewBag.Message
現在考慮索引頁面的視圖(Home-> Index.cshtml):
@{ ViewBag.Title = "Home Page"; } @ViewBag.WebReport.GetHtml();
在頂部我們顯示頁面的標題。 接下來,我們顯示從控制器收到的報告。
在文件_Layout.cshtml中,您需要連接腳本:
@WebReportGlobals.Scripts() @WebReportGlobals.Styles()
現在您需要對兩個Web配置進行更改。 這些文件被稱為相同,但它們位于不同的文件夾中。 第一個位于Views文件夾中。 添加到:
…
第二個文件位于項目的根目錄下。 在其中我們添加一個處理程序:
…
運行我們的應用。
轉到“報告”標簽。 點擊“保存”。 第一次應該是成功的。 再次按保存按鈕。 我們得到一個錯誤。 從文本中可以明顯看出,具有該名稱的報告模板文件已經存在。
所以我們為我們的報告和整個Web應用程序提供了一個調試工具。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn