I have a problem here, I made a C # system using Razor MVC 4 with SQL Server 2014 database, so long ... well now I need to generate reports, I made a report there in Report Builder and added it in my solution, there 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;
}
Now I need to pass the parameters I created there in the report builder to GET, in rdl it has the @IDDescription, @Data and Data2 parameter which is the ID of the description that I have registered in another table and they are ID related for the IDDescription and also has the start date and end date of the report, but I can not make them work, could anyone help me? I wanted to make a view where I could choose it in the dropdownlist description, and two other textbox where I could put the start date and end date of the report, then when I clicked the button it would open the pdf in another tab, for download.