FastReport在線報表設計器工做原理

FastReport Online Designer工做原理

working-principle.jpg
Online Designer能夠與FastReport.Net的Win+Web版,專業版,企業版中的FastReport.Net WebReport對象一塊兒使用。
在線設計器能夠改變報表的報告和事件處理程序的腳本,但默認狀況下,出於安全緣由,該選項被禁用。該功能可在WebReport對象的屬性中來啓用。當這個選項在腳本內容中被禁用,以後的設計將被忽略被原來的文本替換。此外,爲了安全起見,咱們不發送Designer中內置的鏈接字符串。html

  1. WebReport對象在ASP.NET頁面加載。web

  2. WebReport發送一個Ajax請求到FastReport的處理程序,以得到在iframe環境的在線設計器容器(報表設計器的代碼被放置在應用程序站點的一個單獨的文件夾裏)。數據庫

  3. 當在線設計器在瀏覽器中加載,它發送AJAX查詢處處理程序以獲取報表模板(getReportByUUIDFrom)。瀏覽器

  4. 服務器應用程序準備併發送一個報表模板到在線設計器。緩存

  5. 設計器能夠請求預覽當前報表,經過發送請求到服務器中的處理器(makePreviewByUUID)。服務器應用程序運行收到的報表,並以html返回結果。而後設計器在預覽窗口顯示出來,該預覽能夠打印或以多種格式導出。安全

  6. 設計器能夠經過帶有報表內容的AJAX查詢(saveReportByUUIDTo)將報表保存在服務器中。服務器應用程序準備接收數據併發送請求到應用程序的回撥頁面。服務器

WebReport對象存在服務器緩存中的時間有限,而後從存儲器中被刪除。對象在內存中的保存時間由WebReport.CacheDelay屬性決定,以分鐘計算(默認狀況下是60)。併發

>>FastREport Online Designer當即在線體驗ide

Online Designer的設置手冊:

  1. 首先,從安裝路徑複製帶有在線設計器的文件夾(默認:WebReportDesigner)到Web應用程序根的目錄。佈局

2.而後檢查WebReport功能所需的處理程序設置文件web.config:
IIS6:

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

IIS7:

< system.webServer>
< handlers>
< add name="FastReportHandler" path="FastReport.Export.axd" verb="*"
type="FastReport.Web.Handlers.WebExport"/>
< /handlers>
< /system.webServer>

3.而後檢查Web/ ReportDesigner/scripts/ cofig-data.js文件中的報表設計器的設置:

'getReportByUUIDFrom': '/FastReport.Export.axd?getReport=',
'saveReportByUUIDTo': '/FastReport.Export.axd?putReport=',
'makePreviewByUUID': '/FastReport.Export.axd?makePreview=',

這些參數應包含FastReport處理器相對於網站的根目錄的路徑。若是路徑與所寫不一樣,必需要糾正,例如:

'getReportByUUIDFrom': '/oursite/FastReport.Export.axd?getReport=',

4.當WebReport用於ASPX標記中,你須要將對象拖拽到頁面上並設置其屬性。對於MVC,你須要在控制器中寫入代碼:

4.1. 啓用報表的編輯功能:

webReport.DesignReport = true;

4.2. 設置的惟一對象名稱WebReport,必要時能夠在回調頁面設置可進一步可區分的對象名稱:

webReport.ID = "MyDesignReport1";

4.3. 在在線設計器中禁止報表的腳本編輯,或者若是你想啓用編輯功能 - 設置爲true便可:

webReport.DesignScriptCode = false;

4.4. 指定報表設計器的主文件的路徑,將帶有設計器的文件夾複製到網頁應用程序的適當位置:

webReport.DesignerPath = "~/WebReportDesigner/index.html";

4.5. 設置網頁上的回調頁面路徑,該調用在報表被保存到臨時文件夾後執行。例如:MVC的視圖路徑(你須要專門在控制器中建立一個新的相同名稱的空白視圖來執行回調):

webReport.DesignerSaveCallBack = "~/Home/SaveDesignedReport";

或ASPX示例:

webReport.DesignerSaveCallBack = "~/DesignerCallBack.aspx";

下面是GET請求發送的參數:

reportID="here is webReport.ID"&reportUUID="here is saved report file name"

在這兒的reportID對應WebReport.ID對象,而且名爲reportUUID的文件被存儲在臨時文件夾中。開發人員執行進一步的操做,將報表保存到磁盤,數據庫或雲存儲中。在保存後,名爲reportUUID的臨時文件必須從臨時文件夾刪除。也能夠使用POST查詢來回調報表文件的回撥轉移,性情見下面的4.6。
回調頁的示例代碼以下。

4.6設置在執行回調前用來保存編輯後的報表的臨時文件夾的路徑,該文件夾必須設置寫入權限:

webReport.DesignerSavePath = "~/App_Data/DesignedReports";

你也能夠設置屬性webReport.DesignerSavePath爲空字符串以激活POST模式。

4.7. 在服務器緩存中設置WebReport對象的生命週期,以分爲單位,默認時間爲60:

webReport.CacheDelay = 120;

5.建立一個回調頁面來保存編輯後的報表。

5.1. 若是你使用的是ASPX佈局,你須要在Page_Load事件處理程序添加如下代碼:

protected void Page_Load(object sender, EventArgs e)
{
string reportID = Request.QueryString["reportID"];
string reportUUID = Request.QueryString["reportUUID"];
// 1. ReportID value identifies the object that caused the designer. The value
corresponds to the property webReport.ID, which was filled by a call of the designer.
// 2. Combining the path that we have filled in the property webReport.DesignerSavePath,
and the resulting reportUUID, we get the path to the temporary file with edited report.
// 3. This file can be opened and saved in the right place for us to drive or the cloud
or in a database.
// 4. The temporary file must be deleted after saving.
}

5.2. 在MVC標記中,你須要在控制器和空視圖中建立一個方法。控制器中的代碼以下:

public ActionResult SaveDesignedReport(string reportID, string reportUUID)
{
// 1. ReportID value identifies the object that caused the designer. The value
corresponds to the property webReport.ID, which was filled by a call of the designer.
// 2. Combining the path that we have filled in the property webReport.DesignerSavePath,
and the resulting reportUUID, we get the path to the temporary file with edited report.
// 3. This file can be opened and saved in the right place for us to drive or the cloud
or in a database.
// 4. The temporary file must be deleted after saving.
return View();
}

在處理POST傳送時須要在控制器前添加[HttpPost] ,以下:

[HttpPost]
 public ActionResult SaveDesignedReport(string reportID, string reportUUID)
{
...
}

5.3. 你能夠經過webReport.DesignerLocale=「EN」屬性使用在線設計器的任何本地化版本; ("en" 能夠更改成其它任何支持的語言,支持的語言的完整列表存放在設計器分發包中的文件中)。當建立回調頁保存報表的處理器時應特別注意過濾和檢查收到的Get請求的參數。務必確認它們爲null。在線設計器對象的最好放置地方是在頁面的底部。推薦的寬度爲100%或至少930px像素。對象的高度建議設置至少600px。

相關文章
相關標籤/搜索