protected void CrystalReportViewer1_Navigate(object source, CrystalDecisions.Web.NavigateEventArgs e) { getQueryString(); printData(); crConnectionInfo.DatabaseName = strDbname; crConnectionInfo.ServerName = strServername; crConnectionInfo.UserID = strDbuser; crConnectionInfo.Password = strDbpassword; crTables = oRpt.Database.Tables; //apply logon info foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in oRpt.Database.Tables) { crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; crTable.ApplyLogOnInfo(crTableLogOnInfo); } //apply logon info for sub report //foreach (Section crSection in oRpt.ReportDefinition.Sections) //{ // foreach (ReportObject crReportObject in crSection.ReportObjects) // { // if (crReportObject.Kind == ReportObjectKind.SubreportObject) // { // SubreportObject crSubReportObj = (SubreportObject)(crReportObject); // foreach (CrystalDecisions.CrystalReports.Engine.Table oTable in crSubReportObj.OpenSubreport(crSubReportObj.SubreportName).Database.Tables) // { // crTableLogOnInfo = oTable.LogOnInfo; // crTableLogOnInfo.ConnectionInfo = crConnectionInfo; // oTable.ApplyLogOnInfo(crTableLogOnInfo); // } // } // } //} string strReportDirectoryTempPhysicalPath = Server.MapPath(this.ReportDirectoryTemp); Helper.DeleteUnusedFile(strReportDirectoryTempPhysicalPath, ReportAliveTime); string strFilename; strFilename = "report_" + DateTime.Now.ToString("yyyyMMddHH-mm-ss"); oRpt.ExportToDisk(ExportFormatType.PortableDocFormat, Server.MapPath("~/temp/") + strFilename + ".pdf"); //lnkPdfFile.NavigateUrl = "~/temp/" + strFilename + ".pdf"; //imgPdf.Src = "~/images/icon_pdf.gif"; //lnkExcelFile.Visible = false; //if (ViewState["report_code"].ToString() == "Rep_exceldebitall") //{ // oRpt.ExportToDisk(ExportFormatType.ExcelRecord, Server.MapPath("~/temp/") + strFilename + ".xls"); // lnkExcelFile.NavigateUrl = "~/temp/" + strFilename + ".xls"; // imgExcel.Src = "~/images/icon_excel.gif"; // lnkExcelFile.Visible = true; //} //CrystalReportViewer1.ReportSource = oRpt; }
public static void SetReportSourceLocal(ref ReportClass report) { ConnectionInfo crConnection = new ConnectionInfo(); crConnection.ServerName = LocalServerName; crConnection.DatabaseName = LocalDatabaseName; crConnection.UserID = LocalUserID; crConnection.Password = LocalPassword; CrystalDecisions.CrystalReports.Engine.Tables tables = report.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables) { CrystalDecisions.Shared.TableLogOnInfo tableLogonInfo = table.LogOnInfo; tableLogonInfo.ConnectionInfo = crConnection; table.ApplyLogOnInfo(tableLogonInfo); } }
protected void Page_Load(object sender, EventArgs e) { //System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("th-TH"); //lblError.Text = string.Empty; if (!IsPostBack) { getQueryString(); printData(); crConnectionInfo.DatabaseName = strDbname; crConnectionInfo.ServerName = strServername; crConnectionInfo.UserID = strDbuser; crConnectionInfo.Password = strDbpassword; crTables = oRpt.Database.Tables; //apply logon info foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in oRpt.Database.Tables) { crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; crTable.ApplyLogOnInfo(crTableLogOnInfo); } //apply logon info for sub report foreach (Section crSection in oRpt.ReportDefinition.Sections) { foreach (ReportObject crReportObject in crSection.ReportObjects) { if (crReportObject.Kind == ReportObjectKind.SubreportObject) { SubreportObject crSubReportObj = (SubreportObject)(crReportObject); foreach (CrystalDecisions.CrystalReports.Engine.Table oTable in crSubReportObj.OpenSubreport(crSubReportObj.SubreportName).Database.Tables) { crTableLogOnInfo = oTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; oTable.ApplyLogOnInfo(crTableLogOnInfo); } } } } string strReportDirectoryTempPhysicalPath = Server.MapPath(this.ReportDirectoryTemp); Helper.DeleteUnusedFile(strReportDirectoryTempPhysicalPath, ReportAliveTime); string strFilename; strFilename = "report_" + DateTime.Now.ToString("yyyyMMddHH-mm-ss-fff"); var pathPdf = "~/temp/" + strFilename + ".pdf"; oRpt.ExportToDisk(ExportFormatType.PortableDocFormat, Server.MapPath(pathPdf)); var pathExcel = "~/temp/" + strFilename + ".xls"; oRpt.ExportToDisk(ExportFormatType.ExcelRecord, Server.MapPath(pathExcel)); Session["ExportPdfUrl"] = pathPdf; Session["ExportExcelUrl"] = pathExcel; if (Helper.CStr(Session["ExportExcel"]) == "true") { Session["ExportExcel"] = null; //var strMyScript = "window.opener.__doPostBack('ctl00$ASPxRoundPanel1$ASPxRoundPanel2$ContentPlaceHolder1$LinkButton1','');window.close();return false;"; var strMyScript = "window.opener.__doPostBack('ctl00$ASPxRoundPanel1$ASPxRoundPanel2$ContentPlaceHolder1$LinkButton1','');window.close();"; Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", strMyScript, true); } else { Response.Redirect(pathPdf); } //Server.Transfer(path); //lnkPdfFile.NavigateUrl = "~/temp/" + strFilename + ".pdf"; //imgPdf.Src = "~/images/icon_pdf.gif"; //lnkExcelFile.Visible = false; //CrystalReportViewer1.ReportSource = oRpt; } }