using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FastReport;
using FastReport.Data;
using FastReport.Editor;
using FastReport.Design;
using FastReport.Data.ConnectionEditors;
using FastReport.Forms;
using FastReport.Utils;
using FastReport.Table;
using System.Data.SqlClient; namespace DataFromArray
{
/// <summary>
///
/// </summary>
public partial class Form1 : Form
{ private int[] FArray; TableObject Table1 = new TableObject();
Report report = new Report();
/// <summary>
///
/// </summary>
/// <returns></returns>
DataSet bindDB()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.TableName = "Db";
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("cnname", typeof(string));
dt.Columns.Add("bithdate", typeof(DateTime));
dt.Columns.Add("age", typeof(int)); dt.Rows.Add(1, "geovindu", "2001-12-03",12);
dt.Rows.Add(2, "sibodu", "2001-12-03",13);
dt.Rows.Add(3, "ginhongzhao", "2001-12-03",15);
ds.Tables.Add(dt);
return ds;
} /// <summary>
///
/// </summary>
public Form1()
{
InitializeComponent();
Table1.ManualBuild += new System.EventHandler(Table1_ManualBuild);
CreateArray();
}
/// <summary>
///
/// </summary>
private void CreateArray()
{
FArray = new int[10];
for (int i = 0; i < 10; i++)
{
FArray[i] = i + 1;
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCreateNew_Click(object sender, EventArgs e)
{
// create report instance
Report report = new Report(); // register the array
report.RegisterData(FArray, "Array"); // design the report
report.Design(); // free resources used by report
report.Dispose();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnRunExisting_Click(object sender, EventArgs e)
{
// create report instance
Report report = new Report(); string fileurl = @"..\..\report.frx";
// load the existing report
report.Load(fileurl); // register the array
//report.RegisterData(FArray, "Array");
report.RegisterData(FArray, "Db"); // run the report
report.Show(); // free resources used by report
report.Dispose();
} private void Form1_Load(object sender, EventArgs e)
{ }
/// <summary>
///
/// 自定义
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
try
{ //DataTable dd = bindDB().Tables["Db"];
report.RegisterData(bindDB().Tables["Db"], "Db");
report.GetDataSource("Db").Enabled = true; ReportPage page1 = new ReportPage();
page1.Name = "page1";
report.Pages.Add(page1); page1.ReportTitle = new ReportTitleBand();
page1.ReportTitle.Name = "ReportTitle1";
page1.ReportTitle.Height = Units.Centimeters*1.5f; ReportPage page2 = new ReportPage();
page2.Name = "page2";
page2.ReportTitle = new ReportTitleBand();
page2.ReportTitle.Name = "ReportTitle2";
page2.ReportTitle.Height = Units.Centimeters * 1.5f;
report.Pages.Add(page2); GroupHeaderBand group1 = new GroupHeaderBand();
group1.Height = Units.Centimeters * 1;
group1.Name = "GroupHeader1";
group1.Condition = "[Db.cnname]"; //表.字段名
page1.Bands.Add(group1); group1.GroupFooter = new GroupFooterBand();
group1.GroupFooter.Name = "GroupFooter1";
group1.GroupFooter.Height = Units.Centimeters * 1; //create databand
DataBand data1 = new DataBand();
data1.Name = "Data1";
data1.Height = Units.Centimeters * 0.5f;
data1.DataSource = report.GetDataSource("Db");
group1.Data = data1; //
TextObject txt1 = new TextObject();
txt1.Name = "txt1";
txt1.Bounds = new RectangleF(0, 0, Units.Centimeters * 19, Units.Centimeters * 1);
txt1.HorzAlign = HorzAlign.Center;
txt1.Font = new Font("宋体", 14, FontStyle.Bold);
txt1.Text = "DB 数据";
page1.ReportTitle.Objects.Add(txt1); //group
TextObject txt2 = new TextObject();
txt2.Name = "txt2";
txt2.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 1);
txt2.HorzAlign = HorzAlign.Center;
txt2.Font = new Font("宋体", 8, FontStyle.Bold);//Tahoma
txt2.Text = "[Db.cnname]";
group1.Objects.Add(txt2); //data band
TextObject txt3 = new TextObject();
txt3.Name = "txt3";
txt3.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 1);
txt3.HorzAlign = HorzAlign.Center;
txt3.Font = new Font("宋体", 8, FontStyle.Bold);
txt3.Text = "[Db.cnname]";
data1.Objects.Add(txt3);
TextObject txt4 = new TextObject();
txt4.Name = "txt4";
txt4.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 1);
txt4.HorzAlign = HorzAlign.Center;
txt4.Font = new Font("宋体", 8, FontStyle.Bold);
txt4.Text = "[Db.age]";
group1.GroupFooter.Objects.Add(txt4); DataSourceBase masterData = report.GetDataSource("Db");
masterData.Init(); //TableColumn cm = new TableColumn();
//cm.Name = "";
//TableColumn column = new TableColumn();
//column.Name = "column";
//column.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 1);
//column.Height = Units.Centimeters * 2.5f;
//Table1.Columns.Add(column); //TableColumn column2 = new TableColumn();
//column2.Name = "Cell2"; //column2.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 1);
//column2.Height = Units.Centimeters * 2.5f;
//Table1.Columns.Add(column2); //Table1.Border.RightLine = BorderLines.Right;
Table1.ColumnCount = 2;
Table1.Border.LeftLine.Color = Color.Black; Table1.Border.Lines = BorderLines.None;
Table1.Border.TopLine.Color = Color.Black;
Table1.Border.TopLine.Width = 1; Table1.Border.ShadowWidth = 4;
Table1.Border.RightLine.Style = FastReport.LineStyle.Solid;// TableCell cell = new TableCell();
cell.Name = "Cell1";
cell.Text = "Name";
cell.Font = new Font("宋体", 8, FontStyle.Bold);
cell.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 1);
cell.Height = Units.Centimeters * 2.5f;
Table1.Columns.Add(cell); TableCell cell2 = new TableCell();
cell2.Name = "Cell2";
cell2.Text = "Id";
cell2.Font = new Font("宋体", 8, FontStyle.Bold);
cell2.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 1);
cell2.Height = Units.Centimeters * 2.5f;
Table1.Columns.Add(cell2); TableCell cell3 = new TableCell();
cell3.Name = "cell3";
cell3.Text = "[Db.cnname]";
cell3.Font = new Font("宋体", 8, FontStyle.Bold);
cell3.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 1);
cell3.Height = Units.Centimeters * 2.5f;
Table1.Rows.Add(cell3); TableCell cell4 = new TableCell();
cell4.Name = "cell4";
cell4.Text = "[Db.id]";
cell4.Font = new Font("宋体", 8, FontStyle.Bold);
cell4.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 1);
cell4.Height = Units.Centimeters * 2.5f;
Table1.Rows.Add(cell4); //TableRow rw = new TableRow(); //while (masterData.HasMoreRows)
//{
// TableCell cell = new TableCell();
// cell.Name = "Cell1";
// cell.Text = "[Db.cnname]";
// cell.Font = new Font("宋体", 8, FontStyle.Bold);
// cell.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 1);
// cell.Height = Units.Centimeters * 2.5f;
// Table1.Rows.Add(cell); // masterData.Next();
//} //page2.Bands.Add(Table1);
page2.ChildObjects.Add(Table1); report.Show(); }
catch(Exception ex)
{
ex.Message.ToString();
} }
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Table1_ManualBuild(object sender, EventArgs e)
{ DataSourceBase data1 = report.GetDataSource("Db"); // 获取DataSet中表名为Table1的数据源
data1.Init(); // 初始化
Table1.PrintRow(0); // 控件Table1打印第0行
Table1.PrintColumns(); // 每打印一行,都要调用 PrintColumn或PrintColumns
while (data1.HasMoreRows) // 打印重复循环的行
{
Table1.PrintRow(1);
Table1.PrintColumns();
data1.Next(); // 读取下一行
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
Report report = new Report(); string sql = "select top 2 * from Employee";
DataTable dt = null; dt = DBHelper.GetTable(sql, CommandType.Text, null); string fileurl = @"..\..\report2.frx";
// load the existing report
report.Load(fileurl);
// report.Design();
report.RegisterData(dt, "Employee"); // run the report
report.Show(); // free resources used by report
//report.Dispose();
} }
}

  

