コード例 #1
0
ファイル: ReportDetail.ascx.cs プロジェクト: shelsonjava/Rock
        /// <summary>
        /// Handles the Click event of the btnAddField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnAddField_Click(object sender, EventArgs e)
        {
            string fieldSelectionValue = ddlFields.SelectedItem.Value;
            Guid   reportFieldGuid     = Guid.NewGuid();

            string[] fieldSelectionValueParts = fieldSelectionValue.Split('|');
            if (fieldSelectionValueParts.Count() == 2)
            {
                ReportFieldType reportFieldType = fieldSelectionValueParts[0].ConvertToEnum <ReportFieldType>();
                string          fieldSelection  = fieldSelectionValueParts[1];
                ReportFieldsDictionary.Add(new ReportFieldInfo {
                    Guid = reportFieldGuid, ReportFieldType = reportFieldType, Selection = fieldSelection
                });
                AddFieldPanelWidget(reportFieldGuid, reportFieldType, fieldSelection, true, true, new ReportField {
                    ShowInGrid = true
                });
            }
        }
コード例 #2
0
        /// <summary> Convert field to string. </summary>
        /// <typeparam name="T"> Generic type parameter. </typeparam>
        /// <param name="value"> The value. </param>
        /// <param name="fieldType"> Type of the field. </param>
        /// <returns> The field converted to string. </returns>
        public static string ConvertToString <T>(T value, ReportFieldType fieldType)
        {
            if (value == null)
            {
                return("");
            }
            switch (fieldType)
            {
            case ReportFieldType.String:
                return(value.ToString());

            case ReportFieldType.Boolean:
                return(value.ToString());

            case ReportFieldType.Date:
                return(string.Format("{0:d}", value));

            case ReportFieldType.Time:
                return(string.Format("{0:t}", value));

            case ReportFieldType.DateTime:
                return(string.Format("{0:g}", value));

            case ReportFieldType.Minutes:
                return(string.Format("{0}mn", value));

            case ReportFieldType.Int:
                return(string.Format("", value));

            default:
                if (value is Guid)
                {
                    return(string.Format("{0:N}", value));
                }
                return(value.ToString());
            }
        }
コード例 #3
0
ファイル: ReportDetail.ascx.cs プロジェクト: Ganon11/Rock
        /// <summary>
        /// Creates the data select controls.
        /// </summary>
        /// <param name="reportFieldType">Type of the report field.</param>
        /// <param name="fieldSelection">The field selection.</param>
        /// <param name="panelWidget">The panel widget.</param>
        private void CreateFieldTypeSpecificControls( ReportFieldType reportFieldType, string fieldSelection, PanelWidget panelWidget )
        {
            PlaceHolder phDataSelectControls = panelWidget.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == panelWidget.ID + "_phDataSelectControls" );
            if ( phDataSelectControls == null )
            {
                phDataSelectControls = new PlaceHolder();
                phDataSelectControls.ID = panelWidget.ID + "_phDataSelectControls";
                panelWidget.Controls.Add( phDataSelectControls );
            }

            phDataSelectControls.Controls.Clear();

            if ( reportFieldType == ReportFieldType.DataSelectComponent )
            {
                string dataSelectComponentTypeName = EntityTypeCache.Read( fieldSelection.AsInteger() ).GetEntityType().FullName;
                DataSelectComponent dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName );

                if ( dataSelectComponent != null )
                {
                    var dataSelectControls = dataSelectComponent.CreateChildControls( phDataSelectControls );
                }
            }
        }
