BI ReportViewer调用报表服务器报表源

//为报表浏览器指定报表文件
ReportViewer1.SizeToReportContent = true;
ReportViewer1.ShowCredentialPrompts = false;
ReportViewer1.ZoomMode = ZoomMode.PageWidth;
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.1.1/ReportServer");
ReportViewer1.ServerReport.ReportPath = "/report/Report1";
ReportViewer1.ServerReport.ReportServerCredentials = new ReportSCredentials("", "", "");

List<string> listCode = new List<string>();
List<ReportParameter> parameters = new List<ReportParameter>
{
     new ReportParameter("填报期间填报期间", "[填报期间].[填报期间].&[201901]"),
     new ReportParameter("经销商大区代码", "[经销商].[大区代码].[All]"),
     new ReportParameter("经销商小区代码", listCode .ToArray())
};
ReportViewer1.ServerReport.SetParameters(parameters);

报表还需要通过报表服务器的认证

public class ReportSCredentials : IReportServerCredentials
    {
        private string _UserName;
        private string _PassWord;
        private string _DomainName;

        public ReportSCredentials(string UserName, string PassWord, string DomainName)
        {
            _UserName = UserName; _PassWord = PassWord; _DomainName = DomainName;
        }

        public WindowsIdentity ImpersonationUser
        {
            get { return null; }
        }

        public ICredentials NetworkCredentials
        {
            get
            {
                if (string.IsNullOrEmpty(_UserName) || string.IsNullOrEmpty(_PassWord)) { return null; }
                else if (string.IsNullOrEmpty(_DomainName)) { return new NetworkCredential(_UserName, _PassWord); }
                else { 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;
        }
    }
发布了35 篇原创文章 · 获赞 67 · 访问量 8529

猜你喜欢

转载自blog.csdn.net/EngraveSmile/article/details/88309922
今日推荐