grid++report子報表

來源:互聯網
上載者:User
 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);
        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.