/// <summary> /// Creates the table controls. /// </summary> /// <param name="batchId">The batch identifier.</param> /// <param name="dataViewId">The data view identifier.</param> private void BindHtmlGrid(int?batchId, int?dataViewId) { _financialTransactionDetailList = null; RockContext rockContext = new RockContext(); nbSaveSuccess.Visible = false; btnSave.Visible = false; List <DataControlField> tableColumns = new List <DataControlField>(); tableColumns.Add(new RockLiteralField { ID = "lPerson", HeaderText = "Person" }); tableColumns.Add(new RockLiteralField { ID = "lAmount", HeaderText = "Amount" }); tableColumns.Add(new RockLiteralField { ID = "lAccount", HeaderText = "Account" }); tableColumns.Add(new RockLiteralField { ID = "lTransactionType", HeaderText = "Transaction Type" }); string entityColumnHeading = this.GetAttributeValue("EntityColumnHeading"); if (string.IsNullOrEmpty(entityColumnHeading)) { if (_transactionEntityType != null) { entityColumnHeading = _entityTypeQualifiedName; } } tableColumns.Add(new RockLiteralField { ID = "lEntityColumn", HeaderText = entityColumnHeading }); var additionalColumns = this.GetAttributeValue(CustomGridColumnsConfig.AttributeKey).FromJsonOrNull <CustomGridColumnsConfig>(); if (additionalColumns != null) { foreach (var columnConfig in additionalColumns.ColumnsConfig) { int insertPosition; if (columnConfig.PositionOffsetType == CustomGridColumnsConfig.ColumnConfig.OffsetType.LastColumn) { insertPosition = tableColumns.Count - columnConfig.PositionOffset; } else { insertPosition = columnConfig.PositionOffset; } var column = columnConfig.GetGridColumn(); tableColumns.Insert(insertPosition, column); insertPosition++; } } StringBuilder headers = new StringBuilder(); foreach (var tableColumn in tableColumns) { if (tableColumn.HeaderStyle.CssClass.IsNotNullOrWhiteSpace()) { headers.AppendFormat("<th class='{0}'>{1}</th>", tableColumn.HeaderStyle.CssClass, tableColumn.HeaderText); } else { headers.AppendFormat("<th>{0}</th>", tableColumn.HeaderText); } } lHeaderHtml.Text = headers.ToString(); int?transactionId = this.PageParameter("TransactionId").AsIntegerOrNull(); if (batchId.HasValue || dataViewId.HasValue || transactionId.HasValue) { var financialTransactionDetailQuery = new FinancialTransactionDetailService(rockContext).Queryable() .Include(a => a.Transaction) .Include(a => a.Transaction.AuthorizedPersonAlias.Person); if (batchId.HasValue) { financialTransactionDetailQuery = financialTransactionDetailQuery.Where(a => a.Transaction.BatchId == batchId.Value); } if (dataViewId.HasValue && dataViewId > 0) { var dataView = new DataViewService(rockContext).Get(dataViewId.Value); List <string> errorMessages; var transactionDetailIdsQry = dataView.GetQuery(null, rockContext, null, out errorMessages).Select(a => a.Id); financialTransactionDetailQuery = financialTransactionDetailQuery.Where(a => transactionDetailIdsQry.Contains(a.Id)); } if (transactionId.HasValue) { financialTransactionDetailQuery = financialTransactionDetailQuery.Where(a => transactionId == a.TransactionId); } int maxResults = this.GetAttributeValue("MaxNumberofResults").AsIntegerOrNull() ?? 1000; _financialTransactionDetailList = financialTransactionDetailQuery.OrderByDescending(a => a.Transaction.TransactionDateTime).Take(maxResults).ToList(); phTableRows.Controls.Clear(); btnSave.Visible = _financialTransactionDetailList.Any(); string appRoot = this.ResolveRockUrl("~/"); string themeRoot = this.ResolveRockUrl("~~/"); foreach (var financialTransactionDetail in _financialTransactionDetailList) { var tr = new HtmlGenericContainer("tr"); foreach (var tableColumn in tableColumns) { var literalControl = new LiteralControl(); if (tableColumn is RockLiteralField) { tr.Controls.Add(literalControl); var literalTableColumn = tableColumn as RockLiteralField; if (literalTableColumn.ID == "lPerson") { literalControl.Text = string.Format("<td>{0}</td>", financialTransactionDetail.Transaction.AuthorizedPersonAlias); } else if (literalTableColumn.ID == "lAmount") { literalControl.Text = string.Format("<td>{0}</td>", financialTransactionDetail.Amount.FormatAsCurrency()); } else if (literalTableColumn.ID == "lAccount") { literalControl.Text = string.Format("<td>{0}</td>", financialTransactionDetail.Account.ToString()); } else if (literalTableColumn.ID == "lTransactionType") { literalControl.ID = "lTransactionType_" + financialTransactionDetail.Id.ToString(); literalControl.Text = string.Format("<td>{0}</td>", financialTransactionDetail.Transaction.TransactionTypeValue); } else if (literalTableColumn.ID == "lEntityColumn") { var tdEntityControls = new HtmlGenericContainer("td") { ID = "pnlEntityControls_" + financialTransactionDetail.Id.ToString() }; tr.Controls.Add(tdEntityControls); if (_transactionEntityType != null) { if (_transactionEntityType.Id == EntityTypeCache.GetId <GroupMember>()) { var ddlGroup = new RockDropDownList { ID = "ddlGroup_" + financialTransactionDetail.Id.ToString(), EnhanceForLongLists = true }; ddlGroup.Label = "Group"; ddlGroup.AutoPostBack = true; ddlGroup.SelectedIndexChanged += ddlGroup_SelectedIndexChanged; tdEntityControls.Controls.Add(ddlGroup); var ddlGroupMember = new RockDropDownList { ID = "ddlGroupMember_" + financialTransactionDetail.Id.ToString(), Visible = false, EnhanceForLongLists = true }; ddlGroupMember.Label = "Group Member"; tdEntityControls.Controls.Add(ddlGroupMember); } else if (_transactionEntityType.Id == EntityTypeCache.GetId <Group>()) { var ddlGroup = new RockDropDownList { ID = "ddlGroup_" + financialTransactionDetail.Id.ToString(), EnhanceForLongLists = true }; ddlGroup.AutoPostBack = false; tdEntityControls.Controls.Add(ddlGroup); } else if (_transactionEntityType.Id == EntityTypeCache.GetId <DefinedValue>()) { var ddlDefinedValue = new DefinedValuePicker { ID = "ddlDefinedValue_" + financialTransactionDetail.Id.ToString(), EnhanceForLongLists = true }; tdEntityControls.Controls.Add(ddlDefinedValue); } else if (_transactionEntityType.SingleValueFieldType != null) { var entityPicker = _transactionEntityType.SingleValueFieldType.Field.EditControl(new Dictionary <string, Rock.Field.ConfigurationValue>(), "entityPicker_" + financialTransactionDetail.Id.ToString()); tdEntityControls.Controls.Add(entityPicker); } } } } else if (tableColumn is LavaField) { tr.Controls.Add(literalControl); var lavaField = tableColumn as LavaField; Dictionary <string, object> mergeValues = new Dictionary <string, object>(); mergeValues.Add("Row", financialTransactionDetail); string lavaOutput = lavaField.LavaTemplate.ResolveMergeFields(mergeValues); // Resolve any dynamic url references lavaOutput = lavaOutput.Replace("~~/", themeRoot).Replace("~/", appRoot); if (lavaField.ItemStyle.CssClass.IsNotNullOrWhiteSpace()) { literalControl.Text = string.Format("<td class='{0}'>{1}</td>", lavaField.ItemStyle.CssClass, lavaOutput); } else { literalControl.Text = string.Format("<td>{0}</td>", lavaOutput); } } } phTableRows.Controls.Add(tr); pnlTransactions.Visible = true; } } else { pnlTransactions.Visible = false; } }