2011-11-03 50 views
0

我试图完成的事情: - 将Crystal Crystal报告直接转到PDF(绕过查看器) - 它需要数据库登录。 - 需要一个参数。它在CR 11申请中显示为“@rpt_args”。 - 此Crystal报表为其结果集调用Store过程。ASP.NET MVC运行水晶报告直接绕过PDF绕过水晶查看器

Partial solution

我的代码:

 ReportClass rptH = new ReportClass();   
     //rptH.FileName = Server.MapPath("whkinvc.rpt");  
     rptH.FileName = "D:\\whkinvc.rpt";  
     rptH.Load();   
     rptH.SetDatabaseLogon("FAKEUSER", "FAKEPASSWORD", "FAKESERVER", "FAKEDB"); 
     rptH.SetParameterValue("@rpt_args", atm.WorkingModel.Header.TicketNumber);   
     Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);   
     return File(stream, "application/pdf"); 

目前,我得到一个数据库登录失败。我是否正确设置了代码以执行我正在查找的操作?数据库登录失败的任何可能的原因?

感谢,

** **更新

我把它通过VS正与下面的代码(数据库登录错误是一个错字的结果):

 ReportClass rptH = new ReportClass(); 
     rptH.FileName = Server.MapPath(Url.Content("~/app_data/whkinvc.rpt")); 
     rptH.Load(); 

     rptH.SetDatabaseLogon(...); 

     ParameterValues xyz = new ParameterValues(); 
     ParameterDiscreteValue pdv = new ParameterDiscreteValue(); 
     pdv.Value = atm.WorkingModel.Header.TicketNumber; 

     xyz.Add(pdv); 
     rptH.DataDefinition.ParameterFields["@rpt_args"].ApplyCurrentValues(xyz); 
     Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);   
     return File(stream, "application/pdf"); 

我想要输出到新的选项卡或窗口。目前它只是取代当前窗口。

+0

试图做同样的CR 10.5。以下在我的开发框中工作,但不在服务器上: 'ReportDocument doc = new ReportDocument(); – erict

+0

'ReportDocument doc = new ReportDocument(); doc.Load(Server.MapPath(“〜/ app_data/invoice.rpt”)); doc.SetDatabaseLogon(...); ParameterValues xyz = new ParameterValues(); xyz.Add(new ParameterDiscreteValue()。Value = id); doc.DataDefinition.ParameterFields [“Id”]。ApplyCurrentValues(xyz); doc.ExportToDisk(ExportFormatType.PortableDocFormat,Server.MapPath(“〜/ app_data/invoice.pdf”));' 我假设我已经安装在开发中的CR,但不是在服务器上? – erict

+0

嗨,呃。我想你可能需要用“URL.Content”来包装你的路径才能找到正确的路径。防爆。 Url.Content(“〜/ app_data/whkinvc.rpt”) – Elim99

回答

2

我得到它通过VS用下面的代码工作(是一个错字的结果的数据库登录错误):

ReportClass rptH = new ReportClass();   
rptH.FileName = Server.MapPath(Url.Content("~/app_data/whkinvc.rpt"));   
rptH.Load();   
rptH.SetDatabaseLogon(...);   
ParameterValues xyz = new ParameterValues();   
ParameterDiscreteValue pdv = new ParameterDiscreteValue();   
pdv.Value = atm.WorkingModel.Header.TicketNumber;   
xyz.Add(pdv);   
rptH.DataDefinition.ParameterFields["@rpt_args"].ApplyCurrentValues(xyz);   
Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);     
return File(stream, "application/pdf"); 
0

在过去,我必须为报表中的每个表格(或存储的proc或其他)以及每个子报表中的每个表格设置连接字符串。

例如:

(假设RD是的ReportDocument的一个实例,CN是ConnectionInfo的预先制备实例)

void SetupConnection(ReportDocument rd, ConnectionInfo cn) 
{ 

    foreach (Table t in rd.database.Tables) 
    { 
     TableLoginInfo li = t.LogOnInfo; 
     li.ConnectionInfo = cn; 
     t.ApplyLogOnInfo(li); 
     t.Location = t.Location; 
    } 
    if (!rd.IsSubReport) 
    { 
     foreach (ReportDocument sr in rd.SubReports) 
      SetupConnection(sr,cn); 
    } 
} 

我知道一些这方面没有什么意义,(如t.Location = t.Location)。这是我使用它之后的一段时间,但我相信这些是正常工作所必需的。