SAP Crystal Report Visual Studio 2010 - crystal-reports

How can the parameter prompt in SAP Crystal Report be disabled? I'm using Visual Studio 2010.
My Code is:
{
NPB.Report.CrLetter objCrLetter = new NPB.Report.CrLetter();
NPB.Report.frmViewer objView = new NPB.Report.frmViewer();
private void btnGenerateLetters_Click(object sender, EventArgs e)
{
objCrLetter.ParameterFields["LetterDate"].DefaultValues.AddValue(dtpLetterDate.Value.ToShortTimeString());
objCrLetter.ParameterFields["Salutation"].DefaultValues.AddValue(cboboxSalutation.Text);
objCrLetter.ParameterFields["Address"].DefaultValues.AddValue("2");
objCrLetter.ParameterFields["City"].DefaultValues.AddValue("3");
objCrLetter.ParameterFields["State"].DefaultValues.AddValue("4");
objCrLetter.ParameterFields["ZipCode"].DefaultValues.AddValue("5");
objView.crViewer.ReportSource = objCrLetter;
objView.Show();
}
}

I would probably change your code so that for each Parameter in the Crystal Report would clear the current & default values then pass in the correct value.
So you need to do something like this for each parameter:
ParameterDiscreteValue paramDV = new ParameterDiscreteValue();
paramDV.Value = "Parameter Value";
objCrLetter.ParameterFields["#ParameterName"].CurrentValues.Clear();
objCrLetter.ParameterFields["#ParameterName"].DefaultValues.Clear();
objCrLetter.ParameterFields["#ParameterName"].CurrentValues.Add(paramDV);
This should prevent the Parameter Prompt from appearing.

This answers are almost perfect, but, You should pay attention to the when setting de data source.
This setting should happens before you set the parameters.

Related

GLS ShipIt SOAP with Visual Studio

does anyone have experience with the SOAP interface of GLS ShipIt?
I integrated these into Visual Studio VB .net, but after setting the credentials and ContactID, the "CreateParcels" function always reports the error "unauthorized".
Dim glscreateparcel As new GLSShipIT.ShipmentProcessingService
glscreateparcel.PreAuthenticate = True
glscreateparcel.Url = "https://shipit-wbm-test01.gls-group.eu:8443/backend/ShipmentProcessingService/ShipmentProcessingPortType?wsdl"
glscreateparcel.Credentials = New System.Net.NetworkCredential(benutzer, kennwort)
glscreateparcel.InitializeLifetimeService()
Dim glsshipmentrequestdata As New GLS.GLSShipIT.ShipmentRequestData
'some code for shipmentrequestdata details
glsshipmentrequestdata.Shipment.Shipper.ContactID = ContactID
Dim response As GLSShipIT.CreateParcelsResponse = glscreateparcel.createParcels(glsshipmentrequestdata)
the Variables for ContactID, benutzer and kennwort were previously set.
best regards

how to use db name as input control/parameter in jasper report

I am using jasper reports and want to give user to select the db name as input control and want to use that in query.
tool used is ireport /jasper soft studio 6.x
Got the solution for above question I used list of input control and then used the parameter value as
$P!{parametername}
Same as usage of table name as parameter/input control in jasper.
If I am understanding correctly, following code might help you.
Ofcourse "foo DB" and "baz DB" should have same tables.
Connection conn;
// Change the DB depend on input value.
if (userInput.equals("foo")){
conn = DriverManager.getConnection("jdbc:mysql://localhost/foo", "user", "password");
}
else if (userInput.equals("baz")){
conn = DriverManager.getConnection("jdbc:mysql://localhost/baz", "user", "password");
}
else{
// error
}
JasperReport jasper = (JasperReport)JRLoader.loadObject(your_jasper_filePath);
Map paramMap = new HashMap();
paramMap.put("param1", "some_param1");
paramMap.put("param2", "some_param2");
JasperPrint print = JasperFillManager.fillReport(jasper, paramMap, conn);
JasperExportManager.exportReportToPdfFile(print, PdfPath);

