Guest User

Untitled

a guest
Feb 17th, 2022
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @model Company.Suite.Views.MVC.Views.Reports.RdlxModel
  2. @using GrapeCity.ActiveReports.Export.Html.Page
  3. @using Company.Suite.Views.MVC.Controllers
  4. @using System.IO
  5. @using Microsoft.AspNetCore.Http
  6. @using Newtonsoft.Json
  7. @using System.Text
  8. @using System.Data
  9. @{
  10.     object Render()
  11.     {
  12.         var reportName = Model.ReportName;
  13.         var fileName = $"Views\\Reports\\{reportName}.rdlx";
  14.         var reportArgs = Encoding.UTF8.GetString(Convert.FromBase64String(Model.ReportArgs)).Split("|");
  15.  
  16.         if (!System.IO.File.Exists(fileName)) throw new Exception($"Report {reportName} not found.");
  17.  
  18.         using var reader = new System.IO.StreamReader(System.IO.File.OpenRead(fileName));
  19.         var rpt = new GrapeCity.ActiveReports.PageReport(reader);
  20.         var method = typeof(ViewDataProvider).GetMethod(reportName);
  21.         var methodArgs = new List<object>();
  22.         foreach (var p in method.GetParameters())
  23.         {
  24.             var paramFound = false;
  25.             foreach (var arg in reportArgs)
  26.             {
  27.                 var parts = arg.Split("=");
  28.                 if (parts[0].Equals(p.Name, StringComparison.OrdinalIgnoreCase))
  29.                 {
  30.                     methodArgs.Add(parts[1]);
  31.                     paramFound = true;
  32.                     continue;
  33.                 }
  34.             }
  35.             if (!paramFound) try { methodArgs.Add(ConfigurationParameters.GetParameter($"DefaultReportParameter_{reportName}_{p.Name}").Value); } catch { }
  36.         }
  37.         rpt.Document.LocateDataSource += (sender, args) => args.Data = JsonConvert.SerializeObject(method.Invoke(new ViewDataProvider(), methodArgs.ToArray()));
  38.         var htmlRenderer = new GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension();
  39.         var settings = (Settings)htmlRenderer.GetSupportedSettings();
  40.         settings.StyleStream = false;
  41.         settings.Fragment = false;
  42.         settings.OutputTOC = false;
  43.         var output = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
  44.         rpt.Document.Render(htmlRenderer, output, ((GrapeCity.ActiveReports.Extensibility.Rendering.ISettings)settings).GetSettings());
  45.         var stringContent = new System.IO.StreamReader(output.GetPrimaryStream().OpenStream()).ReadToEnd();
  46.         return stringContent;
  47.     }
  48. }
  49.  
  50. @Html.Raw(Render());
RAW Paste Data Copied