crystal report param problems

Oct 1 2008 12:28 PM
WEll im trying to have pass some parameters through C#to my crystalreport iniatlly i have my reportviewer visible=false since i dont want it to be visible till someone puts in parameters.. it compiles good and all, when i click on submit.. it loads.. but nothign happens.. no report or anything... please dont be to hard on my.. im kinda new.. :( look at my code..

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;

public partial class rptOrientacionUsuarioWin : System.Web.UI.Page
{
String nUsuario;
String strFechaIni;
String strFechaFin;
DateTime FechaINI;
DateTime FechaFIN;

private void Page_Init(object sender, EventArgs e)
{

}

ConnectionInfo connectionInfo = new ConnectionInfo();

protected void Page_Load(object sender, EventArgs e)
{

}

public void Loader(ConnectionInfo connectionInfo)
{
// object declration
CrystalDecisions.CrystalReports.Engine.Database crDatabase;
CrystalDecisions.CrystalReports.Engine.Table crTable;
TableLogOnInfo tableLogOnInfos1 = new TableLogOnInfo();

// new report document object
ReportDocument oRpt = new ReportDocument();

// loading the ItemReport in report document
oRpt.Load("rptOrientacionesUsuario.rpt");

// getting the database, the table and the LogOnInfo object which holds login onformation
crDatabase = oRpt.Database;

// getting the table in an object array of one item
object[] arrTables = new object[1];
crDatabase.Tables.CopyTo(arrTables, 0);

// assigning the first item of array to crTable by downcasting the object to Table
crTable = (CrystalDecisions.CrystalReports.Engine.Table)arrTables[0];

// assigning the first item of array to crTable by downcasting the object to Table
crTable = (CrystalDecisions.CrystalReports.Engine.Table)arrTables[0];
tableLogOnInfos1 = crTable.LogOnInfo;
TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo;
foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
{

tableLogOnInfo.ConnectionInfo = connectionInfo;
connectionInfo.DatabaseName = "sisaa";
connectionInfo.UserID = "admin";
connectionInfo.Password = "dida";
}

// applying login info to the table object
crTable.ApplyLogOnInfo(tableLogOnInfos1);

// defining report source
CrystalReportViewer1.ReportSource = oRpt;

// so uptill now we have created everything
// what remains is to pass parameters to our report, so it
// shows only selected records. so calling a method to set
// those parameters.

setReportParameters();

}
private void setReportParameters()
{

// all the parameter fields will be added to this collection
ParameterFields paramFields = new ParameterFields();

// the parameter fields to be sent to the report
ParameterField pfUsuario = new ParameterField();
ParameterField pfFechaIni = new ParameterField();
ParameterField pfFechaFin = new ParameterField();

// setting the name of parameter fields with wich they will be recieved in report
pfUsuario.ParameterFieldName = "Usuario";
pfFechaIni.ParameterFieldName = "FechaIni";
pfFechaFin.ParameterFieldName = "FechaFin";

// the above declared parameter fields accept values as discrete objects
// so declaring discrete objects
ParameterDiscreteValue dcUsuario = new ParameterDiscreteValue();
ParameterDiscreteValue dcFechaIni = new ParameterDiscreteValue();
ParameterDiscreteValue dcFechaFin = new ParameterDiscreteValue();

// setting the values of discrete objects
dcUsuario.Value = nUsuario;

dcFechaIni.Value = DateTime.Parse(strFechaIni);
dcFechaFin.Value = DateTime.Parse(strFechaFin);

// now adding these discrete values to parameters
pfUsuario.CurrentValues.Add(dcUsuario);
pfFechaIni.CurrentValues.Add(dcFechaIni);
pfFechaFin.CurrentValues.Add(dcFechaFin);

// now adding all these parameter fields to the parameter collection
paramFields.Add(pfUsuario);
paramFields.Add(pfFechaIni);
paramFields.Add(pfFechaFin);

// finally add the parameter collection to the crystal report viewer
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.RefreshReport();
}


protected void Button1_Click(object sender, EventArgs e)
{
nUsuario = DropDownList1.SelectedValue; ;
strFechaIni = FechaFIN.ToString("MM/dd/yyyy h:mm:ss tt");
strFechaFin = FechaINI.ToString("MM/dd/yyyy h:mm:ss tt");
Loader(connectionInfo);
CrystalReportViewer1.Visible = true;

}

public void ShowCal1(Object sender, System.Web.UI.ImageClickEventArgs e)
{
Calendar1.Visible = true;
}
public void ShowCal2(Object sender, System.Web.UI.ImageClickEventArgs e)
{
Calendar2.Visible = true;
}

public void Calendar1_SelectionChanged1(object sender, System.EventArgs e)
{
String format = "dd/MM/yyyy";
/* FechaINI = new DateTime(Calendar1.SelectedDate.Year, Calendar1.SelectedDate.Month,
Calendar1.SelectedDate.Day, 0, 0, 0);*/
TextBox1.Text = Calendar1.SelectedDate.ToString(format);
Calendar1.Visible = false;
}

public void Calendar2_SelectionChanged1(object sender, System.EventArgs e)
{
String format = "dd/MM/yyyy";
/*FechaFIN = new DateTime(Calendar2.SelectedDate.Year, Calendar2.SelectedDate.Month,
Calendar2.SelectedDate.Day, 0, 0, 0);*/
TextBox2.Text = Calendar2.SelectedDate.ToString(format);
Calendar2.Visible = false;
}

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
String strfechcink = TextBox1.Text;
FechaINI = new DateTime(Convert.ToDateTime(strfechcink).Year, Convert.ToDateTime(strfechcink).Day,
Convert.ToDateTime(strfechcink).Month, 0, 0, 0);
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
String strfechcink1 = TextBox2.Text;
FechaFIN = new DateTime(Convert.ToDateTime(strfechcink1).Year, Convert.ToDateTime(strfechcink1).Day,
Convert.ToDateTime(strfechcink1).Month, 0, 0, 0);

}
}

Answers (2)