Preview VS designer, string replacement in datasources

Stimulsoft Dashboards.WEB discussion
Post Reply
r.bianco
Posts: 75
Joined: Thu Oct 27, 2016 2:06 pm

Preview VS designer, string replacement in datasources

Post by r.bianco »

In our database we could have the same table for different companies, and a generic version which is used as schema.
Eg:
TABLEAxxx <- generic
TABLEAcompany1
TABLEAcompany2
...

I need to replace the "xxx" string in every datasource because the report/dashboard is generic and could not be bound to a specific table name, as another customer usually has different companies in the DB.
I came up with this code

Code: Select all

protected void StiWebViewer1_GetReport(object sender, EventArgs e)
	{
		Stimulsoft.Report.Dashboard.StiCacheCleaner.Clean();
	
		// Sostituisco i token "xxx" delle tabelle generiche con il codice ditta
		int index;
		StiReport myReport;
		StiSqlSource mySqlSource;

		myReport = StiWebViewer1.Report;
		for(index=0;index < myReport.Dictionary.DataSources.Count; index++  )
		{
			mySqlSource = (StiSqlSource)myReport.Dictionary.DataSources[index];
			mySqlSource.SqlCommand = mySqlSource.SqlCommand.Replace("xxx", Session["sCODAZI"].ToString());
		}
	}
Which works really well in the Preview.

In the designer it's a bit more complicate, since I can't just replace the "xxx" to show the preview, it will be saved!
Is it possible to replace it temporarily only when previewing in the designer without changing the actual datasource?
The only alternative is to remember to change back every occurrence to "xxx" just before saving… but it's really risky

EDIT: I just found about onpreviewreport event which can be used to manipulate the datasources in the same way without influencing the designer!
This is a wonderful tool, thank you
Soft System srl
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Preview VS designer, string replacement in datasources

Post by HighAley »

Hello.

Yes, the OnPreviewReport event is that you need.
You could find some additional information on the Programming Manual.

Thank you.
Post Reply