现在的位置: 首页 > 综合 > 正文

XtraReport 一张纸打印3条记录

2012年08月22日 ⁄ 综合 ⁄ 共 1455字 ⁄ 字号 评论关闭

首先创建二个XtraReport一个是主一个是从

主:在Detail里面加三个xrSubreport控件

View Code

 /// <summary>
        /// 打印
        /// </summary>
        /// <param name="ds">数据集</param> 
        /// <param name="PrinterName">打印机名称</param>
        public NewSuNingReport(DataTable dt1, DataTable dt2, DataTable dt3, string PrinterName)
        {
            InitializeComponent(); 
            if (dt1!=null)
            {
                SuNingReport sunrep1 = new SuNingReport(dt1);
                this.xrSubreport1.ReportSource = sunrep1;
            }
            if (dt2 != null)
            {
                SuNingReport sunrep2 = new SuNingReport(dt2);
                this.xrSubreport2.ReportSource = sunrep2;
            }
            if (dt3 != null)
            {
                SuNingReport sunrep3 = new SuNingReport(dt3);
                this.xrSubreport3.ReportSource = sunrep3;
            }
            this.PrinterName = PrinterName;
            this.Print();
        }

 

从里面设置好你的报表格式绑定好数据

View Code

  public SuNingReport(DataTable dt)
        {
            InitializeComponent();
            if (dt != null && dt.Rows.Count > 0)
            {
                this.xrBarCode1.Text = dt.Rows[0]["订单1"].ToString();
                this.xrBarCode2.Text = dt.Rows[0]["订单2"].ToString();
                this.xrLabel2.Text = String.Format("共 {0} 箱", dt.Rows[0]["共几箱"].ToString());
                this.xrLabel3.Text = String.Format("第 {0} 箱", dt.Rows[0]["第几箱"].ToString());

                this.DetailReport.DataSource = dt;
                this.xrTableCell5.DataBindings.Add("Text", dt, "商品编号");
                this.xrTableCell6.DataBindings.Add("Text", dt, "商品名称");
                this.xrTableCell7.DataBindings.Add("Text", dt, "商品数量");
                this.xrTableCell8.DataBindings.Add("Text", dt, "商品库位");
            }
        }

调用方法

View Code

 for (int j = 0; j < ds.Tables.Count; j = j + 3)
                    {
                        DataTable dt1 = null;
                        DataTable dt2 = null;
                        DataTable dt3 = null;
                        if (count > j)
                        {
                            dt1 = ds.Tables[j];
                        }
                        if (count > j + 1)
                        {
                            dt2 = ds.Tables[j + 1];
                        }
                        if (count > j + 2)
                        {
                            dt3 = ds.Tables[j + 2];
                        }
                        NewSuNingReport suning = new NewSuNingReport(dt1, dt2, dt3, PrinterName);
                    }

抱歉!评论已关闭.