rdlc的打印问题

本文关键字:问题 打印 rdlc | 更新日期: 2023-09-27 18:01:54

我将使用*.rdlc在wpf中创建打印页面。为此,我创建了一个类(以下是这些代码)。我绑定类来报告,但是当我运行程序时,出现以下消息:

没有为数据源'dataset1'提供数据源瞬间

 class rpt_insurance
{
    private string _insurance;
    private int _count_print;
    private int _sum_tariff;
    private int _lot_org;
    public string insurance
    {
        get { return _insurance; }
        set { _insurance = value; }
    }
    public int count_print
    {
        get { return _count_print; }
        set { _count_print = value; }
    }
    public int sum_tariff
    {
        get { return _sum_tariff; }
        set { _sum_tariff = value; }
    }
    public int lot_org
    {
        get { return _lot_org; }
        set { _lot_org = value; }
    }

    public DataTable report_insurance(string from_date,string to_date)
    {
        using (doctorEntities de = new doctorEntities())
        {
            var print = (from Table_infobase_print tip in de.Table_infobase_print
                           where tip.Print_date.CompareTo(from_date) > 0 && tip.Print_date.CompareTo(to_date) < 0
                           select tip).ToList();
            var insurance = (from Table_insurance_org tio in de.Table_insurance_org
                             select tio).ToList();
            List<rpt_insurance> lri = new List<rpt_insurance>();
            foreach (var insurance_row in insurance)
            {
                rpt_insurance ri = new rpt_insurance();
                int number = 0;
                foreach (var print_row in print)
                {
                    if(print_row.insurance_org==insurance_row.org_name)
                    {
                        number++;
                        ri.insurance = print_row.insurance_org;
                        ri.count_print = number;
                        ri.sum_tariff = ri.sum_tariff + print_row.sum_tariff;
                        ri.lot_org=lot_org+(print_row.sum_tariff-print_row.sum_lot_patient);
                    }
                }
                if (ri.insurance != null)
                {
                    lri.Add(ri);
                }
            }
            DataTable dt = new DataTable();
            dt = new DataTable();
            dt.Columns.Add("cinsurance");
            dt.Columns.Add("ccount_print");
            dt.Columns.Add("csum_tariff");
            dt.Columns.Add("clot_org");
            for (int i = 0; i < lri.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr["cinsurance"] = lri[i].insurance;
                dr["ccount_print"] = lri[i].count_print;
                dr["csum_tariff"] = lri[i].sum_tariff;
                dr["clot_org"] = lri[i].lot_org;
                dt.Rows.Add(dr);
            }
            return dt;
        }
    }
}

rdlc的打印问题

您需要向报表提供数据集。比如:

viewer.LocalReport.DataSources.Add(new ReportDataSource("dataset1", dataTable));

编辑:基于你的评论

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    var dataTable = report_insurance(fromDate, toDate);
    viewer_insurance.LocalReport.ReportPath = "E:''desktop''Doctor''Project''Doctor''Doctor''rinsurance.rdlc";
    viewer_insurance.LocalReport.DataSources.Add(new ReportDataSource("dataset1", dataTable);
    viewer_insurance.RefreshReport();
}

您确实无法绕过调用数据检索方法并将该数据发送到报告的需要。