using Microsoft.Reporting.WebForms; using System; using System.Collections.Generic; using System.Web; using System.Web.Mvc; namespace Vrh.Web.OneReport.ReportViewerForMvc { /// /// Encapsulates the methods and properties used for the ReportViewerForMvc extension. /// public static class ReportViewerForMvc { private static ReportViewer reportViewer; internal static ReportViewer ReportViewer { get { return reportViewer; } set { //TODO: Implement dynamic ID reportViewer = value; reportViewer.ID = "ReportViewer1"; } } internal static HtmlString GetIframe(ReportViewer reportViewer, object htmlAttributes, int asyncPostBackTimeout) { string IframeId; if (reportViewer == null) { throw new ArgumentNullException("reportViewer", "Value cannot be null."); } ReportViewerForMvc.ReportViewer = reportViewer; IDictionary parsedHtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); IframeId = parsedHtmlAttributes["id"] == null ? "r" + Guid.NewGuid().ToString() : TagBuilder.CreateSanitizedId(parsedHtmlAttributes["id"].ToString()); if (IframeId == null) { throw new ArgumentNullException("htmlAttributes.id", "Value cannot be null."); } string applicationPath = (HttpContext.Current.Request.ApplicationPath == "/") ? "" : HttpContext.Current.Request.ApplicationPath; var iFrametagBuilder = new TagBuilder("iframe"); iFrametagBuilder.GenerateId(IframeId); iFrametagBuilder.MergeAttribute("src", applicationPath + "/Areas/OneReport/ReportViewerWebForm.aspx?AsyncPostBackTimeOut=" + asyncPostBackTimeout.ToString()); iFrametagBuilder.MergeAttributes(parsedHtmlAttributes, false); iFrametagBuilder.SetInnerText("iframes not supported."); string IFramTagtext = iFrametagBuilder.ToString(); IFramTagtext += ""; IFramTagtext += ""; return new HtmlString(IFramTagtext); } /// /// Constructs a ReporViewer /// /// The object containing the ReportViewer properties. /// An object containing the LocalReport/ServerReport properties. /// An instance of ReportViewer with the specified properties public static ReportViewer AnonymousReportViewer(object reportViewer, object report) { return AnonymousReportViewer(reportViewer, report, null, null); } /// /// Constructs a ReporViewer with parameters /// /// The object containing the ReportViewer properties. /// An object containing the LocalReport/ServerReport properties. /// Object that contains the parameters for a report. /// An instance of ReportViewer with the specified properties public static ReportViewer AnonymousReportViewer(object reportViewer, object report, object parameters) { return AnonymousReportViewer(reportViewer, report, parameters, null); } /// /// Constructs a ReporViewer with parameters and data sources. /// /// The object containing the ReportViewer properties. /// An object containing the LocalReport/ServerReport properties. /// Object that contains the parameters for a report. /// The data sources to be added to the report. /// An instance of ReportViewer with the specified properties public static ReportViewer AnonymousReportViewer(object reportViewer, object report, object parameters, object dataSources) { if (reportViewer == null) { throw new ArgumentNullException("reportViewer", "Value cannot be null."); } if (report == null) { throw new ArgumentNullException("report", "Value cannot be null."); } ReportViewer reportViewerControl = ReportViewerHelper.AnonymousToReportViewer(reportViewer); if (reportViewerControl.ProcessingMode == ProcessingMode.Local) { reportViewerControl.LocalReport.SetProperties(ReportViewerHelper.AnonymousToLocalReport(report)); if (parameters != null) { reportViewerControl.LocalReport.SetParameters(ReportViewerHelper.AnonymousToReportParameter(parameters)); } if (dataSources != null) { reportViewerControl.LocalReport.DataSources.Add(ReportViewerHelper.AnonymousToReportDataSourceList(dataSources)); } } else if (reportViewerControl.ProcessingMode == ProcessingMode.Remote) { reportViewerControl.ServerReport.SetProperties(ReportViewerHelper.AnonymousToServerReport(report)); if (parameters != null) { reportViewerControl.ServerReport.SetParameters(ReportViewerHelper.AnonymousToReportParameter(parameters)); } } return reportViewerControl; } } }