asp.net水晶报表push模式

Push模式基本上分三步:

1、  建立DataSet1

2、  创建CrystalReport1.rpt水晶报表

3、  创建.aspx页面拖入CrystalReportViewer空间

 

SqlConnection con = new SqlConnection("Data Source=服务器名;Initial Catalog=数据库名;User ID=sa;pwd=密码");

            //向dataset中添加数据

            DataSet1 d = new DataSet1();

            SqlDataAdapter da;

            con.Open();

            da = new SqlDataAdapter("select * from teacher", con);

            da.Fill(d, "teacher");

            da = new SqlDataAdapter("select * from task", con);

            da.Fill(d, "task");

            con.Close();

            //将dataset数据绑定到水晶报表中

            CrystalReport1 r = new CrystalReport1();

            r.SetDataSource(d);

            //显示水晶报表

            CrystalReportViewer1.ReportSource = r;

 

 

问题:1、在使用pull模式时,使用多个表时需要在页面上重新写入数据库账号密码

        解决:

        ReportDocument reportdoc = new ReportDocument();

        reportdoc.Load("  ...");//路径v

        TableLogOnInfo logoninfo = new TableLogOnInfo ();

//再读入每个表时添加数据库信息

foreach (CrystalDecisions.CrystalReports.Engine.Table table in reportdoc.Data)

        {

                    logoninfo = table.LogOnInfo;

            logoninfo.connectioninfo.servername = "www";

                  logoninfo.connectioninfo.databasename = "archives";

                  logoninfo.connectioninfo.userid = "sa";

                  logoninfo.connectioninfo.password = "123456";

            table.ApplyLogOnInfo(Logoninfo);

 

        }

crystalreportviewer1.reportsource = reportdoc ;

2、水晶报表导出和打印

导出:

myReport  ReportDoc = new myReport();//表表的名称

private void btnExport_Click(object sender, System.EventArgs e)

  {

   CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new  CrystalDecisions.Shared.DiskFileDestinationOptions();

   ReportDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

   switch (DropDownList1.SelectedItem.Text)

   {

    case "Rich Text (RTF)":

       ReportDoc.ExportOptions.ExportFormatType =   CrystalDecisions.Shared.ExportFormatType.RichText;

       DiskOpts.DiskFileName = "d:\\demo.rtf";

     break;

    case "Portable Document (PDF)":

       ReportDoc.ExportOptions.ExportFormatType =   CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;

       DiskOpts.DiskFileName = "d:\\demo.pdf";

     break;

    case "MS Word (DOC)":

       ReportDoc.ExportOptions.ExportFormatType =   CrystalDecisions.Shared.ExportFormatType.WordForWindows;

       DiskOpts.DiskFileName = "d:\\demo.doc";

     break;

    case "MS Excel (XLS)":

       ReportDoc.ExportOptions.ExportFormatType =   CrystalDecisions.Shared.ExportFormatType.Excel;

       DiskOpts.DiskFileName = "d:\\demo.xls";

     break;

    default:

     break;

   }

   ReportDoc.ExportOptions.DestinationOptions = DiskOpts;

    ReportDoc.Export();

  }

 

  打印:

private void btnPrint_Click(object sender, System.EventArgs e)

  {

     string strPrinterName; // 指定打印机名称    

   strPrinterName = @"Canon Bubble-Jet BJC-210SP";

   PageMargins margins;  // 设置打印页边距

   margins = ReportDoc.PrintOptions.PageMargins;

   margins.bottomMargin = 250;

   margins.leftMargin = 350;

   margins.rightMargin = 350;

   margins.topMargin = 450;    

   ReportDoc.PrintOptions.ApplyPageMargins(margins);    

   ReportDoc.PrintOptions.PrinterName = strPrinterName;  //应用打印机名称   

     // 打印报表.startPageN endPageN

   // 参数设置为 0 表示打印所有页。

   ReportDoc.PrintToPrinter(1, false,0,0);    

   }

3、  水晶报表不显示图片的解决方法

<system.web>

<httpHandlers>

<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>

</httpHandlers>

</system.web>

 

 

<appSettings>

<add key="CrystalImageCleaner-AutoStart" value="true" />

<add key="CrystalImageCleaner-Sleep" value="60000" />

<add key="CrystalImageCleaner-Age" value="120000" />

</appSettings>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

牟云飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值