Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vieweing Crystal Report Form using VS.NET

Status
Not open for further replies.

hne

Programmer
Oct 16, 2003
38
US
I have an application developed in C# VS.NET that 'should' display a Crystal Report Form. However, when I pass my Stored Procedures parameters and set ReportSource, a blank form comes up and does not display any part of my report. Can anyone look at this and see what I am doing wrong? Thank you so much for your help.


DISPLAYPROFILE.CS:

private void DisplayReport()
{
try
{
display_profile.CrystalReportViewer1 crViewer1 = new CrystalReportViewer1(sqlTools);
crViewer1.Show();
}
catch (Exception ex)
{
statusBar1.Text = "Error: " + ex.Message.ToString();
}
}


CrystalReportViewer1:


using System;
using System.Drawing;
using System.Data.SqlClient;
using System.Collections;
using System.Data;
using System.ComponentModel;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Windows.Forms;

using ConfigurationXml;
using common;

namespace display_profile
{
/// <summary>
/// Summary description for CrystalReportViewer1.
/// </summary>
public class CrystalReportViewer1 : System.Windows.Forms.Form
{
private SqlTools sqlTools;

private bool isLoggedOn = false;
private ReportDocument crDocument = new ReportDocument();
private Database crDatabase;
private Tables crTables;
private Table crTable;
private TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
private ConnectionInfo crConnectionInfo;
private ParameterFieldDefinitions crPDefinitions;
private ParameterFieldDefinition crPDefinition;
private ParameterValues crPValues;
protected SqlCommand cmdGateProfile;
protected ParameterField crPField = new ParameterField();
protected ParameterFields crPFields = new ParameterFields();
protected ParameterDiscreteValue crPDValue = new ParameterDiscreteValue();

private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer2;
private display_profile.OA_Profiles oA_Profiles1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public CrystalReportViewer1(SqlTools sqlTools_in)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

sqlTools = sqlTools_in;
}

/// <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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CrystalReportViewer1));
this.crystalReportViewer2 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
this.oA_Profiles1 = new display_profile.OA_Profiles();
this.SuspendLayout();
//
// crystalReportViewer2
this.crystalReportViewer2.ActiveViewIndex = -1;
this.crystalReportViewer2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.crystalReportViewer2.AutoScroll = true;
this.crystalReportViewer2.DisplayGroupTree = false;
this.crystalReportViewer2.Location = new System.Drawing.Point(0, 0);
this.crystalReportViewer2.Name = "crystalReportViewer2";
this.crystalReportViewer2.ReportSource = "C:\\Documents and Settings\\All Users\\Application Data\\DAL\\OA Profiles\\OA_Profiles." +
"rpt";
this.crystalReportViewer2.ShowGroupTreeButton = false;
this.crystalReportViewer2.ShowRefreshButton = false;
this.crystalReportViewer2.Size = new System.Drawing.Size(800, 882);
this.crystalReportViewer2.TabIndex = 0;
this.crystalReportViewer2.Load += new System.EventHandler(this.crystalReportViewer2_Load);
//
// oA_Profiles1
//
this.oA_Profiles1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation;
this.oA_Profiles1.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize;
this.oA_Profiles1.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper;
this.oA_Profiles1.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default;
//
// CrystalReportViewer1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(800, 882);
this.Controls.Add(this.crystalReportViewer2);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "CrystalReportViewer1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "OA Display Profiles";
this.Load += new System.EventHandler(this.crystalReportViewer2_Load);
this.ResumeLayout(false);

}
#endregion

private void crystalReportViewer2_Load(object sender, System.EventArgs e)
{
if (!isLoggedOn)
{
SetReportParameters();
}
}

