//
        // GET: /FileDownload/


        public virtual System.Web.Mvc.FileContentResult GenerateStatementPDF(StatementReportModel statementReportData)
        {
            var assembly = Assembly.GetExecutingAssembly();
            var reportStatementResource   = Properties.Settings.Default.StatementRptResource.ToString();
            var reportStockResource       = Properties.Settings.Default.StockRptResource.ToString();
            var reportTransactionResource = Properties.Settings.Default.TransactionRptResource.ToString();


            LocalReport localReport = new LocalReport();


            // string[] names = assembly.GetManifestResourceNames();



            var statementFile   = assembly.GetManifestResourceStream(reportStatementResource);
            var stocksFile      = assembly.GetManifestResourceStream(reportStockResource);
            var transactionFile = assembly.GetManifestResourceStream(reportTransactionResource);



            localReport.LoadReportDefinition(statementFile);
            localReport.LoadSubreportDefinition("Stock", stocksFile);
            localReport.LoadSubreportDefinition("Transaction", transactionFile);

            var datasource = new List <StatementReportModel> {
                statementReportData
            };

            localReport.DataSources.Add(new ReportDataSource("StatementDataSet", datasource));

            localReport.SubreportProcessing += (o, args) =>
            {
                if (args.ReportPath == "Stock")
                {
                    args.DataSources.Add(
                        new ReportDataSource("StocksDataSet", datasource.First().Stocks));
                }
                else if (args.ReportPath == "Transaction")
                {
                    var stockId      = args.Parameters["StockId"].Values[0];
                    var transactions =
                        datasource.First()
                        .Stocks.FirstOrDefault(x => x.InstrumentCode == stockId)
                        .Transactions;
                    args.DataSources.Add(new ReportDataSource("TransactionDataSet", transactions));
                }
            };
            statementFile.Close();
            stocksFile.Close();
            transactionFile.Close();
            string FileName = "Portfolio_" + Guid.NewGuid().ToString().Replace("-", "") + ".pdf";

            return(this.File(localReport.Render("pdf"), "application/pdf"));
        }
Example #2
0
        public static void GenerateReportByLanguageCode(LocalReport report, string[] subReportPath)
        {
            var doc = new XmlDocument();

            doc.Load(Assembly.GetExecutingAssembly()
                     .GetManifestResourceStream("SureMedPlusRdlc.Rdlc.SureMedReport2ColsView.rdlc"));

            PrepareXmlDocument(doc);

            report.ReportPath = string.Empty;

            using (var rdlcOutputStream = new StringReader(doc.DocumentElement.OuterXml))
            {
                report.LoadReportDefinition(rdlcOutputStream);
            }

            foreach (var sub in subReportPath)
            {
                if (sub != "")
                {
                    var docSubReport = new XmlDocument();
                    var subPath      = "SureMedPlusRdlc.Rdlc." + sub + ".rdlc";
                    docSubReport.Load(Assembly.GetExecutingAssembly().GetManifestResourceStream(subPath));

                    PrepareXmlDocument(docSubReport);

                    using (var rdlcSubReportOutputStream = new StringReader(docSubReport.DocumentElement.OuterXml))
                    {
                        report.LoadSubreportDefinition(sub, rdlcSubReportOutputStream);
                    }
                }
            }
        }
Example #3
0
        private void LoadReport(string reportPath)
        {
            Stream stream = _assembly.GetManifestResourceStream(reportPath + ".rdlc");

            using (MemoryStream memoryStream = new MemoryStream()) {
                stream.CopyTo(memoryStream);
                _localReport          = new LocalReport();
                memoryStream.Position = 0;
                _localReport.LoadReportDefinition(memoryStream);
                _dataSetSources = new Dictionary <string, MethodInfo>();

                var reportNamespace = reportPath.Substring(0, reportPath.LastIndexOf('.'));
                FillSubReports(stream, reportNamespace);

                if (_subReports != null)
                {
                    foreach (var subReport in _subReports)
                    {
                        _localReport.LoadSubreportDefinition(subReport.Key, subReport.Value);
                        FillDataSources(subReport.Value);
                    }
                }

                _localReport.EnableHyperlinks = true;

                FillDataSources(memoryStream);
            }
        }
