Exemplo n.º 1
0
 /// <summary>
 /// Binds the fields grid.
 /// </summary>
 /// <param name="formFields">The fields.</param>
 public void BindFieldsGrid(List <RegistrationTemplateFormField> formFields)
 {
     _gFields.DataSource = formFields
                           .OrderBy(a => a.Order)
                           .Select(a => new
     {
         a.Id,
         a.Guid,
         Name = a.FieldSource == RegistrationFieldSource.PersonField ?
                a.PersonFieldType.ToString() :
                a.Attribute.Name,
         FieldSource = a.FieldSource.ConvertToString(),
         FieldType   = a.FieldSource == RegistrationFieldSource.PersonField ? 0 : a.Attribute.FieldTypeId,
         a.IsInternal,
         a.IsSharedValue,
         a.ShowCurrentValue,
         a.IsRequired,
         a.IsGridField
     })
                           .ToList();
     _gFields.DataBind();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the <see cref="T:System.Web.UI.WebControls.CompositeControl" /> content to the specified <see cref="T:System.Web.UI.HtmlTextWriter" /> object, for display on the client.
        /// </summary>
        /// <param name="writer">An <see cref="T:System.Web.UI.HtmlTextWriter" /> that represents the output stream to render HTML content on the client.</param>
        public override void RenderControl(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "panel panel-widget checkin-grouptype");
            writer.AddAttribute("data-key", _hfGroupTypeGuid.Value);
            writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ID + "_section");
            writer.RenderBeginTag("section");

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "panel-heading clearfix clickable");
            writer.RenderBeginTag("header");

            // Hidden Field to track expansion
            _hfExpanded.RenderControl(writer);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "filter-toggle pull-left");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "panel-title");
            writer.RenderBeginTag(HtmlTextWriterTag.H3);
            _lblGroupTypeName.Text = _tbGroupTypeName.Text;
            _lblGroupTypeName.RenderControl(writer);

            // H3 tag
            writer.RenderEndTag();

            // Name/Description div
            writer.RenderEndTag();

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "pull-right panel-actions");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.WriteLine("<a class='btn btn-link btn-xs checkin-grouptype-reorder'><i class='fa fa-bars'></i></a>");
            writer.WriteLine(string.Format("<a class='btn btn-xs btn-link'><i class='checkin-grouptype-state fa {0}'></i></a>",
                                           Expanded ? "fa fa-chevron-up" : "fa fa-chevron-down"));

            if (IsDeleteEnabled)
            {
                _lbDeleteGroupType.Visible = true;
                _lbDeleteGroupType.RenderControl(writer);
            }
            else
            {
                _lbDeleteGroupType.Visible = false;
            }

            // Add/ChevronUpDown/Delete div
            writer.RenderEndTag();

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "pull-right panel-actions btn-group");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            _lbAddCheckinGroupType.RenderControl(writer);
            writer.WriteLine();
            _lbAddCheckinGroup.RenderControl(writer);
            writer.WriteLine();

            writer.RenderEndTag();

            // header div
            writer.RenderEndTag();

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "panel-body");

            if (!Expanded)
            {
                writer.AddStyleAttribute("display", "none");
            }

            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            // make two span6 columns: Left Column for Name and Attributes. Right Column for Labels Grid
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "row");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "col-sm-6");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            // grouptype edit fields
            _tbGroupTypeName.RenderControl(writer);
            _ddlGroupTypeInheritFrom.RenderControl(writer);

            // attributes
            _phGroupTypeAttributes.RenderControl(writer);

            writer.RenderEndTag();
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "col-sm-6");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            // Check-in Labels grid
            writer.WriteLine("<h3>Check-in Labels</h3>");
            _gCheckinLabels.DataSource = this.CheckinLabels;
            _gCheckinLabels.DataBind();
            _gCheckinLabels.RenderControl(writer);

            // span6
            writer.RenderEndTag();

            // rowfluid
            writer.RenderEndTag();

            // groups
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "checkin-grouptype-list");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            foreach (CheckinGroupTypeEditor checkinGroupTypeEditor in this.Controls.OfType <CheckinGroupTypeEditor>())
            {
                checkinGroupTypeEditor.RenderControl(writer);
            }

            // checkin-grouptype-list div
            writer.RenderEndTag();

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "checkin-group-list");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            foreach (CheckinGroupEditor checkinGroupEditor in this.Controls.OfType <CheckinGroupEditor>())
            {
                checkinGroupEditor.RenderControl(writer);
            }

            // checkin-group-list div
            writer.RenderEndTag();

            // widget-content div
            writer.RenderEndTag();

            // section tag
            writer.RenderEndTag();
        }
