Пример #1
0
        /// <summary>
        /// Gets the single option multiple quantity.
        /// </summary>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        /// <param name="feeValues">The fee values.</param>
        /// <param name="usageCountRemaining">The usage count remaining.</param>
        /// <returns></returns>
        private Control GetFeeSingleOptionMultipleQuantityControl(bool setValues, List <FeeInfo> feeValues, int?usageCountRemaining)
        {
            var fee       = this;
            var numUpDown = new NumberUpDown();

            numUpDown.ID       = "fee_" + fee.Id.ToString();
            numUpDown.Minimum  = fee.IsRequired == true ? 1 : 0;
            numUpDown.Required = fee.IsRequired;

            if (usageCountRemaining.HasValue)
            {
                if (usageCountRemaining <= 0)
                {
                    numUpDown.Enabled = false;
                    numUpDown.Maximum = 0;
                }
                else
                {
                    numUpDown.Maximum = usageCountRemaining.Value;
                }
            }

            if (setValues && feeValues != null && feeValues.Any())
            {
                numUpDown.Value = feeValues.First().Quantity;
            }

            return(numUpDown);
        }
Пример #2
0
        /// <summary>
        /// Gets the multiple option multiple quantity numberupdowngroup control
        /// </summary>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        /// <param name="feeValues">The fee values.</param>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="otherRegistrants">The other registrants that have been registered so far in this registration</param>
        /// <returns></returns>
        private Control GetFeeMultipleOptionMultipleQuantityControl(bool setValues, List <FeeInfo> feeValues, RegistrationInstance registrationInstance, List <RegistrantInfo> otherRegistrants)
        {
            var fee = this;
            var numberUpDownGroup = new NumberUpDownGroup();

            numberUpDownGroup.ID       = "fee_" + fee.Id.ToString();
            numberUpDownGroup.Label    = fee.Name;
            numberUpDownGroup.Required = fee.IsRequired;

            numberUpDownGroup.NumberUpDownControls = new List <NumberUpDown>();

            foreach (var feeItem in fee.FeeItems)
            {
                var feeInfo      = feeValues?.FirstOrDefault(a => a.RegistrationTemplateFeeItemId == feeItem.Id);
                int currentValue = feeInfo?.Quantity ?? 0;

                var numUpDown = new NumberUpDown
                {
                    ID      = $"feeItem_{feeItem.Guid.ToString( "N" )}",
                    Label   = string.Format("{0} ({1})", feeItem.Name, feeItem.Cost.FormatAsCurrency()),
                    Minimum = 0
                };

                int?usageCountRemaining = feeItem.GetUsageCountRemaining(registrationInstance, otherRegistrants);

                if (usageCountRemaining.HasValue)
                {
                    if (usageCountRemaining <= 0)
                    {
                        // if there aren't any remaining, and the currentValue isn't counted in the used counts, disable the option
                        if (currentValue == 0)
                        {
                            numUpDown.Enabled = false;
                        }

                        numUpDown.Label  += " (none remaining)";
                        numUpDown.Maximum = currentValue;
                    }
                    else
                    {
                        numUpDown.Label  += $" ({usageCountRemaining} remaining)";
                        numUpDown.Maximum = usageCountRemaining.Value;
                    }
                }

                numberUpDownGroup.NumberUpDownControls.Add(numUpDown);

                if (setValues && feeValues != null && feeValues.Any())
                {
                    numUpDown.Value = feeValues
                                      .Where(f => f.RegistrationTemplateFeeItemId == feeItem.Id)
                                      .Select(f => f.Quantity)
                                      .FirstOrDefault();
                }
            }

            return(numberUpDownGroup);
        }
