What is the best way to create and print reports?

G

Guest

Hi,
I'm writing a program that helps manging a store. i have one form that deals
with products selling, in this form the user enters the customers details and
the products which he bought. after the user payed for these products, i want
to print a invoice, and now i don't know which way is the best one? one
option i know, is to draw the invoice by myself (using drawlines and etc.),
second way is using crystal reports, i'm not sure which way is better, and if
there any other ways.. so if any one can help me, i will appreciate it.

Thanks,
Gidi.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Between the two options that you mention I thnk that CR is the best, you set
the ReportDocument.SetDataSource() to a dataset containing the invoice data
you want and that's all

making & printing a report manually is a big pain..... you have to deal
with page break, margins, printers, etc


cheers,
 
J

Jeff Louie

Actually you write your own printable components and alignment panels
that know how to print themselves, slide and print across page
borders... so you just drag, drop and print :)

Regards,
Jeff
 
B

Bruce Wood

If I were you I would use Crystal Reports.

That said, there are two ways to use CR. One is the way that Ignacio
mentioned: the "push" model. Put your data in a DataSet, and push your
DataSet at CR by calling ReportDocument.SetDataSource(). The other way
is to write your invoice to a database (which maybe you were going to
do anyway) and then write a Crystal report that knows how to get the
invoice information back out of the database and report it.

We do things the first way (the way that Ignacio suggested). It's a bit
tricky, but once you get it figured out it works OK.

However, if you're using a database, the second way may be superior.
It's the more "usual" way of using CR, and CR tends to behave better
when used as a "pull" reporting tool rather than accepting a "push". As
well, it serves as a confirmation that you have, in fact, committed the
invoice information to the database. No commit, no report.

Either way, it's not terribly difficult, and CR gives you the
flexibility to easily change the look of your invoices, or even have
multiple invoice formats that you can switch between depending upon the
situation.

CR also gives you export-to-PDF and other nifty features for free. Why
reinvent the wheel? CR isn't the best reporting package out there, but
it beats anything you can do yourself.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Bruce Wood said:
If I were you I would use Crystal Reports.

That said, there are two ways to use CR. One is the way that Ignacio
mentioned: the "push" model. Put your data in a DataSet, and push your
DataSet at CR by calling ReportDocument.SetDataSource(). The other way
is to write your invoice to a database (which maybe you were going to
do anyway) and then write a Crystal report that knows how to get the
invoice information back out of the database and report it.

We do things the first way (the way that Ignacio suggested). It's a bit
tricky, but once you get it figured out it works OK.

However, if you're using a database, the second way may be superior.
It's the more "usual" way of using CR, and CR tends to behave better
when used as a "pull" reporting tool rather than accepting a "push". As
well, it serves as a confirmation that you have, in fact, committed the
invoice information to the database. No commit, no report.

Hi,

Regarding accesing the DB directly you should always set the connection info
using code, put the DB info in the config file and use the code below to
make sure you don't get a nasty popup ( or an Exception) asking for the
connection info. Notice that you need to set this info to all the tables of
the report:


TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
ReportDocument reportDocument1 = new OpenRecords(); //this is the
report

ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName =
System.Configuration.ConfigurationSettings.AppSettings["Server"];
crConnectionInfo.DatabaseName =
System.Configuration.ConfigurationSettings.AppSettings["DataBase"] ;
crConnectionInfo.UserID =
System.Configuration.ConfigurationSettings.AppSettings["User"] ;
crConnectionInfo.Password =
System.Configuration.ConfigurationSettings.AppSettings["Password"] ;

foreach (CrystalDecisions.CrystalReports.Engine.Table table in
reportDocument1.Database.Tables)
{
TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
crTableLogonInfo.TableName = table.Name;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
crTableLogonInfos.Add( crTableLogonInfo);
table.ApplyLogOnInfo( crTableLogonInfo);

}
CrystalReportViewer1.LogOnInfo = crTableLogonInfos;
CrystalReportViewer1.ReportSource = reportDocument1;


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top