根据文本框或组合框中的值过滤报表

问题描述 投票:0回答:1

我正在使用vs 2010终极中的c#项目,这需要一个人来过滤报告的结果。我的挑战是根据文本框中的值或表单上的组合框来获取报告。如果值为null或为空,则报告应返回所有结果。

我试图使用参数,但看起来没有得到结果显示。在表单上有一个报表查看器,一个选择特定报表的组合框和一个用户输入要过滤的值的文本框,还有两个日期选择器From-Date和To-Date;

我甚至在报告中添加了参数,每件事似乎都有效,但报告没有返回任何结果。以下是我的代码

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


namespace clinicmis
{
    public partial class AllReports : Form
    {
        //private string xSQL;
        private string str = "";
        private string FromDate;
        private string ToDate;
        private string rptName = "";
        ReportDataSource dsClinic;
        ReportParameter paramRegNo, paramFromDate, paramToDate;
        ReportParameterInfoCollection paramInfo;

        public AllReports()
        {
            InitializeComponent();
        }

        #region "Global Declaration"
        String rptpath = Application.StartupPath;
        #endregion

        private void AllReports_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'clinicmisDataSet.qryRequisitions' table. You can move, or remove it, as needed.
            this.qryRequisitionsTableAdapter.Fill(this.clinicmisDataSet.qryRequisitions);
            // TODO: This line of code loads data into the 'clinicmisDataSet.suppliers' table. You can move, or remove it, as needed.
            this.suppliersTableAdapter.Fill(this.clinicmisDataSet.suppliers);
            // TODO: This line of code loads data into the 'clinicmisDataSet.qryAccountsPhReceipt' table. You can move, or remove it, as needed.
            this.qryAccountsPhReceiptTableAdapter.Fill(this.clinicmisDataSet.qryAccountsPhReceipt);
            // TODO: This line of code loads data into the 'clinicmisDataSet.patients' table. You can move, or remove it, as needed.
            this.patientsTableAdapter.Fill(this.clinicmisDataSet.patients);
            // TODO: This line of code loads data into the 'clinicmisDataSet.labtests' table. You can move, or remove it, as needed.
            this.labtestsTableAdapter.Fill(this.clinicmisDataSet.labtests);
            // TODO: This line of code loads data into the 'clinicmisDataSet.qryStock' table. You can move, or remove it, as needed.
            this.qryStock.Fill(this.clinicmisDataSet.qryStock);
            // TODO: This line of code loads data into the 'clinicmisDataSet.qryOrders' table. You can move, or remove it, as needed.
            this.qryOrdersTableAdapter.Fill(this.clinicmisDataSet.qryOrders);
            // TODO: This line of code loads data into the 'clinicmisDataSet.qryDeliveries' table. You can move, or remove it, as needed.
            this.qryDeliveriesTableAdapter.Fill(this.clinicmisDataSet.qryDeliveries);
            // TODO: This line of code loads data into the 'clinicmisDataSet.drugs' table. You can move, or remove it, as needed.
            this.drugsTableAdapter.Fill(this.clinicmisDataSet.drugs);
            // TODO: This line of code loads data into the 'clinicmisDataSet.qryPatientsLabTestResults' table. You can move, or remove it, as needed.
            this.qryPatientsLabTestResultsTableAdapter.Fill(this.clinicmisDataSet.qryPatientsLabTestResults);

