vs 2010 Ultimate の ac# プロジェクトに取り組んでいます。これには、レポートの結果をフィルター処理する必要があります。私の挑戦は、フォームのテキストボックスまたはコンボボックスの値に基づいてレポートをフィルタリングすることです。値が null または空の場合、レポートはすべての結果を返す必要があります。
パラメータを使用しようとしましたが、結果が表示されていないようです。フォームには、レポート ビューアー、特定のレポートを選択するコンボボックス、ユーザーがフィルター処理する値を入力するテキスト ボックス、および From-Date と To-Date の 2 つの日付ピッカーがあります。
レポートにパラメーターを追加したところ、すべてが機能しているように見えますが、レポートは結果を返しません。以下は私のコードです
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();
}
}
}
誰でもこの状況を解決できます