Ejemplo n.º 1
0
        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            if (_report.IsBusy)
            {
                return;
            }

            string selectedReport = cbReport.SelectedItem as string;

            if (string.IsNullOrEmpty(selectedReport))
            {
                return;
            }
            if (cbExportFilter.SelectedIndex < 0 || cbExportFilter.SelectedIndex >= _report.SupportedExportProviders.Length)
            {
                return;
            }

            // load report
            try
            {
                // load from resource stream
                Assembly asm = Assembly.GetExecutingAssembly();
                using (Stream stream = asm.GetManifestResourceStream("FlexReportSamples.Resources.FlexCommonTasks_XML.flxr"))
                    _report.Load(stream, selectedReport);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Failed to load report [{0}], exception:\r\n{1}", selectedReport, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // prepare ExportFilter object
            ExportProvider ep  = _report.SupportedExportProviders[cbExportFilter.SelectedIndex];
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.FileName        = string.Format("{0}.{1}", selectedReport, ep.DefaultExtension);
            sfd.Filter          = string.Format("{0} Files (*.{1})|*.{1}", ep.FormatName, ep.DefaultExtension);
            sfd.CheckPathExists = true;
            if (!sfd.ShowDialog().Value)
            {
                return;
            }
            ExportFilter ef = ep.NewExporter() as ExportFilter;

            ef.FileName = sfd.FileName;
            ef.Preview  = cbOpenDocument.IsChecked.Value;

            //
            try
            {
                _report.RenderToFilter(ef);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Failed to export report [{0}], exception:\r\n{1}", selectedReport, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }