Ejemplo n.º 1
0
 public static void ProcessReport(ISCDReportClientDocument report, Utf8JsonWriter jsonw, string reportDoc = "ReportClientDocument")
 {
     jsonw.WritePropertyName(reportDoc);
     jsonw.WriteStartObject();
     jsonw.WriteString("DisplayName", report.DisplayName);
     jsonw.WriteString("IsModified", report.IsModified.ToStringSafe());
     jsonw.WriteString("IsOpen", report.IsOpen.ToStringSafe());
     jsonw.WriteString("IsReadOnly", report.IsReadOnly.ToStringSafe());
     jsonw.WriteString("LocaleID", report.LocaleID.ToStringSafe());
     jsonw.WriteString("MajorVersion", report.MajorVersion.ToStringSafe());
     jsonw.WriteString("MinorVersion", report.MinorVersion.ToStringSafe());
     jsonw.WriteString("Path", report.Path);
     jsonw.WriteString("PreferredViewingLocaleID", report.PreferredViewingLocaleID.ToStringSafe());
     jsonw.WriteString("ProductLocaleID", report.ProductLocaleID.ToStringSafe());
     jsonw.WriteString("ReportAppServer", report.ReportAppServer);
     Controllers.ProcessCustomFunctionController(report.CustomFunctionController, jsonw);
     Controllers.ProcessDatabaseController(report.DatabaseController, jsonw);
     Controllers.ProcessDataDefController(report.DataDefController, jsonw);
     Controllers.ProcessPrintOutputController(report.PrintOutputController, jsonw);
     Controllers.ProcessReportDefController(report.ReportDefController, jsonw);
     ReportDefModel.ProcessReportOptions(report.ReportOptions, jsonw);
     Controllers.ProcessSubreportController(report.SubreportController, jsonw);
     DataDefModel.ProcessSummaryInfo(report.SummaryInfo, jsonw);
     jsonw.WriteEndObject();
 }
Ejemplo n.º 2
0
        public RptDefinitionWriter(string filename)
        {
            _createdReport = true;
            _report        = new ReportDocument();
            _report.Load(filename, OpenReportMethod.OpenReportByTempCopy);
            _rcd = _report.ReportClientDocument;

            _oleCompoundFile = new CompoundFile(filename);

            Trace.WriteLine("Loaded report");
        }
Ejemplo n.º 3
0
        public RptDefinitionWriter(string filename)
        {
            _createdReport = true;
            _report = new ReportDocument();
            _report.Load(filename, OpenReportMethod.OpenReportByTempCopy);
            _rcd = _report.ReportClientDocument;

            _oleCompoundFile = new CompoundFile(filename);

            Trace.WriteLine("Loaded report");
        }
Ejemplo n.º 4
0
        private void GetReportClientTables(ISCDReportClientDocument reportClientDocument, XmlWriter writer)
        {
            writer.WriteStartElement("Tables");

            foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table table in reportClientDocument.DatabaseController.Database.Tables)
            {
                GetTable(table, writer);
            }

            writer.WriteEndElement();
        }
Ejemplo n.º 5
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_report != null && _createdReport)
                {
                    _report.Dispose();
                }

                _report = null;
                _rcd    = null;

                if (_oleCompoundFile != null)
                {
                    ((IDisposable)_oleCompoundFile).Dispose();
                    _oleCompoundFile = null;
                }
            }
        }
 public static void ProcessReport(ISCDReportClientDocument report, XmlWriter xmlw, string reportDoc = "ReportClientDocument")
 {
     xmlw.WriteStartElement(reportDoc);
     xmlw.WriteElementString("DisplayName", report.DisplayName);
     xmlw.WriteElementString("IsModified", report.IsModified.ToStringSafe());
     xmlw.WriteElementString("IsOpen", report.IsOpen.ToStringSafe());
     xmlw.WriteElementString("IsReadOnly", report.IsReadOnly.ToStringSafe());
     xmlw.WriteElementString("LocaleID", report.LocaleID.ToStringSafe());
     xmlw.WriteElementString("MajorVersion", report.MajorVersion.ToStringSafe());
     xmlw.WriteElementString("MinorVersion", report.MinorVersion.ToStringSafe());
     xmlw.WriteElementString("Path", report.Path);
     xmlw.WriteElementString("PreferredViewingLocaleID", report.PreferredViewingLocaleID.ToStringSafe());
     xmlw.WriteElementString("ProductLocaleID", report.ProductLocaleID.ToStringSafe());
     xmlw.WriteElementString("ReportAppServer", report.ReportAppServer);
     Controllers.Process(report.CustomFunctionController, xmlw);
     Controllers.Process(report.DatabaseController, xmlw);
     Controllers.Process(report.DataDefController, xmlw);
     Controllers.Process(report.PrintOutputController, xmlw);
     Controllers.Process(report.ReportDefController, xmlw);
     ReportDefModel.ProcessReportOptions(report.ReportOptions, xmlw);
     Controllers.Process(report.SubreportController, xmlw);
     DataDefModel.ProcessSummaryInfo(report.SummaryInfo, xmlw);
     xmlw.WriteEndElement();
 }
