遗忘海岸

江湖程序员 -Feiph(LM战士)

导航

< 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

统计

动态创建报表XRChart

重点是不指定Chart的DataSource与Series1的datasource

动态加载报表

复制代码
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 DevExpress.XtraReports.UI;
using System.Reflection;
using System.IO;
using System.Collections;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private Assembly LoadAssembly()
        {
            var path=Path.Combine( AppDomain.CurrentDomain.BaseDirectory ,@"Plugs\ClassLibrary1.dll");

            return Assembly.LoadFrom(path);
             
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            var assembly = LoadAssembly();
            var rpt = assembly.CreateInstance("ClassLibrary1.XtraReport2") as XtraReport;
            var parent = assembly.CreateInstance("ClassLibrary1.PRIem");
            var itemType= assembly.GetType("ClassLibrary1.RItem");
            var ptyName = itemType.GetProperty("Name");
            var ptyNum = itemType.GetProperty("Num");
            var listType= typeof(List<>).MakeGenericType(itemType);
            var list= Activator.CreateInstance(listType) as IList;
            var rnd = new Random(Environment.TickCount);
            for (int i = 0; i < 4; i++)
            {
                var item = Activator.CreateInstance(itemType);
                ptyName.SetValue(item, "名称" + i,null);
                ptyNum.SetValue(item, rnd.Next(0, 100),null);
                list.Add(item);
            }
            var ptyList= parent.GetType().GetProperty("RItemList");
            ptyList.SetValue(parent, list, null);
            Console.WriteLine("it");
            #region 静态方式
            //var list = list
            //var rnd = new Random(Environment.TickCount);
            //for (int i = 0; i < 5; i++)
            //{
            //    var it = new RItem() { Name = "名称" + i, Num = rnd.Next(0, 100) };
            //    list.Add(it);
            //}
            //var pList = new List<PRIem>();
            //pList.Add(new PRIem() { RItemList = list, Name = "parent" });
            #endregion

            rpt.AllControls<XRTableCell>().ToList().ForEach(cell =>
            {
                cell.Font = new System.Drawing.Font("宋体", 10.0F);

            });
            rpt.AllControls<XRLabel>().ToList().ForEach(lbl =>
            {
                if (lbl.Name == "xrLabel1") return;
                lbl.Font = new System.Drawing.Font("宋体", 10.0F);
            });
            if (list.Count <= 0) throw new Exception("未提供有效列表!");

            rpt.DataSource = new List<Object>(){parent};
            rpt.RequestParameters = false;
            rpt.PrintingSystem.ShowMarginsWarning = false;
            rpt.PrintingSystem.ShowPrintStatusDialog = false;
            ReportPrintTool printTool = new ReportPrintTool(rpt);
            printTool.Report.CreateDocument(false);
            printTool.PrintingSystem.ShowMarginsWarning = false;
            Application.DoEvents();
            var showDialog = true;
            if (showDialog)
            {
                printTool.ShowPreviewDialog();
            }
            else
            {
                printTool.Print();
            }

        }
    }
}
View Code
复制代码

 

posted on   遗忘海岸  阅读(213)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· [AI/GPT/综述] AI Agent的设计模式综述
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
历史上的今天:
2014-09-04 关于InvokeMethod Activity的异步调用
2012-09-04 .Net事件&委托备忘
2012-09-04 匿名委托注册事件的触发
2008-09-04 T-SQL 选择某一记录的前后相关记录
点击右上角即可分享
微信分享提示