Пример #1
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        /// <param name="grid">The grid.</param>
        /// <param name="dataView">The data view.</param>
        /// <returns></returns>
        private bool BindGrid( Grid grid, DataView dataView, int? fetchRowCount = null )
        {
            var errorMessages = new List<string>();
            grid.DataSource = null;

            if ( dataView.EntityTypeId.HasValue )
            {
                var cachedEntityType = EntityTypeCache.Read( dataView.EntityTypeId.Value );
                if ( cachedEntityType != null && cachedEntityType.AssemblyName != null )
                {
                    Type entityType = cachedEntityType.GetEntityType();

                    if ( entityType != null )
                    {
                        grid.CreatePreviewColumns( entityType );

                        var qry = dataView.GetQuery( grid.SortProperty, out errorMessages );

                        if ( fetchRowCount.HasValue )
                        {
                            qry = qry.Take( fetchRowCount.Value );
                        }

                        grid.DataSource = qry.AsNoTracking().ToList();
                    }
                }
            }

            if ( grid.DataSource != null )
            {
                grid.ExportFilename = dataView.Name;
                if ( errorMessages.Any() )
                {
                    nbEditModeMessage.Text = "INFO: There was a problem with one or more of the filters for this data view...<br/><br/> " + errorMessages.AsDelimited( "<br/>" );
                }

                if ( dataView.EntityTypeId.HasValue )
                {
                    grid.RowItemText = EntityTypeCache.Read( dataView.EntityTypeId.Value ).FriendlyName;
                }

                grid.DataBind();
                return true;
            }

            return false;
        }
Пример #2
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        /// <param name="grid">The grid.</param>
        /// <param name="dataView">The data view.</param>
        /// <returns></returns>
        private bool BindGrid( Grid grid, DataView dataView, int? fetchRowCount = null )
        {
            grid.DataSource = null;

            // Only respect the ShowResults option if fetchRowCount is null
            if ( !this.ShowResults && fetchRowCount == null )
            {
                return false;
            }

            var errorMessages = new List<string>();

            if ( dataView.EntityTypeId.HasValue )
            {
                var cachedEntityType = EntityTypeCache.Read( dataView.EntityTypeId.Value );
                if ( cachedEntityType != null && cachedEntityType.AssemblyName != null )
                {
                    Type entityType = cachedEntityType.GetEntityType();

                    if ( entityType != null )
                    {
                        try
                        {
                            grid.CreatePreviewColumns( entityType );

                            var qry = dataView.GetQuery( grid.SortProperty, GetAttributeValue( "DatabaseTimeout" ).AsIntegerOrNull() ?? 180, out errorMessages );

                            if ( fetchRowCount.HasValue )
                            {
                                qry = qry.Take( fetchRowCount.Value );
                            }

                            grid.SetLinqDataSource( qry.AsNoTracking() );
                            grid.DataBind();
                        }
                        catch ( Exception ex )
                        {
                            this.LogException( ex );
                            Exception exception = ex;
                            while ( exception != null )
                            {
                                if ( exception is System.Data.SqlClient.SqlException )
                                {
                                    // if there was a SQL Server Timeout, have the warning be a friendly message about that.
                                    if ( ( exception as System.Data.SqlClient.SqlException ).Number == -2 )
                                    {
                                        nbEditModeMessage.NotificationBoxType = NotificationBoxType.Warning;
                                        nbEditModeMessage.Text = "This dataview did not complete in a timely manner. You can try again or adjust the timeout setting of this block.";
                                        return false;
                                    }
                                    else
                                    {
                                        errorMessages.Add( exception.Message );
                                        exception = exception.InnerException;
                                    }
                                }
                                else
                                {
                                    errorMessages.Add( exception.Message );
                                    exception = exception.InnerException;
                                }
                            }
                        }
                    }
                }
            }

            var errorBox = ( grid == gPreview) ? nbPreviewError : nbGridError;

            if ( errorMessages.Any() )
            {
                errorBox.NotificationBoxType = NotificationBoxType.Warning;
                errorBox.Text = "WARNING: There was a problem with one or more of the filters for this data view...<br/><br/> " + errorMessages.AsDelimited( "<br/>" );
                errorBox.Visible = true;
            }
            else
            {
                errorBox.Visible = false;
            }

            if ( dataView.EntityTypeId.HasValue )
            {
                grid.RowItemText = EntityTypeCache.Read( dataView.EntityTypeId.Value ).FriendlyName;
            }

            if ( grid.DataSource != null )
            {
                grid.ExportFilename = dataView.Name;
                return true;
            }

            return false;
        }