Ejemplo n.º 7
0
 public RptDefinitionWriter(ReportDocument value)
 {
     _report = value;
     _rcd    = _report.ReportClientDocument;
 }
Ejemplo n.º 8
0
        public static void ReplaceTextsRpt(String RptFilePath, String OldText, String NewText, String DestFolder, String DestFilePrefix)
        {
            var CrDoc = new ReportDocument();

            Console.WriteLine(String.Format("Loading file {0}", RptFilePath));
            try {
                CrDoc.Load(RptFilePath);
                Console.WriteLine(String.Format("File {0} loaded successfully, report title: \"{1}\"", RptFilePath, CrDoc.SummaryInfo.ReportTitle));
            } catch (Exception e) {
                Console.WriteLine(String.Format("Error loading {0}: {1}", RptFilePath, e.Message));
                return;
            }
            ISCDReportClientDocument ClientDoc = CrDoc.ReportClientDocument;
            int ChangesCount = 0;

            foreach (var RepObj in CrDoc.ReportDefinition.ReportObjects)
            {
                switch (RepObj.GetType().ToString())
                {
                case "CrystalDecisions.CrystalReports.Engine.TextObject":
                    TextObject TextObj = (TextObject)RepObj;
                    if (TextObj.Text.Contains(OldText))
                    {
                        String TextBefore = TextObj.Text;
                        TextObj.Text = TextObj.Text.Replace(OldText, NewText);
                        Console.WriteLine("Replacing static text:");
                        Console.WriteLine(TextBefore);
                        Console.WriteLine("With:");
                        Console.WriteLine(TextObj.Text);
                        ChangesCount++;
                    }
                    break;

                case "CrystalDecisions.CrystalReports.Engine.FieldObject":
                    FieldObject FldObj = (FieldObject)RepObj;
                    if (FldObj.DataSource.GetType().ToString() == "CrystalDecisions.CrystalReports.Engine.FormulaFieldDefinition")
                    {
                        FormulaFieldDefinition FldDef = (FormulaFieldDefinition)FldObj.DataSource;
                        if (FldDef.Text.Contains(OldText))
                        {
                            String TextBefore = FldDef.Text;
                            FldDef.Text = FldDef.Text.Replace(OldText, NewText);
                            Console.WriteLine("Replacing formula:");
                            Console.WriteLine(Regex.Escape(TextBefore));
                            Console.WriteLine("With:");
                            Console.WriteLine(Regex.Escape(FldDef.Text));
                            ChangesCount++;
                        }
                    }
                    break;
                }
            }
            if (ChangesCount > 0)
            {
                Console.WriteLine(String.Format("No of changes in {0}: {1}", RptFilePath, ChangesCount));
                FileInfo oldRptFileInfo = new FileInfo(RptFilePath);
                String   NewFileName    = oldRptFileInfo.FullName.Replace(oldRptFileInfo.DirectoryName, DestFolder).Replace(@"\" + oldRptFileInfo.Name, @"\" + DestFilePrefix + oldRptFileInfo.Name);
                try {
                    CrDoc.SaveAs(NewFileName);
                    Console.WriteLine(String.Format("Saved as {0}", NewFileName));
                } catch (Exception e) {
                    Console.WriteLine(String.Format("Error saving {0}: {1}", NewFileName, e.Message));
                }
            }
            else
            {
                Console.WriteLine(String.Format("Number \"New text\" occurrences in {0}, skipping", RptFilePath));
            }
        }
Ejemplo n.º 9
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_report != null && _createdReport)
                    _report.Dispose();

                _report = null;
                _rcd = null;

                if (_oleCompoundFile != null)
                {
                    ((IDisposable)_oleCompoundFile).Dispose();
                    _oleCompoundFile = null;
                }
            }
        }
Ejemplo n.º 10
0
        private void GetReportClientTables(ISCDReportClientDocument reportClientDocument, XmlWriter writer)
        {
            writer.WriteStartElement("Tables");

            foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table table in reportClientDocument.DatabaseController.Database.Tables)
            {
                GetTable(table, writer);
            }

            writer.WriteEndElement();
        }
Ejemplo n.º 11
0
 public RptDefinitionWriter(ReportDocument value)
 {
     _report = value;
     _rcd = _report.ReportClientDocument;
 }
