我将VS 2008用于设计器RDL文件并在Report Server SSRS中进行部署。 我将VS 2012 .NET 4.5用于我的ASP.NET应用程序,以PDF或Excel格式呈现报告,并发送到浏览器。现在,我想将RDLC(本地报告)迁移到RDL。
我的问题:
我可以使用自定义对象(我的几个实体列表)作为远程报告(RDL)的来源吗? , 不是RDLC ?
我用
private ReportExecutionService reportExecutionService = new ReportExecutionService(); // Web Service proxy
reportExecutionService.Credentials = CredentialCache.DefaultCredentials;
reportExecutionService.Credentials = new NetworkCredential(Properties.Settings.Default.ReportBrowserUser
, Properties.Settings.Default.ReportBrowserPass
, Properties.Settings.Default.ReportBrowserDomain);
//reportExecutionService.Url = System.Configuration.ConfigurationManager.AppSettings.Get("Reporting.ReportExecutionService.Url");
reportExecutionService.Url = Reporting.Properties.Settings.Default.ReportExecutionServiceUrl;
reportExecutionService.PreAuthenticate = true;
reportExecutionService.ExecutionHeaderValue = new ExecutionHeader();
列出,我的实体为"数据源"填写我的报告:
public void ProcessRequest(HttpContext context)
{
var empresa = Convert.ToInt32(context.Request["empresa"]);
var mediador = Convert.ToInt32(context.Request["mediador"]);
List<TablaEvolucionValorAnterior> listaPolizas = DatosGrafica.GetTablaEvolucionPolizasVentas(empresa, mediador);
List<TablaEvolucionValorAnterior> listaPrimas = DatosGrafica.GetTablaEvolucionPrimasVentas(empresa, mediador);
List<TablaRamosVentas> listaRamos = DatosGrafica.GetTablaRamosVentas(empresa, mediador);
RDLC
<DataSets>
<DataSet Name="TablaRamosVentas">
<Fields>
<Field Name="Ramo">
<DataField>Ramo</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
...
<rd:DataSetInfo>
<rd:ObjectDataSourceSelectMethod>GetTablaRamosVentas</rd:ObjectDataSourceSelectMethod>
<rd:ObjectDataSourceSelectMethodSignature>System.Collections.Generic.List`1[Graficas.Entidades.TablaRamosVentas] GetTablaRamosVentas(Int32, Int32)</rd:ObjectDataSourceSelectMethodSignature>
<rd:ObjectDataSourceType>Graficas.Bll.DatosGrafica, Graficas, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>
</rd:DataSetInfo>
</DataSet>
有关它的任何建议吗?
更新
我见过ReportExecution的Wrapper类:
GetReportContent方法管理一个DataSet,比如
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
ds.WriteXml(sw, XmlWriteMode.WriteSchema);
sw.Close();
完整方法
public byte[] GetReportContent(DataSet ds, string[] extraParams)
{
if (extraParams.Length != extraParamNames.Count)
throw new ArgumentException(string.Format(
"[ReportExecutionWrapper] Wrong number of extra parameters passed in to method Run() [expected {0}, was {1}].",
extraParamNames.Count, extraParams.Length));
initialize();
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
ds.WriteXml(sw, XmlWriteMode.WriteSchema);
sw.Close();
parameters[0].Value = sb.ToString();
for (int i = 0; i < extraParams.Length; i++)
parameters[i + 1].Value = extraParams[i];
reportExecutionService.SetExecutionParameters(parameters, "nl-NL");
string extension, mimeType, encoding;
Warning[] warnings;
string[] streamIds;
byte[] reportContent = reportExecutionService.Render("PDF", "",
out extension, out mimeType, out encoding, out warnings, out streamIds);
return reportContent;
}
定义ReportParameter&#34; DataSource&#34; (键入String)
<ReportParameters>
<ReportParameter Name="DataSource">
<DataType>String</DataType>
<DefaultValue>
<Values>
<Value>C:\Temp\Schemas\FiscalYearOverview.xml</Value>
</Values>
</DefaultValue>
<Prompt>DataSource</Prompt>
<Hidden>true</Hidden>
</ReportParameter>
和DataSet如下:
<DataSet Name="TotalPortfolioValues">
<Fields>
<Field Name="Date">
<DataField>Date</DataField>
<rd:TypeName>System.DateTime</rd:TypeName>
</Field>
...
<Query>
<DataSourceName>dsTotalGiro</DataSourceName>
<CommandText>TotalPortfolioValues</CommandText>
<QueryParameters>
<QueryParameter Name="@DataSource">
<Value>=Parameters!DataSource.Value</Value>
</QueryParameter>
</QueryParameters>
</Query>
</DataSet>
从BusinessObjectList创建DataSet并使用DataSet参数调用ReportExecution:
public static byte[] ViewPrintedReports(int managementCompanyId, int year, string reportLetterTypeName)
{
DataSet dsPrintedReports = GetPrintedReportsDataSet(managementCompanyId, year, reportLetterTypeName);
ReportExecutionWrapper wrapper = new ReportExecutionWrapper();
wrapper.SetReportName(getReportTemplateName(managementCompanyId, ReportReturnClass.ResultOfPrintedReport.ToString()));
wrapper.AddParameters(new string[] { "SelectedReportYear" });
return wrapper.GetReportContent(dsPrintedReports, new string[] { year.ToString() });
}
// Also used by DumpDataSets.aspx
public static DataSet GetPrintedReportsDataSet(int managementCompanyId, int year, string reportLetterTypeName)
{
IDalSession session = NHSessionFactory.CreateSession();
try
{
ReportLetterTypes reportLetterType = ReportLetterMapper.GetReportLetterType(reportLetterTypeName);
DataSet dsPrintedReports = DataSetBuilder.CreateDataSetFromBusinessObjectList(
ReportMapper.GetReports(session, year, reportLetterType, managementCompanyId),
@"Key, Account.Key, ReportLetter.Key, ReportStatusId, ReportLetter.ReportLetterYear, ReportLetter.ReportLetterTypeId,
ModelPortfolio.Key, ModelPortfolio.ModelName");
return getPrintedReportsSummary(dsPrintedReports);
}
finally
{
session.Close();
}
}