Пример #3
0
        /// <summary>
        /// Gets the single option multiple quantity.
        /// </summary>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        /// <param name="controlLabel">The control label.</param>
        /// <param name="feeValues">The fee values.</param>
        /// <param name="usageCountRemaining">The usage count remaining.</param>
        /// <returns></returns>
        private Control GetFeeSingleOptionMultipleQuantityControl(bool setValues, string controlLabel, List <FeeInfo> feeValues, int?usageCountRemaining)
        {
            var fee       = this;
            var numUpDown = new NumberUpDown
            {
                ID       = "fee_" + fee.Id.ToString(),
                Minimum  = fee.IsRequired == true ? 1 : 0,
                Required = fee.IsRequired,
                Label    = controlLabel
            };

            var currentValue = feeValues?.FirstOrDefault()?.Quantity ?? 0;

            if (usageCountRemaining.HasValue)
            {
                if (usageCountRemaining <= 0)
                {
                    numUpDown.Label  += " (none remaining)";
                    numUpDown.Maximum = currentValue;

                    // if there aren't any remaining, and the currentValue isn't counted in the used counts, disable the option
                    if (currentValue == 0)
                    {
                        // Unless this should be hidden, then set to null so it isn't added.
                        if (HideWhenNoneRemaining == true)
                        {
                            numUpDown = null;
                        }
                        else
                        {
                            numUpDown.Enabled = false;
                        }
                    }
                }
                else
                {
                    numUpDown.Label  += $" ({usageCountRemaining} remaining)";
                    numUpDown.Maximum = usageCountRemaining.Value;
                }
            }

            if (numUpDown != null && setValues && feeValues != null && feeValues.Any())
            {
                numUpDown.Value = feeValues.First().Quantity;
            }

            return(numUpDown);
        }
Пример #4
0
        private void BuildFees(bool setValues)
        {
            phFees.Controls.Clear();

            if (TemplateState.Fees != null && TemplateState.Fees.Any())
            {
                divFees.Visible = true;

                foreach (var fee in TemplateState.Fees.OrderBy(f => f.Order))
                {
                    var feeValues = new List <FeeInfo>();
                    if (RegistrantState.FeeValues.ContainsKey(fee.Id))
                    {
                        feeValues = RegistrantState.FeeValues[fee.Id];
                    }

                    if (fee.FeeType == RegistrationFeeType.Single)
                    {
                        string label = fee.Name;
                        var    cost  = fee.CostValue.AsDecimalOrNull();
                        if (cost.HasValue && cost.Value != 0.0M)
                        {
                            label = string.Format("{0} ({1})", fee.Name, cost.Value.FormatAsCurrency());
                        }

                        if (fee.AllowMultiple)
                        {
                            // Single Option, Multi Quantity
                            var numUpDown = new NumberUpDown();
                            numUpDown.ID      = "fee_" + fee.Id.ToString();
                            numUpDown.Label   = label;
                            numUpDown.Minimum = 0;
                            phFees.Controls.Add(numUpDown);

                            if (setValues && feeValues != null && feeValues.Any())
                            {
                                numUpDown.Value = feeValues.First().Quantity;
                            }
                        }
                        else
                        {
                            // Single Option, Single Quantity
                            var cb = new RockCheckBox();
                            cb.ID    = "fee_" + fee.Id.ToString();
                            cb.Label = label;
                            cb.SelectedIconCssClass   = "fa fa-check-square-o fa-lg";
                            cb.UnSelectedIconCssClass = "fa fa-square-o fa-lg";
                            phFees.Controls.Add(cb);

                            if (setValues && feeValues != null && feeValues.Any())
                            {
                                cb.Checked = feeValues.First().Quantity > 0;
                            }
                        }
                    }
                    else
                    {
                        // Parse the options to get name and cost for each
                        var      options    = new Dictionary <string, string>();
                        string[] nameValues = fee.CostValue.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string nameValue in nameValues)
                        {
                            string[] nameAndValue = nameValue.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries);
                            if (nameAndValue.Length == 1)
                            {
                                options.AddOrIgnore(nameAndValue[0], nameAndValue[0]);
                            }
                            if (nameAndValue.Length == 2)
                            {
                                options.AddOrIgnore(nameAndValue[0], string.Format("{0} ({1})", nameAndValue[0], nameAndValue[1].AsDecimal().FormatAsCurrency()));
                            }
                        }

                        if (fee.AllowMultiple)
                        {
                            HtmlGenericControl feeAllowMultiple = new HtmlGenericControl("div");
                            phFees.Controls.Add(feeAllowMultiple);

                            feeAllowMultiple.AddCssClass("feetype-allowmultiples");

                            Label titleLabel = new Label();
                            feeAllowMultiple.Controls.Add(titleLabel);
                            titleLabel.CssClass = "control-label";
                            titleLabel.Text     = fee.Name;

                            foreach (var optionKeyVal in options)
                            {
                                var numUpDown = new NumberUpDown();
                                numUpDown.ID       = string.Format("fee_{0}_{1}", fee.Id, optionKeyVal.Key);
                                numUpDown.Label    = string.Format("{0}", optionKeyVal.Value);
                                numUpDown.Minimum  = 0;
                                numUpDown.CssClass = "fee-allowmultiple";
                                feeAllowMultiple.Controls.Add(numUpDown);

                                if (setValues && feeValues != null && feeValues.Any())
                                {
                                    numUpDown.Value = feeValues
                                                      .Where(f => f.Option == optionKeyVal.Key)
                                                      .Select(f => f.Quantity)
                                                      .FirstOrDefault();
                                }
                            }
                        }
                        else
                        {
                            // Multi Option, Single Quantity
                            var ddl = new RockDropDownList();
                            ddl.ID = "fee_" + fee.Id.ToString();
                            ddl.AddCssClass("input-width-md");
                            ddl.Label          = fee.Name;
                            ddl.DataValueField = "Key";
                            ddl.DataTextField  = "Value";
                            ddl.DataSource     = options;
                            ddl.DataBind();
                            ddl.Items.Insert(0, "");
                            phFees.Controls.Add(ddl);

                            if (setValues && feeValues != null && feeValues.Any())
                            {
                                ddl.SetValue(feeValues
                                             .Where(f => f.Quantity > 0)
                                             .Select(f => f.Option)
                                             .FirstOrDefault());
                            }
                        }
                    }
                }
            }
            else
            {
                divFees.Visible = false;
            }
        }
