Page 1 of 2

How to build a generic report

Posted: Mon Aug 03, 2015 5:22 am
by beginner
I'd like to use Stimulsoft Reports in my ASP.NET MVC application. In my scenario, user will fill some fields and I will show him or her a report. User's values are used to limit the query and they're mostly used in a where clause, and a few of them are used for sorting and grouping.

Unfortunately, Stimulsoft is not able to pass parameters in the get snapshot method.

I'll be grateful if you could guide me to the best and easiest way to design this reports.

Re: How to build a generic report

Posted: Mon Aug 03, 2015 12:10 pm
by Vladimir
Hello,

You can pass parameters to the report in any action of the viewer. For example GetReportSnapshot:

Code: Select all

public ActionResult GetReportSnapshot()
{
    StiReport report = new StiRepot();
    report.Load("repor.mrt");
    report["ParamName1"] = "ParamValue";
    report["ParamName2"] = 123;

    return StiMvcViewer.GetReportSnapshotResult(report);
}
or:

Code: Select all

public ActionResult GetReportSnapshot(string name, int id)
{
    StiReport report = new StiRepot();
    report.Load("repor.mrt");
    report["ParamName1"] = name;
    report["ParamName2"] = id;

    return StiMvcViewer.GetReportSnapshotResult(report);
}
name and id - is a POST parameters


You can use the values of these parameters in report expressions and SQL queries.

Thank you.

Re: How to build a generic report

Posted: Tue Aug 04, 2015 3:39 am
by beginner
Thanks for your replay Vladimir,
Parameters that I want to pass are much higher, maybe about 20. This way I should have different report files and get snapshot methods for each report.

Do I have any better option?

Re: How to build a generic report

Posted: Tue Aug 04, 2015 8:43 am
by HighAley
Hello.

Maybe we don't understand something.
Could you describe your issue more detailed?

Thank you.

Re: How to build a generic report

Posted: Wed Aug 12, 2015 3:29 am
by beginner
I have another similar question,

It seems that the report uses its own Data source to fetch the data from DB, right? Can I change that, I'd like it to use my filtered query and data source. I have a lot of conditions that use can play with, I don't like to define a variable for each one of them, it'd be much easier if I could use my own query and limit the query on server-side. Is that possible?

Thanks for your advance Aleksey.

Re: How to build a generic report

Posted: Wed Aug 12, 2015 8:33 am
by HighAley
Hello.

You could use parameters and variables in SQL queries.
Please, read the Dynamic SQL queries article on our blog.

Thank you.

Re: How to build a generic report

Posted: Sat Aug 15, 2015 7:12 am
by beginner
Thanks for your replay Aleksey,

I was looking to filter data in my own code. I mean what is the reason of `Regdata` then?

Is there anyway that I can use something like this:

var data = from g in goods
.Where(x => x.CGoodCode.Equals("234"))
select g;
report.RegData("DataSource1", data);

Re: How to build a generic report

Posted: Sat Aug 15, 2015 9:31 pm
by Ivan
Hello,

Sorry, maybe we did not exactly understand your question.
Could you explain your issue in more details?

Thank you.

Re: How to build a generic report

Posted: Sun Aug 16, 2015 2:36 am
by beginner
Hi Ivan,

I'm looking for a way to filter data in my own code, because I have so many variables, defining all of them in the report is a little hard. On the other hand, if I was able to filter the data in my own code and in my MVC app and send that data to the report, things would be much easier.

Imagine a scenario where I receive a relatively big form from user, I'll build the data with all of the where and order clauses and send it to the report... .

Thanks for your attention.

Re: How to build a generic report

Posted: Mon Aug 17, 2015 6:54 am
by HighAley
Hello.

You could use RegData method and register your DataSet in the report.

Thank you.