本篇内容主要讲解“怎么用DevExpress Report控件实现pdf打印”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么用DevExpress Report控件实现pdf打印”吧!
按钮弹出(获取当前页面选中的BatchID,通过构造函数传参传入子窗口并打开窗口):
frmQCMTranInspBatchList.cs(父窗口)
private void btnInspBatchPrint_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { GlobalVariable.gaSelectPOID.Clear(); int[] iaPOs = gdvDetail.GetSelectedRows(); if (iaPOs.Length < 1) { CommonFunction.ShowMsgBox("请选择一条或多条参数");//ToDo: Multi-Language return; } int[] iaRAWID = new int[iaPOs.Length];//+2 string sBatchID = ""; for (int i = 0; i < iaPOs.Length; i++) { sBatchID = gdvDetail.GetRowCellValue(iaPOs[i], "BATCH_ID").ToString(); } //saPARA_ID[iaPOs.Length] = cboModelVer.EditValue.ToString(); //saPARA_ID[iaPOs.Length + 1] = "EVENT"; rptQCMInspBatchCard InspBatchCard = new rptQCMInspBatchCard(sBatchID); DevExpress.XtraReports.UI.ReportPrintTool printTool = new DevExpress.XtraReports.UI.ReportPrintTool(InspBatchCard); printTool.ShowPreviewDialog(); } catch (Exception ex) { CommonFunction.ShowMsgBox("frmAPSReleaseWO.btnSelect_Click()\n" + ex.Message); } }
子窗口获取参数,并根据该参数执行SQL语句查询需要的数据,再将查到的数据放入Report中(条形码赋值即可自动生成)
rptQCMInspBatchCard.cs(子窗口):
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; namespace QCMCore.Reports { public partial class rptQCMInspBatchCard : DevExpress.XtraReports.UI.XtraReport { public rptQCMInspBatchCard(string sBatchId) { InitializeComponent(); this.sBatchID = sBatchId; } #region Variable private string sBatchID; #endregion #region Function private bool FillHeader() { try { DataTable dtOrd = new DataTable(); dtOrd.Columns.Add("BATCH_ID"); dtOrd.Columns.Add("LOT_ID"); dtOrd.Columns.Add("START_RES_ID"); dtOrd.Columns.Add("MAT_ID"); TRSNode in_node = new TRSNode("Sql_In"); TRSNode out_node = new TRSNode("Sql_Out"); StringBuilder sb = new StringBuilder(); CommonRoutine.SetInMsg(in_node); string sFactory =in_node.Factory; in_node.ProcStep = '1'; in_node.AddInt("NEXT_ROW", 0); sb.Append("SELECT A.BATCH_ID, A.LOT_ID, A.START_RES_ID, A.MAT_ID FROM WIPLOTSTS A INNER JOIN QCMITEMINSP B ON A.LOT_ID = B.ITEM_ID WHERE A.FACTORY =B.FACTORY "); sb.Append(" AND B.FACTORY= '"+sFactory+"' AND B.BATCH_ID='" + sBatchID+"' "); in_node.SetString("SQL", sb.ToString()); do { if (CommonRoutine.CallService("BAS", "BAS_SQL_Query", in_node, ref out_node) == false) { return false; } CommonRoutine.ConvertToDataTable(dtOrd, out_node); in_node.SetInt("NEXT_ROW", out_node.GetInt("NEXT_ROW")); } while (in_node.GetInt("NEXT_ROW") > 0); if (dtOrd.Rows.Count > 0) { this.xrBarCode1.Text = dtOrd.Rows[0]["BATCH_ID"].ToString(); this.xrtBatchID.Text = dtOrd.Rows[0]["BATCH_ID"].ToString(); this.xrtLotID.Text = dtOrd.Rows[0]["LOT_ID"].ToString(); this.xrtStartResID.Text = dtOrd.Rows[0]["START_RES_ID"].ToString(); this.xrtMatID.Text = dtOrd.Rows[0]["MAT_ID"].ToString(); } return true; } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); return false; } } #endregion #region Control Event #endregion private void BottomMargin_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { FillHeader(); } } }
到此,相信大家对“怎么用DevExpress Report控件实现pdf打印”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。