            cboReports.Items.Add("Patients");
            cboReports.Items.Add("Patients Results");
            cboReports.Items.Add("Lab Tests");
            cboReports.Items.Add("List Of Drugs");
            cboReports.Items.Add("Drugs Stock");
            cboReports.Items.Add("Drug Orders");
            cboReports.Items.Add("Drug Deliveries");
            cboReports.Items.Add("Drug Requisitions");
            cboReports.Items.Add("List Of Suppliers");
            reportViewer1.ProcessingMode = ProcessingMode.Local;

        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            if (cboReports.Text == string.Empty)
            {
                MessageBox.Show("Please Select a Report you wish to Preview", "Select a Report");
            }
            else
            {
                //reportViewer1.LocalReport.DataSources.Clear();
                List<ReportParameter> paramList = new List<ReportParameter>();
                //paramList.Clear();

                str = txtRegNo.Text;
                FromDate = dtFrom.Text;
                ToDate = dtTo.Text;

                paramRegNo = new ReportParameter("RegFNo", str, false);
                paramFromDate = new ReportParameter("FromDate", FromDate, false);
                paramToDate = new ReportParameter("ToDate", ToDate, false);

                switch (cboReports.SelectedIndex)
                {
                    case 0:
                        paramList.Add(paramRegNo);
                        paramList.Add(paramFromDate);
                        paramList.Add(paramToDate);
                        rptName = rptpath + "\\" + "Report2.rdlc";
                        // TODO: This line of code loads data into the 'clinicmisDataSet.accountsfrontdeskreceipts' table. You can move, or remove it, as needed.
                        this.accountsfrontdeskreceiptsTableAdapter.Fill(this.clinicmisDataSet.accountsfrontdeskreceipts);
                        dsClinic = new ReportDataSource("ClinicDataSet", accountsfrontdeskreceiptsBindingSource);
                        break;
                    case 1:
                        paramList.Add(paramRegNo);
                        paramList.Add(paramFromDate);
                        paramList.Add(paramToDate);
                        rptName = rptpath + "\\" + "ReptPatientsLabResults.rdlc";
                        dsClinic = new ReportDataSource("DataSet1", qryPatientsLabTestResultsBindingSource);
                        break;
                    case 2:
                        dsClinic = new ReportDataSource("dsLabTests", labtestsBindingSource);
                        rptName = rptpath + "\\" + "ReptLabTests.rdlc";
                        break;
                    case 3:
                        dsClinic = new ReportDataSource("dsDrugs", drugsBindingSource);
                        rptName = rptpath + "\\" + "ReptDrugs.rdlc";
                        break;
                    case 4:
                        dsClinic = new ReportDataSource("dsDrugsStock", qryStockBindingSource);
                        rptName = rptpath + "\\" + "ReptDrugsStock.rdlc";
                        break;
                    case 5:
                        dsClinic = new ReportDataSource("dsDrugsOrders", qryOrdersBindingSource);
                        rptName = rptpath + "\\" + "ReptDrugsOrders.rdlc";
                        break;
                    case 6:
                        dsClinic = new ReportDataSource("dsDrugsDeliveries", qryDeliveriesBindingSource);
                        rptName = rptpath + "\\" + "ReptDrugsDeliveries.rdlc";
                        break;
                    case 7:
                        dsClinic = new ReportDataSource("dsDrugsRequisitions", qryRequisitionsBindingSource);
                        rptName = rptpath + "\\" + "ReptDrugsRequisitions.rdlc";
                        break;
                    case 8:
                        dsClinic = new ReportDataSource("dsSuppliers", suppliersBindingSource);
                        rptName = rptpath + "\\" + "ReptSuppliers.rdlc";
                        break;
                }

                reportViewer1.LocalReport.ReportPath = rptName;
                paramInfo = reportViewer1.LocalReport.GetParameters();

                if (paramList.Count == 0)
                {
                    //                Console.WriteLine("<No parameters are defined for this report>");
                }
                else
                {
                    reportViewer1.LocalReport.SetParameters(paramList);
                }

                //reportViewer1.LocalReport.SetParameters(paramList);
                reportViewer1.LocalReport.DataSources.Add(dsClinic);
                this.reportViewer1.RefreshReport();
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}

任何人都有这种情况的解决方案

c# visual-studio-2010 parameters reporting filtering
1个回答
0
投票

有同样的问题和这个视频修复它:

[https://www.youtube.com/watch?v=DnagGh_gViE][1]

我唯一改变的是查询,因为我有vs2017。

而不是“WHERE fieldname = @ fieldname”我把“WHERE fieldname =?”

希望它也能帮到你!

© www.soinside.com 2019 - 2024. All rights reserved.