当前位置: 首页 > news >正文

winform连接锐浪GridReport打印示例

image

 

image

 

using grproLib;
using LRTMS.Common;
using LRTMS.DB;
using LRTMS.Report;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;namespace LRTMS.Forms
{public partial class FrmDeliverPrint : DockContent{string sql = "";string taskId="0", taskNo, carNo, driverName, superCargoName, Taskdate;DataTable dt,dtDetail;//定义Grid++Report报表主对象GridppReport Report = new GridppReport();public FrmDeliverPrint(){InitializeComponent();Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(ReportInitialize);}void ReportInitialize(){if (dataGridView1.Rows.Count < 0) return;int i = dataGridView1.CurrentCell.RowIndex;if (i < 0) return;taskNo = dataGridView1.Rows[i].Cells["TASK_BILL_NO"].Value.ToString();carNo = dataGridView1.Rows[i].Cells["car_number"].Value.ToString();driverName = dataGridView1.Rows[i].Cells["driver_name"].Value.ToString();Taskdate = dataGridView1.Rows[i].Cells["create_time"].Value.ToString();superCargoName = dataGridView1.Rows[i].Cells["SUPERCARGO_NAME"].Value.ToString();taskId = dataGridView1.Rows[i].Cells["task_id"].Value.ToString();Report.LoadFromFile("Report\\pcd.grf");Report.ParameterByName("task_no").AsString = taskNo;//主报表传参Report.ParameterByName("car_no").AsString = carNo;//主报表传参Report.ParameterByName("driver_name").AsString = driverName;//主报表传参Report.ParameterByName("supercargo").AsString = superCargoName;//主报表传参Report.ParameterByName("bill_date").AsString = Taskdate;//主报表传参Report.DetailGrid.Recordset.ConnectionString = "Provider=OraOLEDB.Oracle;" + CommFunc.GetConnString();Report.DetailGrid.Recordset.QuerySQL = "select * from lrtms_task_dtl where task_id=" + taskId;}private void DefineReport(){int Selected = 0;Report.Clear();Report.Printer.PaperOrientation = GRPaperOrientation.grpoLandscape;//<<定义报表头IGRReportHeader Reportheader = Report.InsertReportHeader();Reportheader.Height = 1.38;//插入一个静态文本框,显示报表标题文字IGRStaticBox StaticBox = Reportheader.Controls.Add(GRControlType.grctStaticBox).AsStaticBox;if (Selected == 0)StaticBox.Text = "客户清单打印";elseStaticBox.Text = "产品清单打印";StaticBox.Center = GRCenterStyle.grcsHorizontal; //使部件框在节中水平方向上居中对齐StaticBox.Font.Point = 15;StaticBox.Font.Bold = true;StaticBox.Top = 0.40;StaticBox.Width = 5.64;StaticBox.Height = 0.58;//>>定义报表头//<<根据DataGridView的列信息定义明细网格Report.InsertDetailGrid();Report.DetailGrid.ColumnTitle.Height = 0.58;Report.DetailGrid.ColumnContent.Height = 0.58;IGRRecordset RecordSet = Report.DetailGrid.Recordset;for (int i = 0; i < dataGridView1.ColumnCount; ++i){string ColumnName = dataGridView1.Columns[i].Name;RecordSet.AddField(ColumnName, GRFieldType.grftString);double ReportColumnWidth = Convert.ToDouble(dataGridView1.Columns[i].Width) / 50;Report.DetailGrid.AddColumn(ColumnName, dataGridView1.Columns[i].HeaderText, ColumnName, ReportColumnWidth);}}private void tsbSearchDeliver_Click(object sender, EventArgs e){string deliveryNo = txtDeliverNo.Text.Trim();if (string.IsNullOrEmpty(deliveryNo)){MessageBox.Show("请输入交货单号");return;}Report.PrintPreview(true);}private struct MatchFieldPairType{public IGRField grField;public int MatchColumnIndex;}private void tsbClose_Click(object sender, EventArgs e){this.Close();}/// <summary>/// 将 DataTable 的数据转储到 Grid++Report 的数据集中/// </summary>/// <param name="Report">报表对象</param>/// <param name="dt">DataTable对象</param>public void FillRecordToReport(IGridppReport Report, DataTable dt){MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, dt.Columns.Count)];//根据字段名称与列名称进行匹配,建立DataReader字段与Grid++Report记录集的字段之间的对应关系int MatchFieldCount = 0;for (int i = 0; i < dt.Columns.Count; ++i){foreach (IGRField fld in Report.DetailGrid.Recordset.Fields){if (string.Compare(fld.Name, dt.Columns[i].ColumnName, true) == 0){MatchFieldPairs[MatchFieldCount].grField = fld;MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;++MatchFieldCount;break;}}}// 将 DataTable 中的每一条记录转储到 Grid++Report 的数据集中去foreach (DataRow dr in dt.Rows){Report.DetailGrid.Recordset.Append();for (int i = 0; i < MatchFieldCount; ++i){var columnIndex = MatchFieldPairs[i].MatchColumnIndex;if (!dr.IsNull(columnIndex)){MatchFieldPairs[i].grField.Value = dr[columnIndex];}}Report.DetailGrid.Recordset.Post();}}void dt_FetchREcord(){FillRecordToReport(Report, dtDetail);}private void tsmFilter_Click(object sender, EventArgs e){}//主表点击事件,根据主表的TASK_ID,显示子表的数据private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e){if (e.RowIndex < 0) return;string taskId = dataGridView1.Rows[e.RowIndex].Cells["task_id"].Value.ToString();dtDetail = DBHelperOracle.GetTable("select * from lrtms_task_dtl where task_id=" + taskId);dataGridView2.DataSource = dtDetail;}//打印按钮private void tsbPrint_Click(object sender, EventArgs e){//最最重要的一句代码,Report.FetchRecord// Report.FetchRecord += dt_FetchREcord;Report.PrintPreview(true);}private void FrmDeliverPrint_Load(object sender, EventArgs e){sql = "select * from lrtms_task_hdr";dt = DBHelperOracle.GetTable(sql);dataGridView1.DataSource = dt;}}
}

  

http://www.zskr.cn/news/25225.html

相关文章:

  • AI 的能源危机:训练一个模型究竟要耗掉多少电?
  • 2025 年制砂机厂家最新推荐榜,聚焦企业技术实力与市场口碑深度解析高效/冲击式/砂石/新疆制砂机厂家推荐
  • Hyper-V 与 root的Android7模拟器共存
  • PCIe 全高/半高,全长/半长 尺寸介绍 - ENGINEER
  • Linux框架编程:线程控制
  • WebSocket Turbo Intruder:挖掘WebSocket安全漏洞的利器
  • 吱吱企业即时通讯不止通讯,还是数字化协作的安全与效率标杆
  • callout样式
  • Java 8 - Optional类
  • 【循环神经网络5】GRU模型实战,从零开始构建文本生成器 - 详解
  • 实用指南:【Linux 系统】命令行参数和环境变量
  • 国产化Word处理控件Spire.Doc教程:用Java实现TXT文本与Word互转的完整教程
  • 2025年太阳能板定制厂家口碑排行榜前十强:专业评测与选择指南
  • 能源AI天团:多智能体如何破解行业复杂任务 - 实践
  • 实用指南:IEC 60364-7-722-2018低压电气装置中电动车供电安全要求标准介绍
  • c#设计模式—访问者模式 - 教程
  • 【整活】OI的那些奇妙小操作(Part 1)
  • 个微协议,微信号二次开发/ipad协议
  • MySQL索引查看语句show index详解
  • qzmoot 生活合集
  • yocto工程升级要点
  • 微信机器人开发API!3步搞定微信聊天机器人
  • 2022ICPC区域赛济南站
  • 计算机毕业设计PySpark+Hadoop+Hive+LSTM模型美团大众点评分析+评分预测 美食推荐环境(源码+论文+PPT+讲解视频)
  • Unable to register MBean [SftpPool
  • sp681网卡打驱动后的状态--默认是链路是down
  • dlc — Docker Log Cleaner(支持名称、ID前缀、交互序号清理,模糊匹配交互确认)
  • 第二周记
  • 2025年10月deepseek排名优化服务推荐排行榜:十家服务商综合评测与选择指南
  • 克服keepalived的主备服务器都持有VIP——出现脑裂现象