Crystal Reports in MVC - c#

Ok, so I'm building a kind of reporting central for the company I work at and the easy part was building a web based file browser, now I'm moving on to the report aspect of it and to start it off, I'm integrating Crystal Reports.
I've already gotten the files from the SAP website for them, but I'm encountering a couple problems,
First off, all the examples I've found make it so that you have to define the data source/database, and include log in information for it in the code. This is a problem because we have a LOT of crystal reports, with a lot of different database references, so I can't just use one for all of them. In fact, there are reports that we use that reference multiple database at the same time.
Secondly, all the examples I've found make it seem like you have to have a specific page created for each report. My goal is to be able to have the report link as a variable and have one page for all of the reports we have.
I looked at everything I could find yesterday and I couldn't find what I needed. I'm also wondering what on earth the ReportClass.Load function even does. It was in every example I could find and I didn't notice any explicit difference in the ReportClass I had when I used it.
While searching, I found an answer that suggested building a web forms application that would build the Reports, and then use an I-Frame to grab it, but that's something I want to avoid.
So in review:
1) I need to build Crystal Reports without having to reference the Database
2) I need it to be flexible to a variable Report by supplying just the path to the .rpt file
3) I would like it to be in a single application, in MVC, and avoiding IFrames
Thank you so much for your help!!
EDIT: I found a solution that works for me. Instead of using a RAZOR view, I used an ASPX view, which has the Crystal Reports Viewer Tool in the toolbox. In order to make it variable I used the ViewBag.
Controller Code:
[HttpGet]
public ActionResult Viewer(string Path)
{
var sessionID = Session.SessionID;
ViewBag.Path = newPath;
return View();
}
ASPX View Code:
<% Report.Report.FileName = ViewBag.Path; %>
<CR:CrystalReportViewer ID="Viewer" runat="server" AutoDataBind="True" GroupTreeImagesFolderUrl="" Height="100%" ReportSourceID="Report" ToolPanelWidth="200px" Width="100%" />
<CR:CrystalReportSource ID="Report" runat="server">
<Report></Report>
</CR:CrystalReportSource>

A "similar" (not exact) question was asked here. Hopefully that can get you down the right path.

1) I need to build Crystal Reports without having to reference the Database
Have you considered building a data warehouse for your reporting and analysis needs? A data warehouse has many benefits over a traditional reporting structure especially when drawing data from multiple sources.
In regards to point 2 & 3 have you considered that crystal reports may simply not be the most ideal reporting solution?
Crystal reports is a powerful tool but honestly I'm not a big fan of it when it comes providing reporting intelligence over the internet or an intranet.
Having you considered switching tools? For example http://www.tableausoftware.com/ provides some excellent data visualization tools and IMO is a much better tool for the job you are describing.
Note, that this is simply one tool (as there are many out there), but one that I have had some experience with and it exceeded our expectations especially when sitting on top of a data warehouse.

Related

Best method for generating documents/reports in visual studio

I’m looking at options to send user input data from my application (mainly strings and doubles) into a stylised document (such as a quotation or invoice)
I have done quite a bit of research however am even more confused in which method would suit me best, so am looking for some input, as which direction to go, I have found some of the following options:
Crystal Reports - although I think this is more for reporting data from SQL databases, not to mention it looks as though people struggle with running there applications in different environments on different machines.
MajorSilence Reporting (formerly FyiReporting) - a Crystal Report alternative that’s open source so would alleviate a lot of problems again though I think it’s for databases and hasn’t been worked on since2015
Word Or Excel Document - Seems I would have to have a template file of some sort and I did want to control as much as I could in program not to mention it just seems kind of unprofessional in a way when used by other users at my work.
PrintForm - where I print direct from a form in the application while hiding the buttons but this may be hard to do over two pages.
If anyone has any input on the above or new ideas or even if I’m on the correct track to how this is usually done, I would be very appreciative.

Charting tool that generate on memory

