/// <summary>
        /// Creates an instance of MvcReportViewerIframe class.
        /// </summary>
        /// <param name="reportPath">The path to the report on the server.</param>
        /// <param name="reportServerUrl">The URL for the report server.</param>
        /// <param name="username">The report server username.</param>
        /// <param name="password">The report server password.</param>
        /// <param name="reportParameters">The report parameter properties for the report.</param>
        /// <param name="controlSettings">The Report Viewer control's UI settings.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
        /// <param name="method">Method for sending parameters to the iframe, either GET or POST.</param>
        public MvcReportViewerIframe(
            string reportPath,
            string reportServerUrl,
            string username,
            string password,
            IEnumerable <KeyValuePair <string, object> > reportParameters,
            ControlSettings controlSettings,
            IDictionary <string, object> htmlAttributes,
            FormMethod method)
        {
            _reportPath       = reportPath;
            _reportServerUrl  = reportServerUrl;
            _username         = username;
            _password         = password;
            _controlSettings  = controlSettings;
            _reportParameters = reportParameters != null?reportParameters.ToList() : null;

            _htmlAttributes = htmlAttributes;
            _method         = method;
            _aspxViewer     = ConfigurationManager.AppSettings[WebConfigSettings.AspxViewer];
            if (string.IsNullOrEmpty(_aspxViewer))
            {
                throw new MvcReportViewerException("ASP.NET Web Forms viewer is not set. Make sure you have MvcReportViewer.AspxViewer in your Web.config.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an instance of MvcReportViewerIframe class.
        /// </summary>
        /// <param name="reportPath">The path to the report on the server.</param>
        /// <param name="reportServerUrl">The URL for the report server.</param>
        /// <param name="username">The report server username.</param>
        /// <param name="password">The report server password.</param>
        /// <param name="reportParameters">The report parameter properties for the report.</param>
        /// <param name="controlSettings">The Report Viewer control's UI settings.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
        /// <param name="method">Method for sending parameters to the iframe, either GET or POST.</param>
        public MvcReportViewerIframe(
            string reportPath,
            string reportServerUrl,
            string username,
            string password,
            IEnumerable <KeyValuePair <string, object> > reportParameters,
            ControlSettings controlSettings,
            IDictionary <string, object> htmlAttributes,
            FormMethod method)
        {
            var javaScriptApi = ConfigurationManager.AppSettings[WebConfigSettings.JavaScriptApi];

            if (string.IsNullOrEmpty(javaScriptApi))
            {
                throw new MvcReportViewerException("MvcReportViewer.js location is not found. Make sure you have MvcReportViewer.AspxViewerJavaScript in your Web.config.");
            }

            _reportPath       = reportPath;
            _reportServerUrl  = reportServerUrl;
            _username         = username;
            _password         = password;
            _controlSettings  = controlSettings;
            _reportParameters = reportParameters != null?reportParameters.ToList() : null;

            _htmlAttributes = htmlAttributes;
            _method         = method;
            _aspxViewer     = ConfigurationManager.AppSettings[WebConfigSettings.AspxViewer];
            if (string.IsNullOrEmpty(_aspxViewer))
            {
                throw new MvcReportViewerException("ASP.NET Web Forms viewer is not set. Make sure you have MvcReportViewer.AspxViewer in your Web.config.");
            }

            _aspxViewer = _aspxViewer.Trim();
            if (_aspxViewer.StartsWith("~"))
            {
                _aspxViewer = VirtualPathUtility.ToAbsolute(_aspxViewer);
            }

            var encryptParametesConfig = ConfigurationManager.AppSettings[WebConfigSettings.EncryptParameters];

            if (!bool.TryParse(encryptParametesConfig, out _encryptParameters))
            {
                _encryptParameters = false;
            }

            ControlId = Guid.NewGuid();
        }
        public ControlSettings Deserialize(NameValueCollection queryString)
        {
            var settings = new ControlSettings();
            if (queryString == null)
            {
                return settings;
            }

            var actualSettings = queryString.AllKeys.Where(IsControlSetting);
            foreach (var setting in actualSettings)
            {
                var property = UriParameters[setting];
                var value = queryString[setting];
                DeserializeValue(settings, property, value);
            }

            return settings;
        }
 /// <summary>
 /// Creates an instance of MvcReportViewerIframe class.
 /// </summary>
 /// <param name="reportPath">The path to the report on the server.</param>
 /// <param name="reportServerUrl">The URL for the report server.</param>
 /// <param name="username">The report server username.</param>
 /// <param name="password">The report server password.</param>
 /// <param name="reportParameters">The report parameter properties for the report.</param>
 /// <param name="controlSettings">The Report Viewer control's UI settings.</param>
 /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
 /// <param name="method">Method for sending parameters to the iframe, either GET or POST.</param>
 public MvcReportViewerIframe(
     string reportPath,
     string reportServerUrl,
     string username,
     string password,
     IDictionary <string, object> reportParameters,
     ControlSettings controlSettings,
     IDictionary <string, object> htmlAttributes,
     FormMethod method)
     : this(
         reportPath,
         reportServerUrl,
         username,
         password,
         reportParameters != null ? reportParameters.ToList() : null,
         controlSettings,
         htmlAttributes,
         method)
 {
 }
        public ControlSettings Deserialize(NameValueCollection queryString)
        {
            var settings = new ControlSettings();

            if (queryString == null)
            {
                return(settings);
            }

            var actualSettings = queryString.AllKeys.Where(IsControlSetting);

            foreach (var setting in actualSettings)
            {
                var property = UriParameters[setting];
                var value    = queryString[setting];
                DeserializeValue(settings, property, value);
            }

            return(settings);
        }
 /// <summary>
 /// Returns an HTML <b>iframe</b> rendering ASP.NET ReportViewer control with Remote Processing Mode.
 /// </summary>
 /// <param name="helper">The HTML helper instance that this method extends.</param>
 /// <param name="reportPath">The path to the report on the server.</param>
 /// <param name="reportServerUrl">The URL for the report server.</param>
 /// <param name="username">The report server username.</param>
 /// <param name="password">The report server password.</param>
 /// <param name="reportParameters">The report parameter properties for the report.</param>
 /// <param name="controlSettings">The Report Viewer control's UI settings.</param>
 /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
 /// <param name="method">Method for sending parameters to the iframe, either GET or POST.</param>
 /// <returns>An HTML <b>iframe</b> element.</returns>
 public static MvcReportViewerIframe MvcReportViewer(
     this HtmlHelper helper,
     string reportPath,
     string reportServerUrl          = null,
     string username                 = null,
     string password                 = null,
     object reportParameters         = null,
     ControlSettings controlSettings = null,
     object htmlAttributes           = null,
     FormMethod method               = FormMethod.Get)
 {
     return(new MvcReportViewerIframe(
                reportPath,
                reportServerUrl,
                username,
                password,
                HtmlHelper.AnonymousObjectToHtmlAttributes(reportParameters),
                controlSettings,
                HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes),
                method));
 }
        /// <summary>
        /// Creates an instance of MvcReportViewerIframe class.
        /// </summary>
        /// <param name="reportPath">The path to the report on the server.</param>
        /// <param name="reportServerUrl">The URL for the report server.</param>
        /// <param name="username">The report server username.</param>
        /// <param name="password">The report server password.</param>
        /// <param name="reportParameters">The report parameter properties for the report.</param>
        /// <param name="controlSettings">The Report Viewer control's UI settings.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
        /// <param name="method">Method for sending parameters to the iframe, either GET or POST.</param>
        public MvcReportViewerIframe(
            string reportPath,
            string reportServerUrl,
            string username,
            string password,
            IEnumerable <KeyValuePair <string, object> > reportParameters,
            ControlSettings controlSettings,
            IDictionary <string, object> htmlAttributes,
            FormMethod method)
        {
            if (string.IsNullOrEmpty(_config.AspxViewerJavaScript))
            {
                throw new MvcReportViewerException("MvcReportViewer.js location is not found. Make sure you have MvcReportViewer.AspxViewerJavaScript in your Web.config.");
            }

            _reportPath       = reportPath;
            _reportServerUrl  = reportServerUrl;
            _username         = username;
            _password         = password;
            _controlSettings  = controlSettings;
            _reportParameters = reportParameters?.ToList();
            _htmlAttributes   = htmlAttributes;
            _method           = method;
            _aspxViewer       = _config.AspxViewer;
            if (string.IsNullOrEmpty(_aspxViewer))
            {
                throw new MvcReportViewerException("ASP.NET Web Forms viewer is not set. Make sure you have MvcReportViewer.AspxViewer in your Web.config.");
            }

            _aspxViewer = _aspxViewer.Trim();
            if (_aspxViewer.StartsWith("~"))
            {
                _aspxViewer = VirtualPathUtility.ToAbsolute(_aspxViewer);
            }

            _aspxViewer = ApplyAppPathModifier(_aspxViewer);

            _encryptParameters = _config.EncryptParameters;
            ControlId          = Guid.NewGuid();
        }
Esempio n. 8
0
        public IDictionary <string, string> Serialize(ControlSettings settings)
        {
            var activeSettings = new Dictionary <string, string>();

            if (settings == null)
            {
                return(activeSettings);
            }

            foreach (var settingsInfo in Properties)
            {
                var property = settingsInfo.Key;
                var value    = property.GetValue(settings, null);

                if (value == null)
                {
                    continue;
                }

                var    uriKey = settingsInfo.Value;
                string serializedSetting;
                if (property.PropertyType == typeof(Color?))
                {
                    serializedSetting = ((Color?)value).Value
                                        .ToArgb()
                                        .ToString(CultureInfo.CurrentCulture);
                }
                else
                {
                    serializedSetting = value.ToString();
                }

                activeSettings.Add(uriKey, serializedSetting);
            }

            return(activeSettings);
        }
        public IDictionary<string, string> Serialize(ControlSettings settings)
        {
            var activeSettings = new Dictionary<string, string>();
            if (settings == null)
            {
                return activeSettings;
            }

            foreach(var settingsInfo in Properties)
            {
                var property = settingsInfo.Key;
                var value = property.GetValue(settings, null);

                if (value == null)
                {
                    continue;
                }

                var uriKey = settingsInfo.Value;
                string serializedSetting;
                if (property.PropertyType == typeof (Color?))
                {
                    serializedSetting = ((Color?) value).Value
                                                        .ToArgb()
                                                        .ToString(CultureInfo.CurrentCulture);
                }
                else
                {
                    serializedSetting = value.ToString();
                }

                activeSettings.Add(uriKey, serializedSetting);
            }

            return activeSettings;
        }
        private void DeserializeValue(ControlSettings settings, PropertyInfo property, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            if (property.PropertyType == typeof (string))
            {
                property.SetValue(settings, value, null);
            }
            else if (property.PropertyType == typeof (int?))
            {
                int numValue;
                if (int.TryParse(value, out numValue))
                {
                    property.SetValue(settings, numValue, null);
                }
            }
            else if (property.PropertyType == typeof (bool?))
            {
                bool boolValue;
                if (bool.TryParse(value, out boolValue))
                {
                    property.SetValue(settings, boolValue, null);
                }
            }
            else if (property.PropertyType == typeof (Color?))
            {
                int argbColor;
                if (int.TryParse(value, out argbColor))
                {
                    var color = Color.FromArgb(argbColor);
                    property.SetValue(settings, color, null);
                }
            }
            else if (property.PropertyType == typeof (Unit?))
            {
                var unit = new Unit(value);
                property.SetValue(settings, unit, null);
            }
            else if (property.PropertyType == typeof (BorderStyle?))
            {
                BorderStyle style;
                if (Enum.TryParse(value, true, out style))
                {
                    property.SetValue(settings, style, null);
                }
            }
            else if (property.PropertyType == typeof (ZoomMode?))
            {
                ZoomMode mode;
                if (Enum.TryParse(value, true, out mode))
                {
                    property.SetValue(settings, mode, null);
                }
            }
            else
            {
                throw new ArgumentException(
                        string.Format("Unknown property {0} type: {1}", property.Name, property.PropertyType));
            }
        }
 /// <summary>
 /// Sets ReportViewer control UI parameters
 /// </summary>
 /// <param name="settings"></param>
 /// <returns>An instance of MvcViewerOptions class.</returns>
 public IMvcReportViewerOptions ControlSettings(ControlSettings settings)
 {
     _controlSettings = settings;
     return(this);
 }
 /// <summary>
 /// Returns an HTML <b>iframe</b> rendering ASP.NET ReportViewer control with Remote Processing Mode.
 /// </summary>
 /// <param name="helper">The HTML helper instance that this method extends.</param>
 /// <param name="reportPath">The path to the report on the server.</param>
 /// <param name="reportServerUrl">The URL for the report server.</param>
 /// <param name="username">The report server username.</param>
 /// <param name="password">The report server password.</param>
 /// <param name="reportParameters">The report parameter properties for the report.</param>
 /// <param name="controlSettings">The Report Viewer control's UI settings.</param>
 /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
 /// <param name="method">Method for sending parameters to the iframe, either GET or POST.</param>
 /// <returns>An HTML <b>iframe</b> element.</returns>
 public static MvcReportViewerIframe MvcReportViewer(
     this HtmlHelper helper,
     IReportLoader reportLoader,
     IEnumerable<KeyValuePair<string, object>> reportParameters = null,
     ControlSettings controlSettings = null,
     object htmlAttributes = null,
     FormMethod method = FormMethod.Get)
 {
     return new MvcReportViewerIframe(
         reportLoader,
         reportParameters,
         controlSettings,
         HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes),
         method);
 }
 /// <summary>
 /// Returns an HTML <b>iframe</b> rendering ASP.NET ReportViewer control with Remote Processing Mode.
 /// </summary>
 /// <param name="helper">The HTML helper instance that this method extends.</param>
 /// <param name="reportPath">The path to the report on the server.</param>
 /// <param name="reportServerUrl">The URL for the report server.</param>
 /// <param name="username">The report server username.</param>
 /// <param name="password">The report server password.</param>
 /// <param name="reportParameters">The report parameter properties for the report.</param>
 /// <param name="controlSettings">The Report Viewer control's UI settings.</param>
 /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
 /// <param name="method">Method for sending parameters to the iframe, either GET or POST.</param>
 /// <returns>An HTML <b>iframe</b> element.</returns>
 public static MvcReportViewerIframe MvcReportViewer(
     this HtmlHelper helper,
     string reportPath,
     string reportServerUrl = null,
     string username = null,
     string password = null,
     object reportParameters = null,
     ControlSettings controlSettings = null,
     object htmlAttributes = null,
     FormMethod method = FormMethod.Get)
 {
     return new MvcReportViewerIframe(
         reportPath,
         reportServerUrl,
         username,
         password,
         HtmlHelper.AnonymousObjectToHtmlAttributes(reportParameters),
         controlSettings,
         HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes),
         method);
 }
        private static void SetReportViewerSettings(ReportViewer reportViewer, ControlSettings parameters)
        {
            // Hide parameters prompt by default
            if (parameters == null)
            {
                reportViewer.ShowParameterPrompts = false;
                return;
            }

            if (parameters.BackColor != null)
            {
                reportViewer.BackColor = parameters.BackColor.Value;
            }

            if (parameters.DocumentMapCollapsed != null)
            {
                reportViewer.DocumentMapCollapsed = parameters.DocumentMapCollapsed.Value;
            }

            if (parameters.DocumentMapWidth != null)
            {
                reportViewer.DocumentMapWidth = parameters.DocumentMapWidth.Value;
            }

            if (parameters.HyperlinkTarget != null)
            {
                reportViewer.HyperlinkTarget = parameters.HyperlinkTarget;
            }

            if (parameters.InternalBorderColor != null)
            {
                reportViewer.InternalBorderColor = parameters.InternalBorderColor.Value;
            }

            if (parameters.InternalBorderStyle != null)
            {
                reportViewer.InternalBorderStyle = parameters.InternalBorderStyle.Value;
            }

            if (parameters.InternalBorderWidth != null)
            {
                reportViewer.InternalBorderWidth = parameters.InternalBorderWidth.Value;
            }

            if (parameters.LinkActiveColor != null)
            {
                reportViewer.LinkActiveColor = parameters.LinkActiveColor.Value;
            }

            if (parameters.LinkActiveHoverColor != null)
            {
                reportViewer.LinkActiveHoverColor = parameters.LinkActiveHoverColor.Value;
            }

            if (parameters.LinkDisabledColor != null)
            {
                reportViewer.LinkDisabledColor = parameters.LinkDisabledColor.Value;
            }

            if (parameters.PromptAreaCollapsed != null)
            {
                reportViewer.PromptAreaCollapsed = parameters.PromptAreaCollapsed.Value;
            }

            if (parameters.ShowBackButton != null)
            {
                reportViewer.ShowBackButton = parameters.ShowBackButton.Value;
            }

            if (parameters.ShowCredentialPrompts != null)
            {
                reportViewer.ShowCredentialPrompts = parameters.ShowCredentialPrompts.Value;
            }

            if (parameters.ShowDocumentMapButton != null)
            {
                reportViewer.ShowDocumentMapButton = parameters.ShowDocumentMapButton.Value;
            }

            if (parameters.ShowExportControls != null)
            {
                reportViewer.ShowExportControls = parameters.ShowExportControls.Value;
            }

            if (parameters.ShowFindControls != null)
            {
                reportViewer.ShowFindControls = parameters.ShowFindControls.Value;
            }

            if (parameters.ShowPageNavigationControls != null)
            {
                reportViewer.ShowPageNavigationControls = parameters.ShowPageNavigationControls.Value;
            }

            if (parameters.ShowParameterPrompts != null)
            {
                reportViewer.ShowParameterPrompts = parameters.ShowParameterPrompts.Value;
            }

            if (parameters.ShowPrintButton != null)
            {
                reportViewer.ShowPrintButton = parameters.ShowPrintButton.Value;
            }

            if (parameters.ShowPromptAreaButton != null)
            {
                reportViewer.ShowPromptAreaButton = parameters.ShowPromptAreaButton.Value;
            }

            if (parameters.ShowRefreshButton != null)
            {
                reportViewer.ShowRefreshButton = parameters.ShowRefreshButton.Value;
            }

            if (parameters.ShowReportBody != null)
            {
                reportViewer.ShowReportBody = parameters.ShowReportBody.Value;
            }

            if (parameters.ShowToolBar != null)
            {
                reportViewer.ShowToolBar = parameters.ShowToolBar.Value;
            }

            if (parameters.ShowWaitControlCancelLink != null)
            {
                reportViewer.ShowWaitControlCancelLink = parameters.ShowWaitControlCancelLink.Value;
            }

            if (parameters.ShowZoomControl != null)
            {
                reportViewer.ShowZoomControl = parameters.ShowZoomControl.Value;
            }

            if (parameters.SizeToReportContent != null)
            {
                reportViewer.SizeToReportContent = parameters.SizeToReportContent.Value;
            }

            if (parameters.SplitterBackColor != null)
            {
                reportViewer.SplitterBackColor = parameters.SplitterBackColor.Value;
            }

            if (parameters.ToolBarItemBorderColor != null)
            {
                reportViewer.ToolBarItemBorderColor = parameters.ToolBarItemBorderColor.Value;
            }

            if (parameters.ToolBarItemBorderStyle != null)
            {
                reportViewer.ToolBarItemBorderStyle = parameters.ToolBarItemBorderStyle.Value;
            }

            if (parameters.ToolBarItemBorderWidth != null)
            {
                reportViewer.ToolBarItemBorderWidth = parameters.ToolBarItemBorderWidth.Value;
            }

            if (parameters.ToolBarItemHoverBackColor != null)
            {
                reportViewer.ToolBarItemHoverBackColor = parameters.ToolBarItemHoverBackColor.Value;
            }

            if (parameters.ZoomMode != null)
            {
                reportViewer.ZoomMode = parameters.ZoomMode.Value;
            }

            if (parameters.ZoomPercent != null)
            {
                reportViewer.ZoomPercent = parameters.ZoomPercent.Value;
            }

            if (parameters.AsyncRendering != null)
            {
                reportViewer.AsyncRendering = (bool)parameters.AsyncRendering;
            }

            reportViewer.Width = parameters.Width ?? new Unit("100%");
            reportViewer.Height = parameters.Height ?? new Unit("100%");
            reportViewer.KeepSessionAlive = parameters.KeepSessionAlive ?? false;
        }
        private string PrepareViewerUri()
        {
            var query = HttpUtility.ParseQueryString(string.Empty);

            query[UriParameters.ControlId]      = ControlId.ToString();
            query[UriParameters.ProcessingMode] = _processingMode.ToString();
            if (!string.IsNullOrEmpty(_reportPath))
            {
                query[UriParameters.ReportPath] = _reportPath;
            }

            if (!string.IsNullOrEmpty(_reportServerUrl))
            {
                query[UriParameters.ReportServerUrl] = _reportServerUrl;
            }

            if (!string.IsNullOrEmpty(_username) || !string.IsNullOrEmpty(_password))
            {
                query[UriParameters.Username] = _username;
                query[UriParameters.Password] = _password;
            }

            if (!string.IsNullOrEmpty(_eventsHandlerType))
            {
                query[UriParameters.EventsHandlerType] = _eventsHandlerType;
            }

            if (_dataSourceCredentials?.Length > 0)
            {
                query[UriParameters.DataSourceCredentials] = JsonConvert.SerializeObject(_dataSourceCredentials);
            }

            var frameHeight = GetFrameHeight();

            if (frameHeight != null)
            {
                if (_controlSettings == null)
                {
                    _controlSettings = new ControlSettings();
                }

                _controlSettings.FrameHeight = new Unit(frameHeight.Item1, frameHeight.Item2);
            }

            var serializedSettings = _settingsManager.Serialize(_controlSettings);

            foreach (var setting in serializedSettings)
            {
                query[setting.Key] = setting.Value;
            }

            if (_reportParameters != null)
            {
                foreach (var parameter in _reportParameters)
                {
                    if (parameter.Value == null)
                    {
                        continue;
                    }

                    var multiple = parameter.Value as IEnumerable;
                    if (parameter.Value is string || multiple == null)
                    {
                        var value = ConvertValueToString(parameter.Value);
                        query.Add(parameter.Key, value);
                    }
                    else
                    {
                        foreach (var v in multiple)
                        {
                            var value = ConvertValueToString(v);
                            query.Add(parameter.Key, value);
                        }
                    }
                }
            }

            string uri = _aspxViewer;

            if (query.Count == 0)
            {
                return(uri);
            }

            if (!_encryptParameters)
            {
                return(uri + "?" + query);
            }

            var encryptedQuery = UriParameters.Encrypted + "=" + SecurityUtil.Encrypt(query.ToString());

            return(uri + "?" + encryptedQuery);
        }
        private string BuildIframeFormFields()
        {
            var html = new StringBuilder();

            html.Append(CreateHiddenField(UriParameters.ControlId, ControlId));
            html.Append(CreateHiddenField(UriParameters.ProcessingMode, _processingMode));

            if (!string.IsNullOrEmpty(_reportPath))
            {
                html.Append(CreateHiddenField(UriParameters.ReportPath, _reportPath));
            }

            if (!string.IsNullOrEmpty(_reportServerUrl))
            {
                html.Append(CreateHiddenField(UriParameters.ReportServerUrl, _reportServerUrl));
            }

            if (!string.IsNullOrEmpty(_username) || !string.IsNullOrEmpty(_password))
            {
                html.Append(CreateHiddenField(UriParameters.Username, _username));
                html.Append(CreateHiddenField(UriParameters.Password, _password));
            }

            if (!string.IsNullOrEmpty(_eventsHandlerType))
            {
                html.Append(CreateHiddenField(UriParameters.EventsHandlerType, _eventsHandlerType));
            }

            if (_dataSourceCredentials?.Length > 0)
            {
                html.Append(CreateHiddenField(UriParameters.DataSourceCredentials, JsonConvert.SerializeObject(_dataSourceCredentials)));
            }

            var frameHeight = GetFrameHeight();

            if (frameHeight != null)
            {
                if (_controlSettings == null)
                {
                    _controlSettings = new ControlSettings();
                }

                _controlSettings.FrameHeight = new Unit(frameHeight.Item1, frameHeight.Item2);
            }

            var serializedSettings = _settingsManager.Serialize(_controlSettings);

            foreach (var setting in serializedSettings)
            {
                html.Append(CreateHiddenField(setting.Key, setting.Value));
            }

            if (_reportParameters != null)
            {
                foreach (var parameter in _reportParameters)
                {
                    if (parameter.Value == null)
                    {
                        continue;
                    }

                    var multiple = parameter.Value as IEnumerable;
                    if (parameter.Value is string || multiple == null)
                    {
                        var value = ConvertValueToString(parameter.Value);
                        html.Append(CreateHiddenField(parameter.Key, value));
                    }
                    else
                    {
                        foreach (var v in multiple)
                        {
                            var value = ConvertValueToString(v);
                            html.Append(CreateHiddenField(parameter.Key, value));
                        }
                    }
                }
            }

            return(html.ToString());
        }
        private static void SetReportViewerSettings(ReportViewer reportViewer, ControlSettings parameters)
        {
            // Hide parameters prompt by default
            if (parameters == null)
            {
                reportViewer.ShowParameterPrompts = false;
                return;
            }

            if (parameters.BackColor != null)
            {
                reportViewer.BackColor = parameters.BackColor.Value;
            }

            if (parameters.DocumentMapCollapsed != null)
            {
                reportViewer.DocumentMapCollapsed = parameters.DocumentMapCollapsed.Value;
            }

            if (parameters.DocumentMapWidth != null)
            {
                reportViewer.DocumentMapWidth = parameters.DocumentMapWidth.Value;
            }

            if (parameters.HyperlinkTarget != null)
            {
                reportViewer.HyperlinkTarget = parameters.HyperlinkTarget;
            }

            if (parameters.InternalBorderColor != null)
            {
                reportViewer.InternalBorderColor = parameters.InternalBorderColor.Value;
            }

            if (parameters.InternalBorderStyle != null)
            {
                reportViewer.InternalBorderStyle = parameters.InternalBorderStyle.Value;
            }

            if (parameters.InternalBorderWidth != null)
            {
                reportViewer.InternalBorderWidth = parameters.InternalBorderWidth.Value;
            }

            if (parameters.LinkActiveColor != null)
            {
                reportViewer.LinkActiveColor = parameters.LinkActiveColor.Value;
            }

            if (parameters.LinkActiveHoverColor != null)
            {
                reportViewer.LinkActiveHoverColor = parameters.LinkActiveHoverColor.Value;
            }

            if (parameters.LinkDisabledColor != null)
            {
                reportViewer.LinkDisabledColor = parameters.LinkDisabledColor.Value;
            }

            if (parameters.PromptAreaCollapsed != null)
            {
                reportViewer.PromptAreaCollapsed = parameters.PromptAreaCollapsed.Value;
            }

            if (parameters.ShowBackButton != null)
            {
                reportViewer.ShowBackButton = parameters.ShowBackButton.Value;
            }

            if (parameters.ShowCredentialPrompts != null)
            {
                reportViewer.ShowCredentialPrompts = parameters.ShowCredentialPrompts.Value;
            }

            if (parameters.ShowDocumentMapButton != null)
            {
                reportViewer.ShowDocumentMapButton = parameters.ShowDocumentMapButton.Value;
            }

            if (parameters.ShowExportControls != null)
            {
                reportViewer.ShowExportControls = parameters.ShowExportControls.Value;
            }

            if (parameters.ShowFindControls != null)
            {
                reportViewer.ShowFindControls = parameters.ShowFindControls.Value;
            }

            if (parameters.ShowPageNavigationControls != null)
            {
                reportViewer.ShowPageNavigationControls = parameters.ShowPageNavigationControls.Value;
            }

            if (parameters.ShowParameterPrompts != null)
            {
                reportViewer.ShowParameterPrompts = parameters.ShowParameterPrompts.Value;
            }

            if (parameters.ShowPrintButton != null)
            {
                reportViewer.ShowPrintButton = parameters.ShowPrintButton.Value;
            }

            if (parameters.ShowPromptAreaButton != null)
            {
                reportViewer.ShowPromptAreaButton = parameters.ShowPromptAreaButton.Value;
            }

            if (parameters.ShowRefreshButton != null)
            {
                reportViewer.ShowRefreshButton = parameters.ShowRefreshButton.Value;
            }

            if (parameters.ShowReportBody != null)
            {
                reportViewer.ShowReportBody = parameters.ShowReportBody.Value;
            }

            if (parameters.ShowToolBar != null)
            {
                reportViewer.ShowToolBar = parameters.ShowToolBar.Value;
            }

            if (parameters.ShowWaitControlCancelLink != null)
            {
                reportViewer.ShowWaitControlCancelLink = parameters.ShowWaitControlCancelLink.Value;
            }

            if (parameters.ShowZoomControl != null)
            {
                reportViewer.ShowZoomControl = parameters.ShowZoomControl.Value;
            }

            if (parameters.SizeToReportContent != null)
            {
                reportViewer.SizeToReportContent = parameters.SizeToReportContent.Value;
            }

            if (parameters.SplitterBackColor != null)
            {
                reportViewer.SplitterBackColor = parameters.SplitterBackColor.Value;
            }

            if (parameters.ToolBarItemBorderColor != null)
            {
                reportViewer.ToolBarItemBorderColor = parameters.ToolBarItemBorderColor.Value;
            }

            if (parameters.ToolBarItemBorderStyle != null)
            {
                reportViewer.ToolBarItemBorderStyle = parameters.ToolBarItemBorderStyle.Value;
            }

            if (parameters.ToolBarItemBorderWidth != null)
            {
                reportViewer.ToolBarItemBorderWidth = parameters.ToolBarItemBorderWidth.Value;
            }

            if (parameters.ToolBarItemHoverBackColor != null)
            {
                reportViewer.ToolBarItemHoverBackColor = parameters.ToolBarItemHoverBackColor.Value;
            }

            if (parameters.ZoomMode != null)
            {
                reportViewer.ZoomMode = parameters.ZoomMode.Value;
            }

            if (parameters.ZoomPercent != null)
            {
                reportViewer.ZoomPercent = parameters.ZoomPercent.Value;
            }

            reportViewer.Width = parameters.Width ?? new Unit("100%");

            // Use AsyncRendering = false and hard-coded Height to fix problem with Google Chrome report rendering
            // http://stackoverflow.com/questions/778688/reportviewer-control-height-issue

            if (parameters.Height != null)
            {
                reportViewer.Height = parameters.Height.Value;
            }
            else if (parameters.FrameHeight != null)
            {
                reportViewer.Height = parameters.FrameHeight.Value;
            }
            else
            {
                reportViewer.Height = new Unit("100%");
            }

            reportViewer.AsyncRendering = parameters.AsyncRendering ?? false;

            reportViewer.KeepSessionAlive = parameters.KeepSessionAlive ?? false;
        }
        /// <summary>
        /// Creates an instance of MvcReportViewerIframe class.
        /// </summary>
        /// <param name="reportPath">The path to the report on the server.</param>
        /// <param name="reportServerUrl">The URL for the report server.</param>
        /// <param name="username">The report server username.</param>
        /// <param name="password">The report server password.</param>
        /// <param name="reportParameters">The report parameter properties for the report.</param>
        /// <param name="controlSettings">The Report Viewer control's UI settings.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
        /// <param name="method">Method for sending parameters to the iframe, either GET or POST.</param>
        public MvcReportViewerIframe(
            IReportLoader reportLoader,
            IEnumerable<KeyValuePair<string, object>> reportParameters,
            ControlSettings controlSettings,
            IDictionary<string, object> htmlAttributes,
            FormMethod method)
        {
            var javaScriptApi = ConfigurationManager.AppSettings[WebConfigSettings.JavaScriptApi];
            if (string.IsNullOrEmpty(javaScriptApi))
            {
                throw new MvcReportViewerException("MvcReportViewer.js location is not found. Make sure you have MvcReportViewer.AspxViewerJavaScript in your Web.config.");
            }

            _reportLoader = reportLoader;

            _controlSettings = controlSettings;
            _reportParameters = reportParameters != null ? reportParameters.ToList() : null;
            _htmlAttributes = htmlAttributes;
            _method = method;
            _aspxViewer = ConfigurationManager.AppSettings[WebConfigSettings.AspxViewer];
            if (string.IsNullOrEmpty(_aspxViewer))
            {
                throw new MvcReportViewerException("ASP.NET Web Forms viewer is not set. Make sure you have MvcReportViewer.AspxViewer in your Web.config.");
            }

            _aspxViewer = _aspxViewer.Trim();
            if (_aspxViewer.StartsWith("~"))
            {
                _aspxViewer = VirtualPathUtility.ToAbsolute(_aspxViewer);
            }

            var encryptParametesConfig = ConfigurationManager.AppSettings[WebConfigSettings.EncryptParameters];
            if (!bool.TryParse(encryptParametesConfig, out _encryptParameters))
            {
                _encryptParameters = false;
            }

            ControlId = Guid.NewGuid();
        }
