将Crystal报表从Winforms/vb.net迁移到asp.net/c#时出现问题 [英] Problem Migrating Crystal Reports from Winforms/vb.net to asp.net/c#

查看:51
本文介绍了将Crystal报表从Winforms/vb.net迁移到asp.net/c#时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.我一直以vb.net和Windows形式进行开发,但是现在我需要将某些内容迁移到asp.net/c#.我面临的问题之一是Crystal Reports.在我的一个项目中,有一个窗体将所有报表都放在一个网络位置,并将它们的名称放在一个组合框中,然后用户选择一个窗体,并在Crystal报表查看器中显示它.轻松完成...之前!现在问题出在asp中.我尝试了几种技术,但没有任何效果.甚至没有导出.

我正在项目中使用这些引用:

Hello. I''ve always developed in vb.net and windows forms, but now i''m required to migrate some things to asp.net / c#. One of the problems i''m facing is Crystal Reports. In one of my projects there is a form that gets all reports in a network location and puts their names in a combo box, then the user selects one and it displays in a crystal reports viewer. Easily done... before! The problem is now in asp. I''ve tried several techniques and nothing works. Not even exporting.

I''m using these references in the project:

using System;
using System.IO;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Reflection;
using System.Drawing;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Net.Mail;



这是页面加载时填充组合框的代码:



This is the code at page load that populates the combo box:

ReportDocument report;
Database reportDB;
Tables reportTables;
TableLogOnInfo reportLogOnInfo;
private string dirpath = @"\\NetworkLocation\";
protected void Page_Load(object sender, EventArgs e)
{
  DirectoryInfo dir = new DirectoryInfo(dirpath);
  foreach (FileInfo files in dir.GetFiles())
  {
    dd_Reports.Items.Add(files.Name);
  }
  dd_Reports.SelectedIndex = 0;
}



这是填充水晶报表查看器的代码:



This is the code that populates the crystal report viewer:

private void ChangeRPT(string link)
{
try
{

CrystalReportViewer1.Visible = true;

if (IsPostBack)
{
CrystalReportViewer1.ReportSource = null;

ReportDocument report = new ReportDocument();

report.Load(link);

reportDB = report.Database;
reportTables = reportDB.Tables;
SetTableLocation(report.Database.Tables);
CrystalReportViewer1.ReportSource = report;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in reportTables)
{
reportLogOnInfo = table.LogOnInfo;
reportLogOnInfo.ConnectionInfo.ServerName = "server";
reportLogOnInfo.ConnectionInfo.DatabaseName = "db";
reportLogOnInfo.ConnectionInfo.UserID = "user";
reportLogOnInfo.ConnectionInfo.Password = "apass";
table.ApplyLogOnInfo(reportLogOnInfo);
}


//report.SetDatabaseLogon("user", "pass", "server", "db");

CrystalReportViewer1.DataBind();
}
}
catch (Exception)
{
throw;
}

}





我也有这个要导出到PDF:





I also have this to export to PDF:

private void ExportReport(string link)
{

ReportDocument report = new ReportDocument();
report.SetDatabaseLogon("user", "pass", "server", "db");
report.Load(link);

DiskFileDestinationOptions dFileDOpts = new DiskFileDestinationOptions();
ExportOptions eOpts = new ExportOptions();

dFileDOpts.DiskFileName = @"C:\rep.pdf";

eOpts = report.ExportOptions;
eOpts.DestinationOptions = dFileDOpts;
eOpts.ExportDestinationType = ExportDestinationType.DiskFile;

eOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
report.ExportToDisk(ExportFormatType.PortableDocFormat, @"C:\rep.pdf");



Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(@"C:\rep.pdf");
Response.Flush();
Response.Close();
}



这是按钮的代码:



This is the code for the button:

protected void Button1_Click(object sender, EventArgs e)
{
ChangeRPT(dirpath + dd_Reports.SelectedItem.Value);
//ExportReport(dirpath + dd_Reports.SelectedItem.Value);
}



这是页面代码:



This is page code:

<body>
    <form id="form1" runat="server">
    <div>
        <table width="100%">
            <tr>
                <td height="20">
                    <asp:DropDownList ID="dd_Reports" runat="server" Width = "350px">
                    </asp:DropDownList>
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                </td>
            </tr>
            <tr>
                <td>
                    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"

                        AutoDataBind="true" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body




任何人都可以看看我可能做错了什么吗?我在这里有点黑暗!任何帮助表示赞赏...

非常感谢您

[已从答案移至-亨利]
没有输出.我发现了问题的一部分,将Crystal Report解决方案参考从Crystal Report 2008更改为XI,并加载了这些报告.现在的问题是登录参数.即使登录名与报告中的登录名匹配,加载后仍会要求提供凭据.

我已经尝试了这两种方法,但均无济于事.它总是要求输入密码.




Can anyone please just take a look at what i may be doing wrong? I''m a bit in the dark here! Any help is appreciated...

Thank you very much

[Moved from Answer - Henry]
There is no output. I found part of the problem, changed the crystal reports solution references from crystal reports 2008 to XI and it loads the reports. The problem now is with login parameters. Even though the login matches the one in the report, it still asks for credentials after the load.

I''ve tried both these methods but none works. It always asks for the password.

ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;


cryRpt.Load(link);


crConnectionInfo.ServerName = "server";
crConnectionInfo.DatabaseName = "db";
crConnectionInfo.UserID = "user";
crConnectionInfo.Password = "pass";


CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
    crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
}


CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.RefreshReport();


//__________________________________________________________________________

ReportDocument report = new ReportDocument();
report.Load(link);
report.SetDatabaseLogon("user", "pass", @"server", "db");
CrystalReportViewer1.ReportSource = report;



这是从按钮单击事件中调用的.
[/Moved]



This is called from a button click event.
[/Moved]

推荐答案

选中此

C#Crystal Reports动态登录参数 [
Check this

C# Crystal Reports Dynamic Logon parameters[^]


这篇关于将Crystal报表从Winforms/vb.net迁移到asp.net/c#时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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