Crystal parameters

  • Thread starter Robert Schuldenfrei
  • Start date
R

Robert Schuldenfrei

Hello NG,

After a bit of a wait my bookstore, SoftPro of Waltham, MA, got in the Brian
Bischof book: Crystal Reports .NET Programming. I have read a few books on
CR, but I am very new to it, C#, and SQL. The book is excellent.
Undaunted, I have plowed into a conversion of my old COBOL ERP system,
MCS-3, into C#. I have quite a bit of Inventory Control done and working.
For reports I am trying to use CR. I have a half a dozen of them working
directly off of the SQL Server database. In order to do record (OK, I am an
old COBOL hand! Read row.) selection I have a field (OK, column) called
im_planner_code in the database. Using the default parameter ?plannerCode I
am able to select all rows with im_planner_code = "A". I would like to
develop my own parameter dialog box. To start I have invoked the code
listed below at the load event of Form1303. It compiles clean, but has an
execution error at the highlighted line. I would of course like to know
what my problem is, but beyond that I need to know how to debug CR execution
errors.

Is there a good newsgroup for CR under .NET? I currently read:
Microsoft.public.dotnet.languages.csharp. Thank you in advance.



Cheers,

Bob

Robert Schuldenfrei

S. I. Inc.

32 Ridley Road

Dedham, MA 02026



(781) 329-4828

(e-mail address removed)

www.s-i-inc.com



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using CrystalDecisions.Shared;

using CrystalDecisions.CrystalReports.Engine;



namespace Reports

{

/// <summary>

/// Summary description for Form1303.

/// </summary>

public class Form1303 : System.Windows.Forms.Form

{

private CrystalDecisions.Windows.Forms.CrystalReportViewer
crystalReportViewer1;

private Reports.rpt1303 rpt13031;

private ParameterDiscreteValue parameterDiscreteValue;
//used for parameter passing

private ParameterValues parameterValues;

private ParameterFieldDefinition parameterFieldDefinition;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;



public Form1303()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();



//

// TODO: Add any constructor code after
InitializeComponent call

//

}



/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}



#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.crystalReportViewer1 = new
CrystalDecisions.Windows.Forms.CrystalReportViewer();

this.rpt13031 = new Reports.rpt1303();

this.SuspendLayout();

//

// crystalReportViewer1

//

this.crystalReportViewer1.ActiveViewIndex = -1;

this.crystalReportViewer1.Dock =
System.Windows.Forms.DockStyle.Fill;

this.crystalReportViewer1.Location = new
System.Drawing.Point(0, 0);

this.crystalReportViewer1.Name = "crystalReportViewer1";

this.crystalReportViewer1.ReportSource = this.rpt13031;

this.crystalReportViewer1.Size = new
System.Drawing.Size(892, 746);

this.crystalReportViewer1.TabIndex = 0;

//

// rpt13031

//

this.rpt13031.PrintOptions.PaperOrientation =
CrystalDecisions.Shared.PaperOrientation.Landscape;

this.rpt13031.PrintOptions.PaperSize =
CrystalDecisions.Shared.PaperSize.DefaultPaperSize;

this.rpt13031.PrintOptions.PaperSource =
CrystalDecisions.Shared.PaperSource.Upper;

this.rpt13031.PrintOptions.PrinterDuplex =
CrystalDecisions.Shared.PrinterDuplex.Default;

//

// Form1303

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(892, 746);

this.Controls.Add(this.crystalReportViewer1);

this.Name = "Form1303";

this.Text = "Form1303";

this.WindowState =
System.Windows.Forms.FormWindowState.Maximized;

this.Load += new System.EventHandler(this.Form1303_Load);

this.ResumeLayout(false);



}

#endregion



private void Form1303_Load(object sender, System.EventArgs e)

{

this.crystalReportViewer1.Zoom(75);

//Use the ReportDocument object to create plannerCode &
productCode parameters

//note: my ReportDocument is called rpt13031 not
CrystalReport1

rpt1303 myReport = new rpt1303();

//Step 1: property field to modify - ERROR: Invalid field
name.

parameterFieldDefinition =
myReport.DataDefinition.ParameterFields["?plannerCode"];

//Step 2: instantiate parameterValues collection

parameterValues = new ParameterValues();

//Step 3: instantiate a parameterValue

parameterDiscreteValue = new ParameterDiscreteValue();

//Step 4: set Value property

parameterDiscreteValue.Value = "A"; //will get this
from user

//Step 5: use Add() method to add to collection

parameterValues.Add(parameterDiscreteValue);

//Step 6: other parameters go here (productCode)

//Step 7: assign collection to parameter field


parameterFieldDefinition.ApplyCurrentValues(parameterValues);

//Step 8: preview report

crystalReportViewer1.ReportSource = myReport;

}

}

}
 
