/// <summary>
        /// Loads report structure.
        /// </summary>
        /// <param name="templatePath">Report template path.</param>
        /// <returns>Created and inited report core.</returns>
        private ActiveReport3 _LoadReportStructure(string templatePath)
        {
            Debug.Assert(!string.IsNullOrEmpty(templatePath));

            // load report structure
            var rpt = new ActiveReport3();

            rpt.Document.CacheToDisk         = true;
            rpt.Document.CacheToDiskLocation = GetTempFullFileName();

            string filePath =
                ReportsGenerator.GetTemplateAbsolutelyPath(templatePath);

            using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                rpt.LoadLayout(fs);

            return(rpt);
        }
Exemplo n.º 2
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Starts reports operation.
        /// </summary>
        /// <param name="type">Selected reports operation.</param>
        /// <param name="reports">Reports to processing.</param>
        public void DoProcess(ProcessType type, IList <ReportStateDescription> reports)
        {
            Debug.Assert(null != _reports);
            Debug.Assert(null != reports);

            // dispose report only if it not selected for this operation and not loked
            ReportsGenerator generator = App.Current.ReportGenerator;

            for (int index = 0; index < _reports.Count; ++index)
            {
                ReportStateDescription report = _reports[index];
                if (!reports.Contains(report) && !report.IsLocked)
                {
                    generator.DisposeReport(report);
                }
            }

            // start process
            if (0 < _reports.Count)
            {
                switch (type)
                {
                case ProcessType.Preview:
                    _DoPreview(generator, reports);
                    break;

                case ProcessType.Print:
                    _DoPrint(generator, reports);
                    break;

                case ProcessType.Save:
                    _DoSave(generator, reports);
                    break;

                default:
                {
                    Debug.Assert(false);         // NOTE: not supported
                    break;
                }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves report routine.
        /// </summary>
        /// <param name="exporter">Exporter object.</param>
        /// <param name="exportDir">Export directory.</param>
        /// <param name="fileName">Export report file name (can be null).</param>
        /// <param name="fileExt">Export file extension.</param>
        /// <param name="generator">Report generator.</param>
        /// <param name="description">Report state descriiption.</param>
        /// <returns>Status messages.</returns>
        private MessageDetail _DoSaveReport(IDocumentExport exporter,
                                            string exportDir,
                                            string fileName,
                                            string fileExt,
                                            ReportsGenerator generator,
                                            ReportStateDescription description)
        {
            Debug.Assert(null != exporter);
            Debug.Assert(null != generator);
            Debug.Assert(null != description);
            Debug.Assert((null != exportDir) && (null != fileExt));

            MessageDetail detail       = null;
            string        fullFileName = null;

            try
            {
                string filename = (string.IsNullOrEmpty(fileName)) ?
                                  _ValidateFileName(description.ReportName) : fileName;
                fullFileName = Path.Combine(exportDir, filename + fileExt);

                if (null == description.Report)
                {
                    generator.RunReport(description);
                }

                exporter.Export(description.Report.Document, fullFileName);
                string message = App.Current.GetString("ReportPreviewSaveDoneFormat",
                                                       description.ReportName, fullFileName);
                detail = new MessageDetail(MessageType.Information, message);
            }
            catch (Exception ex)
            {
                string message = App.Current.GetString("ReportPreviewSaveFailFormat",
                                                       description.ReportName, fullFileName);
                detail = _DoExceptionRoutine(message, ex, generator, description);
            }

            return(detail);
        }
Exemplo n.º 4
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Does report preview.
        /// </summary>
        /// <param name="generator">Report generator object.</param>
        /// <param name="description">Report state description.</param>
        /// <returns>Operation status message.</returns>
        private MessageDetail _DoPreview(ReportsGenerator generator,
                                         ReportStateDescription description)
        {
            Debug.Assert(null != generator);
            Debug.Assert(null != description);

            MessageDetail detail = null;

            try
            {
                PreviewForm viewerForm = new PreviewForm(null, description, false);
                viewerForm.Show();
            }
            catch (Exception ex)
            {
                string message = App.Current.GetString("ReportPreviewPreviewFailFormat",
                                                       description.ReportName);
                detail = _DoExceptionRoutine(message, ex, generator, description);
            }

            return(detail);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads report template.
        /// </summary>
        /// <param name="nodeReport">Report template node.</param>
        /// <param name="isPredefined">Is predefined flag.</param>
        /// <returns>Report template info.</returns>
        private ReportInfo _LoadTemplate(XmlNode nodeReport, bool isPredefined)
        {
            ReportInfo info = null;

            try
            {
                string template = nodeReport.Attributes[ATTRIBUTE_NAME_FILEPATH].Value;
                if (File.Exists(ReportsGenerator.GetTemplateAbsolutelyPath(template)))
                {
                    string      name        = nodeReport.Attributes[ATTRIBUTE_NAME_NAME].Value;
                    ContextType context     = (ContextType)Enum.Parse(typeof(ContextType), nodeReport.Attributes[ATTRIBUTE_NAME_CONTEXT].Value, true);
                    string      description = _LoadDescription(nodeReport);
                    info = new ReportInfo(name, context, template, description, isPredefined,
                                          _LoadSubReports(nodeReport));
                }
            }
            catch
            {
                info = null;
            }

            return(info);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Does print operation.
        /// </summary>
        /// <param name="generator">Report generator object.</param>
        /// <param name="descriptions">Report state description list.</param>
        private void _DoPrint(ReportsGenerator generator,
                              IList <ReportStateDescription> descriptions)
        {
            Debug.Assert(null != generator);
            Debug.Assert(null != descriptions);
            Debug.Assert(0 < descriptions.Count);

            List <MessageDetail> details = new List <MessageDetail>();

            bool multiPrint = (1 < descriptions.Count);

            bool isCanceled  = false;
            int  copiesCount = 1;

            for (int index = 0; index < descriptions.Count; ++index)
            {
                ReportStateDescription description = descriptions[index];
                MessageDetail          detail      = _DoPrint(generator, description, (0 == index),
                                                              ref copiesCount, ref isCanceled);
                if (null != detail)
                {
                    details.Add(detail);
                }

                if (isCanceled)
                {
                    break;
                }
            }

            if (!isCanceled)
            {
                string errorMessage = App.Current.FindString("ReportPreviewTopLevelPrintFail");
                string infoMessage  = App.Current.FindString("ReportPreviewTopLevelPrintDone");
                _PopulateMessages(errorMessage, infoMessage, details);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Does preview reports.
        /// </summary>
        /// <param name="generator">Report generator object.</param>
        /// <param name="descriptions">Report state description list.</param>
        private void _DoPreview(ReportsGenerator generator,
                                IList <ReportStateDescription> descriptions)
        {
            Debug.Assert(null != generator);
            Debug.Assert(null != descriptions);
            Debug.Assert(0 < descriptions.Count);

            var details = new List <MessageDetail>();

            for (int index = 0; index < descriptions.Count; ++index)
            {
                ReportStateDescription description = descriptions[index];
                MessageDetail          detail      = _DoPreview(generator, description);
                if (null != detail)
                {
                    details.Add(detail);
                }
            }

            // populate errors
            if (0 < details.Count)
            {   // NOTE: only error supported
                string statusMessage = null;
                if (1 == details.Count)
                {
                    statusMessage = details[0].Text;
                    App.Current.Messenger.AddMessage(details[0].Type, statusMessage);
                }
                else
                {
                    statusMessage = App.Current.FindString("ReportPreviewTopLevelPreviewFail");
                    App.Current.Messenger.AddMessage(MessageType.Error, statusMessage, details);
                }

                App.Current.MainWindow.StatusBar.SetStatus(_parentPage, statusMessage);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Free resource reports. Reomeves temparary files.
        /// </summary>
        public void FreeReports()
        {
            if (null != _reports)
            {
                _DisposeReports();

                _reports.Clear();
                _reports = null;

                // delete all files from reports temp directory
                var        di      = new DirectoryInfo(ReportsGenerator.GetTempDirectoryName());
                FileInfo[] rgFiles = di.GetFiles(FILE_FILTER_ALL);
                foreach (FileInfo fi in rgFiles)
                {
                    // delete file safely
                    try
                    {
                        fi.Delete();
                    }
                    catch
                    { } // do nothing
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Does print report.
        /// </summary>
        /// <param name="generator">Report generator object.</param>
        /// <param name="description">Report state description.</param>
        /// <param name="showPrintDialog">Need show print dialog flag.</param>
        /// <param name="copiesCount">Selecetd copies count.</param>
        /// <param name="isCanceled">Is operation ccancel by user.</param>
        /// <returns>Operation status message.</returns>
        private MessageDetail _DoPrint(ReportsGenerator generator,
                                       ReportStateDescription description,
                                       bool showPrintDialog,
                                       ref int copiesCount,
                                       ref bool isCanceled)
        {
            Debug.Assert(null != generator);
            Debug.Assert(null != description);

            isCanceled = false;
            MessageDetail detail = null;

            try
            {
                // generate report
                if (null == description.Report)
                {
                    generator.RunReport(description);
                }

                // init print dialog
                DDActiveReports.Document.Document document = description.Report.Document;
                document.PrintAborted +=
                    new DDActiveReports.Document.PrintAbortedEventHandler(Document_PrintAborted);
                DDActiveReports.Document.Printer printer = document.Printer;
                printer.PrinterSettings.PrintRange = PrintRange.SomePages;
                printer.PrinterSettings.FromPage   = 1;
                printer.PrinterSettings.ToPage     = description.Report.Document.Pages.Count;
                printer.PrinterSettings.PrintRange = PrintRange.AllPages;

                // select application printer
                ArcLogistics.App.PrinterSettingsStore settings = App.Current.PrinterSettingsStore;
                if (!string.IsNullOrEmpty(settings.PrinterName))
                {
                    description.Report.Document.Printer.PrinterName         = settings.PrinterName;
                    description.Report.Document.Printer.DefaultPageSettings = settings.PageSettings;
                }

                // do printing
                if (!description.Report.Document.Print(showPrintDialog, true))
                {
                    isCanceled = true;
                }
                else
                {
                    if (showPrintDialog)
                    {
                        // store copies count
                        copiesCount = description.Report.Document.Printer.PrinterSettings.Copies;

                        // store printer settings in application
                        var prntSettings = description.Report.Document.Printer.PrinterSettings;
                        if (!string.IsNullOrEmpty(prntSettings.PrinterName))
                        {
                            settings.StoreSetting(prntSettings.PrinterName,
                                                  prntSettings.DefaultPageSettings);
                        }
                    }

                    string message = App.Current.GetString("ReportPreviewPrintDoneFormat",
                                                           description.ReportName);
                    detail = new MessageDetail(MessageType.Information, message);
                }
            }
            catch (Exception ex)
            {
                string message = App.Current.GetString("ReportPreviewPrintFailFormat",
                                                       description.ReportName);
                detail = _DoExceptionRoutine(message, ex, generator, description);
            }

            return(detail);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Saves operation.
        /// </summary>
        /// <param name="generator">Reports generator.</param>
        /// <param name="descriptions">Report state description.</param>
        private void _DoSave(ReportsGenerator generator, IList<ReportStateDescription> descriptions)
        {
            Debug.Assert(null != generator);
            Debug.Assert(null != descriptions);
            Debug.Assert(0 < descriptions.Count);

            try
            {
                string exportDir = null;
                string fileName = null;
                string fileExt = null;

                // get export settings
                if (1 == descriptions.Count)
                {   // get settings for one file
                    _GetExportOutputSettings(descriptions[0].ReportName,
                                             out exportDir,
                                             out fileName,
                                             out fileExt);
                }
                else
                {   // get settings for files
                    Debug.Assert(1 < descriptions.Count);
                    _GetExportOutputSettings(out exportDir, out fileExt);
                }

                // export reports
                if (!string.IsNullOrEmpty(exportDir) && !string.IsNullOrEmpty(fileExt))
                {
                    IDocumentExport exporter = ReportsHelpers.GetExporterByFileExtension(fileExt);
                    // do save export files
                    List<MessageDetail> details = new List<MessageDetail>();
                    for (int index = 0; index < descriptions.Count; ++index)
                    {
                        ReportStateDescription description = descriptions[index];
                        MessageDetail detail = _DoSaveReport(exporter, exportDir, fileName, fileExt,
                                                             generator, description);
                        if (null != detail)
                            details.Add(detail);
                    }

                    // export done - show messages
                    string infoMessage = App.Current.FindString("ReportPreviewTopLevelSaveDone");
                    string errorMessage = App.Current.FindString("ReportPreviewTopLevelSaveFail");
                    _PopulateMessages(errorMessage, infoMessage, details);
                }
            }
            catch (Exception ex)
            {
                _DoSaveInitExceptionRoutine(ex);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Saves report routine.
        /// </summary>
        /// <param name="exporter">Exporter object.</param>
        /// <param name="exportDir">Export directory.</param>
        /// <param name="fileName">Export report file name (can be null).</param>
        /// <param name="fileExt">Export file extension.</param>
        /// <param name="generator">Report generator.</param>
        /// <param name="description">Report state descriiption.</param>
        /// <returns>Status messages.</returns>
        private MessageDetail _DoSaveReport(IDocumentExport exporter,
                                            string exportDir,
                                            string fileName,
                                            string fileExt,
                                            ReportsGenerator generator,
                                            ReportStateDescription description)
        {
            Debug.Assert(null != exporter);
            Debug.Assert(null != generator);
            Debug.Assert(null != description);
            Debug.Assert((null != exportDir) && (null != fileExt));

            MessageDetail detail = null;
            string fullFileName = null;
            try
            {
                string filename = (string.IsNullOrEmpty(fileName)) ?
                                    _ValidateFileName(description.ReportName) : fileName;
                fullFileName = Path.Combine(exportDir, filename + fileExt);

                if (null == description.Report)
                    generator.RunReport(description);

                exporter.Export(description.Report.Document, fullFileName);
                string message = App.Current.GetString("ReportPreviewSaveDoneFormat",
                                                       description.ReportName, fullFileName);
                detail = new MessageDetail(MessageType.Information, message);
            }
            catch (Exception ex)
            {
                string message = App.Current.GetString("ReportPreviewSaveFailFormat",
                                                       description.ReportName, fullFileName);
                detail = _DoExceptionRoutine(message, ex, generator, description);
            }

            return detail;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Does print operation.
        /// </summary>
        /// <param name="generator">Report generator object.</param>
        /// <param name="descriptions">Report state description list.</param>
        private void _DoPrint(ReportsGenerator generator,
                              IList<ReportStateDescription> descriptions)
        {
            Debug.Assert(null != generator);
            Debug.Assert(null != descriptions);
            Debug.Assert(0 < descriptions.Count);

            List<MessageDetail> details = new List<MessageDetail>();

            bool multiPrint = (1 < descriptions.Count);

            bool isCanceled = false;
            int copiesCount = 1;
            for (int index = 0; index < descriptions.Count; ++index)
            {
                ReportStateDescription description = descriptions[index];
                MessageDetail detail = _DoPrint(generator, description, (0 == index),
                                                ref copiesCount, ref isCanceled);
                if (null != detail)
                    details.Add(detail);

                if (isCanceled)
                    break;
            }

            if (!isCanceled)
            {
                string errorMessage = App.Current.FindString("ReportPreviewTopLevelPrintFail");
                string infoMessage = App.Current.FindString("ReportPreviewTopLevelPrintDone");
                _PopulateMessages(errorMessage, infoMessage, details);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Does print report.
        /// </summary>
        /// <param name="generator">Report generator object.</param>
        /// <param name="description">Report state description.</param>
        /// <param name="showPrintDialog">Need show print dialog flag.</param>
        /// <param name="copiesCount">Selecetd copies count.</param>
        /// <param name="isCanceled">Is operation ccancel by user.</param>
        /// <returns>Operation status message.</returns>
        private MessageDetail _DoPrint(ReportsGenerator generator,
                                       ReportStateDescription description,
                                       bool showPrintDialog,
                                       ref int copiesCount,
                                       ref bool isCanceled)
        {
            Debug.Assert(null != generator);
            Debug.Assert(null != description);

            isCanceled = false;
            MessageDetail detail = null;
            try
            {
                // generate report
                if (null == description.Report)
                    generator.RunReport(description);

                // init print dialog
                DDActiveReports.Document.Document document = description.Report.Document;
                document.PrintAborted +=
                    new DDActiveReports.Document.PrintAbortedEventHandler(Document_PrintAborted);
                DDActiveReports.Document.Printer printer = document.Printer;
                printer.PrinterSettings.PrintRange = PrintRange.SomePages;
                printer.PrinterSettings.FromPage = 1;
                printer.PrinterSettings.ToPage = description.Report.Document.Pages.Count;
                printer.PrinterSettings.PrintRange = PrintRange.AllPages;

                // select application printer
                ArcLogistics.App.PrinterSettingsStore settings = App.Current.PrinterSettingsStore;
                if (!string.IsNullOrEmpty(settings.PrinterName))
                {
                    description.Report.Document.Printer.PrinterName = settings.PrinterName;
                    description.Report.Document.Printer.DefaultPageSettings = settings.PageSettings;
                }

                // do printing
                if (!description.Report.Document.Print(showPrintDialog, true))
                    isCanceled = true;
                else
                {
                    if (showPrintDialog)
                    {
                        // store copies count
                        copiesCount = description.Report.Document.Printer.PrinterSettings.Copies;

                        // store printer settings in application
                        var prntSettings = description.Report.Document.Printer.PrinterSettings;
                        if (!string.IsNullOrEmpty(prntSettings.PrinterName))
                            settings.StoreSetting(prntSettings.PrinterName,
                                                  prntSettings.DefaultPageSettings);
                    }

                    string message = App.Current.GetString("ReportPreviewPrintDoneFormat",
                                                           description.ReportName);
                    detail = new MessageDetail(MessageType.Information, message);
                }
            }
            catch (Exception ex)
            {
                string message = App.Current.GetString("ReportPreviewPrintFailFormat",
                                                       description.ReportName);
                detail = _DoExceptionRoutine(message, ex, generator, description);
            }

            return detail;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Does preview reports.
        /// </summary>
        /// <param name="generator">Report generator object.</param>
        /// <param name="descriptions">Report state description list.</param>
        private void _DoPreview(ReportsGenerator generator,
                                IList<ReportStateDescription> descriptions)
        {
            Debug.Assert(null != generator);
            Debug.Assert(null != descriptions);
            Debug.Assert(0 < descriptions.Count);

            var details = new List<MessageDetail>();
            for (int index = 0; index < descriptions.Count; ++index)
            {
                ReportStateDescription description = descriptions[index];
                MessageDetail detail = _DoPreview(generator, description);
                if (null != detail)
                    details.Add(detail);
            }

            // populate errors
            if (0 < details.Count)
            {   // NOTE: only error supported
                string statusMessage = null;
                if (1 == details.Count)
                {
                    statusMessage = details[0].Text;
                    App.Current.Messenger.AddMessage(details[0].Type, statusMessage);
                }
                else
                {
                    statusMessage = App.Current.FindString("ReportPreviewTopLevelPreviewFail");
                    App.Current.Messenger.AddMessage(MessageType.Error, statusMessage, details);
                }

                App.Current.MainWindow.StatusBar.SetStatus(_parentPage, statusMessage);
            }
        }
Exemplo n.º 15
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Does report preview.
        /// </summary>
        /// <param name="generator">Report generator object.</param>
        /// <param name="description">Report state description.</param>
        /// <returns>Operation status message.</returns>
        private MessageDetail _DoPreview(ReportsGenerator generator,
                                         ReportStateDescription description)
        {
            Debug.Assert(null != generator);
            Debug.Assert(null != description);

            MessageDetail detail = null;
            try
            {
                PreviewForm viewerForm = new PreviewForm(null, description, false);
                viewerForm.Show();
            }
            catch (Exception ex)
            {
                string message = App.Current.GetString("ReportPreviewPreviewFailFormat",
                                                       description.ReportName);
                detail = _DoExceptionRoutine(message, ex, generator, description);
            }

            return detail;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Does exception routine.
        /// </summary>
        /// <param name="message">Head message text.</param>
        /// <param name="exception">Exception object.</param>
        /// <param name="generator">Report generator.</param>
        /// <param name="description">Report state description.</param>
        /// <returns>Exception status message.</returns>
        private MessageDetail _DoExceptionRoutine(string message,
                                                  Exception exception,
                                                  ReportsGenerator generator,
                                                  ReportStateDescription description)
        {
            Debug.Assert(!string.IsNullOrEmpty(message));
            Debug.Assert(null != exception);
            Debug.Assert(null != generator);
            Debug.Assert(null != description);

            Logger.Error(exception);

            generator.DisposeReport(description);

            string messageReason = (exception is OutOfMemoryException) ?
                                        App.Current.FindString("ReportPreviewReasonOutOfMemory") :
                                        exception.Message;

            if (!string.IsNullOrEmpty(messageReason))
                message = string.Format(MESSAGE_FORMAT, message, messageReason);

            return new MessageDetail(MessageType.Error, message);
        }