duheng
2025-02-17 fea4a016cdc369be9001fb6dd15295eb68e2381f
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
using DevExpress.CodeParser;
using DevExpress.XtraReports.UI;
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
 
namespace HStation.ReportFile.SDK
{
    public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
    {
        public XtraReport1()
        {
            InitializeComponent();
            ininal();
        }
 
        private void ininal()
        {
            // 获取数据源
            List<Product> dataSource = CreateSampleProductList();
            this.DataSource = dataSource;
 
            // this.xrTable1.DataBindings.Add("Text", dataSource, "Price");
            //  this.DataSource = dataSource;
            this.xrTable2.DataBindings.Add("Text", dataSource, "Price");
            this.xrTable2.DataBindings.Add("Text", dataSource, "ProductName");
            // 设置报表的数据源
            // this.DataSource = dataSource;
 
            /*      // 创建表头
                  XRTableRow headerRow = new XRTableRow();
                  headerRow.Cells.Add(new XRTableCell { Text = "ProductName" });
                  headerRow.Cells.Add(new XRTableCell { Text = "Price" });
                  xrTable1.Rows.Add(headerRow);*/
 
            /*      // 自动创建数据行和单元格并绑定数据
                  foreach (var item in dataSource)
                  {
                      XRTableRow dataRow = new XRTableRow();
 
                      XRTableCell productNameCell = new XRTableCell();
                      productNameCell.DataBindings.Add("Text", dataSource, "ProductName");
                      dataRow.Cells.Add(productNameCell);
 
                      XRTableCell priceCell = new XRTableCell();
                      priceCell.DataBindings.Add("Text", dataSource, "Price");
                      dataRow.Cells.Add(priceCell);
 
                      xrTable1.Rows.Add(dataRow);
                  }*/
        }
 
        public class Product
        {
            public string ProductName { get; set; }
            public decimal Price { get; set; }
        }
 
        public List<Product> CreateSampleProductList()
        {
            List<Product> products = new List<Product>
    {
        new Product { ProductName = "苹果", Price = 5.99m },
        new Product { ProductName = "香蕉", Price = 3.99m },
        new Product { ProductName = "橙子", Price = 4.99m }
    };
 
            return products;
        }
    }
}