Exemplo n.º 3
0
        private bool BindGrid( Grid grid, DataView dataView )
        {
            var errors = new List<string>();
            grid.DataSource = dataView.BindGrid( grid, out errors, true );
            if ( grid.DataSource != null )
            {
                if ( errors.Any() )
                {
                    nbEditModeMessage.Text = "INFO: There was a problem with one or more of the filters for this data view...<br/><br/> " + errors.AsDelimited( "<br/>" );
                }

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

                grid.DataBind();
                return true;
            }

            return false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Builds the controls.
        /// </summary>
        /// <param name="setData">if set to <c>true</c> [set data].</param>
        private void BuildControls( bool setData )
        {
            var showGridFilterControls = GetAttributeValue( "ShowGridFilter" ).AsBoolean();
            string errorMessage = string.Empty;

            // get just the schema of the data until we actually need the data
            var dataSetSchema = GetData( out errorMessage, true );

            if ( !string.IsNullOrWhiteSpace( errorMessage ) )
            {
                phContent.Visible = false;

                nbError.Text = errorMessage;
                nbError.Visible = true;
            }
            else
            {
                phContent.Controls.Clear();

                var mergeFields = GetDynamicDataMergeFields();

                if ( dataSetSchema != null )
                {
                    string formattedOutput = GetAttributeValue( "FormattedOutput" );

                    // load merge objects if needed by either for formatted output OR page title
                    if ( !string.IsNullOrWhiteSpace( GetAttributeValue( "PageTitleLava" ) ) || !string.IsNullOrWhiteSpace( formattedOutput ) )
                    {
                        int i = 1;

                        // Formatted output needs all the rows, so get the data regardless of the setData parameter
                        var dataSet = GetData( out errorMessage);
                        foreach ( DataTable dataTable in dataSet.Tables )
                        {
                            var dropRows = new List<DataRowDrop>();
                            foreach ( DataRow row in dataTable.Rows )
                            {
                                dropRows.Add( new DataRowDrop( row ) );
                            }

                            if ( dataSet.Tables.Count > 1 )
                            {
                                var tableField = new Dictionary<string, object>();
                                tableField.Add( "rows", dropRows );
                                mergeFields.Add( "table" + i.ToString(), tableField );
                            }
                            else
                            {
                                mergeFields.Add( "rows", dropRows );
                            }
                            i++;
                        }
                    }

                    // set page title
                    if ( !string.IsNullOrWhiteSpace( GetAttributeValue( "PageTitleLava" ) ) )
                    {
                        string title = GetAttributeValue( "PageTitleLava" ).ResolveMergeFields( mergeFields );

                        RockPage.BrowserTitle = title;
                        RockPage.PageTitle = title;
                        RockPage.Header.Title = title;
                    }

                    if ( string.IsNullOrWhiteSpace( formattedOutput ) )
                    {
                        bool personReport = GetAttributeValue( "PersonReport" ).AsBoolean();

                        int tableId = 0;
                        DataSet dataSet;
                        if ( setData == false )
                        {
                            dataSet = dataSetSchema;
                        }
                        else
                        {
                            dataSet = GetData( out errorMessage );
                        }

                        foreach ( DataTable dataTable in dataSet.Tables )
                        {
                            var div = new HtmlGenericControl( "div" );
                            div.AddCssClass( "grid" );

                            if ( GetAttributeValue( "PaneledGrid" ).AsBoolean() )
                            {
                                div.AddCssClass( "grid-panel" );
                            }

                            phContent.Controls.Add( div );

                            GridFilter = new GridFilter()
                            {
                                ID = string.Format("gfFilter{0}", tableId )
                            };

                            div.Controls.Add( GridFilter );
                            GridFilter.ApplyFilterClick += ApplyFilterClick;
                            GridFilter.DisplayFilterValue += DisplayFilterValue;
                            GridFilter.Visible = showGridFilterControls && (dataSet.Tables.Count == 1);

                            var grid = new Grid();
                            div.Controls.Add( grid );
                            grid.ID = string.Format( "dynamic_data_{0}", tableId++ );
                            grid.AllowSorting = true;
                            grid.EmptyDataText = "No Results";
                            grid.Actions.ShowCommunicate = GetAttributeValue( "ShowCommunicate" ).AsBoolean();
                            grid.Actions.ShowMergePerson = GetAttributeValue( "ShowMergePerson" ).AsBoolean();
                            grid.Actions.ShowBulkUpdate = GetAttributeValue( "ShowBulkUpdate" ).AsBoolean();
                            grid.Actions.ShowExcelExport = GetAttributeValue( "ShowExcelExport" ).AsBoolean();
                            grid.Actions.ShowMergeTemplate = GetAttributeValue( "ShowMergeTemplate" ).AsBoolean();

                            grid.GridRebind += gReport_GridRebind;
                            grid.RowSelected += gReport_RowSelected;
                            if ( personReport )
                            {
                                grid.PersonIdField = "Id";
                            }
                            else
                            {
                                grid.PersonIdField = null;
                            }
                            grid.CommunicateMergeFields = GetAttributeValue( "MergeFields" ).SplitDelimitedValues().ToList<string>();

                            AddGridColumns( grid, dataTable );
                            SetDataKeyNames( grid, dataTable );

                            if ( setData )
                            {
                                FilterTable( grid, dataTable );
                                SortTable( grid, dataTable );
                                grid.DataSource = dataTable;

                                if ( personReport)
                                {
                                    grid.EntityTypeId = EntityTypeCache.GetId<Person>();
                                }

                                grid.DataBind();
                            }
                        }
                    }
                    else
                    {
                        phContent.Controls.Add( new LiteralControl( formattedOutput.ResolveMergeFields( mergeFields ) ) );
                    }
                }

                phContent.Visible = true;
                nbError.Visible = false;
            }
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        private void SetRecipients( Panel pnl, HtmlAnchor htmlAnchor, Literal literalControl, 
            Grid grid, IQueryable<CommunicationRecipient> qryRecipients )
        {
            pnl.CssClass = pnlOpened.Visible ? "col-md-2-10 margin-b-md" : "col-md-3 margin-b-md";

            int count = qryRecipients.Count();

            if ( count <= 0 )
            {
                htmlAnchor.Attributes["disabled"] = "disabled";
            }
            else
            {
                htmlAnchor.Attributes.Remove( "disabled" );
            }

            literalControl.Text = count.ToString( "N0" );

            var sortProperty = grid.SortProperty;
            if ( sortProperty != null )
            {
                qryRecipients = qryRecipients.AsQueryable().Sort( sortProperty );

            }
            else
            {
                qryRecipients = qryRecipients.OrderBy( r => r.PersonAlias.Person.LastName ).ThenBy( r => r.PersonAlias.Person.NickName );
            }

            grid.SetLinqDataSource( qryRecipients );
            grid.DataBind();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Writes the <see cref="T:System.Web.UI.WebControls.CompositeControl" /> content to the specified <see cref="T:System.Web.UI.HtmlTextWriter" /> object, for display on the client.
        /// </summary>
        /// <param name="writer">An <see cref="T:System.Web.UI.HtmlTextWriter" /> that represents the output stream to render HTML content on the client.</param>
        public override void RenderControl(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "panel panel-widget checkin-group");
            writer.AddAttribute("data-key", _hfGroupGuid.Value);
            writer.RenderBeginTag("article");

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "panel-heading clearfix clickable");
            writer.RenderBeginTag("header");

            // Hidden Field to track expansion
            _hfExpanded.RenderControl(writer);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "pull-left");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            _lblGroupName.Text = _tbGroupName.Text;
            _lblGroupName.RenderControl(writer);
            writer.RenderEndTag();

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "pull-right");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.WriteLine("<a class='btn btn-link btn-xs checkin-group-reorder'><i class='fa fa-bars'></i></a>");
            writer.WriteLine(string.Format("<a class='btn btn-xs btn-link'><i class='checkin-group-state fa {0}'></i></a>",
                                           Expanded ? "fa fa-chevron-up" : "fa fa-chevron-down"));

            if (IsDeleteEnabled)
            {
                _lbDeleteGroup.Visible = true;

                _lbDeleteGroup.RenderControl(writer);
            }
            else
            {
                _lbDeleteGroup.Visible = false;
            }

            // Add/ChevronUpDown/Delete div
            writer.RenderEndTag();

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "pull-right panel-actions btn-group");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            _lbAddCheckinGroup.RenderControl(writer);
            writer.WriteLine();

            writer.RenderEndTag();

            // header div
            writer.RenderEndTag();

            if (!Expanded)
            {
                // hide details if the name has already been filled in
                writer.AddStyleAttribute("display", "none");
            }

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "panel-body");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            // make two span6 columns: Left Column for Name and Attributes. Right Column for Locations Grid
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "row");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "col-md-6");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            // edit fields
            _tbGroupName.RenderControl(writer);

            // attributes
            _phGroupAttributes.RenderControl(writer);

            writer.RenderEndTag();
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "col-md-6");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            // Locations grid
            writer.WriteLine("<h3>Locations</h3>");
            _gLocations.DataSource = this.Locations.OrderBy(l => l.FullNamePath).ToList();
            _gLocations.DataBind();
            _gLocations.RenderControl(writer);

            // span6
            writer.RenderEndTag();

            // rowfluid
            writer.RenderEndTag();

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "checkin-group-list");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            foreach (CheckinGroupEditor checkinGroupEditor in this.Controls.OfType <CheckinGroupEditor>())
            {
                checkinGroupEditor.RenderControl(writer);
            }

            // checkin-group-list div
            writer.RenderEndTag();

            // widget-content div
            writer.RenderEndTag();

            // article tag
            writer.RenderEndTag();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Writes the <see cref="T:System.Web.UI.WebControls.CompositeControl" /> content to the specified <see cref="T:System.Web.UI.HtmlTextWriter" /> object, for display on the client.
        /// </summary>
        /// <param name="writer">An <see cref="T:System.Web.UI.HtmlTextWriter" /> that represents the output stream to render HTML content on the client.</param>
        public override void RenderControl(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "panel panel-widget checkin-group");
            writer.AddAttribute("data-key", _hfGroupGuid.Value);
            writer.RenderBeginTag("article");

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "panel-heading clearfix clickable");
            writer.RenderBeginTag("header");

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "pull-left");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            _lblGroupName.Text = _tbGroupName.Text;
            _lblGroupName.RenderControl(writer);
            writer.RenderEndTag();

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "pull-right");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.WriteLine("<a class='btn btn-xs checkin-group-reorder'><i class='fa fa-bars'></i></a>");
            writer.WriteLine("<a class='btn btn-xs'><i class='checkin-group-state fa fa-chevron-down'></i></a>");

            if (IsDeleteEnabled)
            {
                _lbDeleteGroup.Visible = true;

                _lbDeleteGroup.RenderControl(writer);
            }
            else
            {
                _lbDeleteGroup.Visible = false;
            }

            // Add/ChevronUpDown/Delete div
            writer.RenderEndTag();

            // header div
            writer.RenderEndTag();

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "panel-body");

            Group group = this.GetGroup();

            bool forceContentVisible = !group.IsValid || ForceContentVisible;

            if (!forceContentVisible)
            {
                // hide details if the name has already been filled in
                writer.AddStyleAttribute("display", "none");
            }

            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            // make two span6 columns: Left Column for Name and Attributes. Right Column for Locations Grid
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "row");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "col-md-6");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            // edit fields
            _tbGroupName.RenderControl(writer);

            // attributes
            _phGroupAttributes.RenderControl(writer);

            writer.RenderEndTag();
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "col-md-6");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            // Locations grid
            writer.WriteLine("<h3>Locations</h3>");
            _gLocations.DataSource = this.Locations;
            _gLocations.DataBind();
            _gLocations.RenderControl(writer);

            // span6
            writer.RenderEndTag();

            // rowfluid
            writer.RenderEndTag();

            // widget-content div
            writer.RenderEndTag();

            // article tag
            writer.RenderEndTag();
        }
        /// <summary>
        /// Builds the controls.
        /// </summary>
        /// <param name="setData">if set to <c>true</c> [set data].</param>
        private void BuildControls( bool setData )
        {
            string errorMessage = string.Empty;
            var dataSet = GetData( out errorMessage );

            if ( !string.IsNullOrWhiteSpace( errorMessage ) )
            {
                phContent.Visible = false;

                nbError.Text = errorMessage;
                nbError.Visible = true;
            }
            else
            {
                phContent.Controls.Clear();

                if ( dataSet != null )
                {
                    string formattedOutput = GetAttributeValue( "FormattedOutput" );
                    if ( string.IsNullOrWhiteSpace( formattedOutput ) )
                    {
                        bool personReport = GetAttributeValue( "PersonReport" ).AsBoolean();

                        int tableId = 0;
                        foreach ( DataTable dataTable in dataSet.Tables )
                        {
                            var div = new HtmlGenericControl( "div" );
                            div.AddCssClass( "grid" );
                            phContent.Controls.Add( div );

                            var grid = new Grid();
                            div.Controls.Add( grid );
                            grid.ID = string.Format( "dynamic_data_{0}", tableId++ );
                            grid.AllowSorting = true;
                            grid.EmptyDataText = "No Results";
                            grid.GridRebind += gReport_GridRebind;
                            grid.RowSelected += gReport_RowSelected;
                            if ( personReport )
                            {
                                grid.PersonIdField = "Id";
                            }
                            else
                            {
                                grid.PersonIdField = null;
                            }
                            grid.CommunicateMergeFields = GetAttributeValue( "MergeFields" ).SplitDelimitedValues().ToList<string>();

                            AddGridColumns( grid, dataTable );
                            SetDataKeyNames( grid, dataTable );

                            if ( setData )
                            {
                                SortTable( grid, dataTable );
                                grid.DataSource = dataTable;
                                grid.DataBind();
                            }
                        }
                    }
                    else
                    {
                        var mergeFields = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields( CurrentPerson );
                        if ( CurrentPerson != null )
                        {
                            // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line
                            mergeFields.Add( "Person", CurrentPerson );
                            mergeFields.Add( "CurrentPerson", CurrentPerson );
                        }

                        mergeFields.Add( "RockVersion", Rock.VersionInfo.VersionInfo.GetRockProductVersionNumber() );
                        mergeFields.Add( "Campuses", CampusCache.All() );

                        int i = 1;
                        foreach ( DataTable dataTable in dataSet.Tables )
                        {
                            var dropRows = new List<DataRowDrop>();
                            foreach ( DataRow row in dataTable.Rows )
                            {
                                dropRows.Add( new DataRowDrop( row ) );
                            }

                            if ( dataSet.Tables.Count > 1 )
                            {
                                var tableField = new Dictionary<string, object>();
                                tableField.Add( "rows", dropRows );
                                mergeFields.Add( "table" + i.ToString(), tableField );
                            }
                            else
                            {
                                mergeFields.Add( "rows", dropRows );
                            }
                            i++;
                        }

                        phContent.Controls.Add( new LiteralControl( formattedOutput.ResolveMergeFields( mergeFields ) ) );
                    }
                }

                phContent.Visible = true;
                nbError.Visible = false;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Shows the preview.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="gReport">The g report.</param>
        /// <param name="currentPerson">The current person.</param>
        /// <param name="databaseTimeoutSeconds">The database timeout seconds.</param>
        /// <param name="errorMessage">The error message.</param>
        public static void BindGrid( Report report, Grid gReport, Person currentPerson, int? databaseTimeoutSeconds, out string errorMessage )
        {
            errorMessage = null;
            if ( report != null )
            {
                var errors = new List<string>();

                if ( !report.EntityTypeId.HasValue )
                {
                    gReport.Visible = false;
                    return;
                }

                var rockContext = new RockContext();

                if ( !report.IsAuthorized( Authorization.VIEW, currentPerson ) )
                {
                    gReport.Visible = false;
                    return;
                }

                Type entityType = EntityTypeCache.Read( report.EntityTypeId.Value, rockContext ).GetEntityType();
                if ( entityType == null )
                {
                    errorMessage = string.Format( "Unable to determine entityType for {0}", report.EntityType );
                    return;
                }

                gReport.EntityTypeId = report.EntityTypeId;

                bool isPersonDataSet = report.EntityTypeId == EntityTypeCache.Read( typeof( Rock.Model.Person ), true, rockContext ).Id;

                if ( isPersonDataSet )
                {
                    gReport.PersonIdField = "Id";
                    gReport.DataKeyNames = new string[] { "Id" };
                }
                else
                {
                    gReport.PersonIdField = null;
                }

                if ( report.EntityTypeId.HasValue )
                {
                    gReport.RowItemText = EntityTypeCache.Read( report.EntityTypeId.Value, rockContext ).FriendlyName;
                }

                List<EntityField> entityFields = Rock.Reporting.EntityHelper.GetEntityFields( entityType, true, false );

                var selectedEntityFields = new Dictionary<int, EntityField>();
                var selectedAttributes = new Dictionary<int, AttributeCache>();
                var selectedComponents = new Dictionary<int, ReportField>();

                // if there is a selectField, keep it to preserve which items are checked
                var selectField = gReport.Columns.OfType<SelectField>().FirstOrDefault();
                gReport.Columns.Clear();
                int columnIndex = 0;

                if ( !string.IsNullOrWhiteSpace( gReport.PersonIdField ) )
                {
                    // if we already had a selectField, use it (to preserve checkbox state)
                    gReport.Columns.Add( selectField ?? new SelectField() );
                    columnIndex++;
                }

                var reportFieldSortExpressions = new Dictionary<Guid, string>();

                foreach ( var reportField in report.ReportFields.OrderBy( a => a.ColumnOrder ) )
                {
                    columnIndex++;
                    if ( reportField.ReportFieldType == ReportFieldType.Property )
                    {
                        var entityField = entityFields.FirstOrDefault( a => a.Name == reportField.Selection );
                        if ( entityField != null )
                        {
                            selectedEntityFields.Add( columnIndex, entityField );

                            BoundField boundField = entityField.GetBoundFieldType();
                            boundField.DataField = string.Format( "Entity_{0}_{1}", entityField.Name, columnIndex );
                            boundField.HeaderText = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? entityField.Title : reportField.ColumnHeaderText;
                            boundField.SortExpression = boundField.DataField;
                            reportFieldSortExpressions.AddOrReplace( reportField.Guid, boundField.SortExpression );
                            boundField.Visible = reportField.ShowInGrid;
                            gReport.Columns.Add( boundField );
                        }
                    }
                    else if ( reportField.ReportFieldType == ReportFieldType.Attribute )
                    {
                        Guid? attributeGuid = reportField.Selection.AsGuidOrNull();
                        if ( attributeGuid.HasValue )
                        {
                            var attribute = AttributeCache.Read( attributeGuid.Value, rockContext );
                            if ( attribute != null )
                            {
                                selectedAttributes.Add( columnIndex, attribute );

                                BoundField boundField;

                                if ( attribute.FieldType.Guid.Equals( Rock.SystemGuid.FieldType.BOOLEAN.AsGuid() ) )
                                {
                                    boundField = new BoolField();
                                }
                                else if ( attribute.FieldType.Guid.Equals( Rock.SystemGuid.FieldType.DEFINED_VALUE.AsGuid() ) )
                                {
                                    boundField = new DefinedValueField();
                                }
                                else
                                {
                                    boundField = new CallbackField();
                                    boundField.HtmlEncode = false;
                                    ( boundField as CallbackField ).OnFormatDataValue += (sender, e) => {
                                        string resultHtml = null;
                                        if (e.DataValue != null)
                                        {
                                            bool condensed = true;
                                            resultHtml = attribute.FieldType.Field.FormatValueAsHtml( gReport, e.DataValue.ToString(), attribute.QualifierValues, condensed );

                                        }

                                        e.FormattedValue = resultHtml ?? string.Empty;
                                    };
                                }

                                boundField.DataField = string.Format( "Attribute_{0}_{1}", attribute.Id, columnIndex );
                                boundField.HeaderText = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? attribute.Name : reportField.ColumnHeaderText;
                                boundField.SortExpression = boundField.DataField;
                                reportFieldSortExpressions.AddOrReplace( reportField.Guid, boundField.SortExpression );

                                if ( attribute.FieldType.Guid.Equals( Rock.SystemGuid.FieldType.INTEGER.AsGuid() ) ||
                                    attribute.FieldType.Guid.Equals( Rock.SystemGuid.FieldType.DATE.AsGuid() ) ||
                                    attribute.FieldType.Guid.Equals( Rock.SystemGuid.FieldType.FILTER_DATE.AsGuid() ) )
                                {
                                    boundField.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;
                                    boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
                                }

                                boundField.Visible = reportField.ShowInGrid;

                                // NOTE:  Additional formatting for attributes is done in the gReport_RowDataBound event
                                gReport.Columns.Add( boundField );
                            }
                        }
                    }
                    else if ( reportField.ReportFieldType == ReportFieldType.DataSelectComponent )
                    {
                        selectedComponents.Add( columnIndex, reportField );

                        DataSelectComponent selectComponent = DataSelectContainer.GetComponent( reportField.DataSelectComponentEntityType.Name );
                        if ( selectComponent != null )
                        {
                            DataControlField columnField = selectComponent.GetGridField( entityType, reportField.Selection );

                            if ( columnField is BoundField )
                            {
                                ( columnField as BoundField ).DataField = string.Format( "Data_{0}_{1}", selectComponent.ColumnPropertyName, columnIndex );
                                var customSortExpression = selectComponent.SortProperties( reportField.Selection );
                                if ( customSortExpression != null )
                                {
                                    if ( customSortExpression == string.Empty )
                                    {
                                        // disable sorting if customSortExpression set to string.empty
                                        columnField.SortExpression = string.Empty;
                                    }
                                    else
                                    {
                                        columnField.SortExpression = customSortExpression.Split( ',' ).Select( a => string.Format( "Sort_{0}_{1}", a, columnIndex ) ).ToList().AsDelimited( "," );
                                    }
                                }
                                else
                                {
                                    // use default sorting if customSortExpression was null
                                    columnField.SortExpression = ( columnField as BoundField ).DataField;
                                }
                            }

                            columnField.HeaderText = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? selectComponent.ColumnHeaderText : reportField.ColumnHeaderText;
                            if ( !string.IsNullOrEmpty(columnField.SortExpression) )
                            {
                                reportFieldSortExpressions.AddOrReplace( reportField.Guid, columnField.SortExpression );
                            }

                            columnField.Visible = reportField.ShowInGrid;
                            gReport.Columns.Add( columnField );
                        }
                    }
                }

                // if no fields are specified, show the default fields (Previewable/All) for the EntityType
                var dataColumns = gReport.Columns.OfType<object>().Where( a => a.GetType() != typeof( SelectField ) );
                if ( dataColumns.Count() == 0 )
                {
                    // show either the Previewable Columns or all (if there are no previewable columns)
                    bool showAllColumns = !entityFields.Any( a => a.FieldKind == FieldKind.Property && a.IsPreviewable );
                    foreach ( var entityField in entityFields.Where( a => a.FieldKind == FieldKind.Property ) )
                    {
                        columnIndex++;
                        selectedEntityFields.Add( columnIndex, entityField );

                        BoundField boundField = entityField.GetBoundFieldType();

                        boundField.DataField = string.Format( "Entity_{0}_{1}", entityField.Name, columnIndex );
                        boundField.HeaderText = entityField.Name;
                        boundField.SortExpression = boundField.DataField;
                        boundField.Visible = showAllColumns || entityField.IsPreviewable;
                        gReport.Columns.Add( boundField );
                    }
                }

                try
                {
                    gReport.Visible = true;
                    gReport.ExportFilename = report.Name;
                    SortProperty sortProperty = gReport.SortProperty;
                    if ( sortProperty == null )
                    {
                        var reportSort = new SortProperty();
                        var sortColumns = new Dictionary<string, SortDirection>();
                        foreach ( var reportField in report.ReportFields.Where( a => a.SortOrder.HasValue ).OrderBy( a => a.SortOrder.Value ) )
                        {
                            if ( reportFieldSortExpressions.ContainsKey( reportField.Guid ) )
                            {
                                var sortField = reportFieldSortExpressions[reportField.Guid];
                                if ( !string.IsNullOrWhiteSpace( sortField ) )
                                {
                                    sortColumns.Add( sortField, reportField.SortDirection );
                                }
                            }
                        }

                        if ( sortColumns.Any() )
                        {
                            reportSort.Property = sortColumns.Select( a => a.Key + ( a.Value == SortDirection.Descending ? " desc" : string.Empty ) ).ToList().AsDelimited( "," );
                            sortProperty = reportSort;
                        }
                    }

                    dynamic qry = report.GetQueryable( entityType, selectedEntityFields, selectedAttributes, selectedComponents, sortProperty, databaseTimeoutSeconds ?? 180, out errors );
                    gReport.SetLinqDataSource( qry );
                    gReport.DataBind();
                }
                catch ( Exception ex )
                {
                    Exception exception = ex;
                    ExceptionLogService.LogException( ex, HttpContext.Current );
                    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 )
                            {
                                errorMessage = "This report did not complete in a timely manner. You can try again or adjust the timeout setting of this block.";
                                return;
                            }
                            else
                            {
                                errors.Add( exception.Message );
                                exception = exception.InnerException;
                            }
                        }
                        else
                        {
                            errors.Add( exception.Message );
                            exception = exception.InnerException;
                        }
                    }
                }

                if ( errors.Any() )
                {
                    errorMessage = "WARNING: There was a problem with one or more of the report's data components...<br/><br/> " + errors.AsDelimited( "<br/>" );
                }
            }
        }