Ejemplo n.º 1
0
        public static FileStreamResult ToCsvResult(this DataDynamics.ActiveReports.Document.Document reportDocument, string name)
        {
            // Do not close or dispose MemoryStream as the FileStreamResult disposes it after use
            var memoryStream = new MemoryStream();

            using (var exported = new TextExport())
            {
                exported.TextDelimiter = ",";
                exported.Export(reportDocument, memoryStream);

                memoryStream.Flush();
                memoryStream.Seek(0, SeekOrigin.Begin);

                var fileStreamResult = new FileStreamResult(memoryStream, "application/csv");

                fileStreamResult.FileDownloadName = string.Format("{0}.csv", name);

                return(fileStreamResult);
            }
        }
Ejemplo n.º 2
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            TextExport parentExport = Export as TextExport;
            TextExport textExport   = new TextExport();

            using (TextExportPrintForm printDialog = new TextExportPrintForm(textExport))
            {
                textExport.PrinterTypes = parentExport.PrinterTypes;
                textExport.Copies       = parentExport.Copies;
                printDialog.CurrentPage = tbPage.Text;

                if (printDialog.ShowDialog() == DialogResult.OK)
                {
                    if (cbbCodepage.SelectedIndex == 1)
                    {
                        cbbCodepage.SelectedIndex = 2;
                    }
                    textExport.PageBreaks = cbPageBreaks.Checked;
                    textExport.EmptyLines = cbEmptyLines.Checked;
                    textExport.Frames     = cbbFrames.SelectedIndex != 0;
                    textExport.TextFrames = cbbFrames.SelectedIndex == 1;
                    textExport.DataOnly   = cbDataOnly.Checked;
                    if (cbbCodepage.SelectedIndex == 0)
                    {
                        textExport.Encoding = Encoding.Default;
                    }
                    else if (cbbCodepage.SelectedIndex == 2)
                    {
                        textExport.Encoding = Encoding.GetEncoding(CultureInfo.CurrentCulture.TextInfo.OEMCodePage);
                    }
                    textExport.ScaleX           = (float)udX.Value;
                    textExport.ScaleY           = (float)udY.Value;
                    textExport.PrintAfterExport = true;
                    textExport.OpenAfterExport  = false;
                    textExport.AvoidDataLoss    = false;
                    using (MemoryStream memStream = new MemoryStream())
                        textExport.Export(report, memStream);
                }
            }
        }
Ejemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            TextExport parentExport = Export as TextExport;
            TextExport textExport   = new TextExport();

            textExport.PageBreaks = cbPageBreaks.Checked;
            textExport.EmptyLines = cbEmptyLines.Checked;
            textExport.Frames     = cbbFrames.SelectedIndex != 0;
            textExport.TextFrames = cbbFrames.SelectedIndex == 1;
            textExport.DataOnly   = cbDataOnly.Checked;
            if (cbbCodepage.SelectedIndex == 0)
            {
                textExport.Encoding = Encoding.Default;
            }
            else if (cbbCodepage.SelectedIndex == 1)
            {
                textExport.Encoding = Encoding.UTF8;
            }
            else if (cbbCodepage.SelectedIndex == 2)
            {
                textExport.Encoding = Encoding.GetEncoding(CultureInfo.CurrentCulture.TextInfo.OEMCodePage);
            }
            textExport.ScaleX          = (float)udX.Value;
            textExport.ScaleY          = (float)udY.Value;
            textExport.OpenAfterExport = false;
            textExport.AvoidDataLoss   = false;
            using (SaveFileDialog dialog = new SaveFileDialog())
            {
                dialog.FileName = Path.GetFileNameWithoutExtension(Path.GetFileName(report.FileName));
                dialog.Filter   = textExport.FileFilter;
                string defaultExt = dialog.Filter.Split(new char[] { '|' })[1];
                dialog.DefaultExt = Path.GetExtension(defaultExt);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    Application.DoEvents();
                    textExport.Export(report, dialog.FileName);
                }
            }
        }