My-FyiReporting icon indicating copy to clipboard operation
My-FyiReporting copied to clipboard

Add support to directly render from Report class

Open majorsilence opened this issue 11 years ago • 7 comments

The report class should be able to be used directly to create reports and export to pdf/excel/etc... if the program does not need to display on a viewer.

Provide an example in the wiki how to do this and if there are any code changes required make them.

Also include support for direct parameters on Report class. See https://github.com/majorsilence/My-FyiReporting/issues/47 for an example of how they should work.

majorsilence avatar May 11 '13 11:05 majorsilence

If order is entered through web, web server should print it to paper automatically to local printer connected to server.

I tried code below to print report without human interaction. If running from IIS in MVC3 controller significant delay occurs and it does not print anything. Session is cleared, it looks like whole web application was restarted. Should printing code from RdlViewer() moved into RdlEngine method so it can executed without creating RdlViewer() object ?

        var rdlViewer = new fyiReporting.RdlViewer.RdlViewer();
        rdlViewer.SourceRdl = "rdl report xml";
        var pd = new PrintDocument();
        pd.PrinterSettings.FromPage = 1;
        pd.PrinterSettings.ToPage = rdlViewer.PageCount;
        pd.PrinterSettings.MaximumPage = rdlViewer.PageCount;
        pd.PrinterSettings.MinimumPage = 1;
        pd.DefaultPageSettings.Landscape = rdlViewer.PageWidth > rdlViewer.PageHeight;
        pd.PrinterSettings.PrinterName =  "HP Laserjet";
        rdlViewer.Print(pd);

kobruleht avatar May 12 '13 20:05 kobruleht

I deleted GUI methods from RdlViewer and PageDrawing classes, removed base classes. This creates class which can used print reports without System.Windows.Forms dll dependency using code in previous comment. Is this best way to implement direct print ?

kobruleht avatar May 14 '13 10:05 kobruleht

@kobruleht I am going to be very busy until the weekend. I'll review everything then.

majorsilence avatar May 14 '13 22:05 majorsilence

Thank you. If you have interested, I can post modified 2 files.

kobruleht avatar May 15 '13 08:05 kobruleht

Go ahead and post your changes here and I can review them.

What I was thinking is to add a new function called Export to the Report class.

RdlCmd.cs has the function SaveAs. I'd like something like this directly in the Report class so I could do

Report rpt; // do stuff rpt.Export(PDF, SavePath);

majorsilence avatar May 18 '13 21:05 majorsilence

I created pull request https://github.com/majorsilence/My-FyiReporting/pull/52 This is trivial change, winform methods are deleted from code and namespace name and main class name has changed.

It contains also SaveAs method in commented form.

There should be also possibility to save report to memory, without creating file. I'm using this code to save report from RdlEngine:

public FileContentResult Render(string _report ) { string source = GetReportRdlFromDatabase(); var report = GetReport(source, _report); report.RunGetData(null); if (report.ErrorMaxSeverity > 0) { StringBuilder sb = new StringBuilder(); foreach (var it in report.ErrorItems) sb.AppendLine(it.ToString()); if (report.ErrorMaxSeverity > 4) throw new Exception(sb.ToString()); } var sg = new MemoryStreamGen("ShowFile.aspx?type=", null, "PDF"); report.RunRender(sg, OutputPresentationType.PDF); if (report.ErrorMaxSeverity > 0) { StringBuilder sb = new StringBuilder(); foreach (var it in report.ErrorItems) { sb.AppendLine(it.ToString()); sb.AppendLine(); } throw new Exception( sb.ToString()); }

        var pdfcontent = sg.MemoryList[0] as MemoryStream;
        return new FileContentResult(pdfcontent.ToArray(), "application/pdf");

}

kobruleht avatar May 19 '13 06:05 kobruleht

I have not tested this yet. I have been short on time. I'll try to review it tonight.

The ability to save report to memory without creating a file is also very welcome.

majorsilence avatar May 27 '13 11:05 majorsilence