Esempio n. 19
0
        private void DeserializeValue(ControlSettings settings, PropertyInfo property, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            if (property.PropertyType == typeof(string))
            {
                property.SetValue(settings, value, null);
            }
            else if (property.PropertyType == typeof(int?))
            {
                int numValue;
                if (int.TryParse(value, out numValue))
                {
                    property.SetValue(settings, numValue, null);
                }
            }
            else if (property.PropertyType == typeof(bool?))
            {
                bool boolValue;
                if (bool.TryParse(value, out boolValue))
                {
                    property.SetValue(settings, boolValue, null);
                }
            }
            else if (property.PropertyType == typeof(Color?))
            {
                int argbColor;
                if (int.TryParse(value, out argbColor))
                {
                    var color = Color.FromArgb(argbColor);
                    property.SetValue(settings, color, null);
                }
            }
            else if (property.PropertyType == typeof(Unit?))
            {
                var unit = new Unit(value);
                property.SetValue(settings, unit, null);
            }
            else if (property.PropertyType == typeof(BorderStyle?))
            {
                BorderStyle style;
                if (Enum.TryParse(value, true, out style))
                {
                    property.SetValue(settings, style, null);
                }
            }
            else if (property.PropertyType == typeof(ZoomMode?))
            {
                ZoomMode mode;
                if (Enum.TryParse(value, true, out mode))
                {
                    property.SetValue(settings, mode, null);
                }
            }
            else
            {
                throw new ArgumentException(
                          string.Format("Unknown property {0} type: {1}", property.Name, property.PropertyType));
            }
        }
 /// <summary>
 /// Sets ReportViewer control UI parameters
 /// </summary>
 /// <param name="settings"></param>
 /// <returns>An instance of MvcViewerOptions class.</returns>
 public IMvcReportViewerOptions ControlSettings(ControlSettings settings)
 {
     _controlSettings = settings;
     return this;
 }