My question seems confusing but I'll let you explain it more clearly. Me and my team we're currently developing a complex report that comprises of words, tables and charts. As of now we generate this report by using a word document template and filling it up with the model we have. As for chart this is where it becomes complicated, we have two application that we're using in business one is a windows/wpf application and a web application. Both application uses the same engine we have for generating chart (ComponentOne) but the engine itself is only compatible for windows application. We use the assembly we generate from windows/wpf application on our web application for us to generate a report.
Our report generator on website will only have filter and parameters on what kind of report they want to generate and on a press of button. What do you think will be the best to tackle this issue so that we can drop using the assembly we have. We don't like to drop using template for this as these greatly help us on maintaining the report when changes is required the only thing that we think right now on how can we generate a chart on memory and convert it into an image so that we can dump it on our template.
It's not confusing, it's just not clear at all. If I get it right you just have a reporting tools ComponentOne that make reports on software side and it's not adapated for web side.
You somewhat tried to tackle it by using software dll in your website and it doesn't work as well as you expected/wanted. And you keep trying as of now.
Your question is basicly "How can I use a dll designed for software into a website?"
And the answer is simple. It's case by case when not outright impossible.
I invite you to look for another solution than using a software designed dll on a website. Even your idea of putting it inside an image is somewhat bad (lose of all controllers / defeat of the purpose of an interactive report.)
I'm pretty sure that ComponentOne would have think of such a problem as web reports and maybe even a solution to link web reports to soft reports. With a little search, I found a C1WebReport and even found some forums talking about C1Report to C1WebReport. Does it answer your problem?

Recommendation for report in asp.net

