/// <summary> /// Renders the controls. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="filterControl">The filter control.</param> /// <param name="writer">The writer.</param> /// <param name="controls">The controls.</param> public override void RenderControls(Type entityType, FilterField filterControl, HtmlTextWriter writer, Control[] controls) { DropDownList ddlCompare = controls[0] as DropDownList; NumberBox nbValue = controls[1] as NumberBox; NumberRangeEditor numberRangeEditor = controls[2] as NumberRangeEditor; writer.AddAttribute("class", "row field-criteria"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "col-md-4"); writer.RenderBeginTag(HtmlTextWriterTag.Div); ddlCompare.RenderControl(writer); writer.RenderEndTag(); writer.AddAttribute("class", "col-md-8"); writer.RenderBeginTag(HtmlTextWriterTag.Div); nbValue.RenderControl(writer); numberRangeEditor.RenderControl(writer); writer.RenderEndTag(); writer.RenderEndTag(); // row RegisterFilterCompareChangeScript(filterControl); }
/// <summary> /// Sets the value. /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="value">The value.</param> public override void SetEditValue(System.Web.UI.Control control, System.Collections.Generic.Dictionary <string, ConfigurationValue> configurationValues, string value) { NumberRangeEditor editor = control as NumberRangeEditor; if (editor != null) { if (value != null) { string[] valuePair = value.Split(new char[] { ',' }, StringSplitOptions.None); if (valuePair.Length == 2) { int result; if (int.TryParse(valuePair[0], out result)) { editor.LowerValue = result; } if (int.TryParse(valuePair[1], out result)) { editor.UpperValue = result; } } } } }
/// <summary> /// Gets the selection. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="controls">The controls.</param> /// <returns></returns> public override string GetSelection(Type entityType, Control[] controls) { DropDownList ddlCompare = controls[0] as DropDownList; NumberBox nbValue = controls[1] as NumberBox; NumberRangeEditor numberRangeEditor = controls[2] as NumberRangeEditor; return(string.Format("{0}|{1}|{2}", ddlCompare.SelectedValue, nbValue.Text, numberRangeEditor.DelimitedValues)); }
/// <summary> /// Creates the control(s) necessary for prompting user for a new value /// </summary> /// <param name="configurationValues">The configuration values.</param> /// <param name="id"></param> /// <returns> /// The control /// </returns> public override System.Web.UI.Control EditControl(System.Collections.Generic.Dictionary <string, ConfigurationValue> configurationValues, string id) { var numberRangeEditor = new NumberRangeEditor { ID = id }; numberRangeEditor.NumberType = System.Web.UI.WebControls.ValidationDataType.Double; return(numberRangeEditor); }
/// <summary> /// Sets the value. /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="value">The value.</param> public override void SetEditValue(System.Web.UI.Control control, System.Collections.Generic.Dictionary <string, ConfigurationValue> configurationValues, string value) { NumberRangeEditor editor = control as NumberRangeEditor; if (editor != null) { editor.DelimitedValues = value; } }
/// <summary> /// Reads new values entered by the user for the field /// </summary> /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param> /// <param name="configurationValues">The configuration values.</param> /// <returns></returns> public override string GetEditValue(System.Web.UI.Control control, System.Collections.Generic.Dictionary <string, ConfigurationValue> configurationValues) { NumberRangeEditor editor = control as NumberRangeEditor; if (editor != null && (editor.LowerValue.HasValue || editor.UpperValue.HasValue)) { return(editor.DelimitedValues); } return(null); }
/// <summary> /// Reads new values entered by the user for the field /// </summary> /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param> /// <param name="configurationValues">The configuration values.</param> /// <returns></returns> public override string GetEditValue(System.Web.UI.Control control, System.Collections.Generic.Dictionary <string, ConfigurationValue> configurationValues) { NumberRangeEditor editor = control as NumberRangeEditor; if (editor != null) { return(string.Format("{0},{1}", editor.LowerValue, editor.UpperValue)); } return(null); }
/// <summary> /// Gfs the settings_ display filter value. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void gfSettings_DisplayFilterValue(object sender, GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case "Amount": e.Value = NumberRangeEditor.FormatDelimitedValues(e.Value, "N2"); break; case "Frequency": int definedValueId = 0; if (int.TryParse(e.Value, out definedValueId)) { var definedValue = DefinedValueCache.Read(definedValueId); if (definedValue != null) { e.Value = definedValue.Value; } } break; case "Created": e.Value = DateRangePicker.FormatDelimitedValues(e.Value); break; case "Account": int accountId = 0; if (int.TryParse(e.Value, out accountId) && ddlAccount.Visible) { var service = new FinancialAccountService(new RockContext()); var account = service.Get(accountId); if (account != null) { e.Value = account.Name; } } else { e.Value = string.Empty; } break; case "Include Inactive": break; default: e.Value = string.Empty; break; } }
/// <summary> /// Handles the filter display for each saved user value /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> /// <exception cref="System.NotImplementedException"></exception> protected void gfTransactions_DisplayFilterValue(object sender, Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case "Row Limit": // row limit filter was removed, so hide it just in case e.Value = null; break; case "Date Range": e.Value = DateRangePicker.FormatDelimitedValues(e.Value); break; case "Amount Range": e.Value = NumberRangeEditor.FormatDelimitedValues(e.Value, "N2"); break; case "Account": var accountIds = e.Value.SplitDelimitedValues().AsIntegerList().Where(a => a > 0).ToList(); if (accountIds.Any()) { var service = new FinancialAccountService(new RockContext()); var accountNames = service.GetByIds(accountIds).OrderBy(a => a.Order).OrderBy(a => a.Name).Select(a => a.Name).ToList().AsDelimited(", ", " or "); e.Value = accountNames; } else { e.Value = string.Empty; } break; case "Transaction Type": case "Currency Type": case "Credit Card Type": case "Source Type": int definedValueId = 0; if (int.TryParse(e.Value, out definedValueId)) { var definedValue = DefinedValueCache.Read(definedValueId); if (definedValue != null) { e.Value = definedValue.Value; } } break; } }
/// <summary> /// Gets the expression. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="serviceInstance">The service instance.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { DateTime currentDate = RockDateTime.Today; int currentDayOfYear = currentDate.DayOfYear; var values = selection.Split('|'); ComparisonType comparisonType = values[0].ConvertToEnum <ComparisonType>(ComparisonType.EqualTo); int? ageValue = values[1].AsIntegerOrNull(); var rockContext = (RockContext)serviceInstance.Context; var personAgeQuery = new PersonService(rockContext).Queryable(); MemberExpression idExpression = Expression.Property(parameterExpression, "Id"); Expression ageSelect = new Rock.Reporting.DataSelect.Person.AgeSelect().GetExpression(rockContext, idExpression, ""); if (values.Length >= 3 && comparisonType == ComparisonType.Between) { var numberRangeEditor = new NumberRangeEditor(); numberRangeEditor.DelimitedValues = values[2]; decimal ageValueStart = numberRangeEditor.LowerValue ?? 0; decimal ageValueEnd = numberRangeEditor.UpperValue ?? decimal.MaxValue; var personAgeBetweenQuery = personAgeQuery.Where( p => ((p.BirthDate > SqlFunctions.DateAdd("year", -SqlFunctions.DateDiff("year", p.BirthDate, currentDate), currentDate) ? SqlFunctions.DateDiff("year", p.BirthDate, currentDate) - 1 : SqlFunctions.DateDiff("year", p.BirthDate, currentDate)) >= ageValueStart) && ((p.BirthDate > SqlFunctions.DateAdd("year", -SqlFunctions.DateDiff("year", p.BirthDate, currentDate), currentDate) ? SqlFunctions.DateDiff("year", p.BirthDate, currentDate) - 1 : SqlFunctions.DateDiff("year", p.BirthDate, currentDate)) <= ageValueEnd)); BinaryExpression result = FilterExpressionExtractor.Extract <Rock.Model.Person>(personAgeBetweenQuery, parameterExpression, "p") as BinaryExpression; return(result); } else { var personAgeEqualQuery = personAgeQuery.Where( p => (p.BirthDate > SqlFunctions.DateAdd("year", -SqlFunctions.DateDiff("year", p.BirthDate, currentDate), currentDate) ? SqlFunctions.DateDiff("year", p.BirthDate, currentDate) - 1 : SqlFunctions.DateDiff("year", p.BirthDate, currentDate)) == ageValue); BinaryExpression compareEqualExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(personAgeEqualQuery, parameterExpression, "p") as BinaryExpression; BinaryExpression result = FilterExpressionExtractor.AlterComparisonType(comparisonType, compareEqualExpression, null); return(result); } }
/// <summary> /// Handles the filter display for each saved user value /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> /// <exception cref="System.NotImplementedException"></exception> protected void rFilter_DisplayFilterValue(object sender, Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case "Date Range": e.Value = DateRangePicker.FormatDelimitedValues(e.Value); break; case "Amount Range": e.Value = NumberRangeEditor.FormatDelimitedValues(e.Value, "N2"); break; case "Account": int accountId = 0; if (int.TryParse(e.Value, out accountId)) { var service = new FinancialAccountService(); var account = service.Get(accountId); if (account != null) { e.Value = account.Name; } } break; case "Transaction Type": case "Currency Type": case "Credit Card Type": case "Source Type": int definedValueId = 0; if (int.TryParse(e.Value, out definedValueId)) { var definedValue = DefinedValueCache.Read(definedValueId); if (definedValue != null) { e.Value = definedValue.Name; } } break; } }
/// <summary> /// Sets the selection. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="controls">The controls.</param> /// <param name="selection">The selection.</param> public override void SetSelection(Type entityType, Control[] controls, string selection) { var values = selection.Split('|'); DropDownList ddlCompare = controls[0] as DropDownList; NumberBox nbValue = controls[1] as NumberBox; NumberRangeEditor numberRangeEditor = controls[2] as NumberRangeEditor; if (values.Length >= 2) { ddlCompare.SelectedValue = values[0]; nbValue.Text = values[1]; if (values.Length >= 3) { numberRangeEditor.DelimitedValues = values[2]; } } }
/// <inheritdoc/> public override string GetTextValue(string value, Dictionary <string, string> configurationValues) { return(NumberRangeEditor.FormatDelimitedValues(value, "G") ?? value); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { _currencyTypes = new Dictionary <int, string>(); _creditCardTypes = new Dictionary <int, string>(); // If configured for a person and person is null, return int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id; if (ContextTypesRequired.Any(e => e.Id == personEntityTypeId) && _person == null) { return; } // If configured for a batch and batch is null, return int batchEntityTypeId = EntityTypeCache.Read("Rock.Model.FinancialBatch").Id; if (ContextTypesRequired.Any(e => e.Id == batchEntityTypeId) && _batch == null) { return; } // If configured for a batch and batch is null, return int scheduledTxnEntityTypeId = EntityTypeCache.Read("Rock.Model.FinancialScheduledTransaction").Id; if (ContextTypesRequired.Any(e => e.Id == scheduledTxnEntityTypeId) && _scheduledTxn == null) { return; } // Qry var qry = new FinancialTransactionService(new RockContext()) .Queryable("AuthorizedPersonAlias.Person,ProcessedByPersonAlias.Person"); // Set up the selection filter if (_batch != null) { // If transactions are for a batch, the filter is hidden so only check the batch id qry = qry.Where(t => t.BatchId.HasValue && t.BatchId.Value == _batch.Id); // If the batch is closed, do not allow any editing of the transactions if (_batch.Status != BatchStatus.Closed && _canEdit) { gTransactions.IsDeleteEnabled = true; } else { gTransactions.IsDeleteEnabled = false; } } else if (_scheduledTxn != null) { // If transactions are for a batch, the filter is hidden so only check the batch id qry = qry.Where(t => t.ScheduledTransactionId.HasValue && t.ScheduledTransactionId.Value == _scheduledTxn.Id); gTransactions.IsDeleteEnabled = false; } else // Person { // otherwise set the selection based on filter settings if (_person != null) { qry = qry.Where(t => t.AuthorizedPersonAlias.PersonId == _person.Id); } // Date Range var drp = new DateRangePicker(); drp.DelimitedValues = gfTransactions.GetUserPreference("Date Range"); if (drp.LowerValue.HasValue) { qry = qry.Where(t => t.TransactionDateTime >= drp.LowerValue.Value); } if (drp.UpperValue.HasValue) { DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1); qry = qry.Where(t => t.TransactionDateTime < upperDate); } // Amount Range var nre = new NumberRangeEditor(); nre.DelimitedValues = gfTransactions.GetUserPreference("Amount Range"); if (nre.LowerValue.HasValue) { qry = qry.Where(t => t.TransactionDetails.Sum(d => d.Amount) >= nre.LowerValue.Value); } if (nre.UpperValue.HasValue) { qry = qry.Where(t => t.TransactionDetails.Sum(d => d.Amount) <= nre.UpperValue.Value); } // Transaction Code string transactionCode = gfTransactions.GetUserPreference("Transaction Code"); if (!string.IsNullOrWhiteSpace(transactionCode)) { qry = qry.Where(t => t.TransactionCode == transactionCode.Trim()); } // Account Id int accountId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Account"), out accountId)) { qry = qry.Where(t => t.TransactionDetails.Any(d => d.AccountId == accountId)); } // Transaction Type int transactionTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Transaction Type"), out transactionTypeId)) { qry = qry.Where(t => t.TransactionTypeValueId == transactionTypeId); } // Currency Type int currencyTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Currency Type"), out currencyTypeId)) { qry = qry.Where(t => t.CurrencyTypeValueId == currencyTypeId); } // Credit Card Type int creditCardTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Credit Card Type"), out creditCardTypeId)) { qry = qry.Where(t => t.CreditCardTypeValueId == creditCardTypeId); } // Source Type int sourceTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Source Type"), out sourceTypeId)) { qry = qry.Where(t => t.SourceTypeValueId == sourceTypeId); } } SortProperty sortProperty = gTransactions.SortProperty; if (sortProperty != null) { if (sortProperty.Property == "TotalAmount") { if (sortProperty.Direction == SortDirection.Ascending) { qry = qry.OrderBy(t => t.TransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.00M); } else { qry = qry.OrderByDescending(t => t.TransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.0M); } } else { qry = qry.Sort(sortProperty); } } else { // Default sort by Id if the transations are seen via the batch, // otherwise sort by descending date time. if (ContextTypesRequired.Any(e => e.Id == batchEntityTypeId)) { qry = qry.OrderBy(t => t.Id); } else { qry = qry.OrderByDescending(t => t.TransactionDateTime).ThenByDescending(t => t.Id); } } // Row Limit int?rowLimit = gfTransactions.GetUserPreference("Row Limit").AsIntegerOrNull(); if (rowLimit.HasValue) { qry = qry.Take(rowLimit.Value); } gTransactions.DataSource = qry.AsNoTracking().ToList(); gTransactions.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { _currencyTypes = new Dictionary <int, string>(); _creditCardTypes = new Dictionary <int, string>(); // If configured for a registration and registration is null, return int registrationEntityTypeId = EntityTypeCache.Read(typeof(Rock.Model.Registration)).Id; if (ContextTypesRequired.Any(e => e.Id == registrationEntityTypeId) && _registration == null) { return; } // If configured for a person and person is null, return int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id; if (ContextTypesRequired.Any(e => e.Id == personEntityTypeId) && _person == null) { return; } // If configured for a batch and batch is null, return int batchEntityTypeId = EntityTypeCache.Read("Rock.Model.FinancialBatch").Id; if (ContextTypesRequired.Any(e => e.Id == batchEntityTypeId) && _batch == null) { return; } // If configured for a batch and batch is null, return int scheduledTxnEntityTypeId = EntityTypeCache.Read("Rock.Model.FinancialScheduledTransaction").Id; if (ContextTypesRequired.Any(e => e.Id == scheduledTxnEntityTypeId) && _scheduledTxn == null) { return; } // Qry var rockContext = new RockContext(); var qry = new FinancialTransactionService(rockContext).Queryable(); // Transaction Types var txnTypes = GetAttributeValue("TransactionTypes").SplitDelimitedValues().AsGuidList(); if (txnTypes.Any()) { qry = qry.Where(t => txnTypes.Contains(t.TransactionTypeValue.Guid)); } // Set up the selection filter if (_batch != null) { // If transactions are for a batch, the filter is hidden so only check the batch id qry = qry.Where(t => t.BatchId.HasValue && t.BatchId.Value == _batch.Id); // If the batch is closed, do not allow any editing of the transactions if (_batch.Status != BatchStatus.Closed && _canEdit) { gTransactions.IsDeleteEnabled = true; } else { gTransactions.IsDeleteEnabled = false; } } else if (_scheduledTxn != null) { // If transactions are for a batch, the filter is hidden so only check the batch id qry = qry.Where(t => t.ScheduledTransactionId.HasValue && t.ScheduledTransactionId.Value == _scheduledTxn.Id); gTransactions.IsDeleteEnabled = false; } else if (_registration != null) { qry = qry .Where(t => t.TransactionDetails .Any(d => d.EntityTypeId.HasValue && d.EntityTypeId.Value == registrationEntityTypeId && d.EntityId.HasValue && d.EntityId.Value == _registration.Id)); gTransactions.IsDeleteEnabled = false; } else // Person { // otherwise set the selection based on filter settings if (_person != null) { // get the transactions for the person or all the members in the person's giving group (Family) qry = qry.Where(t => t.AuthorizedPersonAlias.Person.GivingId == _person.GivingId); } // Date Range var drp = new DateRangePicker(); drp.DelimitedValues = gfTransactions.GetUserPreference("Date Range"); if (drp.LowerValue.HasValue) { qry = qry.Where(t => t.TransactionDateTime >= drp.LowerValue.Value); } if (drp.UpperValue.HasValue) { DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1); qry = qry.Where(t => t.TransactionDateTime < upperDate); } // Amount Range var nre = new NumberRangeEditor(); nre.DelimitedValues = gfTransactions.GetUserPreference("Amount Range"); if (nre.LowerValue.HasValue) { qry = qry.Where(t => t.TransactionDetails.Sum(d => d.Amount) >= nre.LowerValue.Value); } if (nre.UpperValue.HasValue) { qry = qry.Where(t => t.TransactionDetails.Sum(d => d.Amount) <= nre.UpperValue.Value); } // Transaction Code string transactionCode = gfTransactions.GetUserPreference("Transaction Code"); if (!string.IsNullOrWhiteSpace(transactionCode)) { qry = qry.Where(t => t.TransactionCode == transactionCode.Trim()); } // Account Id var accountIds = (gfTransactions.GetUserPreference("Account") ?? "").SplitDelimitedValues().AsIntegerList().Where(a => a > 0).ToList(); { if (accountIds.Any()) { qry = qry.Where(t => t.TransactionDetails.Any(d => accountIds.Contains(d.AccountId) || (d.Account.ParentAccountId.HasValue && accountIds.Contains(d.Account.ParentAccountId.Value)))); } } // Transaction Type int transactionTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Transaction Type"), out transactionTypeId)) { qry = qry.Where(t => t.TransactionTypeValueId == transactionTypeId); } // Currency Type int currencyTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Currency Type"), out currencyTypeId)) { qry = qry.Where(t => t.FinancialPaymentDetail != null && t.FinancialPaymentDetail.CurrencyTypeValueId == currencyTypeId); } // Credit Card Type int creditCardTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Credit Card Type"), out creditCardTypeId)) { qry = qry.Where(t => t.FinancialPaymentDetail != null && t.FinancialPaymentDetail.CreditCardTypeValueId == creditCardTypeId); } // Source Type int sourceTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Source Type"), out sourceTypeId)) { qry = qry.Where(t => t.SourceTypeValueId == sourceTypeId); } } SortProperty sortProperty = gTransactions.SortProperty; if (sortProperty != null) { if (sortProperty.Property == "TotalAmount") { if (sortProperty.Direction == SortDirection.Ascending) { qry = qry.OrderBy(t => t.TransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.00M); } else { qry = qry.OrderByDescending(t => t.TransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.0M); } } else { qry = qry.Sort(sortProperty); } } else { // Default sort by Id if the transations are seen via the batch, // otherwise sort by descending date time. if (ContextTypesRequired.Any(e => e.Id == batchEntityTypeId)) { qry = qry.OrderBy(t => t.Id); } else { qry = qry.OrderByDescending(t => t.TransactionDateTime).ThenByDescending(t => t.Id); } } gTransactions.SetLinqDataSource(qry.AsNoTracking()); gTransactions.DataBind(); if (_batch == null && _scheduledTxn == null && _registration == null && _person == null) { pnlSummary.Visible = true; // No context - show account summary var qryTransactionDetails = qry.SelectMany(a => a.TransactionDetails); var accountSummaryQry = qryTransactionDetails.GroupBy(a => a.Account).Select(a => new { a.Key.Name, a.Key.Order, TotalAmount = (decimal?)a.Sum(d => d.Amount) }).OrderBy(a => a.Order); var summaryList = accountSummaryQry.ToList(); var grandTotalAmount = (summaryList.Count > 0) ? summaryList.Sum(a => a.TotalAmount ?? 0) : 0; string currencyFormat = GlobalAttributesCache.Value("CurrencySymbol") + "{0:n}"; lGrandTotal.Text = string.Format(currencyFormat, grandTotalAmount); rptAccountSummary.DataSource = summaryList.Select(a => new { a.Name, TotalAmount = string.Format(currencyFormat, a.TotalAmount) }).ToList(); rptAccountSummary.DataBind(); } else { pnlSummary.Visible = false; } }
/// <summary> /// Handles the filter display for each saved user value /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> /// <exception cref="System.NotImplementedException"></exception> protected void rFilter_DisplayFilterValue(object sender, Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case "Subject": case "Content": { break; } case "Communication Type": { if (!string.IsNullOrWhiteSpace(e.Value)) { e.Value = (( CommunicationType )System.Enum.Parse(typeof(CommunicationType), e.Value)).ConvertToString(); } break; } case "Status": { if (!string.IsNullOrWhiteSpace(e.Value)) { e.Value = (( CommunicationStatus )System.Enum.Parse(typeof(CommunicationStatus), e.Value)).ConvertToString(); } break; } case "Created By": { string personName = string.Empty; if (canApprove) { int?personId = e.Value.AsIntegerOrNull(); if (personId.HasValue) { var personService = new PersonService(new RockContext()); var person = personService.Get(personId.Value); if (person != null) { personName = person.FullName; } } } e.Value = personName; break; } case "Created Date Range": case "Sent Date Range": { e.Value = DateRangePicker.FormatDelimitedValues(e.Value); break; } case "Recipient Count": { e.Value = NumberRangeEditor.FormatDelimitedValues(e.Value); break; } default: { e.Value = string.Empty; break; } } }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue(System.Web.UI.Control parentControl, string value, System.Collections.Generic.Dictionary <string, ConfigurationValue> configurationValues, bool condensed) { string formattedValue = NumberRangeEditor.FormatDelimitedValues(value, "G") ?? value; return(base.FormatValue(parentControl, formattedValue, configurationValues, condensed)); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var queryable = new FinancialTransactionService().Queryable(); // Set up the selection filter if (_batch != null) { // If transactions are for a batch, the filter is hidden so only check the batch id queryable = queryable.Where(t => t.BatchId.HasValue && t.BatchId.Value == _batch.Id); } else { // otherwise set the selection based on filter settings if (_person != null) { queryable = queryable.Where(t => t.AuthorizedPersonId == _person.Id); } // Date Range var drp = new DateRangePicker(); drp.DelimitedValues = rFilter.GetUserPreference("Date Range"); if (drp.LowerValue.HasValue) { queryable = queryable.Where(t => t.TransactionDateTime >= drp.LowerValue.Value); } if (drp.UpperValue.HasValue) { DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1); queryable = queryable.Where(t => t.TransactionDateTime < upperDate); } // Amount Range var nre = new NumberRangeEditor(); nre.DelimitedValues = rFilter.GetUserPreference("Amount Range"); if (nre.LowerValue.HasValue) { queryable = queryable.Where(t => t.Amount >= nre.LowerValue.Value); } if (nre.UpperValue.HasValue) { queryable = queryable.Where(t => t.Amount <= nre.UpperValue.Value); } // Transaction Code string transactionCode = rFilter.GetUserPreference("Transaction Code"); if (!string.IsNullOrWhiteSpace(transactionCode)) { queryable = queryable.Where(t => t.TransactionCode == transactionCode.Trim()); } // Account Id int accountId = int.MinValue; if (int.TryParse(rFilter.GetUserPreference("Account"), out accountId)) { queryable = queryable.Where(t => t.TransactionDetails.Any(d => d.AccountId == accountId)); } // Transaction Type int transactionTypeId = int.MinValue; if (int.TryParse(rFilter.GetUserPreference("Transaction Type"), out transactionTypeId)) { queryable = queryable.Where(t => t.TransactionTypeValueId == transactionTypeId); } // Currency Type int currencyTypeId = int.MinValue; if (int.TryParse(rFilter.GetUserPreference("Currency Type"), out currencyTypeId)) { queryable = queryable.Where(t => t.CurrencyTypeValueId == currencyTypeId); } // Credit Card Type int creditCardTypeId = int.MinValue; if (int.TryParse(rFilter.GetUserPreference("Credit Card Type"), out creditCardTypeId)) { queryable = queryable.Where(t => t.CreditCardTypeValueId == creditCardTypeId); } // Source Type int sourceTypeId = int.MinValue; if (int.TryParse(rFilter.GetUserPreference("Source Type"), out sourceTypeId)) { queryable = queryable.Where(t => t.SourceTypeValueId == sourceTypeId); } } SortProperty sortProperty = rGridTransactions.SortProperty; if (sortProperty != null) { queryable = queryable.Sort(sortProperty); } else { queryable = queryable.OrderBy(t => t.TransactionDateTime); } rGridTransactions.DataSource = queryable.AsNoTracking().ToList(); rGridTransactions.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var queryable = new FinancialTransactionService(new RockContext()).Queryable(); // Set up the selection filter if (_batch != null) { // If transactions are for a batch, the filter is hidden so only check the batch id queryable = queryable.Where(t => t.BatchId.HasValue && t.BatchId.Value == _batch.Id); // If the batch is closed, do not allow any editing of the transactions if (_batch.Status != BatchStatus.Open && _canConfigure) { gTransactions.Actions.ShowAdd = false; gTransactions.IsDeleteEnabled = false; } else { gTransactions.Actions.ShowAdd = true; gTransactions.IsDeleteEnabled = true; } } else if (!string.IsNullOrWhiteSpace(PageParameter("financialBatchId")) && _batch == null) { // this makes sure the grid will show no transactions when you're adding a new financial batch. queryable = queryable.Where(t => t.BatchId.HasValue && t.BatchId.Value == 0); } else { // otherwise set the selection based on filter settings if (_person != null) { queryable = queryable.Where(t => t.AuthorizedPersonId == _person.Id); } // Date Range var drp = new DateRangePicker(); drp.DelimitedValues = gfTransactions.GetUserPreference("Date Range"); if (drp.LowerValue.HasValue) { queryable = queryable.Where(t => t.TransactionDateTime >= drp.LowerValue.Value); } if (drp.UpperValue.HasValue) { DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1); queryable = queryable.Where(t => t.TransactionDateTime < upperDate); } // Amount Range var nre = new NumberRangeEditor(); nre.DelimitedValues = gfTransactions.GetUserPreference("Amount Range"); if (nre.LowerValue.HasValue) { queryable = queryable.Where(t => t.TransactionDetails.Sum(d => d.Amount) >= nre.LowerValue.Value); } if (nre.UpperValue.HasValue) { queryable = queryable.Where(t => t.TransactionDetails.Sum(d => d.Amount) <= nre.UpperValue.Value); } // Transaction Code string transactionCode = gfTransactions.GetUserPreference("Transaction Code"); if (!string.IsNullOrWhiteSpace(transactionCode)) { queryable = queryable.Where(t => t.TransactionCode == transactionCode.Trim()); } // Account Id int accountId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Account"), out accountId)) { queryable = queryable.Where(t => t.TransactionDetails.Any(d => d.AccountId == accountId)); } // Transaction Type int transactionTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Transaction Type"), out transactionTypeId)) { queryable = queryable.Where(t => t.TransactionTypeValueId == transactionTypeId); } // Currency Type int currencyTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Currency Type"), out currencyTypeId)) { queryable = queryable.Where(t => t.CurrencyTypeValueId == currencyTypeId); } // Credit Card Type int creditCardTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Credit Card Type"), out creditCardTypeId)) { queryable = queryable.Where(t => t.CreditCardTypeValueId == creditCardTypeId); } // Source Type int sourceTypeId = int.MinValue; if (int.TryParse(gfTransactions.GetUserPreference("Source Type"), out sourceTypeId)) { queryable = queryable.Where(t => t.SourceTypeValueId == sourceTypeId); } } SortProperty sortProperty = gTransactions.SortProperty; if (sortProperty != null) { if (sortProperty.Property == "TotalAmount") { if (sortProperty.Direction == SortDirection.Ascending) { queryable = queryable.OrderBy(t => t.TransactionDetails.Sum(d => d.Amount)); } else { queryable = queryable.OrderByDescending(t => t.TransactionDetails.Sum(d => d.Amount)); } } else { queryable = queryable.Sort(sortProperty); } } else { queryable = queryable.OrderBy(t => t.TransactionDateTime); } gTransactions.DataSource = queryable.AsNoTracking().ToList(); gTransactions.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid(bool isExporting = false) { int?personId = null; int?givingGroupId = null; bool validRequest = false; if (TargetPerson != null) { personId = TargetPerson.Id; givingGroupId = TargetPerson.GivingGroupId; validRequest = true; } else { int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id; if (!ContextTypesRequired.Any(e => e.Id == personEntityTypeId)) { validRequest = true; } } if (validRequest) { var rockContext = new RockContext(); var qry = new FinancialScheduledTransactionService(rockContext) .Queryable("ScheduledTransactionDetails,FinancialPaymentDetail.CurrencyTypeValue,FinancialPaymentDetail.CreditCardTypeValue") .AsNoTracking(); // Valid Accounts var accountGuids = GetAttributeValue("Accounts").SplitDelimitedValues().AsGuidList(); if (accountGuids.Any()) { qry = qry.Where(t => t.ScheduledTransactionDetails.Any(d => accountGuids.Contains(d.Account.Guid))); } // Amount Range var nre = new NumberRangeEditor(); nre.DelimitedValues = gfSettings.GetUserPreference("Amount"); if (nre.LowerValue.HasValue) { qry = qry.Where(t => t.ScheduledTransactionDetails.Sum(d => d.Amount) >= nre.LowerValue.Value); } if (nre.UpperValue.HasValue) { qry = qry.Where(t => t.ScheduledTransactionDetails.Sum(d => d.Amount) <= nre.UpperValue.Value); } // Frequency int?frequencyTypeId = gfSettings.GetUserPreference("Frequency").AsIntegerOrNull(); if (frequencyTypeId.HasValue) { qry = qry.Where(t => t.TransactionFrequencyValueId == frequencyTypeId.Value); } // Date Range var drp = new DateRangePicker(); drp.DelimitedValues = gfSettings.GetUserPreference("Created"); if (drp.LowerValue.HasValue) { qry = qry.Where(t => t.CreatedDateTime >= drp.LowerValue.Value); } if (drp.UpperValue.HasValue) { DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1); qry = qry.Where(t => t.CreatedDateTime < upperDate); } // Account Id int accountId = int.MinValue; if (int.TryParse(gfSettings.GetUserPreference("Account"), out accountId) && ddlAccount.Visible) { qry = qry.Where(t => t.ScheduledTransactionDetails.Any(d => d.AccountId == accountId)); } // Active only (no filter) if (string.IsNullOrWhiteSpace(gfSettings.GetUserPreference("Include Inactive"))) { qry = qry.Where(t => t.IsActive); } if (givingGroupId.HasValue) { // Person contributes with family qry = qry.Where(t => t.AuthorizedPersonAlias.Person.GivingGroupId == givingGroupId); } else if (personId.HasValue) { // Person contributes individually qry = qry.Where(t => t.AuthorizedPersonAlias.PersonId == personId); } SortProperty sortProperty = gList.SortProperty; if (sortProperty != null) { if (sortProperty.Property == "Amount") { if (sortProperty.Direction == SortDirection.Ascending) { qry = qry.OrderBy(t => t.ScheduledTransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.00M); } else { qry = qry.OrderByDescending(t => t.ScheduledTransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.0M); } } else { qry = qry.Sort(sortProperty); } } else { qry = qry .OrderBy(t => t.AuthorizedPersonAlias.Person.LastName) .ThenBy(t => t.AuthorizedPersonAlias.Person.NickName) .ThenByDescending(t => t.IsActive) .ThenByDescending(t => t.StartDate); } _isExporting = isExporting; gList.SetLinqDataSource <FinancialScheduledTransaction>(qry); gList.DataBind(); _isExporting = false; } }
/// <summary> /// Handles the DisplayFilterValue event of the gfAlertFilter control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs"/> instance containing the event data.</param> protected void gfAlertFilter_DisplayFilterValue(object sender, Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs e) { switch (e.Key) { case FilterKey.DateRange: { e.Value = DateRangePicker.FormatDelimitedValues(e.Value); break; } case FilterKey.Person: { int?personId = e.Value.AsIntegerOrNull(); if (personId != null && ppPerson.Visible) { var person = new PersonService(new RockContext()).Get(personId.Value); if (person != null) { e.Value = person.ToString(); } else { e.Value = string.Empty; } } else { e.Value = string.Empty; } break; } case FilterKey.AlertCategory: { e.Value = GetSelectedValues(e.Value, cblAlertCategory); break; } case FilterKey.AlertTypes: { e.Value = GetSelectedValues(e.Value, cblAlertTypes); break; } case FilterKey.Campus: { var campusId = e.Value.AsIntegerOrNull(); if (campusId.HasValue && cpCampus.Visible) { var campusCache = CampusCache.Get(campusId.Value); if (campusCache != null) { e.Value = campusCache.Name; } else { e.Value = string.Empty; } } else { e.Value = string.Empty; } break; } case FilterKey.TransactionAmount: { e.Value = NumberRangeEditor.FormatDelimitedValues(e.Value, "N2"); break; } } }