Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @model Company.Suite.Views.MVC.Views.Reports.RdlxModel
- @using GrapeCity.ActiveReports.Export.Html.Page
- @using Company.Suite.Views.MVC.Controllers
- @using System.IO
- @using Microsoft.AspNetCore.Http
- @using Newtonsoft.Json
- @using System.Text
- @using System.Data
- @{
- object Render()
- {
- var reportName = Model.ReportName;
- var fileName = $"Views\\Reports\\{reportName}.rdlx";
- var reportArgs = Encoding.UTF8.GetString(Convert.FromBase64String(Model.ReportArgs)).Split("|");
- if (!System.IO.File.Exists(fileName)) throw new Exception($"Report {reportName} not found.");
- using var reader = new System.IO.StreamReader(System.IO.File.OpenRead(fileName));
- var rpt = new GrapeCity.ActiveReports.PageReport(reader);
- var method = typeof(ViewDataProvider).GetMethod(reportName);
- var methodArgs = new List<object>();
- foreach (var p in method.GetParameters())
- {
- var paramFound = false;
- foreach (var arg in reportArgs)
- {
- var parts = arg.Split("=");
- if (parts[0].Equals(p.Name, StringComparison.OrdinalIgnoreCase))
- {
- methodArgs.Add(parts[1]);
- paramFound = true;
- continue;
- }
- }
- if (!paramFound) try { methodArgs.Add(ConfigurationParameters.GetParameter($"DefaultReportParameter_{reportName}_{p.Name}").Value); } catch { }
- }
- rpt.Document.LocateDataSource += (sender, args) => args.Data = JsonConvert.SerializeObject(method.Invoke(new ViewDataProvider(), methodArgs.ToArray()));
- var htmlRenderer = new GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension();
- var settings = (Settings)htmlRenderer.GetSupportedSettings();
- settings.StyleStream = false;
- settings.Fragment = false;
- settings.OutputTOC = false;
- var output = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
- rpt.Document.Render(htmlRenderer, output, ((GrapeCity.ActiveReports.Extensibility.Rendering.ISettings)settings).GetSettings());
- var stringContent = new System.IO.StreamReader(output.GetPrimaryStream().OpenStream()).ReadToEnd();
- return stringContent;
- }
- }
- @Html.Raw(Render());
Add Comment
Please, Sign In to add comment