123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using Microsoft.Reporting.WebForms;
- using System.Net;
- using EMIS.Utility;
- namespace EMIS.Web.ReportViewer
- {
- public partial class Page : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- if (!string.IsNullOrEmpty(Request.Params["ReportFolder"]))
- {
- string reportpath = HttpUtility.HtmlDecode(Request.Params["ReportFolder"]);
- int aantalKeys = Request.Params.AllKeys.Length;
- List<ReportParameter> parameters = new List<ReportParameter>();
- for (int i = 1; i < aantalKeys; i++)
- {
- string value = Request.Params[i];
- string key = Request.Params.Keys[i];
- if (key.Contains("_RAP"))
- {
- int index = key.IndexOf('_');
- key = key.Substring(0, index);
- if (string.IsNullOrEmpty(value))
- {
- ReportParameter parameter = new ReportParameter(key, (string)null);
- parameters.Add(parameter);
- }
- else
- {
- ReportParameter parameter = new ReportParameter(key, HttpUtility.HtmlDecode(value));
- parameters.Add(parameter);
- }
- }
- }
- this.RenderReport(reportpath, parameters);
- }
- }
- }
- private void RenderReport(string reportpath, List<ReportParameter> parameters = null)
- {
- string User = Const.LOCAL_SETTING_REPORT_USER_NAME;
- string Pass = Const.LOCAL_SETTING_REPORT_PASSWORD;
- string ReportServerUrl = Const.LOCAL_SETTING_REPORT_URL;
- IReportServerCredentials irsc = new CustomReportCredentials(User, Pass, "");
- Uri uri = new Uri(ReportServerUrl);
- // EVENTS
- //reportViewer.Load += reportViewer_Load;
- //reportViewer.Unload += reportViewer_Unload;
- if (Request.Browser.Browser.Contains("InternetExplorer"))
- {
- reportViewer.SizeToReportContent = false;
- }
- else
- {
- reportViewer.SizeToReportContent = true;
- }
- reportViewer.ShowExportControls = true;
- reportViewer.ShowPrintButton = true;
- reportViewer.ShowParameterPrompts = false;
- //reportViewer.Visible = true;
- reportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
- reportViewer.ServerReport.ReportServerCredentials = irsc;
- reportViewer.ServerReport.ReportServerUrl = uri;
- reportViewer.ServerReport.ReportPath = reportpath;
- if (parameters != null && parameters.Count != 0)
- {
- reportViewer.ServerReport.SetParameters(parameters);
- }
- reportViewer.ServerReport.Refresh();
- }
- private Dictionary<string, object> GetCurrentParameters()
- {
- var parameterCollection = reportViewer.ServerReport.GetParameters();
- var param = new Dictionary<string, object>();
- foreach (var p in parameterCollection)
- {
- var name = p.Name;
- if (p.DataType == ParameterDataType.DateTime)
- {
- var d = Convert.ToDateTime(p.Values[0]);
- param[name] = d.ToString("dd-MM-yyyy");
- }
- else
- {
- var values = p.Values.ToList();
- param[name] = values;
- }
- }
- return param;
- }
- }
- public class CustomReportCredentials : IReportServerCredentials
- {
- private string _UserName;
- private string _PassWord;
- private string _DomainName;
- public CustomReportCredentials(string UserName, string PassWord, string DomainName)
- {
- _UserName = UserName;
- _PassWord = PassWord;
- _DomainName = DomainName;
- }
- public System.Security.Principal.WindowsIdentity ImpersonationUser
- {
- get { return null; }
- }
- public ICredentials NetworkCredentials
- {
- get { return new NetworkCredential(_UserName, _PassWord, _DomainName); }
- }
- public bool GetFormsCredentials(out Cookie authCookie, out string user,
- out string password, out string authority)
- {
- authCookie = null;
- user = password = authority = null;
- return false;
- }
- }
- }
|