Using Custom Save Dialog in the DesignerFx

This example shows how to use the custom save report dialog in the flash designer. By default, the report saving as the POST request in the AJAX mode, but it is possible to change this behavior.

First, you need to add the StiMvcDesignerFx component to the view page. Also you need to pass the object of the StiMvcDesignerFxOptions type to the constructor. The minimum required options are two actions - GetReport and DesignerEvent, which are located in the Actions options group. It is desirable to define the PreviewReport action, which is necessary to preview the report.

To add the ability to save the report, you need to define the SaveReport action. Also you should set the SaveReportMode option to change the behavior of the save the report algorithm.

@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
}
})


Next, you need to add the view with the custom save dialog. For example, create a simple form which a text box that will contain the name of the report file, and a save button. Save this view as a 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>
}


Now we need to add all the actions in the controller. For example use one controller for the flash designer and for the custom save dialog view.

The GetReport action loads the report template and returns answer to the client part of the flash designer using the GetReportResult() static method. In the parameters of this method, the report object should be passed.

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

return StiMvcDesignerFx.GetReportResult(report);
}


The PreviewReport action will be invoked when you open the preview report tab in the flash designer. In this action, you can get the report object and perform any action, for example connect to data. To prepare the answer for the client you should use the PreviewReportResult() static method. In the parameters of this method, the report object should be passed.

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);
}


The SaveReport action will be invoked when you click at the Save button in the flash designer. In this action get the report object and store it in the server session table, as object ID use the "SaveReportTemplate" string constant value. After these actions, we do a redirect to the other view, where is our custom save dialog.

public ActionResult SaveReport()
{
StiReport report = StiMvcDesignerFx.GetReportObject();

// Store the report object in the session
Session["SaveReportTemplate"] = report;
return View("SaveDialog");
}


The DesignerEvent action handles some flash designer events (work with the data dictionary, get report template code and component images, etc.) and returns the answer to the client using the DesignerEventResult() static method.

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


The SaveReportFromDialog action will be invoked when you click at the Save button in the custom save dialog form. In this action get the report object from the server session by ID, which is used in the flahs designer action. Now you can save the report, for example as a file with name, entered in the custon save dialog form. After these actions, we do a redirect to the Index view, where is the flash designer.

public ActionResult SaveReportFromDialog(string filename)
{
StiReport report = Session["SaveReportTemplate"] as StiReport;

// Save report
// report.Save(filepath + filename);

return View("Index");
}


In the screenshot below you can see the result of the sample code.

Using Custom Save Dialog in the DesignerFx