combine multiple reports in crystal reports in c# - crystal-reports

I have designed a crystalReport(myReport.rpt) that is connected to data base without any problem. What I want is to create a report including multiple of this report...!
For example creating a 3-pages report that each page is built by myReport.rpt but with different values...
In fact I want to create some objects from my report class and then combine all of them to be one report and I print that or make pdf from that...
Example:
myReport rpt1= new myReport(); //(some changes in rpt1's fields):
(TextObject)rpt1.ReportDefinition.ReportObjects["time"]).Text=getTime();
((TextObject)rpt1.ReportDefinition.ReportObjects["date"]).Text =getDate();
// or any other changes in fileds
myReport rpt2= new myReport(); //(some changes in rpt2's fields):
(TextObject)rpt2.ReportDefinition.ReportObjects["time"]).Text = getTime();
((TextObject)rpt2.ReportDefinition.ReportObjects["date"]).Text = getDate();
// or any other changes in fileds...
myReport rpt3= new myReport(); //(some changes in rpt3's fields):
(TextObject)rpt3.ReportDefinition.ReportObjects["time"]).Text = getTime();
((TextObject)rpt3.ReportDefinition.ReportObjects["date"]).Text = getDate();
// or any other changes in fileds...
and I want something like this:
CrystalDecisions.CrystalReports.Engine.ReportDocument totalReport=new CrystalDecisions.CrystalReports.Engine.ReportDocument();
totalReport=merge(rpt1,rpt2,rpt3);
totalReport.PrintToPrinter(1, ture, 1, 1);
Thank you for your helping...
I'm using:
VS 2012 & Crystal Reports 13

Related

Getting 3 mins to Generate the Jasper Report

I am developing the Invoice printing System using the Jasper report, Now I have can print the report but it will take 2000ms to load the report, also 2000ms take to start the printing,
These are I am using the JAR FILES,
commons-beanutils-1.4
commons-digester-1.7
commons-logging-1.0.3
commons-beanutils-1.4
groovy-all-1.7.5
batik-all-1.7
barcode4j-2.1
itextpdf-5.1.0
jasperreports-6.0.3
xercesImpl-2.11.0
xml-apis-ext-1.3.04
preparedStatement = conn.prepareStatement(sqlString);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
HashMap<String, Object> hm = new HashMap<>();
JasperDesign jasperDesign = JRXmlLoader.load(new File(
"C:/Invoice/Invoice.jrxml"));
JRDesignQuery designQuery = new JRDesignQuery();
designQuery.setText(sqlString);
jasperDesign.setQuery(designQuery);
JasperReport jasperReport = JasperCompileManager
.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, null, conn);
for (int i = 0; i < copies; i++) {
JasperPrintManager.printReport(jasperPrint, false);
}
JasperViewer.viewReport(jasperPrint);
The above code I used to print the report but, getting too much time to load the report. Please suggest my fault and some other idea...
I guess the SQL query could be the problem. Have you tried executing it in a sql query tool and check how long it runs? Optimizing it should yield a performance win.
You are also running the query twice: before the report and when you are filling it via the JasperFillManager.fillReport() call.
If there are no specific reasons to check wheter the query contains any records, I would recommand to let JasperReports handle the query and the case that no record is found. You can determine a specific behaviour in that case via the "When No Data Type" property in the reportdesign.

SAP Crystal reports for VS 2010. Change the query at run time

