Beispiel #1
0
    protected void MethodAdjustmentAmountNumericValidate_ServerValidate(Object sender, ServerValidateEventArgs e)
    {
        ShippingMethodAdjustmentType adjustmentType =
            (ShippingMethodAdjustmentType)
            Enum.Parse(typeof(ShippingMethodAdjustmentType), MethodAdjustmentTypeField.SelectedValue);

        if (adjustmentType == ShippingMethodAdjustmentType.Amount)
        {
            MethodAdjustmentAmountNumericValidator.ErrorMessage = "The adjustment amount must be a number.";
            MethodAdjustmentAmountNumericValidator.Text         = "<div>Must be a number</div>";
        }
        else
        {
            MethodAdjustmentAmountNumericValidator.ErrorMessage = "The adjustment percentage must be a non-zero number.";
            MethodAdjustmentAmountNumericValidator.Text         = "<div>Must be a non-zero number</div>";
        }

        decimal value;

        if (Decimal.TryParse(e.Value, out value))
        {
            if (adjustmentType == ShippingMethodAdjustmentType.Percentage)
            {
                e.IsValid = (value != 0);
            }
            else
            {
                e.IsValid = true;
            }
        }
        else
        {
            e.IsValid = false;
        }
    }
 public ShippingRateDisplay AdjustRate(ShippingMethodAdjustmentType adjustmentType, decimal amount)
 {
     if (Rate != 0)
     {
         decimal adjustment = 0;
         switch (adjustmentType)
         {
             case ShippingMethodAdjustmentType.None:
                 return this;
             case ShippingMethodAdjustmentType.Amount:
                 adjustment = amount;
                 break;
             case ShippingMethodAdjustmentType.Percentage:
                 adjustment = Math.Round(this.Rate * (amount / 100m), 2);
                 break;
         }
         this.Rate += adjustment;
     }
     return this;
 }
Beispiel #3
0
        public ShippingRateDisplay AdjustRate(ShippingMethodAdjustmentType adjustmentType, decimal amount)
        {
            if (Rate != 0)
            {
                decimal adjustment = 0;
                switch (adjustmentType)
                {
                case ShippingMethodAdjustmentType.None:
                    return(this);

                case ShippingMethodAdjustmentType.Amount:
                    adjustment = amount;
                    break;

                case ShippingMethodAdjustmentType.Percentage:
                    adjustment = Math.Round(Rate * (amount / 100m), 2);
                    break;
                }
                Rate += adjustment;
            }
            return(this);
        }