コード例 #4
0
ファイル: ReportDetail.ascx.cs プロジェクト: Ganon11/Rock
        /// <summary>
        /// Adds the field panel widget.
        /// </summary>
        /// <param name="reportFieldGuid">The report field unique identifier.</param>
        /// <param name="reportFieldType">Type of the report field.</param>
        /// <param name="fieldSelection">The field selection.</param>
        /// <param name="showExpanded">if set to <c>true</c> [show expanded].</param>
        /// <param name="setReportFieldValues">if set to <c>true</c> [set report field values].</param>
        /// <param name="reportField">The report field.</param>
        private void AddFieldPanelWidget( Guid reportFieldGuid, ReportFieldType reportFieldType, string fieldSelection, bool showExpanded, bool setReportFieldValues = false, ReportField reportField = null )
        {
            PanelWidget panelWidget = new PanelWidget();
            panelWidget.ID = string.Format( "reportFieldWidget_{0}", reportFieldGuid.ToString( "N" ) );

            panelWidget.ShowDeleteButton = true;
            panelWidget.DeleteClick += FieldsPanelWidget_DeleteClick;
            panelWidget.ShowReorderIcon = true;
            panelWidget.Expanded = showExpanded;

            Label lbFields = new Label();
            lbFields.Text = "Field Type";

            RockDropDownList ddlFields = new RockDropDownList();
            panelWidget.Controls.Add( ddlFields );
            ddlFields.ID = panelWidget.ID + "_ddlFields";
            ddlFields.AutoPostBack = true;
            ddlFields.SelectedIndexChanged += ddlFields_SelectedIndexChanged;

            panelWidget.HeaderControls = new Control[2] { lbFields, ddlFields };
            this.LoadFieldsDropDown( ddlFields );

            RockCheckBox showInGridCheckBox = new RockCheckBox();
            showInGridCheckBox.ID = panelWidget.ID + "_showInGridCheckBox";
            showInGridCheckBox.Text = "Show in Grid";

            panelWidget.Controls.Add( showInGridCheckBox );

            RockTextBox columnHeaderTextTextBox = new RockTextBox();
            columnHeaderTextTextBox.ID = panelWidget.ID + "_columnHeaderTextTextBox";
            columnHeaderTextTextBox.Label = "Column Label";
            columnHeaderTextTextBox.CssClass = "js-column-header-textbox";
            panelWidget.Controls.Add( columnHeaderTextTextBox );

            phReportFields.Controls.Add( panelWidget );

            CreateFieldTypeSpecificControls( reportFieldType, fieldSelection, panelWidget );

            if ( setReportFieldValues )
            {
                PopulateFieldPanelWidget( panelWidget, reportField, reportFieldType, fieldSelection );
            }
        }
コード例 #5
0
ファイル: ReportDetail.ascx.cs プロジェクト: Ganon11/Rock
        /// <summary>
        /// Populates the field panel widget.
        /// </summary>
        /// <param name="panelWidget">The panel widget.</param>
        /// <param name="reportField">The report field.</param>
        /// <param name="reportFieldType">Type of the report field.</param>
        /// <param name="fieldSelection">The field selection.</param>
        private void PopulateFieldPanelWidget( PanelWidget panelWidget, ReportField reportField, ReportFieldType reportFieldType, string fieldSelection )
        {
            int entityTypeId = etpEntityType.SelectedEntityTypeId ?? 0;
            if ( entityTypeId == 0 )
            {
                return;
            }

            string defaultColumnHeaderText = null;
            DataSelectComponent dataSelectComponent = null;
            bool fieldDefined = false;
            switch ( reportFieldType )
            {
                case ReportFieldType.Property:
                    var entityType = EntityTypeCache.Read( entityTypeId ).GetEntityType();
                    var entityField = EntityHelper.GetEntityFields( entityType ).FirstOrDefault( a => a.Name == fieldSelection );
                    if ( entityField != null )
                    {
                        defaultColumnHeaderText = entityField.Title;
                        fieldDefined = true;
                    }

                    break;

                case ReportFieldType.Attribute:
                    var attribute = AttributeCache.Read( fieldSelection.AsGuid() );
                    if ( attribute != null )
                    {
                        defaultColumnHeaderText = attribute.Name;
                        fieldDefined = true;
                    }

                    break;

                case ReportFieldType.DataSelectComponent:
                    string dataSelectComponentTypeName = EntityTypeCache.Read( fieldSelection.AsInteger() ).GetEntityType().FullName;
                    dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName );
                    if ( dataSelectComponent != null )
                    {
                        defaultColumnHeaderText = dataSelectComponent.ColumnHeaderText;
                        fieldDefined = true;
                    }

                    break;
            }

            if ( !fieldDefined )
            {
                // return if we can't determine field
                return;
            }

            RockDropDownList ddlFields = panelWidget.ControlsOfTypeRecursive<RockDropDownList>().FirstOrDefault( a => a.ID == panelWidget.ID + "_ddlFields" );
            if ( reportField.ReportFieldType == ReportFieldType.Attribute )
            {
                ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection );
            }
            else if ( reportField.ReportFieldType == ReportFieldType.Property )
            {
                ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection );
            }
            else if ( reportField.ReportFieldType == ReportFieldType.DataSelectComponent )
            {
                ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, dataSelectComponent.TypeId );
            }

            string fieldTitle = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText;
            panelWidget.Title = fieldTitle;

            RockCheckBox showInGridCheckBox = panelWidget.ControlsOfTypeRecursive<RockCheckBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_showInGridCheckBox" );
            showInGridCheckBox.Checked = reportField.ShowInGrid;

            RockTextBox columnHeaderTextTextBox = panelWidget.ControlsOfTypeRecursive<RockTextBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_columnHeaderTextTextBox" );
            columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText;

            if ( dataSelectComponent != null )
            {
                PlaceHolder phDataSelectControls = panelWidget.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == panelWidget.ID + "_phDataSelectControls" );
                if ( phDataSelectControls != null )
                {
                    var dataSelectControls = phDataSelectControls.Controls.OfType<Control>().ToArray();
                    dataSelectComponent.SetSelection( dataSelectControls, reportField.Selection ?? string.Empty );
                }
            }
        }