Пример #5
0
        /// <summary>
        /// Gets the multiple option multiple quantity numberupdowngroup control
        /// </summary>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        /// <param name="feeValues">The fee values.</param>
        /// <param name="registrationInstance">The registration instance.</param>
        /// <param name="otherRegistrants">The other registrants that have been registered so far in this registration</param>
        /// <returns></returns>
        private Control GetFeeMultipleOptionMultipleQuantityControl(bool setValues, List <FeeInfo> feeValues, RegistrationInstance registrationInstance, List <RegistrantInfo> otherRegistrants)
        {
            var fee = this;
            var numberUpDownGroup = new NumberUpDownGroup
            {
                ID                   = "fee_" + fee.Id.ToString(),
                Label                = fee.Name,
                Required             = fee.IsRequired,
                NumberUpDownControls = new List <NumberUpDown>()
            };

            foreach (var feeItem in fee.FeeItems)
            {
                var feeInfo      = feeValues?.FirstOrDefault(a => a.RegistrationTemplateFeeItemId == feeItem.Id);
                int currentValue = feeInfo?.Quantity ?? 0;

                string controlLabel = feeItem.Cost == 0.0M ? feeItem.Name : $"{feeItem.Name} ({feeItem.Cost.FormatAsCurrency()})";

                var numUpDown = new NumberUpDown
                {
                    ID      = $"feeItem_{feeItem.Guid.ToString( "N" )}",
                    Label   = controlLabel,
                    Minimum = 0
                };

                int?usageCountRemaining = feeItem.GetUsageCountRemaining(registrationInstance, otherRegistrants);

                if (usageCountRemaining.HasValue)
                {
                    if (usageCountRemaining <= 0)
                    {
                        numUpDown.Label  += " (none remaining)";
                        numUpDown.Maximum = currentValue;

                        // if there aren't any remaining, and the currentValue isn't counted in the used counts, disable the option
                        if (currentValue == 0)
                        {
                            // Unless this should be hidden, then set to null so it isn't added.
                            if (HideWhenNoneRemaining == true)
                            {
                                numUpDown = null;
                            }
                            else
                            {
                                numUpDown.Enabled = false;
                            }
                        }
                    }
                    else
                    {
                        numUpDown.Label  += $" ({usageCountRemaining} remaining)";
                        numUpDown.Maximum = usageCountRemaining.Value;
                    }
                }

                if (numUpDown != null)
                {
                    numberUpDownGroup.NumberUpDownControls.Add(numUpDown);

                    if (setValues && feeValues != null && feeValues.Any())
                    {
                        numUpDown.Value = feeValues
                                          .Where(f => f.RegistrationTemplateFeeItemId == feeItem.Id)
                                          .Select(f => f.Quantity)
                                          .FirstOrDefault();
                    }
                }
            }

            // If there are no items then return null, this will prevent the control from showing and won't count as a control when deciding to show the fee div.
            if (!numberUpDownGroup.NumberUpDownControls.Any())
            {
                return(null);
            }

            return(numberUpDownGroup);
        }