In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use Report-XRTable to bind data in DevExpress. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
The incoming data (dtOrd, BatchID, ModelID) is obtained from the page (A) before the jump, and bound to the control corresponding to the Report report. The code is as follows:
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); } 但是这样绑定的结果是(传入数据有两行数据,但绑定显示的都是第一行的内容):Therefore, the above code is improved to split the multi-row data of the incoming Table into multiple tables and bind them separately (I believe there is a simpler way to bind all the data at one time. If a great god sees it, please give me some advice. Thank you). The code is as follows:
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 ("Please select the ITEM to be printed first!") 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(); } }} 显示结果如下:Also: Report binding picture: drag the xrPictureBox from the toolbox, set the imageUrl to load the picture, and adjust the position and size.
The content below the Table will move down with the amount of Table data (if there is much data), so don't worry about being overwritten.
Other tested methods for binding xrTable (but none of them work, you can only bind a row of data at most). The code is as follows:
Private bool FillHeader () {try {if (dtOrd = = null) {CommonFunction.ShowMsgBox ("Please select the ITEM to be printed first!") 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; / / bind purchase order information BindFormData (drPur) / / get purchase order ID / / sheetID = drPur ["ID"] .ToString (); / / get purchase order detail data set DataSet dsDetail = new DataSet (); dsDetail.Tables.Add (dtOrd) / bind purchase order details 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) / / bind data source {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") } / bind purchase order details / private void BindFormData (DataRow dr) {/ / DataSet ds = DataSetOperator.DataRowToDataSet (dr); / / XRLabel bind data method 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 binding data method 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; iTunes +) / / i:Row {tempRow = dt.NewRow (); tempRow [I] = dtOrd.Rows [I] Dt.Rows.Add (tempRow);} ds.Tables.Add (dt);} return ds;} above is how to bind data with Report-XRTable in DevExpress. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.