private void BindGrid() { var groupTypeGuid = GetAttributeValue("BreakoutGroupType"); if (string.IsNullOrWhiteSpace(groupTypeGuid)) { return; } var groupType = new GroupTypeService(rockContext).Get(groupTypeGuid.AsGuid()); if (groupType == null) { return; } List <BreakoutGroupMember> data = new List <BreakoutGroupMember>(); BindFilter(groupType.Groups, schedules); List <BreakoutGroupMember> breakoutGroupMembers = GetBreakoutGroupMembers(); //remove dynamically added columns if any exist while (gBreakoutGroups.Columns.Count > 8) { gBreakoutGroups.Columns.RemoveAt(8); } foreach (var schedule in schedules) { if (selectedSchedules.Contains(schedule.Id.ToString())) { var field = new RockLiteralField(); field.HeaderText = schedule.Name; gBreakoutGroups.Columns.Add(field); } } gBreakoutGroups.DataSource = breakoutGroupMembers; gBreakoutGroups.DataBind(); }
/// <summary> /// Binds the enrollment grid. /// </summary> protected void BindEnrollmentGrid(bool isExporting = false, bool isCommunication = false) { var streakType = GetStreakType(); if (streakType == null) { pnlEnrollments.Visible = false; return; } pnlEnrollments.Visible = true; rFilter.Visible = true; gEnrollments.Visible = true; lHeading.Text = string.Format("{0} Enrollments", streakType.Name); _fullNameField = gEnrollments.ColumnsOfType <RockLiteralField>().Where(a => a.ID == "lExportFullName").FirstOrDefault(); _nameWithHtmlField = gEnrollments.ColumnsOfType <RockLiteralField>().Where(a => a.ID == "lNameWithHtml").FirstOrDefault(); _lBiStateGraph = gEnrollments.ColumnsOfType <RockLiteralField>().Where(a => a.ID == "lBiStateGraph").FirstOrDefault(); var streakService = GetStreakService(); var query = streakService.Queryable() .Include(se => se.PersonAlias.Person) .AsNoTracking() .Where(se => se.StreakTypeId == streakType.Id); // Filter by First Name var firstName = tbFirstName.Text; if (!string.IsNullOrWhiteSpace(firstName)) { query = query.Where(se => se.PersonAlias.Person.FirstName.StartsWith(firstName) || se.PersonAlias.Person.NickName.StartsWith(firstName)); } // Filter by Last Name var lastName = tbLastName.Text; if (!string.IsNullOrWhiteSpace(lastName)) { query = query.Where(se => se.PersonAlias.Person.LastName.StartsWith(lastName)); } // Filter by Enrollment Date var enrollmentDateRange = DateRangePicker.CalculateDateRangeFromDelimitedValues(drpEnrollmentDate.DelimitedValues); if (enrollmentDateRange.Start.HasValue) { query = query.Where(se => se.EnrollmentDate >= enrollmentDateRange.Start.Value); } if (enrollmentDateRange.End.HasValue) { query = query.Where(se => se.EnrollmentDate <= enrollmentDateRange.End.Value); } // Sort the grid gEnrollments.EntityTypeId = new Streak().TypeId; var sortProperty = gEnrollments.SortProperty; if (sortProperty != null) { query = query.Sort(sortProperty); } else { query = query.OrderBy(a => a.PersonAlias.Person.LastName).ThenBy(a => a.PersonAlias.Person.FirstName); } var viewModelQuery = query.Select(se => new EnrollmentViewModel { Id = se.Id, PersonId = se.PersonAlias.PersonId, LastName = se.PersonAlias.Person.LastName, NickName = se.PersonAlias.Person.NickName, EnrollmentDate = se.EnrollmentDate, Person = se.PersonAlias.Person, EngagementCount = se.EngagementCount, CurrentStreakCount = se.CurrentStreakCount, LongestStreakCount = se.LongestStreakCount, EngagementMap = se.EngagementMap }).AsQueryable(); gEnrollments.SetLinqDataSource(viewModelQuery); gEnrollments.DataBind(); }
/// <summary> /// Add all of the columns to the Registrations grid after the Registrants column. /// The Column.Insert method does not play well with buttons. /// </summary> private void RegistrationsTabAddDynamicControls() { var registrantsField = gRegistrations.ColumnsOfType <RockTemplateField>().FirstOrDefault(a => a.HeaderText == "Registrants"); int registrantsFieldIndex = gRegistrations.Columns.IndexOf(registrantsField); // Remove all columns to the right of Registrants for (int i = registrantsFieldIndex + 2; i < gRegistrations.Columns.Count; i++) { gRegistrations.Columns.RemoveAt(i); } // Add Attribute columns if necessary if (AvailableRegistrationAttributeIdsForGrid != null) { foreach (var attributeCache in AvailableRegistrationAttributeIdsForGrid.Select(a => AttributeCache.Get(a))) { bool columnExists = gRegistrations.Columns.OfType <AttributeField>().FirstOrDefault(a => a.AttributeId == attributeCache.Id) != null; if (!columnExists) { AttributeField boundField = new AttributeField(); boundField.DataField = attributeCache.Key; boundField.AttributeId = attributeCache.Id; boundField.HeaderText = attributeCache.Name; boundField.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue; gRegistrations.Columns.Add(boundField); } } } // Add the rest of the columns var dtWhen = new DateTimeField { DataField = "CreatedDateTime", HeaderText = "When", SortExpression = "CreatedDateTime" }; dtWhen.HeaderStyle.HorizontalAlign = HorizontalAlign.Left; dtWhen.ItemStyle.HorizontalAlign = HorizontalAlign.Left; gRegistrations.Columns.Add(dtWhen); var lDiscount = new RockLiteralField { ID = "lDiscount", HeaderText = "Discount Code", SortExpression = "DiscountCode", Visible = false }; lDiscount.HeaderStyle.HorizontalAlign = HorizontalAlign.Left; lDiscount.ItemStyle.HorizontalAlign = HorizontalAlign.Left; gRegistrations.Columns.Add(lDiscount); var lRegistrationCost = new RockLiteralField { ID = "lRegistrationCost", HeaderText = "Total Cost", SortExpression = "TotalCost" }; lRegistrationCost.HeaderStyle.HorizontalAlign = HorizontalAlign.Right; lRegistrationCost.ItemStyle.HorizontalAlign = HorizontalAlign.Right; gRegistrations.Columns.Add(lRegistrationCost); var lBalance = new RockLiteralField { ID = "lBalance", HeaderText = "Balance Due", SortExpression = "BalanceDue" }; lBalance.HeaderStyle.HorizontalAlign = HorizontalAlign.Right; lBalance.ItemStyle.HorizontalAlign = HorizontalAlign.Right; gRegistrations.Columns.Add(lBalance); DeleteField deleteField = new DeleteField(); deleteField.Click += gRegistrations_Delete; gRegistrations.Columns.Add(deleteField); }
/// <summary> /// Binds the group members grid. /// </summary> protected void BindParticipantsGrid(bool isExporting = false, bool isCommunication = false) { if (_stepType == null) { pnlSteps.Visible = false; return; } pnlSteps.Visible = true; rFilter.Visible = true; gSteps.Visible = true; var campusCount = CampusCache.All(false).Count; if (campusCount <= 1) { var campusColumn = gSteps.ColumnsOfType <RockBoundField>().Where(a => a.DataField == "CampusName").FirstOrDefault(); if (campusColumn != null) { campusColumn.Visible = false; } } lHeading.Text = string.Format("{0} Steps", _stepType.Name); _fullNameField = gSteps.ColumnsOfType <RockLiteralField>().Where(a => a.ID == "lExportFullName").FirstOrDefault(); _nameWithHtmlField = gSteps.ColumnsOfType <RockLiteralField>().Where(a => a.ID == "lNameWithHtml").FirstOrDefault(); var dataContext = GetDataContext(); var stepService = new StepService(dataContext); var qry = stepService.Queryable() .Include(x => x.StepStatus) .Include(x => x.PersonAlias.Person) .AsNoTracking() .Where(x => x.StepTypeId == _stepType.Id); // Filter by First Name string firstName = tbFirstName.Text; if (!string.IsNullOrWhiteSpace(firstName)) { qry = qry.Where(m => m.PersonAlias.Person.FirstName.StartsWith(firstName) || m.PersonAlias.Person.NickName.StartsWith(firstName)); } // Filter by Last Name string lastName = tbLastName.Text; if (!string.IsNullOrWhiteSpace(lastName)) { qry = qry.Where(m => m.PersonAlias.Person.LastName.StartsWith(lastName)); } // Filter by Step Status var validStatusIds = _stepType.StepProgram.StepStatuses.Select(r => r.Id).ToList(); var statusIds = new List <int>(); foreach (var statusId in cblStepStatus.SelectedValues.AsIntegerList()) { if (validStatusIds.Contains(statusId)) { statusIds.Add(statusId); } } if (statusIds.Any()) { qry = qry.Where(m => statusIds.Contains(m.StepStatusId ?? 0)); } // Filter By Start Date var startDateRange = DateRangePicker.CalculateDateRangeFromDelimitedValues(drpDateStarted.DelimitedValues); if (startDateRange.Start.HasValue) { qry = qry.Where(m => m.StartDateTime.HasValue && m.StartDateTime.Value >= startDateRange.Start.Value); } if (startDateRange.End.HasValue) { var exclusiveEndDate = startDateRange.End.Value.Date.AddDays(1); qry = qry.Where(m => m.StartDateTime.HasValue && m.StartDateTime.Value < exclusiveEndDate); } // Filter by Date Completed var completedDateRange = DateRangePicker.CalculateDateRangeFromDelimitedValues(drpDateCompleted.DelimitedValues); if (completedDateRange.Start.HasValue) { qry = qry.Where(m => m.CompletedDateTime.HasValue && m.CompletedDateTime.Value >= completedDateRange.Start.Value); } if (completedDateRange.End.HasValue) { var exclusiveEndDate = completedDateRange.End.Value.Date.AddDays(1); qry = qry.Where(m => m.CompletedDateTime.HasValue && m.CompletedDateTime.Value < exclusiveEndDate); } // Filter by Note string note = tbNote.Text; if (!string.IsNullOrWhiteSpace(note)) { qry = qry.Where(m => m.Note.Contains(note)); } var campusId = cpCampusFilter.SelectedCampusId; if (campusId != null) { qry = qry.Where(m => m.CampusId == campusId); } // Filter query by any configured attribute filters if (AvailableAttributes != null && AvailableAttributes.Any()) { foreach (var attribute in AvailableAttributes) { var filterControl = phAttributeFilters.FindControl("filter_" + attribute.Id.ToString()); qry = attribute.FieldType.Field.ApplyAttributeQueryFilter(qry, filterControl, attribute, stepService, Rock.Reporting.FilterMode.SimpleFilter); } } // Apply Grid Sort var sortProperty = gSteps.SortProperty; if (sortProperty != null) { qry = qry.Sort(sortProperty); } else { qry = qry.OrderBy(a => a.PersonAlias.Person.LastName).ThenBy(a => a.PersonAlias.Person.FirstName); } var stepIdQuery = qry.Select(m => m.Id); _inactiveStatus = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE); gSteps.EntityTypeId = new Step().TypeId; _stepStatusField = gSteps.ColumnsOfType <RockLiteralField>().FirstOrDefault(a => a.ID == lStepStatusHtml.ID); _stepDateStartedField = gSteps.ColumnsOfType <RockBoundField>().FirstOrDefault(a => a.HeaderText == "Date Started"); if (_stepDateStartedField != null) { _stepDateStartedField.Visible = _stepType.HasEndDate; } _showNoteColumn = GetAttributeValue(AttributeKey.ShowNoteColumn).AsBoolean(); gSteps.ColumnsOfType <RockBoundField>().First(a => a.DataField == "Note").Visible = _showNoteColumn; var hasDuration = _stepType.HasEndDate; var qrySteps = qry.Select(x => new StepParticipantListViewModel { Id = x.Id, PersonId = x.PersonAlias.PersonId, LastName = x.PersonAlias.Person.LastName, NickName = x.PersonAlias.Person.NickName, StartedDateTime = x.StartDateTime, CompletedDateTime = x.CompletedDateTime, StepStatusName = (x.StepStatus == null ? "" : x.StepStatus.Name), IsCompleted = (x.StepStatus == null ? false : x.StepStatus.IsCompleteStatus), Note = x.Note, CampusName = x.Campus == null ? string.Empty : x.Campus.Name, Person = x.PersonAlias.Person }); // Add the Step data models to the grid object list to allow custom attribute values to be read. if (this.AvailableAttributes != null && this.AvailableAttributes.Any()) { gSteps.ObjectList = qry.ToDictionary(k => k.Id.ToString(), v => ( object )v); } gSteps.SetLinqDataSource(qrySteps); gSteps.DataBind(); }
/// <summary> /// Adds the attribute columns. /// </summary> private void AddDynamicControls() { // remove Family Campus columns foreach (var column in pnlGroupMembers.Columns .OfType <RockLiteralField>() .ToList()) { pnlGroupMembers.Columns.Remove(column); } // remove Group member attribute columns foreach (var column in pnlGroupMembers.Columns .OfType <AttributeField>().ToList()) { pnlGroupMembers.Columns.Remove(column); } // remove Group member assignment columns foreach (var column in pnlGroupMembers.Columns .OfType <LinkButtonField>().ToList()) { pnlGroupMembers.Columns.Remove(column); } // remove the edit field foreach (var column in pnlGroupMembers.Columns .OfType <EditField>().ToList()) { pnlGroupMembers.Columns.Remove(column); } // Remove the delete field foreach (var column in pnlGroupMembers.Columns .OfType <DeleteField>() .ToList()) { pnlGroupMembers.Columns.Remove(column); } // Set up group member attribute columns var rockContext = new RockContext(); var attributeValueService = new AttributeValueService(rockContext); foreach (var attribute in GetGroupAttributes()) { // add the attribute data column var attributeColumn = pnlGroupMembers.Columns.OfType <AttributeField>().FirstOrDefault(a => a.AttributeId == attribute.Id); if (attributeColumn == null) { var boundField = new AttributeField { DataField = attribute.Id + attribute.Key, AttributeId = attribute.Id, HeaderText = attribute.Name, SortExpression = string.Format("attribute:{0}", attribute.Id), }; boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Center; decimal needsFilled = 0; if (attribute.FieldType != null) { var groupMemberIds = _group.Members.Select(m => m.Id).ToList(); var attributeValues = attributeValueService.GetByAttributeId(attribute.Id) .Where(v => groupMemberIds.Contains((int)v.EntityId) && !(v.Value == null || v.Value.Trim() == string.Empty)) .Select(v => v.Value).ToList(); // if the values are numeric, sum a number value if (attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.INTEGER.AsGuid()) || attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.DECIMAL.AsGuid())) { needsFilled = attributeValues.Sum(v => v.AsDecimal()); } else if (attribute.FieldType.Guid.Equals(Rock.SystemGuid.FieldType.MULTI_SELECT.AsGuid())) { // handles checkboxes and non-empty strings needsFilled = attributeValues.Count(v => !string.IsNullOrWhiteSpace(v)); } else { // handles single select and boolean needsFilled = attributeValues.Count(v => v.AsBoolean()); } } if (needsFilled > 0) { pnlGroupMembers.ShowFooter = true; boundField.FooterText = needsFilled.ToString(); } pnlGroupMembers.Columns.Add(boundField); } if (pnlGroupMembers.ShowFooter) { pnlGroupMembers.Columns[1].FooterText = "Total"; pnlGroupMembers.Columns[1].FooterStyle.HorizontalAlign = HorizontalAlign.Left; } } // Add dynamic assignment columns for volunteer groups if (_resources != null && _group.GroupType.GroupTypePurposeValue != null && _group.GroupType.GroupTypePurposeValue.Value == "Serving Area") { foreach (var groupType in _resourceTypes.Where(gt => gt.GetAttributeValue("AllowVolunteerAssignment").AsBoolean(true))) { if (_resources.ContainsKey(groupType.Name)) { var resourceGroupGuid = _resources[groupType.Name]; if (resourceGroupGuid != null && !string.IsNullOrWhiteSpace(resourceGroupGuid.Value)) { var parentGroup = new GroupService(rockContext).Get(resourceGroupGuid.Value.AsGuid()); if (parentGroup != null && parentGroup.GroupTypeId != _group.GroupTypeId) { var groupAssignment = new LinkButtonField(); groupAssignment.ItemStyle.HorizontalAlign = HorizontalAlign.Center; groupAssignment.ExcelExportBehavior = ExcelExportBehavior.NeverInclude; groupAssignment.HeaderText = parentGroup.Name; groupAssignment.HeaderStyle.CssClass = ""; pnlGroupMembers.Columns.Add(groupAssignment); var assignmentExport = new RockLiteralField(); assignmentExport.ID = string.Format("lAssignments_{0}", groupType.Id); assignmentExport.ItemStyle.HorizontalAlign = HorizontalAlign.Center; assignmentExport.ExcelExportBehavior = ExcelExportBehavior.AlwaysInclude; assignmentExport.HeaderStyle.CssClass = ""; assignmentExport.HeaderText = parentGroup.Name; assignmentExport.Visible = false; pnlGroupMembers.Columns.Add(assignmentExport); } } } } } // Add edit column var editField = new EditField(); pnlGroupMembers.Columns.Add(editField); editField.Click += pnlGroupMembers_EditClick; // Add delete column var deleteField = new DeleteField(); pnlGroupMembers.Columns.Add(deleteField); deleteField.Click += pnlGroupMembers_DeleteClick; }