コード例 #6
0
ファイル: ReportDetail.ascx.cs プロジェクト: pkdevbox/Rock
        /// <summary>
        /// Adds the field panel widget.
        /// </summary>
        /// <param name="reportFieldGuid">The report field unique identifier.</param>
        /// <param name="reportFieldType">Type of the report field.</param>
        /// <param name="fieldSelection">The field selection.</param>
        /// <param name="showExpanded">if set to <c>true</c> [show expanded].</param>
        /// <param name="setReportFieldValues">if set to <c>true</c> [set report field values].</param>
        /// <param name="reportField">The report field.</param>
        private void AddFieldPanelWidget( Guid reportFieldGuid, ReportFieldType reportFieldType, string fieldSelection, bool showExpanded, bool setReportFieldValues = false, ReportField reportField = null )
        {
            int entityTypeId = ddlEntityType.SelectedValueAsInt() ?? 0;
            if (entityTypeId == 0)
            {
                return;
            }
            
            PanelWidget panelWidget = new PanelWidget();
            panelWidget.ID = string.Format( "reportFieldWidget_{0}", reportFieldGuid.ToString( "N" ) );

            string fieldTitle = null;
            DataSelectComponent dataSelectComponent = null;
            switch ( reportFieldType )
            {
                case ReportFieldType.Property:
                    var entityType = EntityTypeCache.Read( entityTypeId ).GetEntityType();
                    var entityField = EntityHelper.GetEntityFields( entityType ).FirstOrDefault( a => a.Name == fieldSelection );
                    if ( entityField != null )
                    {
                        fieldTitle = entityField.Title;
                    }

                    break;

                case ReportFieldType.Attribute:
                    var attribute = AttributeCache.Read( fieldSelection.AsInteger() ?? 0 );
                    if ( attribute != null )
                    {
                        fieldTitle = attribute.Name;
                    }

                    break;

                case ReportFieldType.DataSelectComponent:
                    string dataSelectComponentTypeName = EntityTypeCache.Read( fieldSelection.AsInteger() ?? 0 ).GetEntityType().FullName;
                    dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName );
                    if ( dataSelectComponent != null )
                    {
                        fieldTitle = dataSelectComponent.GetTitle( null );
                    }

                    break;
            }

            if ( fieldTitle == null )
            {
                // return if we can't determine field
                return;
            }

            panelWidget.Title = fieldTitle;
            panelWidget.ShowDeleteButton = true;
            panelWidget.DeleteClick += FieldsPanelWidget_DeleteClick;
            panelWidget.ShowReorderIcon = true;
            panelWidget.Expanded = showExpanded;

            HiddenField hfReportFieldType = new HiddenField();
            hfReportFieldType.ID = panelWidget.ID + "_hfReportFieldType";
            hfReportFieldType.Value = reportFieldType.ConvertToString();
            panelWidget.Controls.Add( hfReportFieldType );

            HiddenField hfFieldSelection = new HiddenField();
            hfFieldSelection.ID = panelWidget.ID + "_hfFieldSelection";
            hfFieldSelection.Value = fieldSelection;
            panelWidget.Controls.Add( hfFieldSelection );

            RockCheckBox showInGridCheckBox = new RockCheckBox();
            showInGridCheckBox.ID = panelWidget.ID + "_showInGridCheckBox";
            showInGridCheckBox.Text = "Show in Grid";

            if ( setReportFieldValues )
            {
                showInGridCheckBox.Checked = reportField.ShowInGrid;
            }

            panelWidget.Controls.Add( showInGridCheckBox );

            RockTextBox columnHeaderTextTextBox = new RockTextBox();
            columnHeaderTextTextBox.ID = panelWidget.ID + "_columnHeaderTextTextBox";
            columnHeaderTextTextBox.Label = "Column Label";
            if ( setReportFieldValues )
            {
                columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? fieldTitle : reportField.ColumnHeaderText;
            }

            panelWidget.Controls.Add( columnHeaderTextTextBox );

            if ( dataSelectComponent != null )
            {
                PlaceHolder phDataSelectControls = new PlaceHolder();
                phDataSelectControls.ID = panelWidget.ID + "_phDataSelectControls";
                panelWidget.Controls.Add( phDataSelectControls );
                var dataSelectControls = dataSelectComponent.CreateChildControls( phDataSelectControls );

                if ( setReportFieldValues )
                {
                    dataSelectComponent.SetSelection( dataSelectControls, reportField.Selection );
                }
            }

            phReportFields.Controls.Add( panelWidget );
        }
