/// <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 ); }
/// <summary> /// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e ) { int? categoryId = null; var reportService = new ReportService(); var report = reportService.Get( int.Parse( hfReportId.Value ) ); if ( report != null ) { string errorMessage; if ( !reportService.CanDelete( report, out errorMessage ) ) { ShowReadonlyDetails( report ); mdDeleteWarning.Show( errorMessage, ModalAlertType.Information ); return; } else { categoryId = report.CategoryId; RockTransactionScope.WrapTransaction( () => { reportService.Delete( report, CurrentPersonId ); reportService.Save( report, CurrentPersonId ); } ); // reload page, selecting the deleted data view's parent var qryParams = new Dictionary<string, string>(); if ( categoryId != null ) { qryParams["categoryId"] = categoryId.ToString(); } NavigateToPage( RockPage.Guid, qryParams ); } } }