コード例 #1
0
        private void LoadReport(string reportName, string ID)
        {
            if (!string.IsNullOrEmpty(reportName))
            {
                MyReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
                MyReportViewer.ServerReport.ReportServerCredentials = new ReportServerCredentials(CommonFunction.Instance.ReportUser(), CommonFunction.Instance.ReportPass(), CommonFunction.Instance.DomainName());
                MyReportViewer.ServerReport.ReportServerUrl         = new Uri(CommonFunction.Instance.ReportPath());
                MyReportViewer.ServerReport.ReportPath = reportName;
                var  Ids          = string.Empty;
                var  Names        = string.Empty;
                bool IsTenantName = false;
                var  loggedinuser = (CustomPrincipal)this.User;
                if (loggedinuser == null)
                {
                    return;
                }
                var db = new ApplicationContext(loggedinuser);

                ReportParameterInfoCollection rptParam = MyReportViewer.ServerReport.GetParameters();
                if (rptParam.Where(wh => wh.Name == "TenantName").Count() > 0)
                {
                    IsTenantName = true;
                }

                if (loggedinuser.MultiTenantLoginSelected.Count > 0)
                {
                    if (loggedinuser.MultiTenantLoginSelected.FirstOrDefault().T_MainEntity == -1)
                    {
                        var mainentityvalue = loggedinuser.MultiTenantLoginSelected.FirstOrDefault().T_MainEntityValue;
                        if (mainentityvalue.ToLower() == "all")
                        {
                            Ids = string.Join(",", (db.T_Facilitys.Select(p => p.Id)));
                            if (IsTenantName)
                            {
                                Names = string.Join(",", (db.T_Facilitys.Select(p => p.DisplayValue)));
                            }
                        }
                        else
                        {
                            Ids = Convert.ToString(db.T_Facilitys.FirstOrDefault(wh => wh.DisplayValue == mainentityvalue).Id);
                            if (IsTenantName)
                            {
                                Names = mainentityvalue;
                            }
                        }
                    }
                    else
                    {
                        Ids = Convert.ToString(loggedinuser.MultiTenantLoginSelected.FirstOrDefault().T_MainEntity);
                        if (IsTenantName)
                        {
                            Names = loggedinuser.MultiTenantLoginSelected.FirstOrDefault().T_MainEntityValue;
                        }
                    }
                }
                else if (loggedinuser.IsAdmin && loggedinuser.MultiTenantLoginSelected.Count == 0)
                {
                    Ids = string.Join(",", (db.T_Facilitys.Select(p => p.Id)));
                    if (IsTenantName)
                    {
                        Names = string.Join(",", (db.T_Facilitys.Select(p => p.DisplayValue)));
                    }
                }
                if (Ids.Length > 0)
                {
                    if (rptParam.Where(wh => wh.Name == "TenantId").Count() > 0)
                    {
                        var reportParameter = new ReportParameter("TenantId");
                        reportParameter.Values.Add(Ids);
                        MyReportViewer.ServerReport.SetParameters(new[] { reportParameter });
                    }
                }
                if (Names.Length > 0)
                {
                    if (rptParam.Where(wh => wh.Name == "TenantName").Count() > 0)
                    {
                        var reportParameter = new ReportParameter("TenantName");
                        reportParameter.Values.Add(Names);
                        MyReportViewer.ServerReport.SetParameters(new[] { reportParameter });
                    }
                }
                if (!string.IsNullOrEmpty(ID))
                {
                    var reportParameter = new ReportParameter("empId");
                    reportParameter.Values.Add(ID);
                    MyReportViewer.ServerReport.SetParameters(new[] { reportParameter });
                }

                MyReportViewer.ServerReport.Refresh();
            }
        }