コード例 #7
0
        /// <summary>
        /// Creates the data select controls.
        /// </summary>
        /// <param name="reportFieldType">Type of the report field.</param>
        /// <param name="fieldSelection">The field selection.</param>
        /// <param name="panelWidget">The panel widget.</param>
        /// <param name="rockContext">The rock context.</param>
        private void CreateFieldTypeSpecificControls( ReportFieldType reportFieldType, string fieldSelection, PanelWidget panelWidget, RockContext rockContext )
        {
            PlaceHolder phDataSelectControls = panelWidget.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == panelWidget.ID + "_phDataSelectControls" );
            if ( phDataSelectControls == null )
            {
                phDataSelectControls = new PlaceHolder();
                phDataSelectControls.ID = panelWidget.ID + "_phDataSelectControls";
                panelWidget.Controls.Add( phDataSelectControls );
            }

            phDataSelectControls.Controls.Clear();

            if ( reportFieldType == ReportFieldType.DataSelectComponent )
            {
                var dataSelectComponent = GetDataSelectComponent( rockContext, fieldSelection.AsInteger() );
                if ( dataSelectComponent != null )
                {
                    dataSelectComponent.CreateChildControls( phDataSelectControls );
                }
            }
        }
コード例 #8
0
ファイル: ReportDetail.ascx.cs プロジェクト: NewSpring/Rock
        /// <summary>
        /// Populates the field panel widget.
        /// </summary>
        /// <param name="panelWidget">The panel widget.</param>
        /// <param name="reportField">The report field.</param>
        /// <param name="reportFieldType">Type of the report field.</param>
        /// <param name="fieldSelection">The field selection.</param>
        /// <param name="rockContext">The rock context.</param>
        private void PopulateFieldPanelWidget( PanelWidget panelWidget, ReportField reportField, ReportFieldType reportFieldType, string fieldSelection, RockContext rockContext )
        {
            int entityTypeId = etpEntityType.SelectedEntityTypeId ?? 0;
            if ( entityTypeId == 0 )
            {
                return;
            }

            string defaultColumnHeaderText = null;
            DataSelectComponent dataSelectComponent = null;
            bool fieldDefined = false;
            switch ( reportFieldType )
            {
                case ReportFieldType.Property:
                    var entityType = EntityTypeCache.Read( entityTypeId, rockContext ).GetEntityType();
                    var entityField = EntityHelper.GetEntityFields( entityType ).FirstOrDefault( a => a.Name == fieldSelection );
                    if ( entityField != null )
                    {
                        defaultColumnHeaderText = entityField.Title;
                        fieldDefined = true;
                    }

                    break;

                case ReportFieldType.Attribute:
                    var attribute = AttributeCache.Read( fieldSelection.AsGuid(), rockContext );
                    if ( attribute != null )
                    {
                        defaultColumnHeaderText = attribute.Name;
                        fieldDefined = true;
                    }

                    break;

                case ReportFieldType.DataSelectComponent:
                    dataSelectComponent = this.GetDataSelectComponent( rockContext, fieldSelection.AsInteger() );

                    if ( dataSelectComponent != null )
                    {
                        defaultColumnHeaderText = dataSelectComponent.ColumnHeaderText;
                        fieldDefined = true;
                    }

                    break;
            }

            // Show the common field properties.
            string fieldTitle = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText;
            panelWidget.Title = fieldTitle;

            RockCheckBox showInGridCheckBox = panelWidget.ControlsOfTypeRecursive<RockCheckBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_showInGridCheckBox" );
            showInGridCheckBox.Checked = reportField.ShowInGrid;

            RockTextBox columnHeaderTextTextBox = panelWidget.ControlsOfTypeRecursive<RockTextBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_columnHeaderTextTextBox" );
            columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText;

            // Show settings that are specific to the field type.
            if ( !fieldDefined )
            {
                // return if we can't determine field
                return;
            }

            RockDropDownList ddlFields = panelWidget.ControlsOfTypeRecursive<RockDropDownList>().FirstOrDefault( a => a.ID == panelWidget.ID + "_ddlFields" );
            if ( reportField.ReportFieldType == ReportFieldType.Attribute )
            {
                var selectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection );
                if ( ddlFields.Items.OfType<ListItem>().Any( a => a.Value == selectedValue ) )
                {
                    ddlFields.SelectedValue = selectedValue;
                }
                else
                {
                    // if this EntityField is not available for the current person, but this reportField already has it configured, let them keep it
                    var attribute = AttributeCache.Read( fieldSelection.AsGuid(), rockContext );
                    ddlFields.Items.Add( new ListItem( attribute.Name, selectedValue ) );
                    ddlFields.SelectedValue = selectedValue;
                }
            }
            else if ( reportField.ReportFieldType == ReportFieldType.Property )
            {
                ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection );
            }
            else if ( reportField.ReportFieldType == ReportFieldType.DataSelectComponent )
            {
                ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, dataSelectComponent.TypeId );
            }

            if ( dataSelectComponent != null )
            {
                PlaceHolder phDataSelectControls = panelWidget.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == panelWidget.ID + "_phDataSelectControls" );
                if ( phDataSelectControls != null )
                {
                    var dataSelectControls = phDataSelectControls.Controls.OfType<Control>().ToArray();
                    dataSelectComponent.SetSelection( dataSelectControls, reportField.Selection ?? string.Empty );
                }
            }
        }
