Exemplo n.º 1
0
        /// <summary>
        /// Binds the report grid.
        /// </summary>
        private void BindReportGrid()
        {
            var    rockContext   = new RockContext();
            var    reportService = new ReportService(rockContext);
            var    reportGuid    = this.GetAttributeValue("Report").AsGuidOrNull();
            var    personIdField = this.GetAttributeValue("PersonIdField");
            Report report        = null;

            if (reportGuid.HasValue)
            {
                report = reportService.Get(reportGuid.Value);
            }

            if (report == null)
            {
                nbConfigurationWarning.Visible = true;
                nbConfigurationWarning.Text    = "A report needs to be configured in block settings";
                pnlView.Visible = false;
            }
            else if (report.DataView == null)
            {
                nbConfigurationWarning.Visible = true;
                nbConfigurationWarning.Text    = string.Format("The {0} report does not have a dataview", report);
                pnlView.Visible = false;
            }
            else
            {
                nbConfigurationWarning.Visible = false;

                report.DataView.DataViewFilter = ReportingHelper.GetFilterFromControls(phFilters);

                string errorMessage;

                ReportingHelper.BindGrid(report, gReport, this.CurrentPerson, null, out errorMessage);

                if (report.EntityTypeId != EntityTypeCache.GetId <Rock.Model.Person>())
                {
                    var personColumn = gReport.ColumnsOfType <BoundField>().Where(a => a.HeaderText == personIdField).FirstOrDefault();
                    if (personColumn != null)
                    {
                        gReport.PersonIdField = personColumn.SortExpression;
                    }
                }

                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    nbReportErrors.NotificationBoxType = NotificationBoxType.Warning;
                    nbReportErrors.Text    = errorMessage;
                    nbReportErrors.Visible = true;
                }
                else
                {
                    nbReportErrors.Visible = false;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Binds the report grid.
        /// </summary>
        private void BindReportGrid()
        {
            var    rockContext   = new RockContext();
            var    reportService = new ReportService(rockContext);
            var    reportGuid    = this.GetAttributeValue("Report").AsGuidOrNull();
            Report report        = null;

            if (reportGuid.HasValue)
            {
                report = reportService.Get(reportGuid.Value);
            }

            if (report == null)
            {
                nbConfigurationWarning.Visible = true;
                nbConfigurationWarning.Text    = "A report needs to be configured in block settings";
                pnlView.Visible = false;
            }
            else if (report.DataView == null)
            {
                nbConfigurationWarning.Visible = true;
                nbConfigurationWarning.Text    = string.Format("The {0} report does not have a dataview", report);
                pnlView.Visible = false;
            }
            else
            {
                nbConfigurationWarning.Visible = false;

                report.DataView.DataViewFilter = ReportingHelper.GetFilterFromControls(phFilters);

                string errorMessage;
                ReportingHelper.BindGrid(report, gReport, this.CurrentPerson, null, out errorMessage);

                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    nbReportErrors.NotificationBoxType = NotificationBoxType.Warning;
                    nbReportErrors.Text    = errorMessage;
                    nbReportErrors.Visible = true;
                }
                else
                {
                    nbReportErrors.Visible = false;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Binds the report grid.
        /// </summary>
        private void BindReportGrid(bool isCommunication = false)
        {
            var    rockContext   = new RockContext();
            var    reportService = new ReportService(rockContext);
            var    reportGuid    = this.GetAttributeValue("Report").AsGuidOrNull();
            var    personIdField = this.GetAttributeValue("PersonIdField");
            Report report        = null;

            if (reportGuid.HasValue)
            {
                report = reportService.Get(reportGuid.Value);
            }

            if (report == null)
            {
                nbConfigurationWarning.Visible = true;
                nbConfigurationWarning.Text    = "A report needs to be configured in block settings";
                pnlView.Visible = false;
            }
            else if (report.DataView == null)
            {
                nbConfigurationWarning.Visible = true;
                nbConfigurationWarning.Text    = string.Format("The {0} report does not have a dataview", report);
                pnlView.Visible = false;
            }
            else if (report.DataView.EntityTypeId != report.EntityTypeId)
            {
                nbConfigurationWarning.Visible = true;
                nbConfigurationWarning.Text    = string.Format("The {0} report's EntityType doesn't match the dataview's EntityType", report);
                pnlView.Visible = false;
            }
            else
            {
                nbConfigurationWarning.Visible = false;


                DataViewFilterOverrides dataViewFilterOverrides = ReportingHelper.GetFilterOverridesFromControls(report.DataView, phFilters);

                ReportingHelper.BindGridOptions bindGridOptions = new ReportingHelper.BindGridOptions
                {
                    CurrentPerson           = this.CurrentPerson,
                    DataViewFilterOverrides = dataViewFilterOverrides,
                    DatabaseTimeoutSeconds  = null,
                    IsCommunication         = isCommunication
                };


                nbReportErrors.Visible = false;

                try
                {
                    bindGridOptions.ReportDbContext = Reflection.GetDbContextForEntityType(EntityTypeCache.Get(report.EntityTypeId.Value).GetEntityType());
                    ReportingHelper.BindGrid(report, gReport, bindGridOptions);

                    if (report.EntityTypeId != EntityTypeCache.GetId <Rock.Model.Person>())
                    {
                        var personColumn = gReport.ColumnsOfType <BoundField>().Where(a => a.HeaderText == personIdField).FirstOrDefault();
                        if (personColumn != null)
                        {
                            gReport.PersonIdField = personColumn.SortExpression;
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionLogService.LogException(ex);
                    var sqlTimeoutException = ReportingHelper.FindSqlTimeoutException(ex);

                    if (sqlTimeoutException != null)
                    {
                        nbReportErrors.NotificationBoxType = NotificationBoxType.Warning;
                        nbReportErrors.Text = "This report did not complete in a timely manner.";
                    }
                    else
                    {
                        if (ex is RockDataViewFilterExpressionException)
                        {
                            RockDataViewFilterExpressionException rockDataViewFilterExpressionException = ex as RockDataViewFilterExpressionException;
                            nbReportErrors.Text = rockDataViewFilterExpressionException.GetFriendlyMessage(report.DataView);
                        }
                        else
                        {
                            nbReportErrors.Text = "There was a problem with one of the filters for this report's dataview.";
                        }

                        nbReportErrors.NotificationBoxType = NotificationBoxType.Danger;

                        nbReportErrors.Details = ex.Message;
                        nbReportErrors.Visible = true;
                    }
                }
            }
        }