Page 1 of 1

Preview VS designer, string replacement in datasources

Posted: Tue Mar 19, 2019 11:07 am
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

Re: Preview VS designer, string replacement in datasources

Posted: Wed Mar 20, 2019 2:02 pm
by HighAley
Hello.

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

Thank you.