Beispiel #1
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
        }
Beispiel #2
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);
                }
            }
        }