rdlc的打印问题

发布于 2024-11-19 15:10:19 字数 2791 浏览 3 评论 0原文

我将使用 *.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;
        }
    }
}

I am going to create print page in wpf with *.rdlc.
For this , i create a class(following is this codes).
I bind the class to report but when i run the program , following message occurs :

A data source instant has not been supplied for data source '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;
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年已逝 2024-11-26 15:10:19

您需要向报告提供数据集。类似于:

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();
}

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

You need to supply the dataset to your report. Something like:

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

Edit: based on your comment

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();
}

You really can't get around the need to call your data retrieval method AND send that data through to the report.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文