Crystal Reports Runtime & Redistributable

Is there a difference between these two things. I am trying to move some reports from a local server to a dev server and I know that we have installed the redist on the dev server, but am still having problems getting the report to run. Is the runtime separate I come accross different sites mentioning both things but havent been able to tell if they are talking about the same thing
*Edit - posting code to see if as dotjoe suggested I have incorrectly labled my report path. the database connection is returned from a method to a string array reportString so that is what that array is.
<CR:CrystalReportViewer ID="CrystalReportViewer2" runat="server"
AutoDataBind="True" Height="50px" Width="350px" ReuseParameterValuesOnRefresh="True" ToolbarImagesFolderUrl="~/images/reportViwerImages"/>
ConnectionInfo myConnectionInfo = new ConnectionInfo();
myConnectionInfo.ServerName = reportString[1];
myConnectionInfo.DatabaseName = reportString[0];
myConnectionInfo.UserID = reportString[2];
myConnectionInfo.Password = reportString[3];
string ReportPath = Server.MapPath("../../mdReports/CrystalReport.rpt");
CrystalReportViewer2.ReportSource = ReportPath;
ParameterField field1 = new ParameterField();
ParameterDiscreteValue val1 = new ParameterDiscreteValue();
val1.Value = hiddenFieldReportNumber.ToString();
field1.CurrentValues.Add(val1);
SetDBLogonForReport(myConnectionInfo);
private void SetDBLogonForReport(ConnectionInfo myConnectionInfo)
{
TableLogOnInfos myTableLogOnInfos = CrystalReportViewer2.LogOnInfo;
foreach (TableLogOnInfo myTableLogOnInfo in myTableLogOnInfos)
{
myTableLogOnInfo.ConnectionInfo = myConnectionInfo;
}
}
you have not load the report from the given Path.
Please see below link

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.

how do you set the default export name in the crystal report viewer

On an ASP.NET page, when a user is viewing a report from the Crystal Report Viewer(CRV) they have the ability to export the report (eg to PDF). The default filename for the export is the ID of the CRV.
I would like to set the default name to be something that is based on the parameters of the report. (eg "Sales for 2008").
I know I can add a link to the page that would and then I could code up a solution where I generated the PDF in code and the stream it to the browser, but I was hoping there might be a way to do this nativity in Crystal Reports.
// You could pass the parameters to the web page
// where you have theCrystalReportViewer control
protected void Page_Load(object sender, EventArgs e)
{
string reportId = Request["rid"];
string reportTitle = Request["rtitle"];
ReportDocument reportDocument = HttpContext.Current.Session[reportId] as ReportDocument;
this.CommonCrystalReportViewer.ReportSource = reportDocument;
this.CommonCrystalReportViewer.DataBind();
// Set the default export file name for the report.
this.CommonCrystalReportViewer.ID = reportTitle;
}
If you are using Visual Studio 2008 to create the report you could edit the ReportClass created to add your DefaultName property.
Natively there was a ReportExporter class to be used instead of ReportViewer class but it's not supported anymore. There are some third-parts similar.
I use this code samples:
Get parameters value from report (if you don't have already from Session, QueryString or somewhere else)
string myParamName="XXX";
object myParamValue;
foreach (ParameterField field in reportDocument.ParameterFields)
{
if (string.Compare(field.Name.TrimStart('#'), myParamName, true) == 0)
myParamValue= field.CurrentValues;
}
Export using report name needed
string myReportName = "sales for " + myParamValue.ToString() + ".pdf";
try
{
reportDocument.ExportToHttpResponse(
ExportFormatType.PortableDocFormat
,Response, true, myReportName);
}
catch (System.Threading.ThreadAbortException)
{
//System.Threading.ThreadAbortException is thrown
//because, Response.End is called internally in ExportToHttpResponse method:
}
protected void Page_Init(object sender, EventArgs e) {
...
// Set the default export file name for the report.
this.mainReportViewer.ID = reportTitle;
...
}
It is mandatory to change reportViewer id in Page_Init function, otherwise will not work.