コード例 #9
0
ファイル: ReportDetail.ascx.cs プロジェクト: shelsonjava/Rock
        /// <summary>
        /// Adds the field panel widget.
        /// </summary>
        /// <param name="reportFieldGuid">The report field unique identifier.</param>
        /// <param name="reportFieldType">Type of the report field.</param>
        /// <param name="fieldSelection">The field selection.</param>
        /// <param name="showExpanded">if set to <c>true</c> [show expanded].</param>
        /// <param name="setReportFieldValues">if set to <c>true</c> [set report field values].</param>
        /// <param name="reportField">The report field.</param>
        private void AddFieldPanelWidget(Guid reportFieldGuid, ReportFieldType reportFieldType, string fieldSelection, bool showExpanded, bool setReportFieldValues = false, ReportField reportField = null)
        {
            int entityTypeId = ddlEntityType.SelectedValueAsInt() ?? 0;

            if (entityTypeId == 0)
            {
                return;
            }

            PanelWidget panelWidget = new PanelWidget();

            panelWidget.ID = string.Format("reportFieldWidget_{0}", reportFieldGuid.ToString("N"));

            string fieldTitle = null;
            DataSelectComponent dataSelectComponent = null;

            switch (reportFieldType)
            {
            case ReportFieldType.Property:
                var entityType  = EntityTypeCache.Read(entityTypeId).GetEntityType();
                var entityField = EntityHelper.GetEntityFields(entityType).FirstOrDefault(a => a.Name == fieldSelection);
                if (entityField != null)
                {
                    fieldTitle = entityField.Title;
                }

                break;

            case ReportFieldType.Attribute:
                var attribute = AttributeCache.Read(fieldSelection.AsInteger() ?? 0);
                if (attribute != null)
                {
                    fieldTitle = attribute.Name;
                }

                break;

            case ReportFieldType.DataSelectComponent:
                string dataSelectComponentTypeName = EntityTypeCache.Read(fieldSelection.AsInteger() ?? 0).GetEntityType().FullName;
                dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent(dataSelectComponentTypeName);
                if (dataSelectComponent != null)
                {
                    fieldTitle = dataSelectComponent.GetTitle(null);
                }

                break;
            }

            if (fieldTitle == null)
            {
                // return if we can't determine field
                return;
            }

            panelWidget.Title            = fieldTitle;
            panelWidget.ShowDeleteButton = true;
            panelWidget.DeleteClick     += FieldsPanelWidget_DeleteClick;
            panelWidget.ShowReorderIcon  = true;
            panelWidget.Expanded         = showExpanded;

            HiddenField hfReportFieldType = new HiddenField();

            hfReportFieldType.ID    = panelWidget.ID + "_hfReportFieldType";
            hfReportFieldType.Value = reportFieldType.ConvertToString();
            panelWidget.Controls.Add(hfReportFieldType);

            HiddenField hfFieldSelection = new HiddenField();

            hfFieldSelection.ID    = panelWidget.ID + "_hfFieldSelection";
            hfFieldSelection.Value = fieldSelection;
            panelWidget.Controls.Add(hfFieldSelection);

            RockCheckBox showInGridCheckBox = new RockCheckBox();

            showInGridCheckBox.ID   = panelWidget.ID + "_showInGridCheckBox";
            showInGridCheckBox.Text = "Show in Grid";

            if (setReportFieldValues)
            {
                showInGridCheckBox.Checked = reportField.ShowInGrid;
            }

            panelWidget.Controls.Add(showInGridCheckBox);

            RockTextBox columnHeaderTextTextBox = new RockTextBox();

            columnHeaderTextTextBox.ID    = panelWidget.ID + "_columnHeaderTextTextBox";
            columnHeaderTextTextBox.Label = "Column Label";
            if (setReportFieldValues)
            {
                columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? fieldTitle : reportField.ColumnHeaderText;
            }

            panelWidget.Controls.Add(columnHeaderTextTextBox);

            if (dataSelectComponent != null)
            {
                PlaceHolder phDataSelectControls = new PlaceHolder();
                phDataSelectControls.ID = panelWidget.ID + "_phDataSelectControls";
                panelWidget.Controls.Add(phDataSelectControls);
                var dataSelectControls = dataSelectComponent.CreateChildControls(phDataSelectControls);

                if (setReportFieldValues)
                {
                    dataSelectComponent.SetSelection(dataSelectControls, reportField.Selection);
                }
            }

            phReportFields.Controls.Add(panelWidget);
        }
