private static ReportDocument BindCrystalReport(string reportFileNmae, string datasourceType) { ConnectionInfo ConnInfo = new ConnectionInfo(); if (datasourceType == EmReportDataSourceType.DWDatabase.ToString()) { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DDSetup.DWDataSourceConnectionString); ConnInfo.UserID = builder.UserID; ConnInfo.Password = builder.Password; ConnInfo.DatabaseName = builder.InitialCatalog; ConnInfo.ServerName = builder.DataSource; } else { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DDSetup.PLMConnectionString); ConnInfo.UserID = builder.UserID; ConnInfo.Password = builder.Password; ConnInfo.DatabaseName = builder.InitialCatalog; ConnInfo.ServerName = builder.DataSource; } ReportDocument reportDocument = new ReportDocument(); string fullpath = DDSetup.ReorptSetup.ReportRootPath + @"\" + reportFileNmae; try { // cannot find the report ! reportDocument.Load(fullpath); Tables RepTbls = reportDocument.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table RepTbl in RepTbls) { TableLogOnInfo RepTblLogonInfo = RepTbl.LogOnInfo; RepTblLogonInfo.ConnectionInfo = ConnInfo; RepTbl.ApplyLogOnInfo(RepTblLogonInfo); } return(reportDocument); } catch { return(null); } }
private void BindReport() { ConnectionInfo ConnInfo = new ConnectionInfo(); if (this._DatasourceType == EmReportDataSourceType.DWDatabase.ToString()) { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DDSetup.DWDataSourceConnectionString); ConnInfo.UserID = builder.UserID; ConnInfo.Password = builder.Password; ConnInfo.DatabaseName = builder.InitialCatalog; ConnInfo.ServerName = builder.DataSource; } else { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DDSetup.PLMConnectionString); ConnInfo.UserID = builder.UserID; ConnInfo.Password = builder.Password; ConnInfo.DatabaseName = builder.InitialCatalog; ConnInfo.ServerName = builder.DataSource; } ReportDocument rep = new ReportDocument(); string fullpath = DDSetup.ReorptSetup.ReportRootPath + @"\" + _ReportFileNmae; // rep.Load(Server.MapPath(fullpath)); rep.Load(fullpath); this.crystalReportViewer.ReportSource = rep; Tables RepTbls = rep.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table RepTbl in RepTbls) { TableLogOnInfo RepTblLogonInfo = RepTbl.LogOnInfo; RepTblLogonInfo.ConnectionInfo = ConnInfo; RepTbl.ApplyLogOnInfo(RepTblLogonInfo); } Session[_ReportFileNmae] = rep; }
protected void Page_Init(object sender, EventArgs e) { try { if (current.SessionReport == null) { return; } this.Focus(); ClsReport rep = new ClsReport(); DataTable dt = new DataTable(); rep = current.SessionReport; rpt1.Load(Server.MapPath(rep.FileName)); CrystalReportViewer1.ParameterFieldInfo = rep.ParametersFields; dt = (DataTable)rep.Dt; if (dt != null) { rpt1.SetDataSource(dt); } ConnectionInfo ConnInfo = new ConnectionInfo(); string SCBLconnStr = _connectionString; string[] ff; string[] ss; ff = SCBLconnStr.Split('='); ss = ff[1].Split(';'); ConnInfo.ServerName = ss[0]; ss = ff[2].Split(';'); ConnInfo.DatabaseName = ss[0]; if (rep.Databasename != null) { ConnInfo.DatabaseName = rep.Databasename; } ss = ff[3].Split(';'); ConnInfo.UserID = ss[0]; ss = ff[4].Split(';'); ConnInfo.Password = ss[0]; // Tables RepTbls = rpt1.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table RepTbl in rpt1.Database.Tables) { TableLogOnInfo RepTblLogonInfo = RepTbl.LogOnInfo; RepTblLogonInfo.ConnectionInfo = ConnInfo; RepTbl.ApplyLogOnInfo(RepTblLogonInfo); } CrystalReportViewer1.ReportSource = rpt1; if (rep.SelectionFormulla != null) { if (rep.SelectionFormulla != "") { CrystalReportViewer1.SelectionFormula = rep.SelectionFormulla; } } if (rep.Pagezoomfactor != null) { CrystalReportViewer1.PageZoomFactor = rep.Pagezoomfactor; } CrystalReportViewer1.DataBind(); } catch { } }