登录水晶报表失败 [英] Login crystal report fails

查看:110
本文介绍了登录水晶报表失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我在其他计算机上安装了软件,当我运行Crystal Report时遇到问题,我在那台计算机上安装了运行时.请帮助我,谢谢大家
http://www.upsieutoc.com/image/zWK [ ^ ]
这是我的代码

Hi everyone,
I setup my soft in other computers, when i run crystal report have problem, i installed runtime in that computer. Please help me, thanks all
http://www.upsieutoc.com/image/zWK[^]
This is my Code

public ReportDocument LoadCrystalReportViewer(CrystalReportInfo crInfo, out string message)
        {
            message = "";
            try
            {
                if (crInfo != null)
                {

                    string ReportPath = null;
                    ReportDocument rptDocument = new ReportDocument();

                    if (crInfo.IsFullPath)
                    {
                        ReportPath = crInfo.ReportName;
                    }
                    else
                    {
                        ReportPath = Application.StartupPath + "/Reports/" + crInfo.ReportName + ".rpt";
                    }

                    if (!System.IO.File.Exists(ReportPath))
                    {
                        message = "Report not found.";
                        return null;
                    }

                    rptDocument.Load(ReportPath);

                    //Set Value to Formulas if exists
                    if (crInfo.FormulaList != null)
                    {
                        foreach (var f in crInfo.FormulaList)
                        {
                            if (f.SubReportName == null || f.SubReportName.Trim() == "")
                            {
                                rptDocument.DataDefinition.FormulaFields[f.FormulaName].Text = "\"" + f.FormulaValue + "\"";
                            }
                            else
                            {
                                rptDocument.Subreports[f.SubReportName].DataDefinition.FormulaFields[f.FormulaName].Text = "\"" + f.FormulaValue + "\"";
                            }
                        }
                    }

                    if (crInfo.IsConnectDirectSQL == false)
                    {
                        ///Set Database to report
                        ///
                        if (crInfo.DataSourceList != null)
                        {
                            foreach (var o in crInfo.DataSourceList)
                            {
                                if (o.SubReportName == null || o.SubReportName.Trim() == "")
                                {
                                    rptDocument.Database.Tables[o.TableName].SetDataSource(o.DataSource);

                                    //rptDocument.SetDataSource(o.DataSource);
                                }
                                else
                                {
                                    rptDocument.Subreports[o.SubReportName].Database.Tables[o.TableName].SetDataSource(o.DataSource);
                                }
                            }
                        }
                    }
                    else
                    {
                        //Set connection info to report login to database sql, oracle, ... & set parameters
                        ConnectionInfo LogonInfo = new ConnectionInfo();

                        LogonInfo.ServerName = crInfo.ServerName;
                        LogonInfo.UserID = crInfo.UserName;
                        LogonInfo.Password = crInfo.Password;
                        LogonInfo.DatabaseName = crInfo.DatabaseName;

                        TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();

                        foreach (Table table in rptDocument.Database.Tables)
                        {
                            tableLogOnInfo = table.LogOnInfo;
                            tableLogOnInfo.ConnectionInfo = LogonInfo;
                            table.ApplyLogOnInfo(tableLogOnInfo);
                        }

                        ////Apply log on Info to Subreport
                        foreach (ReportDocument srd in rptDocument.Subreports)
                        {
                            foreach (CrystalDecisions.CrystalReports.Engine.Table table in srd.Database.Tables)
                            {
                                tableLogOnInfo = table.LogOnInfo;
                                tableLogOnInfo.ConnectionInfo = LogonInfo;
                                table.ApplyLogOnInfo(tableLogOnInfo);
                            }
                        }

                        //Set Params
                        if (crInfo.ParamList != null)
                        {
                            foreach (var p in crInfo.ParamList)
                            {
                                if (p.SubReportName == null || p.SubReportName.Trim() == "")
                                {
                                    rptDocument.SetParameterValue(p.ParamName, p.ParamValue);
                                }
                                else
                                {
                                    rptDocument.SetParameterValue(p.ParamName, p.ParamValue, p.SubReportName);
                                }
                            }
                        }
                    }


                    //Show Preview
                    if (crInfo.IsPreview)
                    {
                        crystalReportViewer1.ReportSource = rptDocument;
                    }
                    else
                    {
                        //Print to Printer
                        if (!string.IsNullOrEmpty(crInfo.PrinterName))
                        {
                            rptDocument.PrintOptions.PrinterName = crInfo.PrinterName;
                        }
                        rptDocument.PrintToPrinter(1, false, 0, 0);
                    }

                    return rptDocument;
                }
                else
                {
                    message = "Please initial information before load report.";
                    return null;
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return null;
            }
        }

推荐答案

RptDocument.SetDatabaseLogon(crInfo.UserName, crInfo.Password, crInfo.ServerName, crInfo.DataBaseName);


这篇关于登录水晶报表失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