彩票走势图

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

翻译|使用教程|编辑:王香|2018-10-12 09:46:25.000|阅读 371 次

概述:此示例项目演示了如何将报表模板加载到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

购买Stimulsoft正版授权,请点击“”哟!

FastReport2018.4


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

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@cahobeh.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP