grid++report子报表

 public partial class Form1 : Form
    {
        GridppReport report = new GridppReport();
        GridppReport subReport;


        int count = 0;
        string uid;
        string connectionString = "server=USER-20150429XY\\SQLEXPRESS;database=B;uid=sa;pwd =123456"; //链接数据库的字符串。
        IGRField field1;
        IGRField field2;


        IGRField field3;
        IGRField field4;
        IGRField field5;
        public Form1()
        {
            InitializeComponent();
            //report.LoadFromFile(Application.StartupPath + @"\\d:\\child.grf");
          
        }
        void subReport_Initialize()
        {
            uid = field1.AsString;
            count++;
        }


        void subReport_FetchRecord()
        {
            string sql = "select * from dbo.childrens where zid='" + uid + "'";


            using (SqlConnection con = new SqlConnection(connectionString))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataReader reader = cmd.ExecuteReader();


                while (reader.Read())
                {
                    subReport.DetailGrid.Recordset.Append();
                    field3.AsString = reader[0].ToString();
                    field4.AsString = reader[1].ToString();
                    field5.AsString = reader[2].ToString();
                    subReport.DetailGrid.Recordset.Post();
                }


            }
        }
        //在C#中一次填入一条记录不能成功,只能使用一次将记录全部填充完的方式
        void report_FetchRecord()
        {
            string sql = "select * from dbo.zhubiao";


            using (SqlConnection con = new SqlConnection(connectionString))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataReader reader = cmd.ExecuteReader();
                //将全部记录一次填入
                while (reader.Read())
                {
                    report.DetailGrid.Recordset.Append();
                    field1.AsString = reader[0].ToString();
                    field2.AsString = reader[1].ToString();
                    report.DetailGrid.Recordset.Post();
                }


            }




        }
        private void axGRDisplayViewer1_ControlClick(object sender, Axgregn6Lib._IGRDisplayViewerEvents_ControlClickEvent e)
        {


        }


        private void Form1_Load(object sender, EventArgs e)
        {
            //report.LoadFromFile("d:\\child.grf");
            //this.axGRDisplayViewer1.Report = report;
            //report.DetailGrid.Recordset.QuerySQL = "select * from dbo.childrens where zid=:id";
            //this.axGRDisplayViewer1.Refresh();
            report.LoadFromFile("d:\\child.grf");
            subReport = report.ControlByName("SubReport1").AsSubReport.Report;


            //定义事件
            //FetchRecord事件 只有当自己填充的数据,才会触发
            report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(report_FetchRecord);


            subReport.Initialize += new _IGridppReportEvents_InitializeEventHandler(subReport_Initialize);
            subReport.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(subReport_FetchRecord);


            field1 = report.FieldByName("id");
            field2 = report.FieldByName("tijiaoMan");


            field3 = subReport.FieldByName("name");
            field4 = subReport.FieldByName("age");
            field5 = subReport.FieldByName("remark");
            this.axGRDisplayViewer1.Report = report;
            this.axGRDisplayViewer1.Refresh();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            report.PrintPreview(true);
        }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值