Creating and printing table reports in C# - c#

I need to create a simple application that would generate reports based on database data and some user input. I have vast C/C++ experience, but for this project we had to choose C#.
I want to avoid using 3rd-party components that would require installation on a client machine as much as possible. Thus, I would like to avoid using even the features provided by MS Office (I could have used an XLS template, just like my predecessor did, but it doesn't look like a way to go; anyways, my predecessor's sources are long lost, which is probably good, since it is a roughly 10-years-old VB monstrosity that crashes every now and then). The same goes for crystal reports and whatnot.
My current idea is to build HTML tables (using an HtmlDocument) on the fly, to present them to the user (using a WebBrowser) and to print them. Is it a right way to go? Are there any simpler/more robust/better approaches? What are the possible pitfalls?

Building tables on the fly would work. I use that technique every so often, but it seems like a hack to me. I only use it because quite often, the business need requires "good enough" and quick turnaround as opposed to "beautiful".
I'm going to preference what I'm about to suggest bysaying that I have a strong bias against 3rd-party components myself.
I flat out refuse to use them in most cases and will go out of my way to come up with another solution, because I've been burned on upgrades/licensing too often.
That said...
Fortunately, with .NET not all 3rd party components need to be installed to your clients PCs. With XCOPY deployment, often you can just reference a .DLL or a project in the solution ans specify the "Copy Always" or "Copy if newer" option to just include the dll (or resulting dll if you're referencing a class library project) and as long as the .dll is present in the same directory as the executable, the 3rd party component works.
With all of that in mind, there's a project that I've used to print a DataGridView from Windows Forms at CodeProject. This is one that you can get the source for, reference it, and use it without having to actually install anything at the client. I've used it in more than one app, and it's one of my favorite tools.
It will print ONLY the DataGridView, but it prints it exactly as it appears on screen, so if that's what you want, I'd recommend at least checking it out.
As a third option, you could consider using ASP.NET. If you're going to be generating HTML, it's just as easy (easier actually) to do it using ASP.NET than in a WinForms app. Using ASP.NET you get Repeaters, ListViews, etc, all of which make the reports easy to create.
I've got more than one real-world app that is primarily a WinForms app but has an associated reporting site.
For example, I have a WinForms app used for scanning coupons accepted at our retail locaitons. It's a WInForms app because I need to interact directly with the scanner on a COM port. However, for the reporting portion, I set up an ASP.NET website. In the WinForms app it's very simple to create a reporting menu option and point to the pages. Our users generally don't even think about the fact that this is two distinct applicaitons. They see it as one - their Coupon Scanning app.
The point of all that is that it's usually possible to do things with any given tool, but it's far easier to use the tool that is meant for the job. If you're going to be generating HTML reports, ASP.NET is a better tool than building the reports manually, and if you need to have a WinForms app for most of the UI, you can still do that and use the website for the reports - using the best tool for each task.

Maybe you would like to check RazorEngine, to create your HTML templates.

I recommend you Razor engine to render html, it is more flexible than working with HtmlDocument objects.
You can create a file with your report template, and then parse it sending a Collection of your report rows objects.

Related

How to clean up blazor server project

I am new to blazor and I've chosen to learn blazorserver but whenever i create a project, it comes along shipped with a lot of stuff i don't need. I don't need the layout it offers. I want to build my own layout from scratch. I also want to get rid of bootstrap and replace it with tailwind. The problem is that there are a lot of files and directories that make me fear to break the app. Is there a kinda command that can generate a much cleaner project or some way of manually cleaning it app without breaking the app. I appreciate any help.
If you are afraid of breaking the app by deleting something then it's better to keep it. You already figured out that you can replace bootstrap library with tailwind and that you can replace the layout with your own. While developing on the project you will start understanding what is the purpose of each folder or file in the starter template. After you understand their purpose, you will be able to decide if you need them or not.
Also learning how to use version control (e.g. git), like #JHBonarius mentioned, is very good advice. So when you break something you can easily revert back to previous working version of code.

How can we get around a ReportViewer's inability to use reports from another project?

I am currently working on a college C# project where I am required to apply N-Tier Architecture with 5 Layers:
Data Access
SQL Layer
Business Layer
Desktop Front End
Web Front End
One of the requirements of the project is to display reports.
I chose to use ReportViewer and RDLC reports to accomplish this. My choice has been working fine until I reached the final iteration of the project.
Before this iteration, I only had to generate reports from the Desktop application and the RDLC report was inside my Desktop application project. Now I need to generate the report on a ASP.Net WebForm.
Since the report needs to be accessed by 2 different projects, I thought all I had to do was move the RDLC report up a layer, to my Business Layer (probably should have been there anyways, oops). Of course, I ran into problems. It's never that easy, is it?
After some searching I found 2 particular useful posts:
Reportviewer and report are in different projects in the same solution. How do I attach the report to the viewer
https://forum.inductiveautomation.com/t/displaying-a-report-over-multiple-projects/12825
The first post told me all that I would need to do is set the Copy to Output Directory of my RDLC file to Copy always and then set the ReportViewer.LocalReport.ReportPath to the rdlc's file name with the extension ("example.rdlc").
Unfortunately, this answer never worked for both me and the OP. Why it didn't work was explained in the second post:
A report viewer cannot view a report from another project, although this may make a good feature request. - adam.morales
I then tried something a little different. Instead of accessing the report with ReportPath from a different project, why don't I create a property in my business layer that will return a LocalReport that already has the report definition?
Unfortunately, ReportViewer.LocalReport is read only. Even if it was writable, I would not be surprised if it didn't solve the issue; because, ReportPath is a string and the issue probably occurs when the LocalReport attempts to render.
This poses a very big problem for me. There is not enough time to completely redo the Reports and I don't want to have to resort to have 2 different RDLC files, 1 for each front end project; because, that's bad design.
To be completely clear on my needs:
I need to be able to access a RDLC report from 2 different projects
I must follow N-Tier Architecture and keep code reusable
So, that's why I ask, what kind of work-around could I possibly try to remedy this problem?
Well, the best I could find is embedding a PDF into the WinForms. This seems to require third-party DLLs, something I've been trying to avoid; because, it's a college project.
While this is not tested yet...
The LocalReport.Render method can generate a PDF (among a variety of things) as an Byte[]. If I use the Render method inside my Business Layer; then, I would expect it work since LocalReport would do its own thing while in the same project as the RDLC file and therefor work.
After that I should be able to simply return the generated report and use it where ever I want.
Unfortunately, I don't want to go through the complexity of adding third-party dlls to the college project so I'm going to simply duplicate the RDLC files... Hate the solution; but, it is what it is.

Do I need to use Microsoft.Office.Tools.Word to create a report in Word?

I cannot seem to understand if I need Microsoft.Office.Tools.Word and how to get it. I know that it works together with Microsoft.Office.Interop.Word as seen in this article, for example:
Visual Studio extends the Microsoft.Office.Interop.Word.Bookmark
object by providing the Microsoft.Office.Tools.Word.Bookmark host
control. The Microsoft.Office.Tools.Word.Bookmark host control behaves
like a native Microsoft.Office.Interop.Word.Bookmark, but has
additional events and data-binding capabilities. You can bind data to
a bookmark control on a document in the same way that you bind data to
a text box control on a Windows Form. For more information, see
Bookmark Control.
and that it enables you to add controls to a word document here, but I am not sure what the added value is (or if I need it).
I am developing an application that will generate a report of cyber security risks in a company (with primarily text and tables), and I am wondering what I have to use to make sure I can create my report properly (Microsoft.Office.Interop.Word at the least).
Also, I do not really understand where to get the Microsoft.Office.Tools.Word from. I included the Microsoft.Office.Interop.Word from NuGet easily, but I cannot find the other one in either NuGet or the Reference Manager. Because of this, I can not play around with this extra functionality and determine whether I need it in my project or not.
If you need more detail about my project to answer this question, feel free to ask.
No, you don't need to do Office Interop. Note that doing Office Interop requires you to have Office installed, also on the PC where you finally want to use it.
For a DOCX report, there are libraries like docx by XCeed (formerly a Github repo by the same author of docx on Codeplex) which can do things a lot easier. However, not all features might be supported.

Get Html from Web page and create Setup project for Wpf Application (C#)

I'm trying to create a wpf application such as a movies library because i would like to manage and sort out my movies with a pretty interface.
I'd like to create a library with all my movies getting information from the web, but i don't know how very well.
I thought to get the information from a web site, for example imdb, but i don't know if it's legally to capture html from page to get the nested information.
It's my first desktop application and I would also like to know if it is necessary to create a database within the project and then create a setup project with specified script for deploy it.
Sorry for the confusion but i would like to know too much things :)
Thanks a lot in advance.
The legality of web scraping is a grey area. See my question, "Legality of Web Scraping vs Normal Use" and the corresponding answers for some insight.
Even if the legality is not a problem, web scraping is a flimsy approach because the webpage structure may change without notice, making your application suddenly useless until you update it to the new format. You are much better off using some sort of web API (if the site providing the information offers it).
Whether you need a database or not depends entirely on what your application will be doing and how you design it - it's not something any of us can tell you.
Same goes for the setup project - in fact I wouldn't worry about that until you actually have a working application. Take it step by step and keep the scope within control.
Yes I did not think about api.
It's a great idea, maybe use "themoviedb".
But if i create an application based on it, that has to show all the movies that you have stored on your hdd and get , for example, the posters, the description and the ranking, i have to create a database according to you?
Thanks a lot.

Good web reports designer

I faced wuth task of creating system that will generate various medical papers for patients based on DB data. There is a lot of 3d party companies that will use this product therefore this product will be web-based. The main purpose of this product is printing this papers I have described above. Users already has prepared paper blank on which personal information will be imprinted. All users has various printers and the main issue I need to solve is that every printer prints in own maner and imprinted characters losts their positions.
The possible way I can solve this is to provide reports designer embedded in system, that allow every user "adjust" report to get printer prints properly.
By the way, we has all necessary documents reports storing in .fr3 files. It's 'cause we use same reports in another desktop application and we use fast report engine in that application. So the only one web reports designer I have found is Stimul soft reports web designer. But it's big, awkward and seems too heavy for this small project. Could you guys advice me some lightweight web reports designer/engine that can solve my issue?
P.S.: sorry for my English. I will use ASP .NET MVC3 (C#) for implementing this project.
The key question is do you need report design via the browser, do you merely need printer positioning, or can the report design be performed on the user's computer and it's just report generation that must be on the browser.
If you need report design in the browser then you are limited to products like Stimulsoft which as you said tend to be ackward and limited.
What you may be facing, based on your question, is that you need to position the report on the printer as all printers set the upper left of the generated report in a slightly different place on the paper. The best way to handle this issue is to make your report work fine regardless of the upper left of the printing on the page as the differences are small. But if that won't work, just prompt the user for the adjustment values.
Finally, if you want a system where it is very easy for non programmers to design reports, and the designer can be on their computer, please take a look at Windward Reports (disclaimer - I'm the CTO at Windward. With Windward you design your reports in Microsoft Word, Excel, or PowerPoint so it is both very easy and very powerful.
I does not understand what your problem is with position. A normal reporting solution print identical on different printers (not valid for old 9 dot printer).
Do you want print in a form (blank)? i-net Clear Reports has a page option for form print and an Online Designer. You find the form print option in the page setup dialog. If you enable the form print option the left and right margin will not change and the print will not scale.
Or do you search a simple designer in a browser? Then you can take a look in the ad-hoc reporting.
Use SQL-Server reporting services (2008 R2 in it's latest and most bug-corrected version).
It can render to HTML, and export to PDF, XLS, CSV and to Word (Word only with a commercial custom extension).
It also has a COM-object, which allows the report to run standalone, without SSRS installed.
SSRS also supports OracleProvider, apart from SQL server.
If a MS-SQL dependency is an overkill, you could take a look at Eclipse BIRT, which is a Java SSRS clone, which has a web viewer and JDBC database connectivity (however, the report format is not compatible).
The bad thing about it is, that it requires the version of Visual Studio that came with the SQL server version (so no designing of SSRS 2008 R1/R2 reports in Visual Studio 2010, you need Visual Studio 2008).
take a look into List & Label. It has a Webserveredition for generating output on web-applications and if you need to modify them there is an ActiveX available. We've done some successful projects with this stuff. Just try it out!
Take a look at Izenda AdHoc
.
In-browser Designer, In-browser Viewes, highly customizable but very simple API, exports feature, multiple databases types support.
You could even change reports looking using CSS styles.
Of course, compatible with MVC.

Categories

Resources