中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

DevExpress中如何使用Report-XRTable綁定數據

發布時間:2021-07-30 13:58:03 來源:億速云 閱讀:478 作者:Leah 欄目:大數據

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

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

 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);
                   

                }

但是這樣綁定的結果是(傳入數據有兩行數據,但綁定顯示的都是第一行的內容):

DevExpress中如何使用Report-XRTable綁定數據

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

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<DataTable> list = new List<DataTable>();
                    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();
        }

       
    }
}

顯示結果如下:

DevExpress中如何使用Report-XRTable綁定數據

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

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

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

   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();
                    //獲取采購單明細數據集
                    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)//綁定數據源
        { 
            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"); 
        }
        /// <summary>
        /// 綁定采購單明細信息
        /// </summary>
        private void BindFormData(DataRow dr)
        {
            //DataSet ds = DataSetOperator.DataRowToDataSet(dr);
            //XRLabel綁定數據 方法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綁定數據 方法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綁定數據,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

苏尼特左旗| 鹤岗市| 商城县| 浙江省| 永兴县| 新泰市| 海阳市| 庆安县| 抚顺县| 宝坻区| 丘北县| 德钦县| 乡城县| 灵璧县| 洛扎县| 漳州市| 古蔺县| 万荣县| 扶沟县| 文山县| 天津市| 龙海市| 封开县| 龙山县| 旺苍县| 梨树县| 云林县| 柏乡县| 手游| 杭州市| 五大连池市| 西和县| 萨迦县| 临沧市| 洪江市| 武陟县| 南阳市| 孟连| 璧山县| 克什克腾旗| 土默特左旗|