Crystal报告给Asp.net [英] Crystal Report to Asp.net

查看:80
本文介绍了Crystal报告给Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一份我在Crystal Reports 2013中制作的报告。我也有一个我已经制作的网络项目。当用户登录系统时,他们可以填写表单并将数据提交到数据库。在会话中,他们可以单击打印以打印他们刚刚提交的数据的报告。我使用Crystal Reports程序(不是通过ASP.NET)进行了报告。我已将报告添加到项目中,并将CrystalReportViewer添加到空白Web表单中。使用我制作的报告,如何使用用户提交的数据库中的数据从我的Web项目中打印报告?我查看了Google,了解了如何在ASP.NET中制作Crystal Reports,而不是如何导入当前报表进行打印。请帮助。



这是迄今为止我所做的更新。



我添加了通过添加新项目,单击报告,单击Crystal Reports Visual C#,在底部重命名报告并单击添加按钮,向项目报告三次。弹出向导,我从现有报告中选择。点击确定并选择我需要的报告。我对我需要的所有三个报告都这样做,因为每个用户都有不同的报告要打印。然后我再次添加了一个新项目,但这次是三个Web表单,我还将CrystalReportViewer添加到每个Web表单。这就是我到目前为止所拥有的。如何将用户刚刚提交到数据库中的数据提供给这些报告,以便在点击按钮时打印?



这是我在Google上找到的代码,但我不知道因为我在Crystal Reports 2013中创建了报表并将它们添加到项目中,所以没有数据集。如何修改此代码以便为我工作?



 使用系统; 

使用 System.Collections.Generic;

使用 System.Linq;

使用 System.Web;

使用 System.Web.UI;

使用 System.Web.UI.WebControls;

使用 CrystalDecisions.CrystalReports.Engine;

使用 CrystalDecisions.Shared;

使用 System.Data;

使用 System.Data.SqlClient;

使用 System.Configuration;

public partial class _Default:System.Web.UI.Page

{

protected void Page_Load( object sender,EventArgs e)

{

CrystalReportViewer1。 Visible = false ;

}

受保护 void cmdcrystal_Click(< span class =code-keyword> object sender,EventArgs e)

{

CrystalReportViewer1.Visible = ;

ReportDocument rDoc = new ReportDocument();

Mydataset dset = new Mydataset(); // 数据集文件名

DataTable dtable = new DataTable(); // 数据表名称

dtable.TableName = Crystal Report; // Crystal Report Name

rDoc.Load(Server.MapPath(< span class =code-string>
mycrystal.rpt)); // 您的.rpt文件路径

rDoc.SetDataSource(dset); // 将数据集设置为报告查看器。

CrystalReportViewer1.ReportSource = rDoc ;

}

}

解决方案

我希望你能想出如何展示或渲染水晶报告。但是要在服务器端打印,我想你正在努力。您需要以下代码

 使用(假冒imp = 模拟(impersonationUsername,impersonationDomain,impersonationPWD))
{
if (!string.IsNullOrEmpty(printerName))
{
myreport.PrintOptions.PrinterName = printerName;
}
myreport.PrintToPrinter(副本, false 0 0 );
}





因为您的进程在IIS localhost用户下运行这里正在进行模拟以便我可以访问SYSTEM / print。通常,水晶报告打印到机器上的默认打印机。



IMHO不使用水晶报告进行打印他们没有实现至少基本的W3C标准,就像你不能获得样式,项目符号数据等。一个简单的细节可以做但如果你想要有点外观和感觉没有世界上有兼容性。



我建议 http://stackoverflow.com/questions/10024273/crystal-report-with-html-content-formatting [ ^ ]和 http://stackoverflow.com/questions/11208167/html-or-pdf-printing-on-server-side-c -sharp [ ^ ]



问候,

Pavan N


检查这些

在ASP.NET中自动打印Crystal Reports [ ^ ]

如何用C#打印Crystal Reports [ ^ ]



编辑




您忘了将 DataTable 添加到 DataSet ,更改如下代码

  protected   void  cmdcrystal_Click( object  sender,EventArgs e)
{
CrystalReportViewer1.Visible = ;
ReportDocument rDoc = new ReportDocument();
Mydataset dset = new Mydataset(); // 数据集文件名
DataTable dtable = DataTable(); // 数据表名称
dtable。 TableName = Crystal Report; // Crystal Report Name
dset.Tables.Add(dtable); < span class =code-comment> //
新添加的行--------------------
rDoc.Load(Server.MapPath( mycrystal.rpt)); // 您的.rpt文件路径
rDoc.SetDataSource(dset); // 将数据集设置为报告查看器。
CrystalReportViewer1.ReportSource = rDoc;
}