/// <summary>
/// Set the parameters for the report
/// </summary>
protected void SetReportParameters()
{
int idx;
string str = null;
DateTime dt = new DateTime();
DateTimePicker dtP = new DateTimePicker();

try
{
crDocument.Load(crystalReportViewer2.ReportSource.ToString());
crConnectionInfo = sqlTools.GetCrConnectionInfo();
crConnectionInfo.ServerName = "SATLRCCDLDB15";
crConnectionInfo.DatabaseName = "oadb";
crConnectionInfo.UserID = "oauser";
crConnectionInfo.Password = "elmwood";

crDocument.SetDatabaseLogon(crConnectionInfo.UserID, crConnectionInfo.Password, crConnectionInfo.ServerName, crConnectionInfo.DatabaseName);

crTableLogOnInfo.TableName = "gate_profile;1";
crTableLogOnInfo.ConnectionInfo.ServerName = "SATLRCCDLDB15";
crTableLogOnInfo.ConnectionInfo.DatabaseName = "oadb";
crTableLogOnInfo.ConnectionInfo.UserID = "oauser";
crTableLogOnInfo.ConnectionInfo.Password = "elmwood";

crDatabase = crDocument.Database;
crTables = crDatabase.Tables;


// loop through all the tables and apply the connection into to each table...
for (int i = 0; i < crTables.Count; i++)
{
crTable = crTables;
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
}
isLoggedOn = true; // I log on 1 time
str = DisplayProfile.myDoW.Remove(0, 2);
idx = Convert.ToInt32(DisplayProfile.myDoW.Remove(1, DisplayProfile.myDoW.Length - 1));
/// <summary>
/// Get the collection of parameters from the report...
/// Access the specified parameter from the collection...
/// Get the values from the parameter field. There are zero values set.
/// Clear existing parameter values...
/// Set the current values for the numeric parameter field
/// Add the current value for the parameter field
/// The current parameter values must be applied for the parameter field.
/// Move to the next parameter field ...
/// </summary>

crPDefinitions = crDocument.DataDefinition.ParameterFields;
crPDefinition = crPDefinitions["@start_date"];
crPValues = crPDefinition.CurrentValues;
crPDValue.Value = DisplayProfile.startDate.ToString("MM/dd/yyyy");
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
crPDefinitions = crDocument.DataDefinition.ParameterFields;
crPDefinition = crPDefinitions["@end_date"];
crPValues = crPDefinition.CurrentValues;
crPValues.Clear();
crPDValue.Value = DisplayProfile.endDate.ToString("MM/dd/yyyy");
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
crDocument.SetParameterValue("WeekDay", str);

if (DisplayProfile.myTZ == "LCL")
{
crPDefinitions = crDocument.DataDefinition.ParameterFields;
crPDefinition = crPDefinitions["@timezone"];
crPValues = crPDefinition.CurrentValues;
crPValues.Clear();
crPDValue.Value = DisplayProfile.myTZ;
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
}
else
{
crPDefinitions = crDocument.DataDefinition.ParameterFields;
crPDefinition = crPDefinitions["@timezone"];
crPValues = crPDefinition.CurrentValues;
crPValues.Clear();
crPDValue.Value = DisplayProfile.myTZ;
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
}
if (idx > -1)
{
crPDefinitions = crDocument.DataDefinition.ParameterFields;
crPDefinition = crPDefinitions["@for_weekday"];
crPValues = crPDefinition.CurrentValues;
crPValues.Clear();
crPDValue.Value = idx;
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
}

if (DisplayProfile.bAdjLog)
{
crDocument.SetParameterValue("AdjCode_Text", "Adjustment Log: ");

crPDefinitions = crDocument.DataDefinition.ParameterFields;
crPDefinition = crPDefinitions["@adj_code"];
crPValues = crPDefinition.CurrentValues;
crPValues.Clear();
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
DisplayProfile.bAdjLog = false;
}
if (ExcludeDates.xldArrList.Count > 0)
{
int i = 0;
crPValues.Clear();
if (ExcludeDates.xldArrList.Count == 1)
crDocument.SetParameterValue("ExcludeDates_Text", "Exclude Date: ");
else
crDocument.SetParameterValue("ExcludeDates_Text", "Exclude Dates: ");
crPDefinitions = crDocument.DataDefinition.ParameterFields;
for (i = 0; i < ExcludeDates.xldArrList.Count; i++)
{
crPDefinition = crPDefinitions["@exclude_date" + (i + 1).ToString()];
crPDefinition.CurrentValues.Clear();
crPValues = crPDefinition.CurrentValues;
dt = Convert.ToDateTime(ExcludeDates.xldArrList);
crPDValue.Value = dt.ToString("MM/dd/yyyy");
crPValues.Add(crPDValue);
}
while (i < 10)
{
crPDefinition = crPDefinitions["@exclude_date" + (i + 1).ToString()];
crPDefinition.CurrentValues.Clear();
crPValues = crPDefinition.CurrentValues;
crPDValue.Value = null;
crPValues.Add(crPDValue);
i++;
}
crPDefinition.ApplyCurrentValues(crPValues);
}
else //null if no Exclude Dates entered...
{
int i = 0;
crPValues.Clear();
crDocument.SetParameterValue("ExcludeDates_Text", "Exclude Date: ");
crPDefinitions = crDocument.DataDefinition.ParameterFields;
while (i < 10)
{
crPDefinition = crPDefinitions["@exclude_date" + (i + 1).ToString()];
crPDefinition.CurrentValues.Clear();
crPValues = crPDefinition.CurrentValues;
crPDValue.Value = null;
crPValues.Add(crPDValue);
i++;
}
crPDefinition.ApplyCurrentValues(crPValues);
}
if (DisplayProfile.SelectedCities.Count > 0)
{
int count = 1;
crPValues.Clear();
crPDValue.Value = null;
if (DisplayProfile.SelectedCities.Count == 1)
crDocument.SetParameterValue("Cities_Text", "City: ");
else
crDocument.SetParameterValue("Cities_Text", "Cities: ");
crPDefinitions = crDocument.DataDefinition.ParameterFields;
for (int i = 0; i < DisplayProfile.SelectedCities.Count; i++)
{
string cty = DisplayProfile.SelectedCities.ToString();
cty = cty.Trim();
crPDefinition = crPDefinitions["@sites"];
crPValues = crPDefinition.CurrentValues;
crPDValue.Value += cty;
if (DisplayProfile.SelectedCities.Count > count)
{
crPDValue.Value += ",";
count++;
}
}
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
}
else
{
crPDefinition = crPDefinitions["@sites"];
crPValues = crPDefinition.CurrentValues;
crPDValue.Value = null;
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
}
if (DisplayProfile.SelectedGates.Count > 0)
{
int count = 1;
crPValues.Clear();
crPDValue.Value = null;
if (DisplayProfile.SelectedGates.Count == 1)
crDocument.SetParameterValue("Gates_Text", "Gate: ");
else
crDocument.SetParameterValue("Gates_Text", "Gates: ");
crPDefinitions = crDocument.DataDefinition.ParameterFields;
for (int i = 0; i < DisplayProfile.SelectedGates.Count; i++)
{
if (DisplayProfile.SelectedGates.Capacity < 255)
crPDefinition = crPDefinitions["@gates1"];
else
crPDefinition = crPDefinitions["@gates2"];
crPValues = crPDefinition.CurrentValues;
crPDValue.Value += DisplayProfile.SelectedGates.ToString();
if (DisplayProfile.SelectedGates.Count > count)
{
crPDValue.Value += ",";
count++;
}
}
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
if (DisplayProfile.SelectedGates.Capacity < 255) // notthing for gates2
{
crPDefinition = crPDefinitions["@gates2"];
crPValues = crPDefinition.CurrentValues;
crPDValue.Value = null;
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
}
}
else /// set values to null...
{
crPDefinition = crPDefinitions["@gates1"];
crPValues = crPDefinition.CurrentValues;
crPDValue.Value = null;
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);

crPDefinition = crPDefinitions["@gates2"];
crPValues = crPDefinition.CurrentValues;
crPDValue.Value = null;
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
}
crystalReportViewer2.ReportSource = crDocument;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
sqlTools.DisposeSqlConnection();
}
}
}
}
 