Esempio n. 21
0
        private static void SetReportViewerSettings(ReportViewer reportViewer, ControlSettings parameters)
        {
            // Hide parameters prompt by default
            if (parameters == null)
            {
                reportViewer.ShowParameterPrompts = false;
                return;
            }

            if (parameters.BackColor != null)
            {
                reportViewer.BackColor = parameters.BackColor.Value;
            }

            if (parameters.DocumentMapCollapsed != null)
            {
                reportViewer.DocumentMapCollapsed = parameters.DocumentMapCollapsed.Value;
            }

            if (parameters.DocumentMapWidth != null)
            {
                reportViewer.DocumentMapWidth = parameters.DocumentMapWidth.Value;
            }

            if (parameters.HyperlinkTarget != null)
            {
                reportViewer.HyperlinkTarget = parameters.HyperlinkTarget;
            }

            if (parameters.InternalBorderColor != null)
            {
                reportViewer.InternalBorderColor = parameters.InternalBorderColor.Value;
            }

            if (parameters.InternalBorderStyle != null)
            {
                reportViewer.InternalBorderStyle = parameters.InternalBorderStyle.Value;
            }

            if (parameters.InternalBorderWidth != null)
            {
                reportViewer.InternalBorderWidth = parameters.InternalBorderWidth.Value;
            }

            if (parameters.LinkActiveColor != null)
            {
                reportViewer.LinkActiveColor = parameters.LinkActiveColor.Value;
            }

            if (parameters.LinkActiveHoverColor != null)
            {
                reportViewer.LinkActiveHoverColor = parameters.LinkActiveHoverColor.Value;
            }

            if (parameters.LinkDisabledColor != null)
            {
                reportViewer.LinkDisabledColor = parameters.LinkDisabledColor.Value;
            }

            if (parameters.PromptAreaCollapsed != null)
            {
                reportViewer.PromptAreaCollapsed = parameters.PromptAreaCollapsed.Value;
            }

            if (parameters.ShowBackButton != null)
            {
                reportViewer.ShowBackButton = parameters.ShowBackButton.Value;
            }

            if (parameters.ShowCredentialPrompts != null)
            {
                reportViewer.ShowCredentialPrompts = parameters.ShowCredentialPrompts.Value;
            }

            if (parameters.ShowDocumentMapButton != null)
            {
                reportViewer.ShowDocumentMapButton = parameters.ShowDocumentMapButton.Value;
            }

            if (parameters.ShowExportControls != null)
            {
                reportViewer.ShowExportControls = parameters.ShowExportControls.Value;
            }

            if (parameters.ShowFindControls != null)
            {
                reportViewer.ShowFindControls = parameters.ShowFindControls.Value;
            }

            if (parameters.ShowPageNavigationControls != null)
            {
                reportViewer.ShowPageNavigationControls = parameters.ShowPageNavigationControls.Value;
            }

            if (parameters.ShowParameterPrompts != null)
            {
                reportViewer.ShowParameterPrompts = parameters.ShowParameterPrompts.Value;
            }

            if (parameters.ShowPrintButton != null)
            {
                reportViewer.ShowPrintButton = parameters.ShowPrintButton.Value;
            }

            if (parameters.ShowPromptAreaButton != null)
            {
                reportViewer.ShowPromptAreaButton = parameters.ShowPromptAreaButton.Value;
            }

            if (parameters.ShowRefreshButton != null)
            {
                reportViewer.ShowRefreshButton = parameters.ShowRefreshButton.Value;
            }

            if (parameters.ShowReportBody != null)
            {
                reportViewer.ShowReportBody = parameters.ShowReportBody.Value;
            }

            if (parameters.ShowToolBar != null)
            {
                reportViewer.ShowToolBar = parameters.ShowToolBar.Value;
            }

            if (parameters.ShowWaitControlCancelLink != null)
            {
                reportViewer.ShowWaitControlCancelLink = parameters.ShowWaitControlCancelLink.Value;
            }

            if (parameters.ShowZoomControl != null)
            {
                reportViewer.ShowZoomControl = parameters.ShowZoomControl.Value;
            }

            if (parameters.SizeToReportContent != null)
            {
                reportViewer.SizeToReportContent = parameters.SizeToReportContent.Value;
            }

            if (parameters.SplitterBackColor != null)
            {
                reportViewer.SplitterBackColor = parameters.SplitterBackColor.Value;
            }

            if (parameters.ToolBarItemBorderColor != null)
            {
                reportViewer.ToolBarItemBorderColor = parameters.ToolBarItemBorderColor.Value;
            }

            if (parameters.ToolBarItemBorderStyle != null)
            {
                reportViewer.ToolBarItemBorderStyle = parameters.ToolBarItemBorderStyle.Value;
            }

            if (parameters.ToolBarItemBorderWidth != null)
            {
                reportViewer.ToolBarItemBorderWidth = parameters.ToolBarItemBorderWidth.Value;
            }

            if (parameters.ToolBarItemHoverBackColor != null)
            {
                reportViewer.ToolBarItemHoverBackColor = parameters.ToolBarItemHoverBackColor.Value;
            }

            if (parameters.ZoomMode != null)
            {
                reportViewer.ZoomMode = parameters.ZoomMode.Value;
            }

            if (parameters.ZoomPercent != null)
            {
                reportViewer.ZoomPercent = parameters.ZoomPercent.Value;
            }

            if (parameters.AsyncRendering != null)
            {
                reportViewer.AsyncRendering = (bool)parameters.AsyncRendering;
            }

            reportViewer.Width            = parameters.Width ?? new Unit("100%");
            reportViewer.Height           = parameters.Height ?? new Unit("100%");
            reportViewer.KeepSessionAlive = parameters.KeepSessionAlive ?? false;
        }
