/// <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); }
/// <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); }