Example #4
0
        private static void Test03(string inputReportFile, string inputSubReportFile, List <Process> processes)
        {
            var outputReportFileBaseName = $"..\\..\\TestResults\\{nameof(Test03)}.PersianRenderer";

            var correctedFileDefinition          = outputReportFileBaseName + ".rdlc";
            var correctedSubReportFileDefinition = outputReportFileBaseName + ".SubReport.rdlc";
            var correctedFileOutput = outputReportFileBaseName + ".pdf";


            PersianRenderer.CorrectReportDefinition(inputReportFile, correctedFileDefinition);
            PersianRenderer.CorrectReportDefinition(inputSubReportFile, correctedSubReportFileDefinition);

            var localReport = new LocalReport();

            localReport.ShowDetailedSubreportMessages = true;

            localReport.LoadReport(correctedFileDefinition, ReportCorrectionMode.None);

            var textReader = File.OpenText(correctedSubReportFileDefinition);

            localReport.LoadSubreportDefinition("Subreport1", textReader);          //I dont' know why it doesn't work

            var report = ReportsLoader.ExportToFile(localReport, new ReportSettings()
            {
                OutputType = ReportingServiceOutputFileFormat.PDF
            });

            File.WriteAllBytes(correctedFileOutput, report);

            Console.WriteLine($"Report {nameof(Test03)} Generated! (and will be opened in a second...)");
            processes.Add(System.Diagnostics.Process.Start(correctedFileOutput));
        }
Example #5
0
        private LocalReport GetReportePlanillaDespacho(int idPedido)
        {
            var pedido = _dbContext.Pedidos.Find(idPedido);

            var polizas = pedido.Polizas.Where(a => a.DetallePolizas.Any()).ToList();

            _tempPolizas = polizas;

            var datosCabecera = new List <PlanillaDespachoDto>
            {
                new PlanillaDespachoDto
                {
                    NombreCompleto = pedido.Cliente.NombreCompleto,
                    NitCi          = pedido.Cliente.Carnet,
                    Descripcion    = string.IsNullOrEmpty(pedido.Contenedores) ? "": pedido.Contenedores,
                    Poliza         = string.Join(" - ", polizas.Select(a => a.Codigo)),
                    LugarFecha     =
                        $"Santa Cruz - {DateTime.Now.Day} de {DateTime.Now.ToString("MMMM")} del {DateTime.Now.Year}",
                    TotalPedido = polizas.Sum(a => a.DetallePolizas.Sum(b => b.Precio))
                }
            };

            var datosPolizas = new List <PolizaDto>();

            foreach (var poliza in polizas)
            {
                var datoPoliza = new PolizaDto
                {
                    IdPoliza    = poliza.Id,
                    Nombre      = poliza.Nombre,
                    Codigo      = poliza.Codigo,
                    TotalPoliza = poliza.DetallePolizas.Sum(a => a.Precio)
                };
                datosPolizas.Add(datoPoliza);
            }

            var localReport = new LocalReport();

            localReport.SubreportProcessing += SubReporteDetalleContenedor;

            localReport.DataSources.Clear();
            var memory = pedido.EmpresaId == (int)EmpresaEnum.MaxiTrader
               ? new MemoryStream(ReportesResources.PlanillaDespachoMaxT)
               : new MemoryStream(ReportesResources.PlanillaDespacho);
            var subMemory = new MemoryStream(ReportesResources.SubDetalleContenedor);

            localReport.LoadReportDefinition(memory);
            localReport.LoadSubreportDefinition("SubDetalleContenedor", subMemory);

            ////Agregar nuevo ReportDataSource con el nombre y lista correspondiente.
            localReport.DataSources.Add(new ReportDataSource("PlantillaDespacho", datosCabecera));
            localReport.DataSources.Add(new ReportDataSource("Poliza", datosPolizas));
            return(localReport);
        }
        private static void InitializeLocalReport(LocalReport localReport, IPoProvider poProvider, Stream reportDefinitionStream, Dictionary <string, Stream> subReportDefinitionStreams)
        {
            localReport.SubreportProcessing += (sender, args) => poProvider.SubReportProcessingEventHandler(sender, new ServerSubReportProcessingEventArgs(args));

            localReport.LoadReportDefinition(reportDefinitionStream);
            localReport.EnableExternalImages = true;

            foreach (var subReportKeyValuePair in subReportDefinitionStreams)
            {
                localReport.LoadSubreportDefinition(subReportKeyValuePair.Key, subReportKeyValuePair.Value);
            }

            ReportDataSource.SetDataSources(new ServerReportDataSourceCollection(localReport.DataSources), poProvider.DataSources);
            localReport.SetParameters(poProvider.ReportParameters.Select(svp => svp.ReportParameter));
        }
        /// <summary>
        /// Renders the report.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="reportFormat">The report format.</param>
        /// <param name="dataSources">The data sources.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="subreportDefinitions">The sub-report definitions.</param>
        /// <returns>
        /// The report contents.
        /// </returns>
        private byte[] RenderReport(LocalReport report, string reportFormat, IDictionary <string, IEnumerable> dataSources, IDictionary <string, string> parameters, IDictionary <string, Stream> subreportDefinitions)
        {
            if (dataSources != null)
            {
                foreach (KeyValuePair <string, IEnumerable> ds in dataSources)
                {
                    ReportDataSource rds = new ReportDataSource(ds.Key, ds.Value);
                    report.DataSources.Add(rds);
                }
            }

            if (parameters != null)
            {
                foreach (KeyValuePair <string, string> param in parameters)
                {
                    report.SetParameters(new ReportParameter(param.Key, param.Value));
                }
            }

            if (subreportDefinitions != null)
            {
                foreach (KeyValuePair <string, Stream> sub in subreportDefinitions)
                {
                    report.LoadSubreportDefinition(sub.Key, sub.Value);
                }

                report.SubreportProcessing += Report_SubreportProcessing;
            }

            string mimeType, encoding, extension;

            string[]  streams;
            Warning[] warnings;

            byte[] reportContents = report.Render(reportFormat, null, out mimeType, out encoding, out extension, out streams, out warnings);
            this.MimeType  = mimeType;
            this.Encoding  = encoding;
            this.Extension = extension;
            this.Streams   = streams.ToList();
            this.Warnings  = warnings.Select(x => x.Message).ToList();

            return(reportContents);
        }
