真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

DevExpress中如何使用Report-XRTable綁定數(shù)據(jù)

本篇文章給大家分享的是有關(guān)DevExpress中如何使用Report-XRTable綁定數(shù)據(jù),小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

創(chuàng)新互聯(lián)主營洞口網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app軟件開發(fā)公司,洞口h5重慶小程序開發(fā)搭建,洞口網(wǎng)站營銷推廣歡迎洞口等地區(qū)企業(yè)咨詢

將從跳轉(zhuǎn)前的頁面(A)中獲取傳入的數(shù)據(jù)(dtOrd、BatchID、ModelID),綁定到Report報表對應(yīng)的控件 ,代碼如下:

 this.xrtBatchID.Text = sBatchID;
                this.xrtModel.Text = sModelID;
                this.xrtDateTime.Text = DateTime.Now.ToShortDateString().ToString();    // 20018-9-4
                if (dtOrd.Rows.Count > 0)
                {
                    

                    XRTable table = new XRTable();
                    
                    for (int i = 0; i < dtOrd.Rows.Count; i++)
                    {
                        if (list[i]!=null) {
                        XRTableRow row = new XRTableRow();
                        XRTableCell TESTING_ITEM = new XRTableCell();
                        XRTableCell TESTING_RESULT = new XRTableCell();
                        XRTableCell TESTING_SPECIFICATION = new XRTableCell();
                        XRTableCell DIMENS = new XRTableCell();
                        XRTableCell TESTING_METHOD = new XRTableCell();

                        row.Cells.Add(TESTING_ITEM);
                        row.Cells.Add(TESTING_RESULT);
                        row.Cells.Add(TESTING_SPECIFICATION);
                        row.Cells.Add(DIMENS);
                        row.Cells.Add(TESTING_METHOD);
                        //TESTING_ITEM.WidthF = 140.14f;
                        //TESTING_RESULT.WidthF = 140.14f;
                        //TESTING_SPECIFICATION.WidthF = 140.14f;
                        //DIMENS.WidthF = 140.14f;
                        //TESTING_METHOD.WidthF = 140.14f;
                        TESTING_ITEM.DataBindings.Add("Text", dtOrd, "TESTING_ITEM");
                        TESTING_RESULT.DataBindings.Add("Text",dtOrd, "TESTING_RESULT");
                        TESTING_SPECIFICATION.DataBindings.Add("Text", dtOrd, "TESTING_SPECIFICATION");
                        DIMENS.DataBindings.Add("Text", dtOrd, "DIMENS");
                        TESTING_METHOD.DataBindings.Add("Text", dtOrd, "TESTING_METHOD");
                        xrTable7.Rows.Add(row);
                        }
                    }
                    
                    DetailBand detailBand = new DetailBand();
                    detailBand.Controls.Add(table);
                    report.Bands.Add(detailBand);
                   

                }

但是這樣綁定的結(jié)果是(傳入數(shù)據(jù)有兩行數(shù)據(jù),但綁定顯示的都是第一行的內(nèi)容):

DevExpress中如何使用Report-XRTable綁定數(shù)據(jù)

于是,將上述代碼改進,把傳入的Table的多行數(shù)據(jù)拆分成多個表,分別進行綁定(相信有更簡單的,可以直接一次性綁定全部數(shù)據(jù)的方法,如果有大神看到,請指教一下,多謝),代碼如下:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;
using TRSCore;
using System.Text;
using MESCore;
using DevExpress.DataAccess.EntityFramework;
using System.Collections.Generic;

