Reports in C# MVC

Asked

Viewed 3,813 times

0

How do I report to ?

I use a third-party component or make an HTML page myself?

What you use in everyday life?

I ask, because I need to print reports that follow a government standard. In I do it with my feet on my back, but in C# is my first need.

  • I’m using iTextSharp to generate PDF’s. But I believe there are better tools

3 answers

2

I recommend using Crystal Reports. Here are some links:

The implementation is simple and very similar to any reporting software. Here is a simple example that returns the report by inserting some parameters in the report:

  public ActionResult relatorio_pdf()
    {
        connection.ConectarBanco();

        ReportClass rptH = new ReportClass();

        rptH.FileName = Server.MapPath("~/Views/Relatorios/relatorio.rpt");//Indica o endereço do relatório
        rptH.Load();//Carrega o relatório
        rptH.OpenSubreport("relatorio.rpt");
        rptH.SetDatabaseLogon("usuario_banco","senha_banco");//Indica o usuário e senha do banco no qual o relatório está relacionado
        rptH.SetParameterValue("id_produto", 120);//Indica o parametro para o relatório
        Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);//Diz o tipo de stream, no pdf para Crystal Reports

        connection.FecharConexaoBanco();

        return File(stream, "application/pdf");
    }

Note: Remembering that this example is applicable to reports that are linked to a database in its configuration. This process does not become necessary in reports with a related Dataset, just use a Controller to load the page by returning a Stream from your report.

2

Man, I wouldn’t recommend using any components. Uses a well-made model that returns your fields correctly. The components to export to pdf, Excel most have native.

So you gain performance and don’t get stuck to any component versions.

  • However how to make the View to have the standard size of an A4 sheet, this I think will be my biggest problem, the rest of doing on hand I think would be much easier to do than using components.

1

I believe that HTML is not the output for this case - you will be bothered enough to assemble and then fine-tune the layout.

If your need in C# is punctual (you will continue to develop in Delphi), you can continue processing the report in Delphi generating as a result a PDF file, which can then be viewed to the end user in the browser (For some legacy reports we have, we do this with ASP.NET + COBOL!).

In addition, there are several good tools on the market - worth (much) the investment if this type of project turns into practice. I list here which ones have the report rendering interface on the Web (not necessarily MVC):

  • The need is to do it online. I’m slowly taking the project from Delphi to C# MVC

Browser other questions tagged

You are not signed in. Login or sign up in order to post.