尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

Winform开发报表(锐浪推方式)

Winform开发报表(锐浪推方式)
📅 发布时间:2026/6/18 23:22:45

Grid++Report 的报表数据来源既可以是推(PUSH)模式,也可以是拉(PULL)模式。所谓推模式就是由报表宿主程序向报表填充数据,报表引擎处于被动接受数据的形式。所谓拉模式就是报表引擎根据报表的数据源取数参数主动从数据源提取数据。

Grid++Report 的拉模式采用 OLE DB 数据引擎,OLE DB 是 Windows 系统提供的具有广泛数据访问能力的最新一代数据引擎。只要指定数据源的连接参数与查询SQL语句,就可以从各种数据源中提取数据。

Grid++Report 的推模式通过报表事件向报表宿主程序发出请求报表数据的通知,由报表宿主程序在此事件中将数据填入到报表的记录集中。采用推模式,可以将一切宿主程序能得到的数据提供给报表,这样更进一步扩大报表数据的来源。如果数据需要在程序中重新整理与加工运算,就必须采用推模式。

例子 Normal 中的报表都是采用拉模式获取报表数据。例子 ManualFillRecord 演示了推模式提供报表数据,同时也说明了在推模式下,任何数据都可以提供给 Grid++Report。

using System;
using System.Collections.Generic;
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 sdd Forms
{public partial class FrmTestPrint : DockContent{string sql = "";string taskId = "0", taskNo, carNo, driverName, superCargoName, Taskdate;DataTable dt, dtDetail;//定义Grid++Report报表主对象GridppReport Report = new GridppReport();public FrmTestPrint(){InitializeComponent();Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(ReportInitialize);Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecord);}private void tsbPrint_Click(object sender, EventArgs e){//最最重要的一句代码,Report.FetchRecord,一定要写在程序的初始事件中;Report.PrintPreview(true);}private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e){}//在C#中一次填入一条记录不能成功,只能使用一次将记录全部填充完的方式private void ReportFetchRecord(){if (dtDetail.Rows.Count == 0) return;FillRecordToReport(Report, dtDetail);}private void FrmTestPrint_Load(object sender, EventArgs e){sql = "select * from wewe";dt = DBHelperOracle.GetTable(sql);dataGridView1.DataSource = dt;}//定义保存报表记录集的结构private struct MatchFieldPairType{public IGRField grField;public int MatchColumnIndex;}/// <summary>/// 将 DataTable 的数据转储到 Grid++Report 的数据集中/// </summary>/// <param name="Report">报表对象</param>/// <param name="dt">DataTable对象</param>public void FillRecordToReport(IGridppReport Report, DataTable dt){if (dtDetail.Rows.Count == 0) return;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();}}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 wewg where task_id=" + taskId);dataGridView2.DataSource = dtDetail;}//报表初始化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;//主报表传参
        }}
}

 

活到老,学到老。

相关新闻

  • 详细介绍:《掰开揉碎讲编程-短篇》 2025 汉化idea控制台出现乱码解决方案 看完这篇解决不了乱码也是神人了
  • 多晶硅
  • Qt 解决 ld: framework ‘AGL‘ not found

最新新闻

  • Windows老游戏终极兼容解决方案:dxwrapper完全指南
  • 编写自定义脚本来自动化 vLLM 部署流程
  • 宣城市宁国吃正宗皖南徽菜 + 宁国农家土菜推荐去哪家? - 速递信息
  • 武汉买猫买狗去哪看?梦宠山庄实地体验分享 - 园友3800037
  • 从零到一:Jetlinks物联网平台服务器部署实战与避坑指南
  • (转)一次ANSYS EM 2023R1 “Request name electronics_desktop does not exist in the licensing pool.“的离谱解决记录

日新闻

  • 5分钟掌握Python进化算法:Geatpy高性能优化工具完全指南
  • Microchip 24AA044 EEPROM选型与应用全指南:从参数解析到实战编程
  • 华为的鸿蒙到底有多牛?为什么称作遥遥领先?

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号