My-FyiReporting
My-FyiReporting copied to clipboard
Add support to directly render from Report class
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.
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);
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 I am going to be very busy until the weekend. I'll review everything then.
Thank you. If you have interested, I can post modified 2 files.
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);
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");
}
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.