Ejemplo n.º 12
0
        public Dictionary <string, object> Execute(OutputDocument document, Dictionary <string, object> namedPassThroughParameters)
        {
            Dictionary <string, object> results = new Dictionary <string, object>();
            bool   goOn      = true;
            int    retry     = 0;
            string errorText = string.Empty;

            while (goOn) //Loop to be able to make retries of printouts in case of exceptions.
            {
                //There can not be more than 75 reports open at the same time.
                bool exitWaitLoop = false;

                while (!exitWaitLoop)
                {
                    lock (_NumOfConcurrentJobsLockObj)
                    {
                        if (_NumberOfConcurrentJobs < 75)
                        {
                            _NumberOfConcurrentJobs++;
                            exitWaitLoop = true;
                        }
                    }

                    if (!exitWaitLoop)
                    {
                        Thread.Sleep(25);
                    }
                }

                try
                {
                    errorText = string.Empty;
                    using (ReportDocument report = GetReportDocument(document.ReportID, document.ReportFile, out errorText))
                    {
                        if (report == null || !string.IsNullOrEmpty(errorText))
                        {
                            throw new Exception("Error loading report\r\n\r\n" + errorText);
                        }

                        DataSet dataSet = null;

                        try
                        {
                            errorText = string.Empty;
                            if (document.MetaParameters[StdMetaParamNames.DocumentIDKey] == "GenericReport")
                            {
                                ConnectionInfo info = new ConnectionInfo();
                                info.ServerName = _configurationParameters[CONFPARAM_DBNAME];
                                info.UserID     = _configurationParameters[CONFPARAM_DBUSER];
                                info.Password   = _configurationParameters[CONFPARAM_DBPASS];

                                SetReportConnectionInfo(info, report);

                                ApplyReportParameters(document.Parameters, report, out errorText);
                            }
                            else
                            {
                                dataSet = new DataSet();
                                document.Data.Seek(0, SeekOrigin.Begin);
                                dataSet.ReadXml(document.Data);

                                //DateTime before = DateTime.Now;
                                report.SetDataSource(dataSet);
                                //DateTime after = DateTime.Now;

                                //System.Diagnostics.Debug.WriteLine("SetDataSource: " + (after - before).ToString());
                            }

                            if (!string.IsNullOrEmpty(errorText))
                            {
                                throw new Exception(errorText);
                            }

                            if (Convert.ToBoolean(_configurationParameters[CONFPARAM_OUTPUTENABLE]))
                            {
                                PrintReportOptions clientReportOptions = new PrintReportOptions();
                                clientReportOptions.PrinterName    = document.PrinterDeviceName;
                                clientReportOptions.NumberOfCopies = int.Parse(document.MetaParameters[StdMetaParamNames.NumberOfCopiesKey]);
                                clientReportOptions.Collated       = true;
                                clientReportOptions.JobTitle       = document.OutputJobId + "_" + document.OutputJobSequence.ToString();

                                ISCDReportClientDocument clientDoc = report.ReportClientDocument;

                                try
                                {
                                    clientDoc.PrintOutputController.PrintReport(clientReportOptions);
                                }
                                catch (Exception ex)
                                {
                                    throw new PrintFailureException("Print out failed", ex);
                                }
                            }

                            try
                            {
                                byte[] exportData   = null;
                                Stream exportStream = null;

                                lock (_exportLockObj) //Lock this part to avoid unhandled exceptions
                                {
                                    exportStream = report.ExportToStream(ExportFormatType.PortableDocFormat);
                                }

                                exportData = new byte[exportStream.Length];
                                exportStream.Read(exportData, 0, Convert.ToInt32(exportStream.Length));
                                exportStream.Close();

                                if (results.ContainsKey(StdResultParamNames.BinaryResultKey))
                                {
                                    results.Remove(StdResultParamNames.BinaryResultKey);
                                }

                                results.Add(StdResultParamNames.BinaryResultKey, exportData);
                            }
                            catch {} //Ignore exceptions from PDF export.
                        }
                        finally
                        {
                            if (dataSet != null)
                            {
                                dataSet.Dispose();
                            }

                            try { report.Close(); }
                            catch { }
                            finally { report.Dispose(); }

                            lock (_NumOfConcurrentJobsLockObj)
                            {
                                _NumberOfConcurrentJobs--;
                            }

                            GC.Collect();
                            GC.WaitForPendingFinalizers();
                            GC.Collect();
                        }
                    }
                    goOn = false;
                }
                catch (PrintFailureException ex)
                {
                    //Make three tries to print.
                    if (retry >= 3)
                    {
                        string txt = "Error printing Crystal Report\r\n\r\n" + ex.Message;
                        if (ex.InnerException != null)
                        {
                            txt += "\r\n" + ex.InnerException.Message;
                            if (ex.InnerException.InnerException != null)
                            {
                                txt += "\r\n" + ex.InnerException.InnerException.Message;
                            }
                        }
                        throw new Exception(txt);
                    }
                    else
                    {
                        retry++;
                        goOn = true;
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                catch (Exception ex)
                {
                    goOn = false;
                    string txt = "Error printing Crystal Report\r\n\r\n" + ex.Message;
                    if (ex.InnerException != null)
                    {
                        txt += "\r\n" + ex.InnerException.Message;
                        if (ex.InnerException.InnerException != null)
                        {
                            txt += "\r\n" + ex.InnerException.InnerException.Message;
                        }
                    }
                    throw new Exception(txt);
                }
            }

            return(results);
        }