none
Passando textbox por parametros e gerando um relatorio Crystal Reports RRS feed

  • Pergunta

  • Ola possuo uma aplicação com algumastextbox e gostaria de passar elas por parametros para serem geradas em Crystal Reports.

    Tenho um modelo no reportview, teria com alterar para o cristal reports:

    //Reportview

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Reporting.WinForms;

    namespace Recibo1
    {
        public partial class Recibo : Form
        {
            public Recibo(string Nome, string Valor)
            {
                InitializeComponent();            
                
                //seta o arquivo
                reportViewer1.LocalReport.ReportEmbeddedResource = "Recibo1.Recibo.rdlc";

                //setando os parametro
                Microsoft.Reporting.WinForms.ReportParameter[] p = new Microsoft.Reporting.WinForms.ReportParameter[1];
                p[0] = new Microsoft.Reporting.WinForms.ReportParameter("Nome", Nome);
                p[1] = new Microsoft.Reporting.WinForms.ReportParameter("Valor", Valor);
                reportViewer1.LocalReport.SetParameters(p);  
            }

    //CristalReports

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Reporting.WinForms;

    namespace Recibo1
    {
        public partial class Recibo : Form
        {
            public Recibo(string Nome, string Valor)
            {
                InitializeComponent();            
                
                //seta o arquivo
                crystalReportViewer1.LocalReport.ReportEmbeddedResource = "Recibo1.rptImpressao.rpt";

                //setando os parametro
                Microsoft.Reporting.WinForms.ReportParameter[] p = new Microsoft.Reporting.WinForms.ReportParameter[1];
                p[0] = new Microsoft.Reporting.WinForms.ReportParameter("Nome", Nome);
                p[1] = new Microsoft.Reporting.WinForms.ReportParameter("Valor", Valor);
                crystalReportViewer1.LocalReport.SetParameters(p);  
            }

    Porem no metodo do cristalReports apresenta erro no LocalReport

    segunda-feira, 21 de outubro de 2013 19:09

Respostas

  • Pesquisei a fundo e conseguir assim:

    using Microsoft.Reporting.WinForms;
    using CrystalDecisions.CrystalReports.Engine;

      private void button1_Click(object sender, EventArgs e)
            {
                ReportDocument cryRpt = new ReportDocument();
                cryRpt.Load(@"G:\Documentos\Documents\Visual Studio 2010\Projects\Recibo1\Recibo1\rptImpressao.rpt");

                ParameterFieldDefinitions crParameterFieldDefinitions;

                ParameterFieldDefinition crParameterFieldDefinition;

                ParameterValues crParameterValues = new ParameterValues();

                ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

                crParameterDiscreteValue.Value = textBox1.Text;

                crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;

                crParameterFieldDefinition = crParameterFieldDefinitions["nome"];

                crParameterValues = crParameterFieldDefinition.CurrentValues;

                crParameterValues.Add(crParameterDiscreteValue);

                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

                crystalReportViewer1.ReportSource = cryRpt;

                crParameterDiscreteValue.Value = textBox2.Text;

                crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;

                crParameterFieldDefinition = crParameterFieldDefinitions["valor"];

                crParameterValues = crParameterFieldDefinition.CurrentValues;

                crParameterValues.Add(crParameterDiscreteValue);

                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

                crystalReportViewer1.ReportSource = cryRpt;

                crystalReportViewer1.Refresh();  
            }

    Ate

    • Marcado como Resposta Sigrids LIma quarta-feira, 23 de outubro de 2013 12:29
    quarta-feira, 23 de outubro de 2013 12:29