예제 #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Creates a new instance of the <c>ReportProcessor</c> class.
        /// </summary>
        /// <param name="parentPage">Paren page for status update.</param>
        public ReportProcessor(Page parentPage)
        {
            Debug.Assert(null != parentPage);

            _exportDialogFilter = ReportsHelpers.AssemblyDialogFilter();
            _parentPage         = parentPage;
        }
예제 #2
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);
            }
        }
예제 #3
0
        /// <summary>
        /// Dialog save FileOk handler.
        /// </summary>
        /// <param name="sender">Sender object (SaveFileDialog).</param>
        /// <param name="e">Ignored.</param>
        private void _DialogSave_FileOk(object sender, CancelEventArgs e)
        {
            Debug.Assert(null != sender);

            var dlgSave = sender as WinForms.SaveFileDialog;
            int index   = dlgSave.FilterIndex - 1;

            dlgSave.FileName =
                Path.ChangeExtension(dlgSave.FileName, ReportsHelpers.GetFileExtension(index));
            // NOTE: FilterIndex 1st based
        }
예제 #4
0
        /// <summary>
        /// Gets export output settings for files (directory and file extension).
        /// </summary>
        /// <param name="exportDir">Export directory.</param>
        /// <param name="fileExt">Export file extension.</param>
        private void _GetExportOutputSettings(out string exportDir,
                                              out string fileExt)
        {
            exportDir = null;
            fileExt   = null;

            // create dialog
            ReportsSaveDlg dlg = new ReportsSaveDlg();

            dlg.Owner = App.Current.MainWindow;
            dlg.WindowStartupLocation = WindowStartupLocation.CenterOwner;

            // show dialog
            if (true == dlg.ShowDialog())
            {
                exportDir = dlg.savePathEdit.Text;
                string typeName = dlg.comboboxType.Text;
                fileExt = ReportsHelpers.GetFileExtensionByName(typeName);
            }
        }
예제 #5
0
        /// <summary>
        /// Gets export output settings for files (directory, file name and extension).
        /// </summary>
        /// <param name="reportName">Report name.</param>
        /// <param name="exportDir">Export directory.</param>
        /// <param name="fileName">Report file name.</param>
        /// <param name="fileExt">Export file extension.</param>
        private void _GetExportOutputSettings(string reportName,
                                              out string exportDir,
                                              out string fileName,
                                              out string fileExt)
        {
            Debug.Assert(!string.IsNullOrEmpty(reportName));

            exportDir = null;
            fileName  = null;
            fileExt   = null;

            using (var dlgSave = new WinForms.SaveFileDialog())
            {
                dlgSave.AutoUpgradeEnabled = true;
                dlgSave.RestoreDirectory   = true;
                dlgSave.CheckPathExists    = true;
                dlgSave.CheckFileExists    = false;
                dlgSave.OverwritePrompt    = false;
                int typeIndex = ReportsHelpers.DefaultSelectedTypeIndex;
                dlgSave.FilterIndex = typeIndex + 1; // NOTE: FilterIndex 1st based
                dlgSave.Filter      = _exportDialogFilter;
                string extension = ReportsHelpers.GetFileExtension(typeIndex);

                var format = App.Current.FindString("ReportPreviewSaveDialogTitleFormat");
                dlgSave.Title      = string.Format(format, reportName);
                dlgSave.FileName   = _ValidateFileName(reportName) + extension;
                dlgSave.FileOk    += new CancelEventHandler(_DialogSave_FileOk);
                dlgSave.DefaultExt = extension;

                if (dlgSave.ShowDialog(null) == WinForms.DialogResult.OK)
                {
                    string selectedFileName = dlgSave.FileName;
                    exportDir = Path.GetDirectoryName(selectedFileName);
                    fileExt   = ReportsHelpers.GetFileExtension(dlgSave.FilterIndex - 1);
                    // NOTE: FilterIndex 1st based
                    fileName = Path.GetFileNameWithoutExtension(selectedFileName);
                }
            }
        }