4
I have a problem here, I made a system in C# using Razor MVC 4 with SQL Server 2014 database, so far so good... but now I need to generate reports, I made a report there in Report Builder and added it in my solution, so I created the methods:
public ActionResult ListagemDescricao(int IDDescricao)
{
LocalReport relatorio = new LocalReport();
relatorio.ReportPath = Server.MapPath("~/Relatorios/RelatorioDatainicioDatafim.rdl");
var query = db.OrdemServicos.Where(o => o.IDDescricao == IDDescricao).ToList();
relatorio.DataSources.Add(new ReportDataSource("DataSet1", ToDataTable(query)));
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExt;
string deviceInfo =
"<DeviceInfo>" +
"<OutputFormat>PDF</OutputFormat>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] bytes;
bytes = relatorio.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExt, out streams, out warnings);
return File(bytes, mimeType);
}
and
public DataTable ToDataTable<T>(List<T> items)
{
DataTable dataTable = new DataTable(typeof(T).Name);
PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public |
BindingFlags.Instance);
foreach (PropertyInfo prop in Props)
{
dataTable.Columns.Add(prop.Name);
}
foreach (T item in items)
{
var values = new object[Props.Length];
for (int i = 0; i < Props.Length; i++)
{
values[i] = Props[i].GetValue(item, null);
}
dataTable.Rows.Add(values);
}
return dataTable;
}
only now I need to pass the parameters I created there in the report Builder for GET, in rdl has the parameter @Iddescricao , @Date and Data2 which are the ID of the description that I have registered in another table and they are related from ID to Iddescricao and also have the start and end date of the report, only that I can’t make them work, could anyone help me? i wanted to make a view where I could choose it in the dropdownlist the description, and two other textbox where I could put the start date and end date of the report, then when I clicked on the button it would open the pdf in another tab, to download.
Just so I understand: you are not being able to print the values in the report or you would like to set up a screen with the parameters so you can better filter your report?
– Leonel Sanches da Silva
I’m trying to assemble the screen with the parameters but I don’t know how, I tried to run the report by GET, going there in the browser and calling the method via page/Listingdescription? Iddescricao=1 , it works but with more than 1 parameter I can’t make it work, there in the report Uilder I put the right parameters, there appear in a field above the report to be filled
– Jeferson Santos