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

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.

Related

Birt Conditional Page Break

I'm designing a BIRT report that should print on a form. In this report it is printing in both sides so the client is asking to do a Page Break if the details of a WorkOrder ends in a odd number so both WorkOrders wouldnt be in the same sheet.
Is it possible to add a pagecount() and do a page break if it is the end of the work order an its an odd number?
Thanks in advance.
I only have part of the answer. It would be possible on the adding pagination in the beforeFactory on the ReportDesign section. Out of the box Maximo reports have a pagination statement for PDF's. You can extend the if statement - see example of OOTB code below.
You would need to be able to bring back the WO number as a global parameter. That part is what you would need to do some additional research on.
if ( (reportContext.getParameterValue("usepagebreaks") == "false")|| reportContext.getOutputFormat() == "pdf" ) {
// Give each table in the report a name, and add the names to the list below, e.g. ["mainTable", "childTable1"]
var tableListing = ["dataSet_inventory_id13#"];
for each(var tableName in tableListing) {
var table = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement(tableName)
if (table != null) {
table.setProperty("pageBreakInterval", 0);
}
}
}

SyncFusion to SQL connection and showing on the Dashboard

I just wanted to know whether there is a possibility to connect to the SQL table using SyncFusion, and display the table in the form of a pivot in the Front end. I am using TypeScript for coding. I can also use C# if I need to use. If yes let me know how can I create connection between the SyncFusion and the SQL Table.
Any help on this is appreciated.
Thanks in advance.
Regards,
Raja
The connection to SQL using SyncFusion can be achieved by using the below code snippet.
DataSet ds = new DataSet();
//In below provide full path of your database(*.sdf) location.
string conStringforDB = HttpContext.Current.Server.MapPath("Northwind.sdf").Split(new string[] { "\\wcf" }, StringSplitOptions.None)[0] + "\\Northwind.sdf";
SqlCeConnection con = new SqlCeConnection(conStringforDB);
con.Open();
SqlCeCommand cmd = new SqlCeCommand(#"SELECT Top(100) [Order ID], [Product ID], [Unit Price], Quantity
FROM [Order Details] ", con);
SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
da.Fill(ds);
//Creation of DataView
DataView dataView = new DataView(ds.Tables[0]);

combine multiple reports in crystal reports in c#

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

Linq to Entities does not recognize the method System.DateTime.. and cannot translate this into a store expression

I have a problem that has taken me weeks to resolve and I have not been able to.
I have a class where I have two methods. The following is supposed to take the latest date from database. That date represents the latest payment that a customer has done to "something":
public DateTime getLatestPaymentDate(int? idCustomer)
{
DateTime lastDate;
lastDate = (from fp in ge.Payments
from cst in ge.Customers
from brs in ge.Records.AsEnumerable()
where (cst.idCustomer == brs.idCustomer && brs.idHardBox == fp.idHardbox
&& cst.idCustomer == idCustomer)
select fp.datePayment).AsEnumerable().Max();
return lastDate;
}//getLatestPaymentDate
And here I have the other method, which is supposed to call the previous one to complete a Linq query and pass it to a Crystal Report:
//Linq query to retrieve all those customers'data who have not paid their safebox(es) annuity in the last year.
public List<ReportObject> GetPendingPayers()
{
List<ReportObject> defaulterCustomers;
defaulterCustomers = (from c in ge.Customer
from br in ge.Records
from p in ge.Payments
where (c.idCustomer == br.idCustomer
&& br.idHardBox == p.idHardBox)
select new ReportObject
{
CustomerId = c.idCustomer,
CustomerName = c.nameCustomer,
HardBoxDateRecord = br.idHardRecord,
PaymentDate = getLatestPaymentDate(c.idCustomer),
}).Distinct().ToList();
}//GetPendingPayers
No compile error is thrown here, but when I run the application and the second method tries to call the first one in the field PaymentDate the error mentioned in the header occurs:
Linq to Entities does not recognize the method System.DateTime.. and cannot translate this into a store expression
Please anybody with an useful input that put me off from this messy error? Any help will be appreciated !
Thanks a lot !
Have a look at these other questions :
LINQ to Entities does not recognize the method
LINQ to Entities does not recognize the method 'System.DateTime Parse(System.String)' method
Basically, you cannot use a value on the C# side and translate it into SQL. The first question offers a more thorough explanation ; the second offers a simple solution to your problem.
EDIT :
Simply put : the EF is asking the SQL server to perform the getLatestPaymentDate method, which it has no clue about. You need to execute it on the program side.
Simply perform your query first, put the results into a list and then do your Select on the in-memory list :
List<ReportObject> defaulterCustomers;
var queryResult = (from c in ge.Customer
from br in ge.Records
from p in ge.Payments
where (c.idCustomer == br.idCustomer
&& br.idHardBox == p.idHardBox)).Distinct().ToList();
defaulterCustomers = from r in queryResult
select new ReportObject
{
CustomerId = r.idCustomer,
CustomerName = r.nameCustomer,
HardBoxDateRecord = r.idHardRecord,
PaymentDate = getLatestPaymentDate(r.idCustomer),
}).Distinct().ToList();
I don't have access to your code, obviously, so try it out and tell me if it works for you!
You'll end up with an in-memory list

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.