此外, TableName 应与报告表相同。我已解释过,在我过去的答案中,请查看。

在水晶报告中显示数据 [ ^ ]


I have a Report that I made in Crystal Reports 2013. I also have a web project that I have made as well. When a user logs into the system they can fill out the forms and submit the data to the database. While in a session, then they can click on print to print a report of the data they just submitted. I made a report using Crystal Reports program, (not through ASP.NET). I have added the reports to the project and add a CrystalReportViewer to a blank web form. Using the report that I made, How can I get the report to print from my web project with the data that is in the database that the user submitted? I looked through Google and came up with how to make Crystal Reports in ASP.NET but not on how to import a current report to print. Please Help.

This the update for what I have done so far.

I have added the three reports to the project by adding a new item, clicking reporting, clicked on Crystal Reports Visual C#, renamed the report at the bottom and clicked add button. The Wizard pops up and I choose From an Existing Report. Clicked ok and chose the report I needed. I did this to all three reports that I needed because each user has a different report to print. Then I added a new item again but this time it is three web forms that I also added the CrystalReportViewer to each web form. That is what i have so far. How can I get the data the user just submitted into the database to these Reports to be printed on button click?

Here is a code I found on Google but I don't have a data set because I created the Reports in Crystal Reports 2013 and added them to the project. How can I modify this code to work for me?

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        CrystalReportViewer1.Visible = false;

    }

    protected void cmdcrystal_Click(object sender, EventArgs e)

    {

        CrystalReportViewer1.Visible = true;

        ReportDocument rDoc = new ReportDocument();

        Mydataset dset = new Mydataset(); // dataset file name

        DataTable dtable = new DataTable(); // data table name

        dtable.TableName = "Crystal Report ";  // Crystal Report Name

        rDoc.Load(Server.MapPath("mycrystal.rpt")); // Your .rpt file path

        rDoc.SetDataSource(dset); //set dataset to the report viewer.

        CrystalReportViewer1.ReportSource = rDoc;

    }

}

解决方案

I hope you figured how to show or render a crystal report. But to print it on server side i guess you are trying for. you need the following code

using (Impersonation imp = new Impersonation(impersonationUsername, impersonationDomain, impersonationPWD))
{
 if (!string.IsNullOrEmpty(printerName))
   {
       myreport.PrintOptions.PrinterName = printerName;
   }
  myreport.PrintToPrinter(copies, false, 0, 0);
}



Since your process runs under IIS localhost user Here am doing Impersonation so that i can access the SYSTEM/print. Generally crystal report prints to the default printer on the machine.

IMHO dont use crystal reports for printing they didn't implemented atleast basic W3C standards like you cant get styles, bulleted data etc. A simple details can be done but if you want bit look and feel none in world had the compatibility.

I recommend http://stackoverflow.com/questions/10024273/crystal-report-with-html-content-formatting[^] and http://stackoverflow.com/questions/11208167/html-or-pdf-printing-on-server-side-c-sharp[^]

Regards,
Pavan N


Check these
Automatically Printing Crystal Reports in ASP.NET[^]
How to print Crystal Reports in C#[^]

EDIT


You forgot to add the DataTable to DataSet, Change the code like below

protected void cmdcrystal_Click(object sender, EventArgs e)
{
    CrystalReportViewer1.Visible = true;
    ReportDocument rDoc = new ReportDocument();
    Mydataset dset = new Mydataset(); // dataset file name
    DataTable dtable = new DataTable(); // data table name
    dtable.TableName = "Crystal Report ";  // Crystal Report Name
    dset.Tables.Add(dtable);//Newly added line--------------------
    rDoc.Load(Server.MapPath("mycrystal.rpt")); // Your .rpt file path
    rDoc.SetDataSource(dset); //set dataset to the report viewer.
    CrystalReportViewer1.ReportSource = rDoc;
}


Besides, TableName should be same as the Report Table. I have explained that in my past answer, check it out.
display data in crystal reports[^]


这篇关于Crystal报告给Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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