【Stimulsoft Reports.Net教程】在DesignerFx中加载和保存 表

【下载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 ><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

下载示例

购买Stimulsoft正版授权,请点击“咨询在线客服”哟!

FastReport2018.4

标签: 表解决方案 表.NETFLASH 表控件 表设计stimulsoft report .netStimulsoft

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年9月9日
下一篇 2018年9月9日

相关推荐

发表回复

登录后才能评论