Example #1
0
        /// <summary>
        /// Возвращает расширение файла по элементу перечисления ReportExportFormat типов файлов
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public static string GetExtensionByFormat(ReportExportFormat format)
        {
            string extension = string.Empty;

            switch (format)
            {
            case ReportExportFormat.Csv:
                extension = "csv";
                break;

            case ReportExportFormat.Pdf:
                extension = "pdf";
                break;

            case ReportExportFormat.Rtf:
                extension = "rtf";
                break;

            case ReportExportFormat.Xls:
                extension = "xls";
                break;

            case ReportExportFormat.Xlsx:
                extension = "xlsx";
                break;

            default:
                new ArgumentOutOfRangeException(nameof(format), Droid.Resources.Messages.Text_Error_Could_not_determine_file_format);
                break;
            }

            return(extension);
        }
Example #2
0
        void CmdFileExportResults()
        {
            string             fileName = _grid.Schema.Name.Replace(".", "-");
            ReportExportFormat format   = ReportManager.GetExportReportFormat(fileName, ReportExportFormats.Formats.First().Value.ID);

            if (format != null)
            {
                format.CreateParam.Sign = false;                 //!!! (_grid.Form.GetProperty("Sign").ToIntOrDefault() != 0);
                ReportManager.ExportCurrentForm(_grid, format);
            }
        }
Example #3
0
        void IReporter.ExportCurrentForm(IObjectHost objectHost, ReportExportFormat format)
        {
            DBGrid grid = (objectHost as DBGrid);

            if (grid == null)
            {
                return;
            }

            StiReport report = MakeReport(grid, format.CreateParam);

            report.Render(true);
            report.ExportDocument(GetExportFormat(format.ID), format.CreateParam.ExportFileName);
        }
Example #4
0
        /// <summary>
        /// Сохраняет ответ от сервера по генерации отчета в файл, указанного типа, и возвращает полное имя файла
        /// </summary>
        /// <param name="response"></param>
        /// <param name="exportFormat"></param>
        public static string SaveResponse(ExportedReport response, ReportExportFormat exportFormat)
        {
            string extension = ReportService.GetExtensionByFormat(exportFormat);

            string fileName = response.FileName;

            fileName = Lers.Utils.FileUtils.SanitizeFileName(fileName);

            string directoryName = StorageDirectoryService.Get();

            string fullName = Lers.Utils.FileUtils.CreateFullFileName(directoryName, fileName, extension);

            File.WriteAllBytes(fullName, response.Content);

            return(fullName);
        }
Example #5
0
        //Для возможного использования
        //foreach (Stimulsoft.Report.Dictionary.StiVariable variable in report.Dictionary.Variables)
        //{
        //    variable.Value = dbs.GetSetting(variable.Name.Replace('_', ';'));
        //}
        //StiReport r = new StiReport();
        //r.Render();
        //r.RenderedPages.Remove(r.RenderedPages[0]);
        //r.RenderedPages.AddRange(report.RenderedPages);
        //r.RenderedPages.Add(report.RenderedPages[0]);
        //r.Show(true);
        static void _outputReport(string reportName, DataTable dataSource, ReportDestinations outputTarget, ReportExportFormat format, ActionParameters reportParameters)
        {
            string reportsPath    = System.IO.Path.Combine(PathHelper.ApplicationPath, "Reports");
            string reportFilePath = System.IO.Path.Combine(reportsPath,
                                                           reportName.EndsWith(ReportFileExtension) ? reportName : reportName + ReportFileExtension);

            StiReport report = new StiReport();
            bool      loaded = false;

            if (System.IO.File.Exists(reportFilePath))
            {
                report.Load(reportFilePath);
                loaded = true;
            }
            else
            {
                throw new System.IO.FileNotFoundException($"Report file {reportsPath} not fount");
            }
            if (loaded)
            {
                string      tableName = TableAliasDefault;;
                StiDataBand db        = report.GetComponents().OfType <StiDataBand>().FirstOrDefault();
                if (db != null)
                {
                    if (!string.IsNullOrEmpty(db.DataSourceName))
                    {
                        tableName = db.DataSourceName;
                    }
                    else
                    {
                        db.DataSourceName = tableName;
                    }
                }
                dataSource.TableName = tableName;
                report.RegData(dataSource.TableName, dataSource);
                report.Dictionary.Synchronize();
                report.Dictionary.DataSources[0].Name  = tableName;
                report.Dictionary.DataSources[0].Alias = tableName;


                if (reportParameters != null)
                {
                    foreach (KeyValuePair <string, object> kvp in reportParameters)
                    {
                        if (!report.Dictionary.Variables.Contains(kvp.Key))
                        {
                            report.Dictionary.Variables.Add("Parameters", kvp.Key, kvp.Value);
                        }
                        else
                        {
                            report.Dictionary.Variables[kvp.Key].ValueObject = kvp.Value;
                        }
                    }
                }
                if (outputTarget == ReportDestinations.Designer)
                {
                    report.Design(false);
                }
                else if (outputTarget == ReportDestinations.Printer)
                {
                    report.Render(true);
                    report.Print(true);
                }
                else if (outputTarget == ReportDestinations.File)
                {
                    if (format == null)
                    {
                        format = ReportManager.GetExportReportFormat(
                            reportName.EndsWith(ReportFileExtension) ? reportName.Left(reportName.Length - ReportFileExtension.Length) : reportName,
                            ReportExportFormats.Formats.First().Value.ID);
                    }
                    if (format != null)
                    {
                        report.Render(true);
                        if (format.CreateParam.Charset == ReportExportCharsets.Windows_1251)
                        {
                            report.ExportDocument(GetExportFormat(format.ID), format.CreateParam.ExportFileName,
                                                  new Stimulsoft.Report.Export.StiHtmlExportSettings()
                            {
                                Encoding = System.Text.Encoding.Default
                            });
                        }
                        else
                        {
                            report.ExportDocument(GetExportFormat(format.ID), format.CreateParam.ExportFileName);
                        }
                    }
                }
                else
                {
                    report.Render(true);
                    report.Show();
                }
            }
        }
Example #6
0
 void IReporter.OutputReport(string reportName, DataTable dataSource, ReportExportFormat format, ActionParameters reportParameters)
 {
     _outputReport(reportName, dataSource, ReportDestinations.File, format, reportParameters);
 }