Esempio n. 22
0
        private static void SetReportViewerSettings(ReportViewer reportViewer, ControlSettings parameters)
        {
            // Hide parameters prompt by default
            if (parameters == null)
            {
                reportViewer.ShowParameterPrompts = false;
                return;
            }

            if (parameters.BackColor != null)
            {
                reportViewer.BackColor = parameters.BackColor.Value;
            }

            if (parameters.DocumentMapCollapsed != null)
            {
                reportViewer.DocumentMapCollapsed = parameters.DocumentMapCollapsed.Value;
            }

            if (parameters.DocumentMapWidth != null)
            {
                reportViewer.DocumentMapWidth = parameters.DocumentMapWidth.Value;
            }

            if (parameters.HyperlinkTarget != null)
            {
                reportViewer.HyperlinkTarget = parameters.HyperlinkTarget;
            }

            if (parameters.InternalBorderColor != null)
            {
                reportViewer.InternalBorderColor = parameters.InternalBorderColor.Value;
            }

            if (parameters.InternalBorderStyle != null)
            {
                reportViewer.InternalBorderStyle = parameters.InternalBorderStyle.Value;
            }

            if (parameters.InternalBorderWidth != null)
            {
                reportViewer.InternalBorderWidth = parameters.InternalBorderWidth.Value;
            }

            if (parameters.LinkActiveColor != null)
            {
                reportViewer.LinkActiveColor = parameters.LinkActiveColor.Value;
            }

            if (parameters.LinkActiveHoverColor != null)
            {
                reportViewer.LinkActiveHoverColor = parameters.LinkActiveHoverColor.Value;
            }

            if (parameters.LinkDisabledColor != null)
            {
                reportViewer.LinkDisabledColor = parameters.LinkDisabledColor.Value;
            }

            if (parameters.PromptAreaCollapsed != null)
            {
                reportViewer.PromptAreaCollapsed = parameters.PromptAreaCollapsed.Value;
            }

            if (parameters.ShowBackButton != null)
            {
                reportViewer.ShowBackButton = parameters.ShowBackButton.Value;
            }

            if (parameters.ShowCredentialPrompts != null)
            {
                reportViewer.ShowCredentialPrompts = parameters.ShowCredentialPrompts.Value;
            }

            if (parameters.ShowDocumentMapButton != null)
            {
                reportViewer.ShowDocumentMapButton = parameters.ShowDocumentMapButton.Value;
            }

            if (parameters.ShowExportControls != null)
            {
                reportViewer.ShowExportControls = parameters.ShowExportControls.Value;
            }

            if (parameters.ShowFindControls != null)
            {
                reportViewer.ShowFindControls = parameters.ShowFindControls.Value;
            }

            if (parameters.ShowPageNavigationControls != null)
            {
                reportViewer.ShowPageNavigationControls = parameters.ShowPageNavigationControls.Value;
            }

            if (parameters.ShowParameterPrompts != null)
            {
                reportViewer.ShowParameterPrompts = parameters.ShowParameterPrompts.Value;
            }

            if (parameters.ShowPrintButton != null)
            {
                reportViewer.ShowPrintButton = parameters.ShowPrintButton.Value;
            }

            if (parameters.ShowPromptAreaButton != null)
            {
                reportViewer.ShowPromptAreaButton = parameters.ShowPromptAreaButton.Value;
            }

            if (parameters.ShowRefreshButton != null)
            {
                reportViewer.ShowRefreshButton = parameters.ShowRefreshButton.Value;
            }

            if (parameters.ShowReportBody != null)
            {
                reportViewer.ShowReportBody = parameters.ShowReportBody.Value;
            }

            if (parameters.ShowToolBar != null)
            {
                reportViewer.ShowToolBar = parameters.ShowToolBar.Value;
            }

            if (parameters.ShowWaitControlCancelLink != null)
            {
                reportViewer.ShowWaitControlCancelLink = parameters.ShowWaitControlCancelLink.Value;
            }

            if (parameters.ShowZoomControl != null)
            {
                reportViewer.ShowZoomControl = parameters.ShowZoomControl.Value;
            }

            if (parameters.SizeToReportContent != null)
            {
                reportViewer.SizeToReportContent = parameters.SizeToReportContent.Value;
            }

            if (parameters.SplitterBackColor != null)
            {
                reportViewer.SplitterBackColor = parameters.SplitterBackColor.Value;
            }

            if (parameters.ToolBarItemBorderColor != null)
            {
                reportViewer.ToolBarItemBorderColor = parameters.ToolBarItemBorderColor.Value;
            }

            if (parameters.ToolBarItemBorderStyle != null)
            {
                reportViewer.ToolBarItemBorderStyle = parameters.ToolBarItemBorderStyle.Value;
            }

            if (parameters.ToolBarItemBorderWidth != null)
            {
                reportViewer.ToolBarItemBorderWidth = parameters.ToolBarItemBorderWidth.Value;
            }

            if (parameters.ToolBarItemHoverBackColor != null)
            {
                reportViewer.ToolBarItemHoverBackColor = parameters.ToolBarItemHoverBackColor.Value;
            }

            if (parameters.ZoomMode != null)
            {
                reportViewer.ZoomMode = parameters.ZoomMode.Value;
            }

            if (parameters.ZoomPercent != null)
            {
                reportViewer.ZoomPercent = parameters.ZoomPercent.Value;
            }

            reportViewer.Width = parameters.Width ?? new Unit("100%");

            // Use AsyncRendering = false and hard-coded Height to fix problem with Google Chrome report rendering
            // http://stackoverflow.com/questions/778688/reportviewer-control-height-issue

            if (parameters.Height != null)
            {
                reportViewer.Height = parameters.Height.Value;
            }
            else if (parameters.FrameHeight != null)
            {
                reportViewer.Height = parameters.FrameHeight.Value;
            }
            else
            {
                reportViewer.Height = new Unit("100%");
            }

            reportViewer.AsyncRendering = parameters.AsyncRendering ?? false;

            reportViewer.KeepSessionAlive = parameters.KeepSessionAlive ?? false;
        }