Example #8
0
        protected void btnPrintReport_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(ReportName))
            {
                return;
            }
            List <UCAReports.ReportCommon.ReportDataSource> reportDataSource = GetReportDataSource();

            LocalReport LR = new LocalReport();

            LR.LoadReportDefinition(UCAReports.ReportCommon.GetReportStream(ReportName));

            // Loading Sub reports
            if (SubReportsName != null && SubReportsName.Count > 0)
            {
                foreach (UCAReports.ReportCommon.SubReportDetail subRep in SubReportsName)
                {
                    LR.LoadSubreportDefinition(subRep.ReportName, UCAReports.ReportCommon.GetReportStream(subRep.ReportPath));
                }
            }

            LR.DataSources.Clear();
            if (reportDataSource != null)
            {
                foreach (UCAReports.ReportCommon.ReportDataSource rds in reportDataSource)
                {
                    LR.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource(rds.DataSetName, rds.DataSource));
                }
            }

            LR.SubreportProcessing += LocalReport_SubreportProcessing;
            LR.Refresh();

            DirectPrint DP = new DirectPrint();

            DP.Print(LR);
        }
 // Reports Load
 public static void LoadSubReport(LocalReport rpt, string reportName, string reportPath)
 {
     rpt.LoadSubreportDefinition(reportName, File.OpenRead(reportPath));
 }
