翻譯|使用教程|編輯:王香|2018-10-12 09:46:25.000|閱讀 463 次
概述:此示例項目演示了如何將報表模板加載到Flash設計器并在編輯后保存,還顯示了如何為報表注冊數據以進行預覽。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
【下載Stimulsoft Reports.Net最新版本】
首先,我們需要將Flash設計器組件放在ASPX頁面上并定義必要的事件處理器:OnSaveReport用于保存報表模板,而OnPreviewReport用于注冊預覽數據。還可以創建一個表和Web控件,允許以多種方式加載報表。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Load_and_Save_Report_in_the_DesignerFx.Default" %> <%@ Register assembly="Stimulsoft.Report.WebDesign" namespace="Stimulsoft.Report.Web" tagprefix="cc1" %> <!DOCTYPE html> <html xmlns="//www.w3.org/1999/xhtml"> <head runat="server"> <title>Load and Save Report in the DesignerFx</title> <style type="text/css"> .style1 { width: 80px; text-align: center; } .style2 { width: 260px; vertical-align: top; } </style> </head> <body> <form id="form1" runat="server"> <div> <cc1:StiWebDesignerFx ID="StiWebDesignerFx1" runat="server" visible="false" OnSaveReport="StiWebDesignerFx1_SaveReport" OnPreviewReport="StiWebDesignerFx1_PreviewReport" /> <table> <tr> <td class="style2"> <asp:Label ID="Label1" runat="server" Font-Names="Arial" Font-Size="11pt" Text='1. Choose ".mrt" file'></asp:Label><br /> <asp:Label ID="Label2" runat="server" Font-Names="Arial" Font-Size="11pt" Text='2. Click "Design" button'></asp:Label><br /> <br /> <asp:FileUpload ID="FileReport" runat="server" Font-Names="Arial" Font-Size="11pt" Width="264px" /> <br /> <br /> <asp:Button ID="ButtonDesignFile" runat="server" Text="Design" Width="141px" OnClick="ButtonDesignFile_Click" /> <br /> </td> <td class="style1"><b>or</b></td> <td class="style2"> <asp:Label ID="Label3" runat="server" Font-Names="Arial" Font-Size="11pt" Text='1. Choose Report on server'></asp:Label><br /> <asp:Label ID="Label4" runat="server" Font-Names="Arial" Font-Size="11pt" Text='2. Click "Design" button'></asp:Label><br /> <br /> <asp:DropDownList ID="DropDownListReport" runat="server" Width="250px"> <asp:ListItem Value="SimpleList.mrt"></asp:ListItem> <asp:ListItem Value="TwoSimpleLists.mrt"></asp:ListItem> <asp:ListItem Value="Invoice.mrt"></asp:ListItem> <asp:ListItem Value="Shapes.mrt"></asp:ListItem> </asp:DropDownList> <br /> <br /> <asp:Button ID="ButtonDesignServer" runat="server" Text="Design" Width="141px" onclick="ButtonDesignServer_Click" /> <br /> <td class="style1"><b>or</b></td> <td class="style2"> <br /> <br /> <br /> <asp:Button ID="ButtonDesignNew" runat="server" Text="Design New Report" Width="157px" onclick="ButtonDesignNew_Click" /> </td> </td> </tr> </table> </div> </form> </body> </html>
在下一步中,創建按鈕三個單擊處理程序,以多種方式加載報表模板。該ButtonDesignFile_Click方法加載從本地計算機的報表中,ButtonDesignServer_Click方法從列表加載selecter報表和ButtonDesignNew_Click方法創建新的報表模板。
protected void ButtonDesignFile_Click(object sender, EventArgs e) { if (FileReport.PostedFile != null && FileReport.PostedFile.FileName.Length > 0 && FileReport.PostedFile.InputStream != null) { StiReport report = new StiReport(); report.Load(FileReport.PostedFile.InputStream); StiWebDesignerFx1.Design(report); } } protected void ButtonDesignServer_Click(object sender, EventArgs e) { if (DropDownListReport.Text != null && DropDownListReport.Text.Length > 0) { string applicationDirectory = HttpContext.Current.Server.MapPath(string.Empty); string reportFileName = applicationDirectory + "\\Reports\\" + DropDownListReport.Text; StiReport report = new StiReport(); report.Load(reportFileName); StiWebDesignerFx1.Design(report); } } protected void ButtonDesignNew_Click(object sender, EventArgs e) { StiReport report = new StiReport(); StiWebDesignerFx1.Design(report); }
該StiWebDesignerFx1_SaveReport方法通過點擊Flash設計的保存按鈕調用。在此方法的參數中,將傳遞報表模板對象。您可以將此報表模板保存到文件,將數據庫保存為打包字符串或使用其他方式保存。您還可以設置保存報表后將在設計器中顯示的錯誤代碼或字符串消息。
protected void StiWebDesignerFx1_SaveReport(object sender, StiSaveReportEventArgs e) { // Web Designer return StiReport object in the e.Report property var reportString = e.Report.SaveToString(); // You can set the error code which will be displayed by the designer after saving // -1: default value, the message is not displayed // 0: display 'Report is successfully saved' message //e.ErrorCode = 1; // Also you can set the custom message, it will be displayed after saving e.ErrorString = "Your report has been saved."; }
如果需要為報表預覽注冊一些數據,則應定義StiWebDesignerFx1_PreviewReport方法。在此方法中,您可以加載和注冊必要的數據集,例如加載樣本報表的XML數據。
protected void StiWebDesignerFx1_PreviewReport(object sender, StiReportDataEventArgs e) { string applicationDirectory = HttpContext.Current.Server.MapPath(string.Empty); DataSet data = new DataSet(); data.ReadXml(applicationDirectory + "\\Data\\Demo.xml"); data.ReadXmlSchema(applicationDirectory + "\\Data\\Demo.xsd"); e.Report.RegData(data); }
示例代碼的結果如下圖所示:
購買Stimulsoft正版授權,請點擊“”喲!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn