FastReport.Net

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
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();
    }
 
  }
}

  

posted @   ®Geovin Du Dream Park™  阅读(875)  评论(2编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示