如何获取水晶报表所有查询

问题描述 投票:0回答:2

我的项目中有24个数据库。一个数据库已分离为另外 3 个数据库。现在,我必须更改水晶报表的所有查询。

如何通过C#批量更新所有查询?是否可以? 或者 如何找出需要更改的问题?

c# sql-server database crystal-reports multi-database
2个回答
0
投票

这不是要求开发者有授权的RAS SDK吗?

无论如何,这可以通过我的 CR 开发人员许可证进行 AFAICT,所以很高兴开始。
我确实对其进行了一些修改以使用 StringBuilder 等,如下所示...... 还有

  • 使用 log4net 转储查询...
  • 显示 RPT 的加载位置 来自 (rptSourceName)
  • 显示来自 RPT SummaryInfo 对象的数据

      private void DumpQueries(CrystalDecisions.CrystalReports.Engine.ReportDocument doc, string rptSourceName)
    {
        try
        {
            //CrystalDecisions.CrystalReports.Engine.ReportDocument boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
    
            CommandTable boCommandTable;
            var boReportClientDocument = doc.ReportClientDocument;
            var boDataDefController = boReportClientDocument.DataDefController;
            var boDatabase = boDataDefController.Database;
    
            var reportSummary = doc.SummaryInfo;
            var reportName = doc.Name ?? doc.FileName;
    
            //return; // disabled for now.
    
            //foreach (dynamic table in doc.ReportClientDocument.DatabaseController.Database.Tables)
            //{
            //    if (table.ClassName == "CrystalReports.CommandTable")
            //    {
            //        string commandSql = table.CommandText;
    
            //        Log?.DebugFormat(@"Report object: {0} - SQL: {1}", doc.Name, commandSql);
            //    }
            //}
    
            // revised based on  https://stackoverflow.com/questions/43208449/how-to-get-crystal-report-all-queries/57822774#57822774
    
    
    
            var sb = new StringBuilder();
            sb.AppendLine();
            sb.AppendLine("---------- Summary -----------");
            sb.AppendLine($@"Report source: {rptSourceName}");
            sb.AppendLine($"Title: {reportSummary.ReportTitle}");
            sb.AppendLine($"Subject: {reportSummary.ReportSubject}");
            sb.AppendLine($"Comments: {reportSummary.ReportComments}");
            sb.AppendLine($"Author: {reportSummary.ReportAuthor}");
            sb.AppendLine($"Keywords: {reportSummary.KeywordsInReport}");
            sb.AppendLine($"Last Saved By: {reportSummary.LastSavedBy}");
            sb.AppendLine($"Revision #: {reportSummary.RevisionNumber}");
            sb.AppendLine("------------------------------");
    
    
    
            for (var i = 0; i < boDatabase.Tables.Count; i++)
            {
                ISCRTable tableObject = boDatabase.Tables[i];
    
                if (tableObject.ClassName == "CrystalReports.Table")
                {
                    sb.AppendLine(@"Table " + i + ": " + tableObject.Name);
    
                }
                else
                {
                    boCommandTable = (CrystalDecisions.ReportAppServer.DataDefModel.CommandTable)boDatabase.Tables[i];
                    sb.AppendLine(@"Query " + i + ": " + boCommandTable.CommandText);
                }
    
    
            }
    
            sb.AppendLine("------------------------------");
            sb.AppendLine("");
    
            sb.AppendLine("--------- Subreports ---------");
    
            foreach (string subName in boReportClientDocument.SubreportController.GetSubreportNames())
            {
    
    
    
                SubreportClientDocument subRcd = boReportClientDocument.SubreportController.GetSubreport(subName);
                sb.AppendLine($@"Subreport object: {subRcd.Name}");
                sb.AppendLine("------------------------------");
                for (var i = 0; i < boDatabase.Tables.Count; i++)
                {
                    CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable tableObject = boDatabase.Tables[i];
    
                    if (tableObject.ClassName == "CrystalReports.Table")
                    {
                        sb.AppendLine(@"Table " + i + ": " + tableObject.Name);
                    }
                    else
                    {
                        boCommandTable = (CrystalDecisions.ReportAppServer.DataDefModel.CommandTable)subRcd.DatabaseController.Database.Tables[i];
                        sb.AppendLine(@"Query " + i + ": " + boCommandTable.CommandText);
                    }
                    //sql += Environment.NewLine;
                }
    
    
            }
    
            Log?.Debug($@"Report contents: {  sb.ToString()}");
    
        }
        catch (Exception ex)
        {
            Log?.Error(ex);
            throw;
        }
    }
    

生成:

    Report contents: 
---------- Summary -----------
Report source: zzzzzzzzz
Title: zzzzzzzz
Subject: zzzzzzzzz
Comments: zzzzzzzzz
Author: XXXXXXX
Keywords: XXXXXXX
Last Saved By:XXXXXXX
Revision #: 411
------------------------------
Query 0: SELECT B1.Brkey,I1.inspkey,
   B1.Strucname,
   P2.Pon_Session_Batch_Key,
   B1.Bridge_Id,
   B1.Struct_Num,
...
...
...

0
投票
private string getSQL(InfoObject iObject, EnterpriseSession eSession)
{
    CrystalDecisions.CrystalReports.Engine.ReportDocument boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
    CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument boReportClientDocument;
    CrystalDecisions.ReportAppServer.Controllers.DataDefController boDataDefController;
    CrystalDecisions.ReportAppServer.DataDefModel.Database boDatabase;
    CrystalDecisions.ReportAppServer.DataDefModel.CommandTable boCommandTable;

    // Load the report using the CR .NET SDK and get a handle on the ReportClientDocument
    boReportDocument.Load(iObject, eSession);
    boReportClientDocument = boReportDocument.ReportClientDocument;

    // Use the DataDefController to access the database and the command table.
    // Then display the current command table SQL in the textbox.
    boDataDefController = boReportClientDocument.DataDefController;
    boDatabase = boDataDefController.Database;

    string sql;
    sql = "";

    for (int i = 0; i < boDatabase.Tables.Count; i++)
    {
        CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable tableObject = boDatabase.Tables[i];

        if (tableObject.ClassName == "CrystalReports.Table")
        {
            sql = sql + "Table " + i + ": " + tableObject.Name;
        }
        else
        {
            boCommandTable = (CrystalDecisions.ReportAppServer.DataDefModel.CommandTable)boDatabase.Tables[i];
            sql = sql + "Query " + i + ": " + boCommandTable.CommandText;
        }
        sql += Environment.NewLine;

    }

    foreach (string subName in boReportClientDocument.SubreportController.GetSubreportNames())
    {
        CrystalDecisions.ReportAppServer.Controllers.SubreportClientDocument subRCD = boReportClientDocument.SubreportController.GetSubreport(subName);

        for (int i = 0; i < boDatabase.Tables.Count; i++)
        {
            CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable tableObject = boDatabase.Tables[i];

            if (tableObject.ClassName == "CrystalReports.Table")
            {
                sql = sql + "Table " + i + ": " + tableObject.Name;
            }
            else
            {
                boCommandTable = (CrystalDecisions.ReportAppServer.DataDefModel.CommandTable)subRCD.DatabaseController.Database.Tables[i];
                sql = sql + "Subreport " + subName + " - Query " + i + ": " + boCommandTable.CommandText;
            }
            sql += Environment.NewLine;
        }

    }


    // Clean up
    return sql;

} 
© www.soinside.com 2019 - 2024. All rights reserved.