【问题标题】:Crystal Reports - Search DependenciesCrystal Reports - 搜索依赖项
【发布时间】:2012-05-25 14:01:46
【问题描述】:

是否有工具可以让您搜索多个不同的水晶报表以查看特定表格/视图/SP 的使用位置?

场景是这样的:我们有超过 200 份报告,因此在对视图或存储过程进行更改时,如果不打开每个报告并检查“数据库专家”或“数据源位置”,就很难找到哪些报告会受到影响”。

我已经在他们身上尝试过 Agent Ransack,但它没有选择任何表或视图名称。

【问题讨论】:

    标签: crystal-reports dependencies crystal-reports-2008


    【解决方案1】:

    我从未找到执行此操作的工具,因此在 C# .Net 4.0 中推出了我自己的工具。

    如果水晶报表使用“SQL 命令”而不是拖入表格,那就有点棘手了。我建议只搜索 TableName 而不是完全限定的 Database.dbo.TableName - 因为这可能在粘贴的 SQL 命令中被省略了。

    用法:

    var reports = CrystalExtensions.FindUsages("C:/Reports", "table_name");
    

    代码:

    namespace Crystal.Helpers
    {
        using System.Collections.Generic;
        using System.IO;
        using System.Linq;
        using System.Reflection;
        using CrystalDecisions.CrystalReports.Engine;
        using Microsoft.CSharp.RuntimeBinder;
    
        public static class CrystalExtensions
        {
            public static List<string> FindUsages(string directory, string tableName)
            {
                var result = new List<string>();
    
                foreach (var file in Directory.EnumerateFiles(directory, "*.rpt", SearchOption.AllDirectories))
                {
                    using (var report = new ReportClass { FileName = file })
                    {
                        if (report.Database == null) continue;
    
                        var tables = report.Database.Tables.ToList();
                        var hasTable = tables.Any(x => x.Name == tableName || x.GetCommandText().Contains(tableName));
    
                        if (hasTable)
                            result.Add(file);
                    }
                }
    
                return result;
            }
    
            public static List<Table> ToList(this Tables tables)
            {
                var list = new List<Table>();
                var enumerator = tables.GetEnumerator();
    
                while (enumerator.MoveNext())
                    list.Add((Table)enumerator.Current);
    
                return list;
            }
    
            public static string GetCommandText(this Table table)
            {
                var propertyInfo = table.GetType().GetProperty("RasTable", BindingFlags.NonPublic | BindingFlags.Instance);
    
                try
                {
                    return ((dynamic)propertyInfo.GetValue(table, propertyInfo.GetIndexParameters())).CommandText;
                }
                catch (RuntimeBinderException)
                {
                    return ""; // for simplicity of code above, really should return null
                }
            }
        }
    }
    

    希望有帮助!

    【讨论】:

    • 非常有用...谢谢。我利用您的知识为自己编写了一个简单的控制台工具,我将研究编写一个 Visual Studio 自定义扩展或其他可以验证 Crystal 报表中对 SQL 数据库项目的引用的东西。我们有很多这样的报告...... 颤抖
    【解决方案2】:

    在此处查看问题: Any way to search inside a Crystal Report

    另一种选择是使用您自己的软件来完成此操作,但这可能比您预期的要耗时。或者,找一个已经这样做过的人 :) 如果你找到了可行的方法,请让我们其他人知道,因为我们都在同一条船上。祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-15
      • 1970-01-01
      • 2011-09-12
      • 2021-12-25
      • 2016-09-20
      • 2018-06-21
      • 1970-01-01
      相关资源
      最近更新 更多