R

Robert Schuldenfrei

Hi NG,

I changed my approach and made progress. The code below now uses the
CrystalReportViewer classes. It works except that:

1/ It displays the default parameter screen in spite of the fact that I am
providing my own parameters. It then flashes the correct result of the
standard parameter screen before running my parameter .Value = "A"
correctly. Is the Load event the correct placement for parameter
over-rides?

2/ The final report does not set the Zoom(75) property but reverts back to
100%.

TIA

Bob
(e-mail address removed)



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using CrystalDecisions.Shared;

using CrystalDecisions.CrystalReports.Engine;

namespace Reports

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1301 : System.Windows.Forms.Form

{

private CrystalDecisions.Windows.Forms.CrystalReportViewer
crystalReportViewer1;

private Reports.rpt1301 rpt13011;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

private ParameterDiscreteValue parameterDiscreteValue; //used for parameter
passing

private ParameterFields parameterFields;

private ParameterField parameterField; //note: removed I

public Form1301()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.crystalReportViewer1 = new
CrystalDecisions.Windows.Forms.CrystalReportViewer();

this.rpt13011 = new Reports.rpt1301();

this.SuspendLayout();

//

// crystalReportViewer1

//

this.crystalReportViewer1.ActiveViewIndex = -1;

this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;

this.crystalReportViewer1.Location = new System.Drawing.Point(0, 0);

this.crystalReportViewer1.Name = "crystalReportViewer1";

this.crystalReportViewer1.ReportSource = this.rpt13011;

this.crystalReportViewer1.Size = new System.Drawing.Size(696, 374);

this.crystalReportViewer1.TabIndex = 0;

//

// rpt13011

//

this.rpt13011.PrintOptions.PaperOrientation =
CrystalDecisions.Shared.PaperOrientation.Landscape;

this.rpt13011.PrintOptions.PaperSize =
CrystalDecisions.Shared.PaperSize.DefaultPaperSize;

this.rpt13011.PrintOptions.PaperSource =
CrystalDecisions.Shared.PaperSource.Upper;

this.rpt13011.PrintOptions.PrinterDuplex =
CrystalDecisions.Shared.PrinterDuplex.Default;

//

// Form1301

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(696, 374);

this.Controls.Add(this.crystalReportViewer1);

this.Name = "Form1301";

this.Text = "Crystal Reports - 1301";

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

this.Load += new System.EventHandler(this.Form1301_Load);

this.ResumeLayout(false);

}

#endregion

private void Form1301_Load(object sender, System.EventArgs e)

{

this.crystalReportViewer1.Zoom(75);

//Use the viewer object to create plannerCode & productCode parameters

rpt1301 myReport = new rpt1301();

//Step 1: assign report object to viewer

crystalReportViewer1.ReportSource = myReport;

//Step 2: reference parameterFields collection

parameterFields = crystalReportViewer1.ParameterFieldInfo;

//Step 3: reference the parameterField

//parameterField = new ParameterField();

//parameterField.ParameterFieldName = "plannerCode";

parameterField = parameterFields["plannerCode"];

//Step 4: create a parameterValue object

parameterDiscreteValue = new ParameterDiscreteValue();

//Step 5: assign a value to the object

parameterDiscreteValue.Value = "A";

//Step 6: add the parameterValue object to the CurrentValues collection

parameterField.CurrentValues.Add(parameterDiscreteValue);

//MessageBox.Show("In load event.", "Info");

}

}

}
 
K

Kevin Yu [MSFT]

Hi Robert,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you have two questions. The first is
that there is something wrong with the parameter screen. The second is zoom
is not working properly. If there is any misunderstanding, please feel free
to let me know.

I'm not quite familiar with Crystal Report. But based on the code you have
provided, I recommend you to put the line of code
this.crystalReportViewer1.Zoom(75); after setting the report source. (Try
to move this line to the bottom of Form_Load.) Because setting the report
source might refresh the view, which causes Zoom not working properly.

I'm not quite sure why parameter issue happens. If you could send me a
repro with whole project, I will try to debug it. Thank you!