FastReport.Net的更多相关文章

  1. 使用FastReport打印二维码

    简单介绍一下该功能所在的项目背景:C#语言编写的WPF客户端应用程序,在“结账”模块中,打印出的收款小票上需要显示一个二维码,服务生拿着小票去找顾客,顾客可以选择现金.银行卡等普通支付方式,也可以直接 ...

  2. FastReport.Net 常用功能总汇

    一.常用控件 文本框:输入文字或表达式 表格:设置表格的行列数,输入数字或表达式 子报表:放置子报表后,系统会自动增加一个页面,你可以在此页面上设计需要的报表.系统在打印处理时,先按主报表打印,当碰到 ...

  3. FastReport自定义数据源及ListView控件的使用

    ##1.想批量生成一堆物资信息卡,效果如下图所示,fastreport可以一下全部生成,并且发现不用单独写东西, ##2.发现FastReport官方给出的Demo.exe很友好,基本可以满足要求,想 ...

  4. 使用功能强大的插件FastReport.Net打印报表实例

    我第一次使用FastReport插件做的功能是打印一个十分复杂的excel表格,有几百个字段都需要绑定数据,至少需要4个数据源,而且用到横向.竖向合并单元格. 我不是直接连接数据库,而是使用Regis ...

  5. FastReport使用DataSet作数据源

    1.打开FastReport的设计器, 2.选择[File]->[New] 新建FastReport模板. 3.选择[View]->[Data],显示如下,导出Dictionary,保存. ...

  6. MVC架构 使用FastReport

    1.Web.config文件 添加配置 <httpHandlers> <add path="FastReport.Export.axd" verb="* ...

  7. FastReport 中添加二维码功能.(Delphi)

    http://www.cnblogs.com/fancycloud/archive/2011/07/24/2115240.html FastReport 中添加二维码功能.(Delphi)   在实际 ...

  8. 配置FastReport,FastReport报表加载不出来

    插件链接: Demo地址:http://pan.baidu.com/s/1dEXUvsP FastReport.Net软件地址:https://pan.baidu.com/s/1c2kNBVi     ...

  9. web应用程序传递连接字符串给FastReport数据源

    public static FastReport.Report fr = new FastReport.Report(); public static FastReport.EnvironmentSe ...

  10. Web调用FastReport的配置问题

    1.修改配置webconfig文件 IIS6: <system.web> <httpHandlers> <add path="FastReport.Export ...