I'm developing a system in asp.net (webforms) where the users can log in and see their reports. I was using RDL from my reports, but now I wanna use another technology when reports be more dynamics, just like this:
http://ap.demo.qlikview.com/QvAJAXZfc/opendoc.htm?document=qvdocs/Plant%20Operations.qvw&host=Demo11&anonymous=true
But I need a free tech and this have to work with my project in asp.net. What could I use?
I've toyed with reporting systems like Crystal Reports or SQL Reports, and found them to have a learning curve, but also be rigid and inflexible, or generate horrid HTML.
ASP.NET MVC can be used as a great reporting system, here's how:
Optionally use a VirtualPathProvider to allow you to store your MVC .aspx files in a database.
Have a Controller class with an action "GenerateReport" that only creates an EF Context / Repository object or even a raw database connection and passes that as an object to the view, there is no other model.
Break the rules of MVC "no data-access logic in the view"! Your view (in the .aspx file) should have a <% %> area that does all of the report-generation logic by running queries and stuff.
For graphs and charts and stuff, use a RESTful chart generation library, you can also write your own. This basically means that instead of the report generating a static image file and storing it somewhere and putting the path in an <img src=""> element, it instead does this: <img src="RestfulImage.ashx?line1={1.2,4.6,8...." />. Google actually has a service you can use: https://developers.google.com/chart/image/docs/making_charts
So each report is an .aspx file that is given a data-access object it then queries directly and generates reports itself. Obviously this does not work well for reports that take a long time to build (but that's usually a symptom of bad DB design or a lack of indexes), but if your requirements are simple (i.e. a bunch of SQL SELECT queries rendered to <table> and some charts to go along with) then this approach works great.
You can use SAP CRYSTAL REPORTS for your reports.
First, pick the reporting engine you want to use... Crystal Reports, DevExpress Reporting, Telerik Reporting, ComponentOne ActiveReports are the main players outside of Microsoft's SSRS. Base your decision on which tool you want to "marry", because creating reports can be a pain or it can be easy, depending on which tool you pick for the job.
Once you have that, pick the server software that works for your situation. There are several choices for Crystal servers (including SAP Crystal Server, VersaReports ReportServer, etc.), only a few choices for the other engines.

How to write a simple designer for printed reports

I'm currently having a couple of reports which I print from my Forms applications.
However building printed reports only with the built-in .NET printing methods is very tedious. Even just printing a simple table on a couple of pages with a little bit of formatting is a task for a couple of hours (if it should look nice).
What I need is a WYSIWYG-Designer for the layouts, so I'd like to write one.
It shouldn't be for End-Users, but for me as a developer, it's just about to create the layout what the report will look like with various arrangements/fonts/images/formats and so on and not have to do that by trial & error in code (and restart the app a zillion times).
So my specific questions:
What would I use as a canvas for editing and display of the report? An image-control/bitmap which I draw upon like on the printed document? Is there a better way?
Is drawing on a form comparable to drawing on a printed page? What about differences in resolution printer vs. screen?
How to get real WYSIWYG? Should I get the printer settings and create my canvas with the same resolution? Is there something else to consider?
I know that there are report designers around but I think it's sometimes good to understand the basic working principles of what you use and implementing them is for me the best way to do that.
I'm aware that this is not a specific question A to which the answer is always B, but if it were that way I would find an answer in Google pretty quickly.
Thanks in advance!
I can't say much about designing a WYSIWYG editor, but I have written a few custom in-house reporting engines for use by our development team.
There's two main ways I've created reports. The first is using PDFsharp (MIT-licensed) to manually layout pages which isn't for the faint-of-heart.
The second is using Winnovative's HTML to PDF library (not free, but royalty-free) which uses the current installed version of IE to do the layout and spit out a PDF. It looks like they've recently released a new version called EVO PDF which I have never used before.*
For the HTML to PDF solution, it supports JavaScript so you can add in charts from JavaScript libraries like flot or jqplot.
*I'm not affiliated with Winnovative.
You might want to save time and use Visual Studio HTML designer as your WYSIWYG editor.
What I'm currently doing is using ASP.NET MVC 3 as a simple reporting engine. You can use the MVC pattern to really separate your reporting data source (Model) and the rendering (View) while using Visual Studio as your report designer.
From your application you can easily call your actions with the report optional parameters. For example:
http://localhost/Report/Customer/Orders/1
You simply get the returning string from a WebClient's DownloadString method and you have your report generated.
There is some down side using HTML, mainly the difficulties to know when a page would break, but by using code in your View you can calculate the amount of repeating items and add a CSS break-page and re-starting your table's header on the next page.
You can achieve anything from graphics, to table, you can even generate link to other reports.
HTH.
Printing Reports in Windows Forms
http://msdn.microsoft.com/en-us/library/ms996472.aspx

How to restrict download options on a single report in SSRS?

This question asks how to restrict for a whole server. I just want to do so for a single report. I found a code snippet but it doesn't provide any clues on how to implement:
foreach (RenderingExtension extension in this.reportViewer.LocalReport.ListRenderingExtensions()) {
if (extension.Name == "PDF") {
((Extension)(extension.GetType().GetField("m_serverExtension", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(extension))).Visible = false;
}
I can't see how to make the report reference this code upon loading. Does anyone know how I am supposed to make the report execute this code?
EDIT: Incidentally report access is through the SSRS Report Manager web app. We are, in the main, delighted with this product so wouldn't consider reinventing the wheel in order to implement a hack to produce what is, essentially a "would be nice" feature.
It still boggles the mind slightly that the report's available rendering options are not controllable at the report level. Ho hum.
Incidentally I found this blog entry which clarifies the above code a little. Turns out we're talking about using a reportviewer component to limit the export options. Apparently this requires a dirty, dirty hack and besides it's not how we want to run our reporting function.
So unless anyone has a better idea than this within the next fortnight I'll mark this as the answer which basically sums up to:
You can only restrict functionality like this under certain conditions and by no means easily even when you do.
This seems like a clear failure in the wider fitness of SSRS for purpose as we have users who require Excel export functionality and users who need to be limited to PDF only. Oh well.
Does it matter?
Once they've downloaded the data and taken it offsite, you've lost it anyway.
You haven't really described how you are calling the reports - have you created some kind of application? Are you actually using the report viewer control?
You can generate a report in a specific format using the report URL and including the rs:Format parameter, e.g.
http://SERVER/reportserver?%2fSomeFolder%2fSomeReport&rs:Command=Render&rs:Format=PDF
The above URL generates the report as a PDF. You can also use the URL to hide the report toolbar etc. so you could create these URLs as links in your application, maybe one using just rs:Command=Render as a "View Report" link and one link that includes rs:Format=PDF as an "Export to PDF" link.
More on Reporting Services URL access.

Categories