制作多页报告:水晶报表查看器仅生成第一页(C#)

时间:2017-03-13 07:26:25

标签: c# crystal-reports

我正在使用Windows窗体和c#创建应用程序。 我尝试使用从Datagridview中提取的数字列表在同一个查看器上生成多页报告,但是水晶报表查看器仅生成第一页,即使我为水晶报表的存储过程传递了多个参数观看者。

我想要的是:对于每个参数,使用相同的存储过程为所有参数生成在同一报表查看器中但在每个报表的不同页面中对应于该参数的报表。例如:我传递参数1,报告查看器显示页面#1中的报告#1,传递参数2,报告查看器显示页面#2中的报告#2,依此类推。

我错过了什么?或者我做错了什么?

提前致谢。

这是加载我的报告的代码:

using System;
using System.Configuration;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using MySql.Data.MySqlClient;

namespace Sistema_Facturacion
{
public partial class frmReporteTodasFacturas : Form
{
    public int NumeroFactura { get; set; }
    public IList<int> ListaFacturas { get; set; }

    public frmReporteTodasFacturas()
    {
        InitializeComponent();
    }

    private void crystalReportViewer1_Load(object sender, EventArgs e)
    {
        ReportDocument Reporte = new ReportDocument();


        ParameterFields arregloParametros = new ParameterFields();
        ParameterField FacturaNumero = new ParameterField();
        FacturaNumero.Name = "p_idFactura";

        //for each Number in the list generate a different report in a different page

        foreach (int NoFactura in ListaFacturas)
        {
            ParameterDiscreteValue valorNumeroFactura = new ParameterDiscreteValue();
            valorNumeroFactura.Value = NoFactura;
            FacturaNumero.CurrentValues.Add(valorNumeroFactura);
            arregloParametros.Add(FacturaNumero);
        }

        this.crystalReportViewer1.ParameterFieldInfo = arregloParametros;
        string path =
        Application.StartupPath + System.IO.Path.DirectorySeparatorChar + "Reportes" +
            System.IO.Path.DirectorySeparatorChar + "TodasFacturasSistemaFacturacion.rpt";
        Reporte.Load(path);


        string CadenaConexion = ConfigurationManager.ConnectionStrings["MySQLAutentication"].ToString();

        MySqlConnectionStringBuilder CSB = new MySqlConnectionStringBuilder(CadenaConexion);            

        string BaseDatos= CSB.Database;
        string Usuario = CSB.UserID;
        string Contrasena = CSB.Password;
        string Puerto = CSB.Port.ToString();
        string Servidor = "Driver={MySQL ODBC 5.3 Unicode Driver};Server=" + CSB.Server + ";" +"Port="+ Puerto + ";" +"Option=3;";

        ConnectionInfo ciReportConnection = new ConnectionInfo();

        ciReportConnection.ServerName = Servidor;
        ciReportConnection.DatabaseName = BaseDatos;
        ciReportConnection.UserID = Usuario;
        ciReportConnection.Password = Contrasena;


        foreach (Table table in Reporte.Database.Tables)
        {
            table.LogOnInfo.ConnectionInfo = ciReportConnection;
            table.ApplyLogOnInfo(table.LogOnInfo);
        }

        foreach (ReportDocument subrep in Reporte.Subreports)
        {
            foreach (Table table in subrep.Database.Tables)
            {
                table.LogOnInfo.ConnectionInfo = ciReportConnection;
                table.ApplyLogOnInfo(table.LogOnInfo);
            }
        }


        if (this.crystalReportViewer1.LogOnInfo != null)
        {
            TableLogOnInfos tlInfo = this.crystalReportViewer1.LogOnInfo;
            foreach (TableLogOnInfo tbloginfo in tlInfo)
            {
                tbloginfo.ConnectionInfo = ciReportConnection;
            }
        }

        crystalReportViewer1.ReportSource = Reporte;

        crystalReportViewer1.Refresh();
    }
  }
}

1 个答案:

答案 0 :(得分:1)

coleguee告诉我,显然不可能用Crystal Reports做到这一点。所以我决定用iTextSharp生成一个包含多个页面的pdf。