namespace QCMCore.Reports
{
    public partial class rptQCMCOACard : DevExpress.XtraReports.UI.XtraReport
    {
        public rptQCMCOACard()
        {
            InitializeComponent();
        }
        public rptQCMCOACard(DataTable dt,string sBatchID,string sModelID)
        {
            InitializeComponent();
            this.dtOrd = dt;
            this.sBatchID = sBatchID;
            this.sModelID = sModelID;

            
        }
        DataTable dtOrd = null;
        string sBatchID = "";
        string sModelID = "";
        private bool FillHeader()
        {
            try
            {
                if (dtOrd == null)
                {
                    CommonFunction.ShowMsgBox("請先選擇需要打印的ITEM!");
                    return false;
                }
                this.xrtBatchID.Text = sBatchID;
                this.xrtModel.Text = sModelID;
                this.xrtDateTime.Text = DateTime.Now.ToShortDateString().ToString();    // 20018-9-4
                if (dtOrd.Rows.Count > 0)
                {
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dtOrd);
                    XtraReport report = new XtraReport();
                    report.DataSource = ds;
                    report.DataMember = "queryProducts";
                    List list = new List();
                    for (int i = 0; i < dtOrd.Rows.Count;i++) {

                        DataTable dt = new DataTable();
                        dt.Columns.Add("ITEM_SEQ");
                        dt.Columns.Add("TESTING_ITEM");
                        dt.Columns.Add("TESTING_RESULT");
                        dt.Columns.Add("TESTING_SPECIFICATION");
                        dt.Columns.Add("DIMENS");
                        dt.Columns.Add("TESTING_METHOD");

                        dt.Rows.Add(dtOrd.Rows[i].ItemArray);
                        list.Add(dt);
                    }

                    XRTable table = new XRTable();
                    
                    for (int i = 0; i < dtOrd.Rows.Count; i++)
                    {
                        if (list[i]!=null) {
                        XRTableRow row = new XRTableRow();
                        XRTableCell TESTING_ITEM = new XRTableCell();
                        XRTableCell TESTING_RESULT = new XRTableCell();
                        XRTableCell TESTING_SPECIFICATION = new XRTableCell();
                        XRTableCell DIMENS = new XRTableCell();
                        XRTableCell TESTING_METHOD = new XRTableCell();

                        row.Cells.Add(TESTING_ITEM);
                        row.Cells.Add(TESTING_RESULT);
                        row.Cells.Add(TESTING_SPECIFICATION);
                        row.Cells.Add(DIMENS);
                        row.Cells.Add(TESTING_METHOD);
                        //TESTING_ITEM.WidthF = 140.14f;
                        //TESTING_RESULT.WidthF = 140.14f;
                        //TESTING_SPECIFICATION.WidthF = 140.14f;
                        //DIMENS.WidthF = 140.14f;
                        //TESTING_METHOD.WidthF = 140.14f;
                        TESTING_ITEM.DataBindings.Add("Text", list[i], "TESTING_ITEM");
                        TESTING_RESULT.DataBindings.Add("Text", list[i], "TESTING_RESULT");
                        TESTING_SPECIFICATION.DataBindings.Add("Text", list[i], "TESTING_SPECIFICATION");
                        DIMENS.DataBindings.Add("Text", list[i], "DIMENS");
                        TESTING_METHOD.DataBindings.Add("Text", list[i], "TESTING_METHOD");
                        xrTable7.Rows.Add(row);
                        }
                    }
                    
                    DetailBand detailBand = new DetailBand();
                    detailBand.Controls.Add(table);
                    report.Bands.Add(detailBand);
                   

                }

                return true;
            }
            catch (Exception ex)
            {
                CommonFunction.ShowMsgBox(ex.Message);
                return false;
            }
        }
        private void ReportHeader_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            FillHeader();
        }

       
    }
}

顯示結(jié)果如下:

DevExpress中如何使用Report-XRTable綁定數(shù)據(jù)

另:Report綁定圖片:從工具箱拖入xrPictureBox,設(shè)置imageUrl載入圖片,調(diào)整位置和大小即可。

Table下方內(nèi)容會隨著Table數(shù)據(jù)的多少進行下移(如果數(shù)據(jù)多的話),所以不用擔(dān)心會被覆蓋。

