I'm working in visual studio 2010 and have included a crystal report in the project. The report includes all products owned by a client. The problem is that there are thousands of clients and I need to print a selected clients information through code. I have tried printing page numbers matching the id of the client, but some clients have more than one page of products, which causes a printout of page... say 100 for the client with an id of 100, but that page might be for client 91 since some reports for prior clients are multiple pages. My question is how would I go about printing a page for a specific client? I have been working on this for days and can't find anything helpful on the internet.
Thanks for any help in advance.
It seems to me by your question that you are returning all of the data and then trying to filter it by code. The easier way - in terms of programming and server load - is to filter the data on the server and only return what you need.
To do this use parameters in your reports. You can use the ClientID field as a paramter in the report. You then pass that value into your report from your code. You can then create a PDF of your report to display to your users. I use this method all the time and it works great.
I have found this link to get you started. Look at the last answer for the more precise option.
Related
Is it possible to save a user's report parameter choices so that it can be used again, let's say a week later when the user wants to run the report again?
I am using SSRS reporting services in my asp.net(C#) application and using report viewer to display report in website. I want to make some personilization to reports interface. I want users to save his report parameters and give it any name, so that he can generate report any time in future.
There is a solution on Codeplex for a way of building reports to store the users last used parameters as the default choice next time they run the reports.
However it sounds like you actually want to store the report itself for future reference, including a history of different report results. If so, then you may want to look at Report Snapshots.
If your case (report) is not too complicated, try follow this document and see if it helps. I have applied to a couple reports with this and work well. iParameter SSRS - Report Parameter Saving
I would like to know if exists the way to send a crystal report directly to the printer without print dialog. Ex. I have an asp.net page with a crystal report viewer and I want send to print once the report have been loaded into the viewer.
I saw an application what it is doing that but I don't know how that work.
I am using
Visual Studios 2010
Crystal Report for .NET Framework (Version=13.0.2000.0)
C# 4
if have a code sample (will be great!!!!)
I have read lot of resources in internet but nothing give me idea how to do what I need.
Thanks in Advance.
J.S.
It does not working like you think. Method PrintToPrinter generates printout directly to printer. Report preview also do the same. If you are executing both methods then report is generating twice. If you have more pritnout pages then report preview generates only visible pages. In most cases this does not change anything, but if report is generating a lot of time, then you are getting a lot of resources from system and you can expect deadlock on database. You also have to remember that if your report is generating new data per each executing then you will have doubled data.
Good I did it
I Just set this values to the ReportDocument.
CrystalReportDocument.PrintOptions.PrinterName = "Printer Name";
CrystalReportDocument.PrintToPrinter(1, true, 1, 1);
anyways I am open to other ideas and suggestion.
We've created a Crystal Report viewer application to house all of our company reports. It's built in such a way that any time we add, modify or delete a report, the viewer application itself does not need to change. The viewer app is completely driven by an XML configure file that tells it what reports are available, where they are, connection information etc. We want to keep it this way too. When we add a new report, we don't want to have to update everyone's viewer application.
The problem is that Crystal talks to our DB directly and we would prefer it didn't. Therefore, for each report, the viewer needs to query the database to retrieve the data each report needs. The problem is that many of our reports allow the user to enter a large number of filter criteria. Ideally, what we would like to be able to do is to have Crystal prompt the user to enter their filter criteria, like it currently does, and then be able to somehow get the SQL statement it would send on to the DB, pass it on to the DB ourselves, and tell Crystal not to. the viewer would then supply the report with data.
Does anyone know if this can be done? An alternative we've considered is to have the viewer prompt the user for the filter criteria, and then build the SQL statement. However, then each report becomes a C# coding project with an update to the viewer. We're trying to avoid that.
Thanks.
Interesting approach. I have only ever done the opposite.
Normally people like to build their own reports using a Crystal client. The report connects to a datasource specified in the report itself.
Using .NET to query the reports needs, set parameters and formulas then view the report is a piece of cake.
Anyway, there are only two methods that I know of called "pull" and "push". Pull is what I just described above. Push is what you described as a solution that you considered but it would involve coding for each report.
I'm afraid what you are trying to do has never been done before. However, I would recommend the "pull" method. It has worked very well for me with a client with dozens of users and hundreds of reports.
Maybe not specific to reports but still...
In my asp.net mvc web application there's a section for reports that show 5 columns of data that map almost directly to a table in the db.
The problem is, in some cases, the length of that report may exceed 40,000 records (I know, nobody can really process 40,000 records of data but the report is what it is) and as you can expect, it times out and throws an error.
The question is, what's a good way to process and deliver a report of that size? I thought about creating a small little console app that would build the report outside of the webserver but I'm kind of at a loss as to what direction to look into?
Does the report need to have up-to-the-minute data? If not, you can look at generating the report as a PDF at night (or whenever your server isn't busy) and just providing a link to the PDF. A scheduled task that runs a console app as you suggested could create the report and output it to a file. A lot of reporting tools like Crystal Reports will allow you to export the report to a PDF or an Excel spreadsheet. For that matter, you could generate the report on a completely different machine and then copy it over to the web server. This could allow you to update the report every hour (or whatever) without putting such a load on your web server.
Generating the report while the user waits is probably not a good idea (not to mention SQL / IIS timeouts etc)
You could get the user request a report, then have a windows service pick up these requests, generate the report and email the user? (or have some kind of ajax polling script on the site to notify users when their reports are ready?)
You could extend this to scheduling of the same report at recurring intervals etc.
I would look into SQL Reporting Services (assuming this is running on SQL Server). There's several delivery options which may be better suited to your application's needs (you can schedule a PDF or Excel document to show up in someone's mailbox every night, for example).
There's also a great article from the StackOverflow team that allows background processes within ASP.NET if you can simply generate this report every so often instead of on-demand (maybe every 5-10 minutes?)
https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
Another frequent usage I've seen to handle large scale reporting is setting up a windows service that does the physical generation of the report which dumps the completed binary into a database or file store somewhere and then updates data to show the report is complete with the information needed for the application to link the completed report.
Then you could have your do report button fire off a request to initiate a report and then move them to a processing report page where it lists all the reports queued up / processing for them.
It's doubtful that a user would ever actually look at all of a 40,000 row report. So why not show just the top 1,000 most current rows ordered backwards? If you're using a reporting solution that supports on-demand reports, you could always drill down to second report that shows the next 1,000 most current rows. Just a thought...
I need to create reports in a C# .NET Windows app. I've got an SQL Server 2005 database, Visual Studio 2005 and am quite OK with creating stored procedures and datasets.
Can someone please point me in the right direction for creating reports? I just can't seem work it out. Some examples would be a good start, or a simple How-to tutorial... anything really that is a bit better explained than the MSDN docs.
I'm using the CrystalDecisions.Windows.Forms.CrystalReportViewer control to display the reports, I presume this is correct.
If I'm about to embark on a long and complex journey, what's the simplest way to create and display reports that can also be printed?
I have managed to make this work now.
Brief Overview
It works by having a 'data class' which is just a regular C# class containing variables and no code. This is then instantiated and filled with data and then placed inside an ArrayList. The ArrayList is bound to the report viewer, along with the name of the report to load. In the report designer '.Net Objects' are used, rather than communicating with the database.
Explanation
I created a class to hold the data for my report. This class is manually filled by me by manually retrieving data from the database. How you do this doesn't matter, but here's an example:
DataSet ds = GeneratePickingNoteDataSet(id);
foreach (DataRow row in ds.Tables[0].Rows) {
CPickingNoteData pickingNoteData = new CPickingNoteData();
pickingNoteData.delivery_date = (DateTime)row["delivery_date"];
pickingNoteData.cust_po = (int)row["CustomerPONumber"];
pickingNoteData.address = row["CustomerAddress"].ToString();
// ... and so on ...
rptData.Add(pickingNoteData);
}
The class is then put inside an ArrayList. Each element in the arraylist corresponds to one 'row' in the finished report.
The first element in the list can also hold the report header data, and the last element in the list can hold the report footer data. And because this is an ArrayList, normal Array access can be used to get at them:
((CPickingNoteData)rptData[0]).header_date = DateTime.Now;
((CPickingNoteData)rptData[rptData.Count-1]).footer_serial = GenerateSerialNumber();
Once you have an arraylist full of data, bind it to your report viewer like this, where 'rptData' is of type 'ArrayList'
ReportDocument reportDoc = new ReportDocument();
reportDoc.Load(reportPath);
reportDoc.SetDataSource(rptData);
crystalReportViewer.ReportSource = reportDoc;
Now you will need to bind your data class to the report itself. You do this inside the designer:
Open the Field Explorer tab (which might be under the 'View' menu), and right-click "Database Fields"
Click on 'Project Data'
Click on '.NET Objects'
Scroll down the list to find your
data class (if it isn't there,
compile your application)
Press '>>' and then OK
You can now drag the class members
onto the report and arrange them as
you want.
Crystal is one possible option for creating reports. It has been around a long time and a lot of people seem to like it.
You might want to take a look at SQL reporting services. I have used both but my preferance is SQL reporting services. Its pretty well integrated into studio and works similar to the other microsoft projects. Its also free with the sql express etc.
This is a good article on beginning reporting services:
http://www.simple-talk.com/sql/learn-sql-server/beginning-sql-server-2005-reporting-services-part-1/
You can use the report viewer with client side reporting built into vs.net (ReportBuilder/ReportViewer control). You can create reports the same way as you do for sql reporting services, except you dont need sql server(nor asp.net). Plus you have complete control over them(how you present, how you collect data, what layer they are generated in, what you do with them after generating, such as mailing them, sending to ftp, etc). You can also export as PDF and excel.
And in your case building up a report from data and user input, this may work great as you can build up your own datasource and data as you go along. Once your data is ready to be reported on, bind it to your report.
The reports can easily be built in Visual Studio 2005 (Add a report to your project), and be shown in a Winforms app using the ReportViewer control.
Here is a great book i recommend to everyone to look at if interested in client side reports. It gives a lot of great info and many different scenarios and ways to use client side reporting.
http://www.apress.com/book/view/9781590598542
I second alex's recommendation to look at sql reporting services - if you have a sql developer license, then you probably already have reporting services
i don't like crystal reports, too much tedium in the designer (editing expressions all the time) too many server-deployment issues (check those license files!)
I use Crystal. I will outline my method briefly, but be aware that I'm a one man shop and it may not translate to your environment.
First, create a form with a CR Viewer. Then:
1) Figure out what data you need, and create a view that retrieves the desired columns.
2) Create a new Crystal report using the wizard giving your view as the source of the data.
3) Drag, drop, insert, delete, and whatever to rough your report into shape. Yes, it's tedious.
4) Create the necessary button click or whatever, and create the function in which to generate the report.
5) Retrieve the data to a DataTable (probably in a DataSet). You do not have to use the view.
6) Create the report object. Set the DataTable to be the DataSource. Assign the report object to the CR Viewer. This is one part for which there are examples.
Comments:
If you lose the window with the database fields, etc (Field Explorer), go to View/Document Outline. (It's my fantasy to have Bill Gates on a stage and ask him to find it.)
The reason for setting up the view is that if you want to add a column, you revise the view, and the Field Explorer will update automatically. I've had all sorts of trouble doing it other ways. This method also is a work-around for a bug that requires scanning through all the tables resetting which table they point to. You want to hand Crystal a single table. You do not want to try to get Crystal to join tables, etc. I don't say it doesn't work; I say it's harder.
There is (or was) documentation for the VS implementation of Crystal on the Business Objects web site, but I believe that it has disappeared behind a register/login screen. (I could stand more info on that myself.)
I've had trouble getting Crystal to page break when I want, and not page break when I don't want, etc. It's far from the best report writer I've ever used and I do not understand why it seems to have put so many others out of business. In addition, their licensing policies are very difficult to deal with in a small, fluid organization.
Edited to add example:
AcctStatement oRpt = new AcctStatement() ;
oRpt.Database.Tables[0].SetDataSource(dsRpt.Tables[0]);
oRpt.SetParameterValue("plan_title",sPlanName) ;
crViewer.ReportSource = oRpt ;
I found the following websites solved my problems. Included here for future reference.
CrystalReportViewer Object Model Tutorials for the tutorial on how to make the whole thing work. And also Setting up a project to use Crystal Reports
and specifically preparing the form and adding the control
i think this may help you out
http://infynet.wordpress.com/2010/10/06/crystal-report-in-c/
I strongly recommend trying an alternative reporting solution - I have a lot of experience with Crystal, and have managed to do some funky things with it in .Net, but quite honestly the integration of Crystal and .Net is an absolute pig for anything but the simplest cases.
I have tried RS. I am converting from RS back to Crystal. RS is just too heavy and slow (or something). There is no reason to have to wait 30 seconds for a report to render is RS when Crystal does it in under a second.