コード例 #10
0
ファイル: ReportDetail.ascx.cs プロジェクト: shelsonjava/Rock
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Report report = null;

            using (new UnitOfWorkScope())
            {
                ReportService      service            = new ReportService();
                ReportFieldService reportFieldService = new ReportFieldService();

                int reportId = int.Parse(hfReportId.Value);

                if (reportId == 0)
                {
                    report          = new Report();
                    report.IsSystem = false;
                }
                else
                {
                    report = service.Get(reportId);
                }

                report.Name         = tbName.Text;
                report.Description  = tbDescription.Text;
                report.CategoryId   = cpCategory.SelectedValueAsInt();
                report.EntityTypeId = ddlEntityType.SelectedValueAsInt();
                report.DataViewId   = ddlDataView.SelectedValueAsInt();

                if (!Page.IsValid)
                {
                    return;
                }

                if (!report.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                RockTransactionScope.WrapTransaction(() =>
                {
                    // delete all the reportFields so we can cleanly add them
                    foreach (var reportField in report.ReportFields.ToList())
                    {
                        var field = reportFieldService.Get(reportField.Guid);
                        reportFieldService.Delete(field, this.CurrentPersonId);
                        reportFieldService.Save(field, this.CurrentPersonId);
                    }

                    report.ReportFields.Clear();

                    var allPanelWidgets = phReportFields.ControlsOfTypeRecursive <PanelWidget>();
                    int displayOrder    = 0;
                    foreach (var panelWidget in allPanelWidgets)
                    {
                        string hfReportFieldTypeID    = panelWidget.ID + "_hfReportFieldType";
                        HiddenField hfReportFieldType = phReportFields.ControlsOfTypeRecursive <HiddenField>().First(a => a.ID == hfReportFieldTypeID);

                        string hfFieldSelectionID    = panelWidget.ID + "_hfFieldSelection";
                        HiddenField hfFieldSelection = phReportFields.ControlsOfTypeRecursive <HiddenField>().First(a => a.ID == hfFieldSelectionID);

                        ReportFieldType reportFieldType = hfReportFieldType.Value.ConvertToEnum <ReportFieldType>();
                        string fieldSelection           = hfFieldSelection.Value;
                        ReportField reportField         = new ReportField();
                        reportField.ReportFieldType     = reportFieldType;

                        string showInGridCheckBoxId     = string.Format("{0}_showInGridCheckBox", panelWidget.ID);
                        RockCheckBox showInGridCheckBox = phReportFields.ControlsOfTypeRecursive <RockCheckBox>().First(a => a.ID == showInGridCheckBoxId);
                        reportField.ShowInGrid          = showInGridCheckBox.Checked;

                        string columnHeaderTextTextBoxId    = string.Format("{0}_columnHeaderTextTextBox", panelWidget.ID);
                        RockTextBox columnHeaderTextTextBox = phReportFields.ControlsOfTypeRecursive <RockTextBox>().First(a => a.ID == columnHeaderTextTextBoxId);
                        reportField.ColumnHeaderText        = columnHeaderTextTextBox.Text;

                        reportField.Order = displayOrder++;

                        if (reportFieldType == ReportFieldType.DataSelectComponent)
                        {
                            reportField.DataSelectComponentEntityTypeId = fieldSelection.AsInteger();

                            string dataSelectComponentTypeName      = EntityTypeCache.Read(reportField.DataSelectComponentEntityTypeId ?? 0).GetEntityType().FullName;
                            DataSelectComponent dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent(dataSelectComponentTypeName);

                            string placeHolderId  = string.Format("{0}_phDataSelectControls", panelWidget.ID);
                            var placeHolder       = phReportFields.ControlsOfTypeRecursive <PlaceHolder>().Where(a => a.ID == placeHolderId).FirstOrDefault();
                            reportField.Selection = dataSelectComponent.GetSelection(placeHolder.Controls.OfType <Control>().ToArray());
                        }
                        else
                        {
                            reportField.Selection = fieldSelection;
                        }

                        report.ReportFields.Add(reportField);
                    }

                    if (report.Id.Equals(0))
                    {
                        service.Add(report, CurrentPersonId);
                    }

                    service.Save(report, CurrentPersonId);
                });
            }

            var qryParams = new Dictionary <string, string>();

            qryParams["ReportId"] = report.Id.ToString();
            NavigateToPage(RockPage.Guid, qryParams);
        }