Since Crystal Report is a third-party product by Business Objects,
currently we have no newsgroup for Crystal Report discussion. Besides
posting here, you can also check Business Objects support website for help.
Here is the link:

http://support.businessobjects.com/

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
R

Robert Schuldenfrei

Hi Kevin and NG,

Once again thank you for taking time out to address my problems. Before I
pack up the project and send it to you I would like to know if I am going
off in the right direction. First, and most important, is Crystal Reports
(CR) the right tool for printing reports? I have well over 100 reports in
my application and I would like to use the best tool for the job.

Second, if CR is the right tool, am I using it correctly? Because it was
easy to do, I started using CR directly against the SQL database. This
seems to be called the "Pull" technique by books on CR. For 90% of my
reports this will work. For the last 10% I will have to reformat and/or
restructure the data in a C# program. At this point I could either create a
temporary SQL table and print the report use the same "Pull" technique I
have been using on the 90%, or send it to CR using the "Push" technique. I
have not yet learned the "Push" technique. A good example of such a report
in my ERP application would be an indented Bill of Materials report. This
is a report that follows a tree structure rather than a simple listing of
records (rows) in a table.

Third, moving the .Zoom(75) property to the end of the report made the
message that appears in the bottom of the window say 75%, but the view was
at 100%. I can use the icons at the top of the window to force it to 75%.
Other properties now set by code take effect correctly such as the
..DisplayGroupTree property.
crystalReportViewer1.DisplayGroupTree = false;
crystalReportViewer1.Zoom(75);

Finally, is the report load event the proper place for this code?

As ever, thank you for your help,

Cheers,

Bob

--
Robert Schuldenfrei
S. I. Inc.
32 Ridley Road
Dedham, MA 02026
(e-mail address removed)
781/329-4828
 
K

Kevin Yu [MSFT]

Hi Robert,

1. Yes, I think CR is a good tool for use to generate reports both on
winform and web form.

For 2,3,4 I'm not quite familiar about this. I can just take a look at your
code and try my best to help. Since it is not Crystal Report is a 3rd-party
product, it is not supported by Microsoft. If you can't get a satifying
answer here, I think you can also have a try in the Crystal Report support
website.

http://support.businessobjects.com/

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
R

Robert Schuldenfrei

Hi Kevin,

Thanks a lot. OK, I will keep at it using CR as my principal report writer.
If by this time tomorrow, I do not get an obvious answer, I will send you my
project. Understand that there are a number of working reports in the
project such that the folder that contains the problem class is not the only
thing that will be sent. There is 256 KB of uncompressed files in the
source folder. I have gone through the BusinessObjects web site and it has
not been all that helpful.

Cheers,

Bob
--
Robert Schuldenfrei
S. I. Inc.
32 Ridley Road
Dedham, MA 02026
(e-mail address removed)
781/329-4828
 
K

Kevin Yu [MSFT]

Hi Bob,

I will wait for your project and try my best to help. However, my knowlege
in Crystal Report is limited. So please excuse, if I can't help much.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
R

Robert Schuldenfrei

Hi NG and Kevin,



Here is my Reports folder. (NG: I sent this directly to Kevin, but I did
not want to gum up the NG with a ZIP file) The report with the parameter
passing is rpt1301.rpt. If you try to run the report you are going to need
the SQL Server data. Let me know if you need this capability. If you do
need this capability give me instructions on how to make a copy of the SQL
data. I am using the MSDE version of SQL right now. Thank you for your
help.



Cheers,



Bob


--
Robert Schuldenfrei
S. I. Inc.
32 Ridley Road
Dedham, MA 02026
(e-mail address removed)
781/329-4828
 
K

Kevin Yu [MSFT]

Hi Bob,

I tried to check how that error happens. But based on the error message
ERROR: Invalid field name, I think there might be something wrong with the
field name "plannerCode". Please check if this field is in the parameter
collection.

I'm sorry but debugging Crystal Report is really beyond my ability. I think
you will get more information and advice from
http://support.businessobjects.com/

Sorry that I didn't provide much help on this issue.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
R

Robert Schuldenfrei

Thanks anyway Kevin,

I am not getting an error message. In fact my code executes correctly
except for the "extra" dialog box for the standard parameter.

Cheers,

Bob
--
Robert Schuldenfrei
S. I. Inc.
32 Ridley Road
Dedham, MA 02026
(e-mail address removed)
781/329-4828
 

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