Crystal Report報表開發(八)_The maximum report processing jobs limit configured by your system administrator has been reached.

 

最近由於需要在大量rpt檔案中去search是否有要替換的關鍵字
簽名字有一些人員職務調整就更換人員名稱
但尷尬的是報表檔裡面人名是直接寫死的.....>~<
而誕生需要寫這段程式的小需求

為何要寫程式盤點?
因為rpt檔案數量大概有300個吧每一個都一個個打開來盤點大概2~3天就過去了
而且下次又有類似需求
你要花一樣多時間甚至更久......


在此用vs2008來開發 水晶報表的小程式
創建好的winform專案
直接跑

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 System.IO;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportAppServer;
using CrystalDecisions.ReportSource;

namespace CrystalReportFilterTool
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //Control.CheckForIllegalCrossThreadCalls = false;
            /*
            for (int i = 1; i <= 100; i++)
            {
                this.textBox1.Text += "item." + i.ToString();
                this.textBox1.Text += Environment.NewLine;
            }*/
            string keyWord = "XXXX";

            var rpt_files = Directory.GetFiles(@"D:\SOM_Local\CR10_rpt", "*.rpt");
            foreach (string file in rpt_files)
            {
                try
                {
                    Console.WriteLine(String.Format("Processing {0}...", file));

                    FileInfo fi = new FileInfo(file);

                    var doc = new ReportDocument();
                    doc.Load(file);
                    
                    int effectCnt = 0;
                    StringBuilder sb = new StringBuilder();


                    foreach (ReportObject obj in doc.ReportDefinition.ReportObjects)
                    {
                        if (obj.GetType().Name == "TextObject" && ((TextObject)obj).Text.Contains(keyWord))
                        {
                            effectCnt++;
                            sb.AppendLine(string.Format("TextObject Name:{0},Value:{1}", ((TextObject)obj).Name, ((TextObject)obj).Text));
                            
                            //this.textBox1.Text += string.Format("TextObject Name:{0},Value:{1}", ((TextObject)obj).Name, ((TextObject)obj).Text);
                            //this.textBox1.Text += Environment.NewLine;
                        }
                    }

                    if (doc.DataDefinition.FormulaFields.Count > 0)
                    {
                        //this.textBox1.Text += fi.Name;
                        //this.textBox1.Text += Environment.NewLine;
                        
                        //this.listBox1.Items.Add(fi.Name);

                        foreach (FormulaFieldDefinition field in doc.DataDefinition.FormulaFields)
                        {
                            if (field.Name.Contains(keyWord))
                            {
                                effectCnt++;
                                sb.AppendLine(String.Format("Formula Name:{0} ,Formula Value:{1}", field.Name, field.Text));
                                //this.textBox1.Text += String.Format("Formula Name:{0} ,Formula Value:{1}", field.Name, field.Text);
                                //this.textBox1.Text += Environment.NewLine;
                            }
                        }
                    }

                    if(effectCnt >0){
                        this.textBox1.Text += string.Format("report file:{0}" , fi.Name) + Environment.NewLine;
                        this.textBox1.Text += sb.ToString();
                        this.textBox1.Text += Environment.NewLine;
                    }
                }
                catch (Exception ex)
                {
                    continue;
                }

            }


        }
    }
}


那突然有報一個錯誤
The maximum report processing jobs limit configured by your system administrator has been reached.

機上就是記得ReportDocument物件doc
迴圈尾端記得.Close()跟.Dispose() 把記憶體資源給釋放乾淨即可。
太久沒用又稍微忘記了


Ref:
https://blog.csdn.net/ankun6003/article/details/102320463
https://stackoverflow.com/questions/9579914/crystal-reports-exception-the-maximum-report-processing-jobs-limit-configured-b

留言

這個網誌中的熱門文章

何謂淨重(Net Weight)、皮重(Tare Weight)與毛重(Gross Weight)

Architecture(架構) 和 Framework(框架) 有何不同?_軟體設計前的事前規劃的藍圖概念

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header