其他測試過的綁定xrTable的方法(但是都行不通,最多只能綁定一行數(shù)據(jù)),代碼如下:

   private bool FillHeader()
        {
            try
            {
                if (dtOrd == null)
                {
                    CommonFunction.ShowMsgBox("請先選擇需要打印的ITEM!");
                    return false;
                }
                this.xrtBatchID.Text = sBatchID;
                this.xrtModel.Text = sModelID;
                this.xrtDateTime.Text = DateTime.Now.ToShortDateString().ToString();    // 20018-9-4
                if (dtOrd.Rows.Count > 0)
                {
                    DataSet ds = new DataSet();
                    ds = GetTempDataSet();
                    if (ds != null)
                    {
                        SetDataBind(ds);
                    }
                    DataRow drPur = dtOrd.Rows[0];
                    string sheetID = string.Empty;
                    if (drPur == null) return false;
                    //綁定采購單信息
                    BindFormData(drPur);
                    //獲取采購單ID
                    //sheetID = drPur["ID"].ToString();
                    //獲取采購單明細數(shù)據(jù)集
                    DataSet dsDetail = new DataSet();
                    dsDetail.Tables.Add(dtOrd);
                    //綁定采購單明細信息
                    BindTableData(dsDetail);
                   
                }

                return true;
            }
            catch (Exception ex)
            {
                CommonFunction.ShowMsgBox(ex.Message);
                return false;
            }
        }

 private void BindTableData(DataSet ds)
        {
            
            this.xrTableCell11.DataBindings.Add("Text", ds, "TESTING_ITEM");
            this.xrTableCell12.DataBindings.Add("Text", ds, "TESTING_RESULT");
            this.xrTableCell13.DataBindings.Add("Text", ds, "TESTING_SPECIFICATION");
            this.xrTableCell14.DataBindings.Add("Text", ds, "DIMENS");
            this.xrTableCell15.DataBindings.Add("Text", ds, "TESTING_METHOD");
        }
        private void SetDataBind(DataSet  ds)//綁定數(shù)據(jù)源
        { 
            this.xrTableCell11.DataBindings.Add("Text",ds, "TESTING_ITEM");
            this.xrTableCell12.DataBindings.Add("Text",ds, "TESTING_RESULT"); 
            this.xrTableCell13.DataBindings.Add("Text",ds, "TESTING_SPECIFICATION"); 
            this.xrTableCell14.DataBindings.Add("Text",ds, "DIMENS"); 
            this.xrTableCell15.DataBindings.Add("Text",ds, "TESTING_METHOD"); 
        }
        /// 
        /// 綁定采購單明細信息
        /// 
        private void BindFormData(DataRow dr)
        {
            //DataSet ds = DataSetOperator.DataRowToDataSet(dr);
            //XRLabel綁定數(shù)據(jù) 方法1:
            this.xrTableCell11.Text = dr["TESTING_ITEM"].ToString();
            this.xrTableCell12.Text = dr["TESTING_RESULT"].ToString();
            this.xrTableCell13.Text = dr["TESTING_SPECIFICATION"].ToString();
            this.xrTableCell14.Text = dr["DIMENS"].ToString();
            this.xrTableCell15.Text = dr["TESTING_METHOD"].ToString();
            //XRLabel綁定數(shù)據(jù) 方法2:
            //this.txtDB0337A.DataBindings.Add(new XRBinding("Text", ds, "DB0337A", "{0:yyyy-MM-dd}"));
            //this.txtDB0005A.Text = dr["DB0005A"].ToString();
            //this.txtDB0339A.Text = dr["DB0339A"].ToString();
            //this.txtDB0345A.DataBindings.Add(new XRBinding("Text", ds, "DB0345A", "{0:n2}"));
            //this.labPrintTime.Text = DateTime.Now.Date.ToString();

        }
        private void ReportHeader_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            FillHeader();
        }


        private DataSet GetTempDataSet()
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable("tempTable");
            dt.Columns.Add("TESTING_ITEM");
            dt.Columns.Add("TESTING_RESULT");
            dt.Columns.Add("TESTING_SPECIFICATION");
            dt.Columns.Add("DIMENS");
            dt.Columns.Add("TESTING_METHOD");
            DataRow tempRow;
            if (dtOrd != null)
            {
                for (int i = 0; i < dtOrd.Rows.Count; i++)//i:Row
                {
                    tempRow = dt.NewRow();
                    tempRow[i] = dtOrd.Rows[i];
                    dt.Rows.Add(tempRow);
                }
                ds.Tables.Add(dt);
            }
           
            return ds;
        }

以上就是DevExpress中如何使用Report-XRTable綁定數(shù)據(jù),小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


分享題目:DevExpress中如何使用Report-XRTable綁定數(shù)據(jù)
分享鏈接:http://weahome.cn/article/ggehpp.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部