• fastreport for .net 数据邦定


    C# Code:

    private void button4_Click(object sender, EventArgs e)
    {
       //打印主从表数据 
       string file = Application.StartupPath @"MasterDetail.frx";
       rptMasterDetail.Load(file);//加载报表模板文件 
       
       DataSet ds = DAL.GetMasterDetailData();//取报表数据 
       
       rptMasterDetail.RegisterData(ds.Tables[0], "tb_SO"); //注册数据源,主表 
       rptMasterDetail.RegisterData(ds.Tables[1], "tb_SOs"); //注册数据源,从表 
       
       // 
       //直接注册DataSet也行,但必须对DataSet.Tables指定表名! 
       //FastReport是跟据表名取DataTable对象的。 
       // 
       //rptMasterDetail.RegisterData(ds); 
       // 
       
       //给DataBand(主表数据)绑定数据源 
       DataBand masterBand = rptMasterDetail.FindObject("Data1") as DataBand;
       masterBand.DataSource = rptMasterDetail.GetDataSource("tb_SO"); //主表 
       
       //给DataBand(明细数据)绑定数据源 
       DataBand detailBand = rptMasterDetail.FindObject("Data2") as DataBand;
       detailBand.DataSource = rptMasterDetail.GetDataSource("tb_SOs"); //明细表 
       
       //重要!!给明细表设置主外键关系! 
       detailBand.Relation = new Relation();
       detailBand.Relation.ParentColumns = new string[] { "SONO" };
       detailBand.Relation.ParentDataSource = rptMasterDetail.GetDataSource("tb_SO"); //主表 
       detailBand.Relation.ChildColumns = new string[] { "SONO" };
       detailBand.Relation.ChildDataSource = rptMasterDetail.GetDataSource("tb_SOs"); //明细表 
       
       //准备工作,显示报表预览窗体 
       rptMasterDetail.Prepare();
       rptMasterDetail.ShowPrepared(true, this);
       
    }

    具体步骤:

    1. 加载报表模板文件,Load()。
    2. 通过DAL层获取报表数据,返回DataSet类型,包含两张数据表(主表tb_SO, 明细表tb_SOs)。
    3. RegisterData,注册数据源。(重要)
    4. 给DataBand对象绑定数据源,名为Data1绑定主表,Data2绑定明细表。(重要)
    5. 给明细表DataBand设置主外键关系。 (重要)
    6. 准备报表,显示预览窗体。
  • 相关阅读:
    docker三剑客之docker compose
    docker三剑客之一docker compose
    dockerfile创建镜像(二)
    dockerfile创建镜像
    dockerfile创建镜像
    端口映射和容器映射
    鼠标点击左侧字母,字母变色
    body滚动时左侧菜单固定
    左侧菜单收缩展开
    车林通购车之家--购车计算器模块--算法js
  • 原文地址:https://www.cnblogs.com/lecone/p/4086747.html
Copyright © 2020-2023  润新知