using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
namespace WebApplication1.Basic.Reports
{
/// <summary>
/// Summary description for rptExchRefReport1.
/// </summary>
public class rptExchRefReport1 : System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer CRV;
protected System.Web.UI.WebControls.Label lblError;
protected CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc;
private void Page_Load(object sender, System.EventArgs e)
{
string userid="", pwd="", server="", database="";
getConn(ref userid, ref pwd, ref server, ref database);
string conStr = System.Configuration.ConfigurationSettings.AppSettings["connectionString"];
SqlConnection con = new SqlConnection(conStr);
SqlCommand cmd = new SqlCommand("Select Exch_Ref_Date, Exch_Ref_Rate From tms_Exc_Ref Order by Exch_Ref_Date Desc", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
da.Fill(ds,"ExchangeRef");
rptDoc.Load(Server.MapPath("rptExchangeRefReport.rpt"));
rptDoc.SetDataSource(ds);
rptDoc.SetDatabaseLogon(userid,pwd,server,database);
CRV.ReportSource = rptDoc;
}
catch (LogOnException ex)
{
lblError.Text = ex.Message;
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
finally
{
ds.Dispose();
da.Dispose();
cmd.Dispose();
}
}
private void getConn(ref string userid, ref string pwd, ref string server, ref string database)
{
string strCon = System.Configuration.ConfigurationSettings.AppSettings["connectionString"];
int pos1,pos2, pos3;
//To get user id from the connectionString property defined in Web.Config file
pos1 = strCon.IndexOf("user id",0);
pos2 = strCon.IndexOf("=",pos1);
pos3 = strCon.IndexOf(";",pos2);
userid = strCon.Substring(pos2+1,pos3-pos2-1);
//To get password from the connectionString property defined in Web.Config file
pos1 = strCon.IndexOf("pwd",0);
pos2 = strCon.IndexOf("=",pos1);
pos3 = strCon.IndexOf(";",pos2);
pwd = strCon.Substring(pos2+1, pos3-pos2-1);
//To get server name from the connectionString property defined in Web.Config file
pos1 = strCon.IndexOf("server",0);
pos2 = strCon.IndexOf("=",pos1);
pos3 = strCon.IndexOf(";",pos2);
server = strCon.Substring(pos2+1, pos3-pos2-1);
//To get the database name from the connectionString defined in Web.Config file
pos1 = strCon.IndexOf("initial catalog",0);
pos2 = strCon.IndexOf("=",pos1);
pos3 = strCon.IndexOf(";",pos2);
database = strCon.Substring(pos2+1,pos3-pos2-1);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <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(rptExchRefReport1));
this.rptDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
//
// rptDoc
//
this.rptDoc.FileName = "";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}