c# FastReport开发报表--没讲如何建立fastreport报表模板

 一个需要看的网址:

http://www.cppcns.com/ruanjian/csharp/492282.html

1 打开visual studio 2010创建一个工程名称为WfmFastReport,编辑界面,然后添加FastReport.dll ,FastReport.Bars.dll,FastReport.Editor.dll的引用。

FastReport.dll ,FastReport.Bars.dll,FastReport.Editor.dll在下载包里有的。

代码非常简单,如下:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

using FastReport;
using FastReport.Editor;

namespace WfmFastReport
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private DataSet data;//定义dataset 类型字段 类下 方法外定义 会被此类下所有方法调用

//构建数据源 的 按钮 方法
        private void button1_Click(object sender, EventArgs e)
        {  

            string conStr = @"server=***;user id=**;password=***;initial catalog=****";
            try
            {
                SqlConnection con = new SqlConnection(conStr);
                con.Open();
                SqlCommand sqlcmd = new SqlCommand();
                sqlcmd.Connection = con;
                sqlcmd.CommandText = "select top 100 * from item";
                SqlDataAdapter sda = new SqlDataAdapter(sqlcmd);
                data = new DataSet();
                sda.Fill(data);
                con.Close();
                sda.Dispose();
                MessageBox.Show("加载数据成功!");
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
    
        }

//显示 打印 报表

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                FastReport.Report report = new FastReport.Report();
                string filename = @"C:\Documents and Settings\Administrator\桌面\检查项目.frx";
                report.Load(filename);
                report.RegisterData(data);
                report.GetDataSource(data.Tables[0].TableName).Enabled = true;
                report.Show();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
    }
}

 

检查项目.frx文件就是FastReport设计出的报表模板,非常简单,有兴趣的朋友可以试一试。

下面看看效果:

 

posted @ 2022-06-22 22:49  techNote  阅读(781)  评论(0编辑  收藏  举报