Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Login Window Re-Appears Post Reply Post New Topic
Author Message
Alldaypilot
Newbie
Newbie


Joined: 18 Sep 2008
Online Status: Offline
Posts: 3
Quote Alldaypilot Replybullet Topic: Login Window Re-Appears
    Posted: 18 Sep 2008 at 7:15pm
Hi,

I'm new to Crystal Reports and this is the first report I have written. I'm having an issue that I cannot get to work.
 
 
 I've generated a report viewer that automatically logs in to the SQL server to pull the data. This part works fine and shows the report. I have also created two date pickers for the user to select a date range and refresh the report. When the user clicks the generate button, a Crystal Database login window prompt opens. All the information is already filled in except the password.

How can I make it so this refreshed report also automatically logs in.


namespace Val_Report
{
public partial class Form1 : Form
{


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
//Set up database and report path
ConfigureCrystalReports();

//Set Report Dates Initially at first of month to current date

//Get first day of month
DateTime firstDay = DateTime.Now;
DateTime FirstDayInMonth = new DateTime(firstDay.Year, firstDay.Month, 1);
string strStartDate = FirstDayInMonth.ToShortDateString();
//Set the orderStartDate TimePicker to value
orderStartDate.Value = FirstDayInMonth;

//Get current date
string strEndDate = DateTime.Now.ToShortDateString();

//Set the orderEndDate TimePicker to value
orderEndDate.Value = DateTime.Now;

//Set up my report parameters (date, etc)
setReportParameters(strStartDate, strEndDate);
}

private void ConfigureCrystalReports()
{
//Set up sql connection
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "xxx";
connectionInfo.DatabaseName = "xxx";
connectionInfo.UserID = "xxx";
connectionInfo.Password = "xxx";

//Set report path
string reportPath = Application.StartupPath + "\\" + "CrystalReport1.rpt";
crystalReportViewer.ReportSource = reportPath;

//Make sure we iterate through all the tables
SetDBLogonForReport(connectionInfo);

}

private void SetDBLogonForReport(ConnectionInfo connectionInfo)
{
TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;
foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
{
tableLogOnInfo.ConnectionInfo = connectionInfo;

}

}


private void crystalReportViewer_Load(object sender, EventArgs e)
{

}


private void setReportParameters(string strStartDate, string strEndDate)
{

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

// the parameter fields to be sent to the report
ParameterField pfStartDate = new ParameterField();
ParameterField pfEndDate = new ParameterField();

// setting the name of parameter fields with wich they will be recieved in report

pfStartDate.ParameterFieldName = "StartDate";
pfEndDate.ParameterFieldName = "EndDate";

// the above declared parameter fields accept values as discrete objects
// so declaring discrete objects
ParameterDiscreteValue dcStartDate = new ParameterDiscreteValue();
ParameterDiscreteValue dcEndDate = new ParameterDiscreteValue();

// setting the values of discrete objects

dcStartDate.Value = DateTime.Parse(strStartDate);
dcEndDate.Value = DateTime.Parse(strEndDate);

// now adding these discrete values to parameters

pfStartDate.CurrentValues.Add(dcStartDate);
pfEndDate.CurrentValues.Add(dcEndDate);

// now adding all these parameter fields to the parameter collection

paramFields.Add(pfStartDate);
paramFields.Add(pfEndDate);

/* Set the modified parameters collection back to the viewer so that
the new parameter information can be used for the report. */
crystalReportViewer.ParameterFieldInfo = paramFields;
}

private void redisplay_Click_1(object sender, EventArgs e)
{

// ConfigureCrystalReports();

string strStartDate = orderStartDate.Text;
string strEndDate = orderEndDate.Text;

string reportPath = Application.StartupPath + "\\" + "CrystalReport1.rpt";
crystalReportViewer.ReportSource = reportPath;

setReportParameters(strStartDate, strEndDate);
}
 
 
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.