that's a lot of code.

why do you clear the parameters in the middle of setting them?

Code:
crPDefinition = crPDefinitions["@end_date"];
crPValues = crPDefinition.CurrentValues;
[b]crPValues.Clear();[/b]
crPDValue.Value = DisplayProfile.endDate.ToString("MM/dd/yyyy");
crPValues.Add(crPDValue);
crPDefinition.ApplyCurrentValues(crPValues);
crDocument.SetParameterValue("WeekDay", str);

mr s. <;)

 
Thanks for your response. I do have the Clear method a little further than I need to. However, I try the clear my values because I am passing parameters to a Stored Procedure. Regardless, even if I comment out the clear method, when I set ReportSource, I still get a blank Window Form. Again, thanks for your response.
 
it's a little difficult to judge why you'd be getting a blank form since there's so much code.

at a first guess it's because the parameters given return no data.

try taking out all the parameters code and replacing it with a set of parameters you know will return data.

if it doesn't, you know that it's crystal that's broken.

if it does, you know to start adding the complex parameter code back a block at a time until something breaks.

hope this helps,

mr s. <;)

 
In Crystal Reports, manually entering the parameters I get a returned output. In my code, if I comment out everything starting from where I set my parameters definitions and just include logging to the database and tables and set the ReprotSource, I get just the canned display of what is already in the report template file. That is, whatever data that was last saved in the .rpt file. Thanks for your response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top