예제 #1
0
        public bool Export(fyiReporting.RDL.OutputPresentationType type)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title = "Export to " + type.ToString().ToUpper();
            switch (type)
            {
            case  OutputPresentationType.CSV:
                sfd.Filter = "CSV file (*.csv)|*.csv|All files (*.*)|*.*";
                break;

            case OutputPresentationType.XML:
                sfd.Filter = "XML file (*.xml)|*.xml|All files (*.*)|*.*";
                break;

            case OutputPresentationType.PDF:
            case OutputPresentationType.PDFOldStyle:
                sfd.Filter = "PDF file (*.pdf)|*.pdf|All files (*.*)|*.*";
                break;

            case OutputPresentationType.TIF:
                sfd.Filter = "TIF file (*.tif, *.tiff)|*.tiff;*.tif|All files (*.*)|*.*";
                break;

            case OutputPresentationType.RTF:
                sfd.Filter = "RTF file (*.rtf)|*.rtf|All files (*.*)|*.*";
                break;

            case OutputPresentationType.Word:
                sfd.Filter = "DOC file (*.doc)|*.doc|All files (*.*)|*.*";
                break;

            case OutputPresentationType.Excel:
                sfd.Filter = "Excel file (*.xlsx)|*.xlsx|All files (*.*)|*.*";
                break;

            case OutputPresentationType.HTML:
                sfd.Filter = "Web Page (*.html, *.htm)|*.html;*.htm|All files (*.*)|*.*";
                break;

            case OutputPresentationType.MHTML:
                sfd.Filter = "MHT (*.mht)|*.mhtml;*.mht|All files (*.*)|*.*";
                break;

            default:
                throw new Exception("Only HTML, MHT, XML, CSV, RTF, DOC, Excel, TIF and PDF are allowed as Export types.");
            }
            sfd.FilterIndex = 1;

            if (SourceFile != null)
            {
                sfd.FileName = Path.GetFileNameWithoutExtension(SourceFile.LocalPath) + "." + type;
            }
            else
            {
                sfd.FileName = "*." + type;
            }

            try
            {
                if (sfd.ShowDialog(this) != DialogResult.OK)
                {
                    return(false);
                }

                // save the report in the requested rendered format
                bool rc = true;
                // tif can be either in color or black and white; ask user what they want
                if (type == OutputPresentationType.TIF)
                {
                    DialogResult dr = MessageBox.Show(this, "Do you want to display colors in TIF?", "Export", MessageBoxButtons.YesNoCancel);
                    if (dr == DialogResult.No)
                    {
                        type = OutputPresentationType.TIFBW;
                    }
                    else if (dr == DialogResult.Cancel)
                    {
                        return(false);
                    }
                }
                try { SaveAs(sfd.FileName, type); }
                catch (Exception ex)
                {
                    MessageBox.Show(this,
                                    ex.Message, "Export Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    rc = false;
                }
                return(rc);
            }
            finally
            {
                sfd.Dispose();
            }
        }
예제 #2
0
        public bool Export(fyiReporting.RDL.OutputPresentationType type)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title = string.Format(Strings.MDIChild_Export_ExportTitleFormat, type.ToString().ToUpper());
            switch (type)
            {
            case OutputPresentationType.CSV:
                sfd.Filter = Strings.MDIChild_Export_CSV;
                break;

            case OutputPresentationType.XML:
                sfd.Filter = Strings.MDIChild_Export_XML;
                break;

            case OutputPresentationType.PDF:
            case OutputPresentationType.PDFOldStyle:
                sfd.Filter = Strings.MDIChild_Export_PDF;
                break;

            case OutputPresentationType.TIF:
                sfd.Filter = Strings.MDIChild_Export_TIF;
                break;

            case OutputPresentationType.RTF:
                sfd.Filter = Strings.MDIChild_Export_RTF;
                break;

            case OutputPresentationType.Word:
                sfd.Filter = Strings.MDIChild_Export_DOC;
                break;

            case OutputPresentationType.ExcelTableOnly:
                sfd.Filter = Strings.MDIChild_Export_Excel;
                break;

            case OutputPresentationType.HTML:
                sfd.Filter = Strings.MDIChild_Export_Web_Page;
                break;

            case OutputPresentationType.MHTML:
                sfd.Filter = Strings.MDIChild_Export_MHT;
                break;

            default:
                throw new Exception(Strings.MDIChild_Error_AllowedExportTypes);
            }
            sfd.FilterIndex = 1;

            if (SourceFile != null)
            {
                sfd.FileName = Path.GetFileNameWithoutExtension(SourceFile.LocalPath) + "." + type;
            }
            else
            {
                sfd.FileName = "*." + type;
            }

            try
            {
                if (sfd.ShowDialog(this) != DialogResult.OK)
                {
                    return(false);
                }

                // save the report in the requested rendered format
                bool rc = true;
                // tif can be either in color or black and white; ask user what they want
                if (type == OutputPresentationType.TIF)
                {
                    DialogResult dr = MessageBox.Show(this, Strings.MDIChild_ShowF_WantDisplayColorsInTIF, Strings.MDIChild_ShowF_Export, MessageBoxButtons.YesNoCancel);
                    if (dr == DialogResult.No)
                    {
                        type = OutputPresentationType.TIFBW;
                    }
                    else if (dr == DialogResult.Cancel)
                    {
                        return(false);
                    }
                }
                try { SaveAs(sfd.FileName, type); }
                catch (Exception ex)
                {
                    MessageBox.Show(this,
                                    ex.Message, Strings.MDIChild_ShowG_ExportError,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    rc = false;
                }
                return(rc);
            }
            finally
            {
                sfd.Dispose();
            }
        }