Stimulsoft ASP.NET MVC报表教程:在DESIGNERFX中使用自定义保存对话框

本示例说明了如何在Flash Designer中使用自定义保存报表对话框。默认情况下,该报表在AJAX模式下另存为POST请求,但是可以更改此行为。

本示例说明了如何在Flash Designer中使用自定义保存报表对话框。默认情况下,该报表在AJAX模式下另存为POST请求,但是可以更改此行为。

首先,您需要将StiMvcDesignerFx组件添加到视图页面。您还需要将StiMvcDesignerFxOptions类型的对象传递给构造函数。所需的最少选项是两个操作——GetReport和DesignerEvent,它们位于操作“Actions”选项组中。最好定义PreviewReport操作,这对于预览报表是必需的。

要添加保存报表的功能,您需要定义SaveReport操作。您还应该设置SaveReportMode选项来更改保存报表算法的行为。

@using Stimulsoft.Report.Web;@using Stimulsoft.Report.Mvc;...@Html.Stimulsoft().StiMvcDesignerFx(new StiMvcDesignerFxOptions(){    Actions =    {        GetReport = "GetReport",        PreviewReport = "PreviewReport",        SaveReport = "SaveReport",        DesignerEvent = "DesignerEvent"    },    Behavior =    {        SaveReportMode = StiSaveMode.Visible    }})

接下来,您需要使用自定义保存对话框添加视图。例如,创建一个简单的表单,其中包含将包含报表文件名称的文本框和一个保存按钮。将此视图另存为SaveDialog。

<h2>Custom Save Dialog</h2>@using (Html.BeginForm("SaveReportFromDialog", "DesignerFx", FormMethod.Post)){    <fieldset>        Report file name:<br />        <input name="filename" type="text" value="MyReport.mrt" width="100" /><br /><br />        <input type="submit" value="Save" />    </fieldset>}

现在,我们需要在控制器中添加所有动作。例如,将一个控制器用于Flash Designer和自定义保存对话框视图。

GetReport操作将加载报表模板,并使用GetReportResult()静态方法将答案返回给Flash Designer的客户端部分。在此方法的参数中,应传递报表对象。

public ActionResult GetReport(){    StiReport report = new StiReport();    report.Load(Server.MapPath("~/Content/Reports/TwoSimpleLists.mrt"));     return StiMvcDesignerFx.GetReportResult(report);}

当您在Flash设计器中打开预览报表选项卡时,将调用PreviewReport操作。在此操作中,您可以获取报表对象并执行任何操作,例如连接到数据。要为客户准备答案,您应该使用PreviewReportResult()静态方法。在此方法的参数中,应传递报表对象。

public ActionResult PreviewReport(){    DataSet data = new DataSet("Demo");    data.ReadXml(Server.MapPath("~/Content/Data/Demo.xml"));     StiReport report = StiMvcDesignerFx.GetReportObject();    report.RegData(data);    return StiMvcDesignerFx.PreviewReportResult(report);}

当您单击Flash Designer中的保存按钮时,将调用SaveReport操作。在此操作中,获取报表对象并将其存储在服务器会话表中,因为对象ID使用“SaveReportTemplate”字符串常量值。完成这些操作后,我们将重定向到另一个视图,即我们的自定义保存对话框。

public ActionResult SaveReport(){    StiReport report = StiMvcDesignerFx.GetReportObject();    // Store the report object in the session    Session["SaveReportTemplate"] = report;    return View("SaveDialog");}

DesignerEvent操作将处理一些Flash Designer事件(使用数据字典、获取报表模板代码和组件图像等),并使用DesignerEventResult()静态方法将答案返回给客户端。

public ActionResult DesignerEvent(){    return StiMvcDesignerFx.DesignerEventResult();}

当您单击自定义保存对话框表单中的保存按钮时,将调用SaveReportFromDialog操作。在此操作中,按ID从服务器会话中获取报表对象,该ID在flahs设计器操作中使用。现在,您可以将报表保存为例如带有名称的文件,该文件在custon save对话框表单中输入。完成这些操作后,我们将重定向到索引视图,即Flash设计器。

public ActionResult SaveReportFromDialog(string filename){    StiReport report = Session["SaveReportTemplate"] as StiReport;    // Save report    // report.Save(filepath + filename);    return View("Index");}

在下面的屏幕截图中,您可以看到示例代码的结果。

Stimulsoft ASP.NET MVC报表教程:在DESIGNERFX中使用自定义保存对话框

下载示例代码

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年9月27日
下一篇 2019年9月27日

相关推荐

发表回复

登录后才能评论