using System.Data.SqlClient; // needed for database
using CrystalDecisions.CrystalReports.Engine; //needed for dynamic Crystal
string reportName = string.Empty;
static ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["WannalancitConnectionString"];
protected void Page_Prerender(object sender, EventArgs e)
{
reportName = (string)Cache["CrystalRptName"];
if (!IsPostBack)
{
CrystalReportSource1.Report.FileName = reportName;
}
if (reportName.IndexOf("testuntrained.rpt") > -1)
{
setDynamicDB();
}
if (CrystalReportSource1.Report.FileName != reportName)
CrystalReportSource1.Report.FileName = reportName;
}
protected void btnBack_Click(object sender, EventArgs e)
{
Response.Redirect("f_MenuReports.aspx");
}
private void setDynamicDB()
{
try
{
string conStr = System.Configuration.ConfigurationManager.AppSettings["WannalancitConnectionString"];
string strReportPath = Server.MapPath("~/Reports/testuntrained.rpt");
//SqlConnection sqlConnection = new SqlConnection(conStr);
string connectionInfo = conSettings.ConnectionString;
SqlConnection sqlConnection = new SqlConnection(connectionInfo);
SqlCommand Command = new SqlCommand();
Command.Connection = sqlConnection;
Command.CommandText = "UnTrainedReport";
Command.CommandType = CommandType.StoredProcedure;
SqlDataAdapter Adapter = new SqlDataAdapter(Command);
dsUntrainedRpt ds = new dsUntrainedRpt();
Adapter.Fill(ds,"UntrainedReport");
ReportDocument cr = new ReportDocument();
cr.Load(strReportPath);
cr.SetDataSource(ds.Tables["UntrainedReport"]);
CrystalReportViewer1.ReportSource = cr;
}
catch (Exception exp)
{
lblErrorMsg.Text = exp.Message;
}
}
}
|