随机推荐

  1. RabbitMQ 任务分发机制

    在上篇文章中,我们解决了从发送端(Producer)向接收端(Consumer)发送“Hello World”的问题.在实际的应用场景中,这是远远不够的.从本篇文章开始,我们将结合更加实际的应用场景来 ...

  2. Windows 10 IoT Core 17127 for Insider 版本更新

    昨天,微软发布了Windows 10 IoT Core 17127 for Insider 版本更新,本次更新只修正了一些Bug,没有发布新的特性.相比于17120,修复了一个已知的问题. 一些已知的 ...

  3. 一分钟理解 HTTPS 到底解决了什么问题

    本文原作者“虞大胆的叽叽喳喳”,原文链接:jianshu.com/p/8861da5734ba,感谢原作者. 1.引言 很多人一提到 HTTPS,第一反应就是安全,对于普通用户来说这就足够了: 但对于 ...

  4. Javascript高级编程学习笔记(51)—— DOM2和DOM3(3)操作样式表

    操作样式表 在JS中样式表用一种类型来表示,以便我们在JS对其进行操作 这一类型就是CSSStyleSheet 即CSS样式表类型,包括了之前 style 对象所不包括的外部样式表以及嵌入样式表 其中 ...

  5. 第62节:探索Java中的网络编程技术

    前言 感谢! 承蒙关照~ 探索Java中的网络编程技术 网络编程就是io技术和网络技术的结合,网络模型的定义,只要共用网络模型就可以两者连接.网络模型参考. 一座塔有七层,我们需要闯关. 第一层物理层 ...

  6. 客户端ip获取蹲坑启示: 不要侥幸

    怎么获取一个客户端ip ? 我想这个问题,在网上遍地都是答案! 而且多半是像下面这样: public static String getIpAddress(HttpServletRequest req ...

  7. php 中构造函数和析构函数

    构造函数: 在对象实例化时被调用,一个类中只能有一个构造函数,在类中起初始化的作用. 析构函数: 在对象结束时被自动调用. 话不多说,用一段代码来说明两者的区别: <?php //定义一个类 c ...

  8. spark面试总结4

    Spark on Yarn面试篇04 1.MRV1有哪些不足? 1)可扩展性(对于变化的应付能力) a) JobTracker内存中保存用户作业的信息 b) JobTracker使用的是粗粒度的锁 2 ...

  9. Oracle客户端连接数据库配置

    配置文件和路径 配置文件:tnsnames.ora 默认路径:%ORACLE_HOME%\network\admin\tnsnames.ora,%ORACLE_HOME%通常在环境变量中使用. 我的路 ...

  10. IdentityServer4(7)- 使用客户端认证控制API访问(客户端授权模式)

    一.前言 本文已更新到 .NET Core 2.2 本文包括后续的Demo都会放在github:https://github.com/stulzq/IdentityServer4.Samples (Q ...