/// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Control[] controls, string selection)
        {
            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 4)
            {
                var comparisonControl = controls[0] as DropDownList;
                var numberBox         = controls[1] as CurrencyBox;
                var accountPicker     = controls[2] as AccountPicker;
                SlidingDateRangePicker slidingDateRangePicker = controls[3] as SlidingDateRangePicker;
                var cbCombineGiving = controls[4] as RockCheckBox;
                var cbUseAnalytics  = controls[5] as RockCheckBox;

                comparisonControl.SetValue(selectionValues[0]);
                decimal?amount = selectionValues[1].AsDecimal();
                if (amount.HasValue)
                {
                    numberBox.Text = amount.Value.ToString("F2");
                }
                else
                {
                    numberBox.Text = string.Empty;
                }


                if (selectionValues.Length >= 7)
                {
                    // convert comma delimited to pipe
                    slidingDateRangePicker.DelimitedValues = selectionValues[6].Replace(',', '|');
                }
                else
                {
                    // if converting from a previous version of the selection
                    var lowerValue = selectionValues[2].AsDateTime();
                    var upperValue = selectionValues[3].AsDateTime();

                    slidingDateRangePicker.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.DateRange;
                    slidingDateRangePicker.SetDateRangeModeValue(new DateRange(lowerValue, upperValue));
                }

                if (selectionValues.Length >= 5)
                {
                    var accountGuids = selectionValues[4].Split(',').Select(a => a.AsGuid()).ToList();
                    var accounts     = new FinancialAccountService(new RockContext()).GetByGuids(accountGuids);
                    if (accounts != null && accounts.Any())
                    {
                        accountPicker.SetValues(accounts);
                    }
                }

                if (selectionValues.Length >= 6)
                {
                    cbCombineGiving.Checked = selectionValues[5].AsBooleanOrNull() ?? false;
                }

                if (selectionValues.Length >= 8)
                {
                    cbUseAnalytics.Checked = selectionValues[7].AsBooleanOrNull() ?? false;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Formats the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override string FormatSelection(Type entityType, string selection)
        {
            string result = "Giving Amount";

            string[] selectionValues = selection.Split('|');

            if (selectionValues.Length >= 4)
            {
                ComparisonType comparisonType = selectionValues[0].ConvertToEnum <ComparisonType>(ComparisonType.GreaterThanOrEqualTo);
                decimal        amount         = selectionValues[1].AsDecimalOrNull() ?? 0.00M;
                string         accountNames   = string.Empty;
                if (selectionValues.Length >= 5)
                {
                    var accountGuids = selectionValues[4].Split(',').Select(a => a.AsGuid()).ToList();
                    accountNames = new FinancialAccountService(new RockContext()).GetByGuids(accountGuids).Select(a => a.Name).ToList().AsDelimited(",");
                }

                bool combineGiving = false;
                if (selectionValues.Length >= 6)
                {
                    combineGiving = selectionValues[5].AsBooleanOrNull() ?? false;
                }

                SlidingDateRangePicker fakeSlidingDateRangePicker = new SlidingDateRangePicker();

                if (selectionValues.Length >= 7)
                {
                    // convert comma delimited to pipe
                    fakeSlidingDateRangePicker.DelimitedValues = selectionValues[6].Replace(',', '|');
                }
                else
                {
                    // if converting from a previous version of the selection
                    var lowerValue = selectionValues[2].AsDateTime();
                    var upperValue = selectionValues[3].AsDateTime();

                    fakeSlidingDateRangePicker.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.DateRange;
                    fakeSlidingDateRangePicker.SetDateRangeModeValue(new DateRange(lowerValue, upperValue));
                }

                result = string.Format(
                    "{4}Giving amount total {0} {1} {2}. Date Range: {3}",
                    comparisonType.ConvertToString().ToLower(),
                    amount.ToString("C"),
                    !string.IsNullOrWhiteSpace(accountNames) ? " to accounts:" + accountNames : string.Empty,
                    SlidingDateRangePicker.FormatDelimitedValues(fakeSlidingDateRangePicker.DelimitedValues),
                    combineGiving ? "Combined " : string.Empty);
            }

            return(result);
        }
        /// <summary>
        /// Formats the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override string FormatSelection(Type entityType, string selection)
        {
            string result = "First Contribution Date";

            string[] selectionValues = selection.Split('|');

            if (selectionValues.Length >= 3)
            {
                SlidingDateRangePicker fakeSlidingDateRangePicker = new SlidingDateRangePicker();

                if (selectionValues.Length >= 5)
                {
                    // convert comma delimited to pipe
                    fakeSlidingDateRangePicker.DelimitedValues = selectionValues[4].Replace(',', '|');
                }
                else
                {
                    // if converting from a previous version of the selection
                    var lowerValue = selectionValues[0].AsDateTime();
                    var upperValue = selectionValues[1].AsDateTime();

                    fakeSlidingDateRangePicker.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.DateRange;
                    fakeSlidingDateRangePicker.SetDateRangeModeValue(new DateRange(lowerValue, upperValue));
                }

                string accountNames = string.Empty;
                var    accountGuids = selectionValues[2].Split(',').Select(a => a.AsGuid()).ToList();
                accountNames = new FinancialAccountService(new RockContext()).GetByGuids(accountGuids).Select(a => a.Name).ToList().AsDelimited(",");

                bool combineGiving = false;
                if (selectionValues.Length >= 4)
                {
                    combineGiving = selectionValues[3].AsBooleanOrNull() ?? false;
                }

                result = string.Format(
                    "{2}First contribution date{0}. Date Range: {1}",
                    !string.IsNullOrWhiteSpace(accountNames) ? " to accounts:" + accountNames : string.Empty,
                    SlidingDateRangePicker.FormatDelimitedValues(fakeSlidingDateRangePicker.DelimitedValues),
                    combineGiving ? "Giving Group " : string.Empty
                    )
                ;
            }

            return(result);
        }