I am using SAP CR for VS 2010 in C sharp. i have five tables and i am linking them with the following query:
query = "SELECT Items.AccessionNo, Items.Name, Items.LocalName, Items.Usage, Items.Province, Items.District, Items.VillTown, Items.EthnicCommunity, Arts.Name, Items.PurchasedDonated, Items.PurchasedFrom, Items.YearOfCollection, Items.Material, Items.Height, Items.Width, Items.Length, Items.Circumference, Items.Diameter, Items.Color, Items.Age, Items.Weight, Items.PurchasedValue, Items.Rare, Items.LivingDyingTrad, Items.ManufacturingProcess, Items.PlaceOfManufacturing, Items.ConditionReport, Items.Recommandations, Items.DateOfAddition, Items.Placement, Donators.Name, Collectors.Name, Placement.Name FROM Items INNER JOIN Arts ON Items.ArtId=Arts.ArtId INNER JOIN Donators ON Items.DonatorId=Donators.id INNER JOIN Collectors ON Items.CollectorId=Collectors.id INNER JOIN Placement ON Items.PlacementId=Placement.id WHERE Items.id=" + itemid;
The problem is that the report still shows up multiple results using the already embedded query at the time of design.
I am using the following code to pass the above query
SqlCommand cmd = new SqlCommand(query, dbconn.conn);
if (dbconn.conn.State == ConnectionState.Closed)
{
dbconn.conn.Open();
}
SqlDataAdapter Datadpt = new SqlDataAdapter(cmd);
DataSet dtset = new DataSet("items");
Datadpt.Fill(dtset);
//rep is the Report document object already defined
rep.Load(#"..\..\Reports\CRItem.rpt");
rep.SetDataSource(dtset);
CRViewer.ReportSource = rep;
if (dbconn.conn.State == ConnectionState.Open)
{
dbconn.conn.Close();
}
this.CRViewer.RefreshReport();
Any suggestions?
whoooosss.....i got it. the the crystalreportviewer selection formula is separate from report document record selection formula. Record Selection Formula that you've created in crystal report is stored in ReportDoc.RecordSelectionFormula property. When you load your ReportDoc to ReportViewer it doesn't adopt the value of .RecordSelectionFormula to its ReportViewer.SelectionFormula property. so what i did is....
My objects are:
ReportDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
ReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer
FlexReportDoc.SetParameterValue("Reference", gsReference)
After passing necessary parameters if you have any...
ReportViewer.ReportSource = FlexReportDoc
ReportViewer.SelectionFormula = FlexReportDoc.RecordSelectionFormula
you need to assign the value of FlexReportDoc.RecordSelectionFormula property to ReportViewer.SelectionFormula.

jasper reports table creation

I would like to create a table in my Jasper Report.
This could be done (and it is done :-) ) in iReport, but the content of the table (for example names of the columns) are changing, so I would like to create the report solely from JAVA code (by not using jrxml files).
How is it possible?
So far, this is what I have done (the main parts only):
//table component
final StandardTable table = new StandardTable();
final StandardColumn col1 = new StandardColumn();
final DesignCell col1Header = new DesignCell();
final JRDesignStaticText textElement = new JRDesignStaticText();
col1Header.addElement(textElement);
col1.setDetailCell(col1Header);
table.addColumn(col1);
/datasource
final JRDesignDatasetParameter param = new JRDesignDatasetParameter();
param.setName("REPORT_DATA_SOURCE");
final JRDesignExpression exp = new JRDesignExpression("$P{REPORT_DATA_SOURCE}");
param.setExpression(exp);
//datasetrun
final JRDesignDatasetRun drs = new JRDesignDatasetRun();
table.setDatasetRun(drs);
drs.addParameter( param );
How to continue?
Thank you,
krisy
In case anyone stumbles upon the same problem (and for future myself :-) ) here is how to continue the code above, to add a table element to the summary of the report:
//create reportElement (inside componentelement)
JRDesignComponentElement reportElem = new JRDesignComponentElement();
//reportElem.setKey("table");
reportElem.setComponentKey(new ComponentKey("http://jasperreports.sourceforge.net/jasperreports/components", "jr", "table"));
reportElem.setComponent(table);
reportElem.setHeight(100);
reportElem.setWidth(100);
//add to summary
jRSummary.addElement(reportElem);
(the hard part was to find out how to create the ComponentKey object)
Note: in order to use the table, the subdataset element needs to be created as well.
For htmlComponent the ComponentKey should be:
new ComponentKey("http://jasperreports.sourceforge.net/htmlcomponent", "jr",
"html");

crystal report parameters

I use the following code to pass parameters into a CR
// Reuse myDiscreteValue, and assign second country
myParam = new ParameterField();
myDiscreteValue = new ParameterDiscreteValue();
myParam.Name = "#toDate";
myDiscreteValue.Value = RmtUtility.Utility.DisplayDate(toDate);
myParam.CurrentValues.Add(myDiscreteValue);
myParams.Add(myParam);
I get an error message "Missing Parameter Value" when I tried to export the document using CR Option.
:(
Try clearing and then setting the values of the parameters within the Report object.
Something like this:
ParameterDiscreteValue paramDV = new ParameterDiscreteValue();
paramDV.Value = RmtUtility.Utility.DisplayDate(toDate);
report.ParameterFields["#toDate"].CurrentValues.Clear();
report.ParameterFields["#toDate"].DefaultValues.Clear();
report.ParameterFields["#toDate"].CurrentValues.Add(paramDV);
Note: report being your Crystal Report Document

Crystal Report on C#

Well I have a Cyrstal report which has 4 sub reports on and it is linked through an ItemID column and a Culture, so it has a parameter value "?Pm-ItemID" and "?Pm-Culture" now i'm using DataSet to load the data to the Crystal Report's datasource, when I run the report its giving me an error which was an asking parameter field was not suplied, so i think my question would be what am I going to pass to those ParameterFields?
here's an idea.
ReportDocument myreport = new ReportDocument();
myreport.Load("C:\MyReport.rpt");
DataSet ds = GenerateReportData();
myreport.SetDataSource(ds);
//Loop through each to Load the DataSet
for (int i = 0; i < myreport.Subreports.Count; i++)
{
ReportDocument subreport = myreport.SubReports[i];
DataSet subds = GenerateReportData(subreport.name)
subreport.SetDataSource(subds);
}
//I can see that there's a parameterfields in myreport.ParameterFields
//As I look through inside it there are 8 ParameterFields repeating Pm-ItemID and Pm-Culture
foreach (ParameterField pf in myreport.ParameterFields)
{
myreport.SetParameterValue(pf.Name, Value???);
}
Well, I see what's wrong.
ReportDocument subreport = myreport.SubReports[i];
DataSet subds = GenerateReportData(subreport.name)
subreport.SetDataSource(subds);
should not be done this way, it should be
DataSet subds = GenerateReportData(subreport.name)
myreport.SubReports[i].SetDataSource(subds);
I don't know about Crystal, but in SSRS it works like this:
1) create a subreport and create some parameters
2) create the main report, put there the subreport and in the properties you can specify what to bind to the subreport's parameters
Conclusion: I don't think this is supposed to be set in code, rather report designer.