Example #10
0
        private ActionResult GetResultReport <TSession, TResult>(
            IDictionary <TSession, TResult> sessionResults,
            Func <TSession, int> userModeIdSelector,
            Func <TSession, IDictionary <int, string>, object> resultConverter,
            string reportName,
            string outputName,
            string format = "PDF",
            IDictionary <string, KeyValuePair <string, SubreportProcessingEventHandler> > subReports = null)
        {
            format = format.ToUpper();
            if (!this.SupportedReportFormats().Contains(format))
            {
                format = "PDF";
            }

            string mimeType;
            var    localReport = new LocalReport {
                EnableHyperlinks = true
            };

            string reportPath   = string.Format("EdugameCloud.MVC.Reports.{0}.rdlc", reportName);
            Stream reportSource = Assembly.GetExecutingAssembly().GetManifestResourceStream(reportPath);

            localReport.LoadReportDefinition(reportSource);

            if (null != subReports)
            {
                foreach (string placeholder in subReports.Keys)
                {
                    string subReportName = string.Format(
                        "EdugameCloud.MVC.Reports.{0}.rdlc",
                        subReports[placeholder].Key);

                    Stream subReportSource = Assembly.GetExecutingAssembly().GetManifestResourceStream(subReportName);
                    if (null != subReportSource)
                    {
                        localReport.LoadSubreportDefinition(placeholder, subReportSource);
                    }
                }

                localReport.SubreportProcessing += (sender, args) =>
                {
                    string placeholder = args.ReportPath;

                    if (!string.IsNullOrEmpty(placeholder))
                    {
                        KeyValuePair <string, SubreportProcessingEventHandler> rep;
                        if (subReports.TryGetValue(placeholder, out rep))
                        {
                            rep.Value(sender, args);
                        }
                    }
                    else
                    {
                        var trickReportName = args.Parameters.FirstOrDefault(x => x.Name.StartsWith("trick"));
                        if (trickReportName != null)
                        {
                            string rptName = trickReportName.Name.Substring("trick".Length);

                            KeyValuePair <string, SubreportProcessingEventHandler> rep;
                            if (subReports.TryGetValue(rptName, out rep))
                            {
                                rep.Value(sender, args);
                            }
                        }
                    }
                };
            }

            localReport.DataSources.Clear();

            var userModes =
                this.userModeModel.GetAllByIds(sessionResults.Keys.Select(userModeIdSelector).Distinct().ToList())
                .ToDictionary(m => m.Id, m => m.UserMode);

            var results = (from s in sessionResults.Keys select resultConverter(s, userModes)).ToList();

            localReport.DataSources.Add(new ReportDataSource("ItemDataSet", results));
            string encoding;
            string fileNameExtension;

            Warning[] warnings;
            string[]  streams;
            var       renderedBytes = localReport.Render(
                format,
                this.GetDeviceInfo(format),
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);

            if (renderedBytes != null)
            {
                return(this.File(
                           renderedBytes,
                           mimeType,
                           string.Format("{0}.{1}", outputName, this.GetFileExtensions(format))));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
        }
Example #11
0
        protected byte[] ProcessReport(LocalReport report, string reportRenderType, string deviceInfo)
        {
            Warning[] warnings;
            string[]  streamids;
            string    mimeType;
            string    encoding;
            string    extension;

            byte[] bytes;

            IReportDataSourceBuilder reportBuilder;

            if (SingleMode)
            {
                reportBuilder = new SingleReportDataSourceBuilder(reportDataAdapter);
            }
            else
            {
                reportBuilder = new MultiReportDataSourceBuilder(reportDataAdapters);
            }

            try
            {
                genReport = reportBuilder.GenerateReport();
                string GeneratedRDLC = genReport.Rdlc;
                report.LoadReportDefinition(new StringReader(GeneratedRDLC));

                if (!SingleMode)
                {
                    foreach (ReportBase subreport in genReport.SubReports)
                    {
                        report.LoadSubreportDefinition(subreport.Name, new StringReader(subreport.Rdlc));
                    }
                    report.SubreportProcessing += new SubreportProcessingEventHandler(report_SubreportProcessing);
                }

                #region ReportParameters

                //List<ReportParameter> reportParameters = new List<ReportParameter>();
                //IEnumerable<object> objReportParameters = reportDataAdapter.GetReportParameters();

                //if (objReportParameters != null)
                //{
                //  IEnumerator<object> enumerator = objReportParameters.GetEnumerator();
                //  try
                //  {
                //    enumerator.Reset();
                //    while (enumerator.MoveNext())
                //    {
                //      object currentParameter = enumerator.Current;
                //      if (currentParameter is ReportParameter)
                //      {
                //        reportParameters.Add((ReportParameter)currentParameter);
                //      }
                //    }
                //  }
                //  finally
                //  {
                //    enumerator.Dispose();
                //  }
                //}

                #endregion

                report.EnableExternalImages = true;
                report.EnableHyperlinks     = true;
                report.DataSources.Add(new ReportDataSource(genReport.DataSourceName, genReport.ExportedTable));
                //report.SetParameters(reportParameters);

                bytes = report.Render(reportRenderType, deviceInfo, out mimeType, out encoding,
                                      out extension, out streamids, out warnings);
            }
            finally
            {
                //
            }

            return(bytes);
        }
        public byte[] GetExportFileFromEmbeddedReport(string reportName, DataSet reportData, string formatNm, IEnumerable <ReportParameter> reportParams, Dictionary <string, string> dataSrcDataTableMapping, List <string> subReportNames, bool includeDeviceInfo, out string fileExtension, out string mimeNType)
        {
            Warning[] warnings; string[] streamids; string mimeType; string encoding; string filenameExtension;

            //Set deviceInfo parameter
            string deviceInfo = null;

            if (includeDeviceInfo)
            {
                if (formatNm == "PDF")
                {
                    deviceInfo = pdfDeviceInfo;
                }
            }

            Microsoft.Reporting.WebForms.LocalReport locReport = new LocalReport();
            locReport.LoadReportDefinition(GetResourceStream(reportName.Trim()));
            if (dataSrcDataTableMapping != null && dataSrcDataTableMapping.Count > 0)
            {
                foreach (var dataSrcMapping in dataSrcDataTableMapping)
                {
                    if (reportData.Tables.Contains(dataSrcMapping.Value))
                    {
                        locReport.DataSources.Add(new ReportDataSource(dataSrcMapping.Key, reportData.Tables[dataSrcMapping.Value]));
                    }
                }
            }
            else
            {
                foreach (DataTable dtbl in reportData.Tables)
                {
                    //locReport.DataSources.Add(new ReportDataSource(string.Format("{0}_{1}", reportData.DataSetName, dtbl.TableName), dtbl));
                    locReport.DataSources.Add(new ReportDataSource(string.Format("{0}", reportData.DataSetName), dtbl));
                }
            }
            if (subReportNames != null && subReportNames.Count > 0)
            {
                foreach (string subReport in subReportNames)
                {
                    locReport.LoadSubreportDefinition(subReport, GetResourceStream(subReport));
                }
                locReport.SubreportProcessing += new SubreportProcessingEventHandler(locReport_SubreportProcessing);
            }
            if (formatNm.ToUpper() == "EXCEL")
            {
                RenderingExtension[] renderExts = locReport.ListRenderingExtensions();
                foreach (RenderingExtension renExt in renderExts)
                {
                    if (renExt.Name.ToUpper() == "EXCELOPENXML")
                    {
                        formatNm = renExt.Name;
                        break;
                    }
                }
            }
            if (reportParams != null)
            {
                locReport.SetParameters(reportParams);
            }
            byte[] pdfBytes = locReport.Render(formatNm, deviceInfo, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
            fileExtension = filenameExtension;
            mimeNType     = mimeType;
            return(pdfBytes);
        }
        public void Generate(Models.ReportModel reportModel, string destinationPath)
        {
            using (LocalReport localReport = new LocalReport())
            {
                localReport.DataSources.Add(new ReportDataSource("DataSet1", reportModel.MidYearReportData));

                Func<string, System.IO.FileStream> openReadOnlyStream =
                    (file) => System.IO.File.Open(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                localReport.LoadSubreportDefinition("StatsChart",
                    System.IO.StringReader.Synchronized(new System.IO.StreamReader(this.definitions.StatsChartPath)));

                localReport.LoadSubreportDefinition("CognitiveReportsUnlocked",
                    System.IO.StringReader.Synchronized(new System.IO.StreamReader(this.definitions.CognitiveReportsUnlockedPath)));

                localReport.LoadSubreportDefinition("StudentsOnTrack",
                    System.IO.StringReader.Synchronized(new System.IO.StreamReader(this.definitions.StudentsOnTrackPath)));

                localReport.LoadSubreportDefinition("CognitiveWeaknesses",
                    System.IO.StringReader.Synchronized(new System.IO.StreamReader(this.definitions.CognitiveWeaknessesPath)));

                localReport.LoadSubreportDefinition("LeadingCohorts",
                    System.IO.StringReader.Synchronized(new System.IO.StreamReader(this.definitions.LeadingCohortsPath)));

                SubreportProcessingEventHandler processSubreport = (s, e) =>
                {
                    if (e.ReportPath == "StatsChart")
                    {
                        e.DataSources.Add(new ReportDataSource("DataSet1", reportModel.BasicStats));
                    }
                    if (e.ReportPath == "CognitiveReportsUnlocked")
                    {
                        e.DataSources.Add(new ReportDataSource("DataSet1", reportModel.UnlockedReports));
                    }

                    if (e.ReportPath == "StudentsOnTrack")
                    {
                        e.DataSources.Add(new ReportDataSource("DataSet1", reportModel.OnTrack));
                    }

                    if (e.ReportPath == "CognitiveWeaknesses")
                    {
                        e.DataSources.Add(new ReportDataSource("DataSet1", reportModel.CognitiveWeakness));
                    }

                    if (e.ReportPath == "LeadingCohorts")
                    {
                        e.DataSources.Add(new ReportDataSource("DataSet1", reportModel.LeadingCohorts));
                    }
                };

                localReport.SubreportProcessing += processSubreport;
                localReport.ReportPath = this.definitions.MidYearReportPath;

                byte[] completedReport = localReport.Render("PDF");

                using (var writer = new System.IO.FileStream(destinationPath, System.IO.FileMode.Create))
                {
                    writer.Write(completedReport, 0, completedReport.Count());
                }
                localReport.SubreportProcessing -= processSubreport;

            }

        }
 // Reports Load
 public static void LoadSubReport(LocalReport rpt, string reportName, string reportPath)
 {
     rpt.LoadSubreportDefinition(reportName, File.OpenRead(reportPath));
 }