从 web.config 文件获取值到 rdlc 报告?
Getting Values from web.config file to rdlc report?
如何从 web.config (appsettings) 文件获取值到我的 rdlc 报告?
我需要在我的 rdlc 发票中显示来自 web.config 文件的多个值?我怎样才能得到这个?
<add key="siteName" value="desktopapplications" />
<add key="companyName" value="ProSoftware Limited" />
在rdlc中哪里可以写代码,如何实现上面的值?
我知道如何从 web.config 获取值到 .cs 页面
string siteName= WebConfigurationManager.AppSettings["siteName"]
它在 rdlc 中是如何工作的?任何帮助谢谢
在 RDLC 设计器的“报表数据”面板中,为 siteName 和 companyName 添加参数。在后面的代码中:
Dim myReport As New LocalReport
Dim params() As ReportParameter = New ReportParameter(1) {}
params(0) = New ReportParameter("siteName", siteName)
params(1) = New ReportParameter("companyName", companyName)
With myReport
.ReportPath = ReportPath '"MyReport.rdlc"
.DataSources.Clear()
.DataSources.Add(mydatasource)
.Refresh()
.SetParameters(params)
End With
来自 Lon Prosser 的回答
using (var lr = new LocalReport())
{
var path = Path.Combine(HttpRuntime.AppDomainAppPath, "Report", "MyInvoice.rdlc");
lr.ReportPath = path;
var siteName = ConfigurationManager.AppSettings["siteName"];
var companyName = ConfigurationManager.AppSettings["companyName"];
var @params = new ReportParameter[2];
@params[0] = new ReportParameter("siteName", siteName);
@params[1] = new ReportParameter("companyName",companyName);
var usersinv = db.Invoices.Where(i => i.Id == invoiceid.Id);
var invoice = usersinv.SingleOrDefault();
if (invoice != null)
{
var invoiceitems = db.InvoiceItems.Where(i => i.InvoiceId == invoiceid.Id);
var rd1 = new ReportDataSource("Invoice", usersinv);
var rd2 = new ReportDataSource("InvoiceItems", invoiceitems.ToList());
lr.DataSources.Add(rd1);
lr.DataSources.Add(rd2);
lr.SetParameters(@params);
}
string encoding;
string fileNameExtention;
const string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>21cm</PageWidth>" +
" <PageHeight>29.7cm</PageHeight>" +
" <MarginTop>0.0cm</MarginTop>" +
" <MarginLeft>0.0cm</MarginLeft>" +
" <MarginRight>0.0cm</MarginRight>" +
" <MarginBottom>0.0cm</MarginBottom>" +
"</DeviceInfo>";
Microsoft.Reporting.WebForms.Warning[] warnings;
string[] streams;
renderedBytes = lr.Render("PDF",
deviceInfo,
out mimeType,
out encoding,
out fileNameExtention,
out streams,
out warnings);
}
return File(renderedBytes, mimeType);
现在,web.config 文件
将调用 PDF 发票中的参数
如何从 web.config (appsettings) 文件获取值到我的 rdlc 报告? 我需要在我的 rdlc 发票中显示来自 web.config 文件的多个值?我怎样才能得到这个?
<add key="siteName" value="desktopapplications" />
<add key="companyName" value="ProSoftware Limited" />
在rdlc中哪里可以写代码,如何实现上面的值?
我知道如何从 web.config 获取值到 .cs 页面
string siteName= WebConfigurationManager.AppSettings["siteName"]
它在 rdlc 中是如何工作的?任何帮助谢谢
在 RDLC 设计器的“报表数据”面板中,为 siteName 和 companyName 添加参数。在后面的代码中:
Dim myReport As New LocalReport
Dim params() As ReportParameter = New ReportParameter(1) {}
params(0) = New ReportParameter("siteName", siteName)
params(1) = New ReportParameter("companyName", companyName)
With myReport
.ReportPath = ReportPath '"MyReport.rdlc"
.DataSources.Clear()
.DataSources.Add(mydatasource)
.Refresh()
.SetParameters(params)
End With
来自 Lon Prosser 的回答
using (var lr = new LocalReport())
{
var path = Path.Combine(HttpRuntime.AppDomainAppPath, "Report", "MyInvoice.rdlc");
lr.ReportPath = path;
var siteName = ConfigurationManager.AppSettings["siteName"];
var companyName = ConfigurationManager.AppSettings["companyName"];
var @params = new ReportParameter[2];
@params[0] = new ReportParameter("siteName", siteName);
@params[1] = new ReportParameter("companyName",companyName);
var usersinv = db.Invoices.Where(i => i.Id == invoiceid.Id);
var invoice = usersinv.SingleOrDefault();
if (invoice != null)
{
var invoiceitems = db.InvoiceItems.Where(i => i.InvoiceId == invoiceid.Id);
var rd1 = new ReportDataSource("Invoice", usersinv);
var rd2 = new ReportDataSource("InvoiceItems", invoiceitems.ToList());
lr.DataSources.Add(rd1);
lr.DataSources.Add(rd2);
lr.SetParameters(@params);
}
string encoding;
string fileNameExtention;
const string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>21cm</PageWidth>" +
" <PageHeight>29.7cm</PageHeight>" +
" <MarginTop>0.0cm</MarginTop>" +
" <MarginLeft>0.0cm</MarginLeft>" +
" <MarginRight>0.0cm</MarginRight>" +
" <MarginBottom>0.0cm</MarginBottom>" +
"</DeviceInfo>";
Microsoft.Reporting.WebForms.Warning[] warnings;
string[] streams;
renderedBytes = lr.Render("PDF",
deviceInfo,
out mimeType,
out encoding,
out fileNameExtention,
out streams,
out warnings);
}
return File(renderedBytes, mimeType);
现在,web.config 文件
将调用 PDF 发票中的参数