FastReport.Net

来源:https://www.cnblogs.com/geovindu/archive/2018/05/25/9088311.html
-Advertisement-
Play Games

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.... ...


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();
    }

  }
}

  


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 現有一份血壓數據,樣本記錄500條數據,包括三個值:血壓、是否抽煙、體重過重級別。 數據樣例: 血壓數據的可視化和分析(1)—— 利用 Excel 查看數據概況 在 Excel 中,利用散點圖首先對這三列數據進行可視化,瞭解數據分佈的概況。 可見收縮壓數據在250左右有一個明顯的分界,之前的數據都在 ...
  • 今天和大家分享的是自定義配置信息的讀取;近期有寫博客這樣的計劃,分別交叉來寫springboot方面和springcloud方面的文章,因為springboot預計的篇章很多,這樣cloud的文章就需要等到很後面才能寫了;分享這兩種文章的原因主要是為了方便自己查找資料使用和對將要使用的朋友起到便捷作 ...
  • maven作為一個項目構建工具,在開發的過程中很受歡迎,可以幫助管理項目中的bao依賴問題,另外它的很多功能都極大的減少了開發的難度,下麵來介紹maven的安裝及與eclipse的集成。 maven的官網地址為:http://maven.apache.org/ 下載步驟如下: 進入官網,點擊下載 進 ...
  • PHP匿名函數和閉包 匿名函數[官方文檔][2] 本篇文章的代碼測試使用的是[php線上測試工具][1]5.6 匿名函數 匿名函數就是沒有定義函數名的函數,php從5.3版本開始支持匿名函數 php ...
  • #coding:utf-8import random,stringdef GetPassword(length): # 隨機生成數字個數 Ofnum=random.randint(1,length) Ofletter=length-Ofnum # 選中ofnum個數字 slcNum=[random. ...
  • 隱藏圖不是什麼新鮮的東西,具體表現在大部分社交軟體中,預覽圖看到的是一張圖,而點開後看到的又是另一張圖。雖然很早就看到過這類圖片,但是一直沒有仔細研究過它的原理,今天思考了一下,發現挺有趣的,所以自己也寫了個簡單的演算法把兩張圖片合成為一張隱藏圖。 比如下麵這張圖。 當背景顏色為白色時,通常也就是在預 ...
  • 準備工作: 建立.NET Core Web Api項目 新建一個用於Api請求的UserInfo類 2、建立.NET Core Web項目 一、使用jQuery Ajax訪問 (一)、表單 [FromForm] 數據類型:Object ContenyType類型:application/x-www- ...
  • 這是一個ASP.NET Core2.0專題文章列表 ...
一周排行
    -Advertisement-
    Play Games
  • 概述:本文代碼示例演示瞭如何在WPF中使用LiveCharts庫創建動態條形圖。通過創建數據模型、ViewModel和在XAML中使用`CartesianChart`控制項,你可以輕鬆實現圖表的數據綁定和動態更新。我將通過清晰的步驟指南包括詳細的中文註釋,幫助你快速理解並應用這一功能。 先上效果: 在 ...
  • openGauss(GaussDB ) openGauss是一款全面友好開放,攜手伙伴共同打造的企業級開源關係型資料庫。openGauss採用木蘭寬鬆許可證v2發行,提供面向多核架構的極致性能、全鏈路的業務、數據安全、基於AI的調優和高效運維的能力。openGauss深度融合華為在資料庫領域多年的研 ...
  • openGauss(GaussDB ) openGauss是一款全面友好開放,攜手伙伴共同打造的企業級開源關係型資料庫。openGauss採用木蘭寬鬆許可證v2發行,提供面向多核架構的極致性能、全鏈路的業務、數據安全、基於AI的調優和高效運維的能力。openGauss深度融合華為在資料庫領域多年的研 ...
  • 概述:本示例演示了在WPF應用程式中實現多語言支持的詳細步驟。通過資源字典和數據綁定,以及使用語言管理器類,應用程式能夠在運行時動態切換語言。這種方法使得多語言支持更加靈活,便於維護,同時提供清晰的代碼結構。 在WPF中實現多語言的一種常見方法是使用資源字典和數據綁定。以下是一個詳細的步驟和示例源代 ...
  • 描述(做一個簡單的記錄): 事件(event)的本質是一個委托;(聲明一個事件: public event TestDelegate eventTest;) 委托(delegate)可以理解為一個符合某種簽名的方法類型;比如:TestDelegate委托的返回數據類型為string,參數為 int和 ...
  • 1、AOT適合場景 Aot適合工具類型的項目使用,優點禁止反編 ,第一次啟動快,業務型項目或者反射多的項目不適合用AOT AOT更新記錄: 實實在在經過實踐的AOT ORM 5.1.4.117 +支持AOT 5.1.4.123 +支持CodeFirst和非同步方法 5.1.4.129-preview1 ...
  • 總說周知,UWP 是運行在沙盒裡面的,所有許可權都有嚴格限制,和沙盒外交互也需要特殊的通道,所以從根本杜絕了 UWP 毒瘤的存在。但是實際上 UWP 只是一個應用模型,本身是沒有什麼許可權管理的,許可權管理全靠 App Container 沙盒控制,如果我們脫離了這個沙盒,UWP 就會放飛自我了。那麼有沒... ...
  • 目錄條款17:讓介面容易被正確使用,不易被誤用(Make interfaces easy to use correctly and hard to use incorrectly)限制類型和值規定能做和不能做的事提供行為一致的介面條款19:設計class猶如設計type(Treat class de ...
  • title: 從零開始:Django項目的創建與配置指南 date: 2024/5/2 18:29:33 updated: 2024/5/2 18:29:33 categories: 後端開發 tags: Django WebDev Python ORM Security Deployment Op ...
  • 1、BOM對象 BOM:Broswer object model,即瀏覽器提供我們開發者在javascript用於操作瀏覽器的對象。 1.1、window對象 視窗方法 // BOM Browser object model 瀏覽器對象模型 // js中最大的一個對象.整個瀏覽器視窗出現的所有東西都 ...