public static class ReportDocumentExtensions
{
public static void SetConnectionInfo(this ReportDocument report, ReportContextArgs context)
{
SetConnectionInfo(report, context.UserId, context.Password, context.ServerName, context.DatabaseName);
}
public static void SetConnectionInfo(this ReportDocument report, string userId, string password, string serverName, string databaseName)
{
foreach (Table oTable in report.Database.Tables)
{
TableLogOnInfo oInfo = oTable.LogOnInfo;
ConnectionInfo oConnection = oTable.LogOnInfo.ConnectionInfo;
oConnection.UserID = userId;
oConnection.Password = password;
oConnection.ServerName = serverName;
oConnection.DatabaseName = databaseName;
oTable.ApplyLogOnInfo(oInfo);
}
}
}
public class ReportContextArgs
{
private string _userId;
private string _password;
private string _serverName;
private string _databaseName;
public string ServerName
{
get { return _serverName; }
set { _serverName = value; }
}
public string UserId
{
get { return _userId; }
set { _userId = value; }
}
public string Password
{
get { return _password; }
set { _password = value; }
}
public string DatabaseName
{
get { return _databaseName; }
set { _databaseName = value; }
}
}