Example #1
0
        protected override void GoEx()
        {
            BasePrice       = InputParser.ConvertInputStringToDecimal(Input.BasePrice, "BasePrice", "Base Price", true, null, null, false, false, false).Value;
            SalesTaxPercent = InputParser.ConvertInputStringToDecimal(Input.SalesTaxPercent, "SalesTaxPercent", "Sales Tax Percent", true, 100M, null, true, false, true).Value;
            DiscountPercent = InputParser.ConvertInputStringToDecimal(Input.DiscountPercent, "DiscountPercent", "Discount Percent", false, 100M, null, true, false, true);
            DiscountedPrice = InputParser.ConvertInputStringToDecimal(Input.DiscountedPrice, "DiscountedPrice", "Discounted Price", false, null, null, true, false, false);
            FinalPrice      = InputParser.ConvertInputStringToDecimal(Input.FinalPrice, "FinalPrice", "Final Price", false, null, null, true, false, false);

            int count = (DiscountPercent.HasValue ? 1 : 0) + (DiscountedPrice.HasValue ? 1 : 0) + (FinalPrice.HasValue ? 1 : 0);

            if (count == 0)
            {
                throw new DwInputException(null, "No numbers from Section B were entered.  Please enter any one number in Section B.  The other two will be calculated.");
            }
            if (count == 2)
            {
                throw new DwInputException(null, "Two numbers from Section B were entered.  Please enter any one number in Section B.  The other two will be calculated.");
            }
            if (count == 3)
            {
                throw new DwInputException(null, "All three numbers from Section B were entered.  Please enter any one number in Section B.  The other two will be calculated.");
            }

            if (DiscountPercent.HasValue)
            {
                DiscountedPrice = BasePrice * (1M - DiscountPercent.Value / 100M);
                FinalPrice      = DiscountedPrice * (1M + SalesTaxPercent / 100M);
            }
            else if (DiscountedPrice.HasValue)
            {
                DiscountPercent = 100M * (1M - DiscountedPrice.Value / BasePrice);
                FinalPrice      = DiscountedPrice * (1M + SalesTaxPercent / 100M);
            }
            else
            {
                if (SalesTaxPercent == 100M)
                {
                    throw new DwInputException("SalesTaxPercent", "Cannot calculate the Discount Percent and Discount Price if the Sales Tax Percent is 100%.");
                }
                DiscountedPrice = FinalPrice / (1M + SalesTaxPercent / 100M);
                DiscountPercent = 100M * (1M - DiscountedPrice / BasePrice);
            }

            DiscountAmount = BasePrice - DiscountedPrice.Value;

            SalesTaxAmount = FinalPrice.Value - DiscountedPrice.Value;

            BasePrice       = decimal.Round(BasePrice, 2);
            DiscountPercent = decimal.Round(DiscountPercent.Value, 2);
            DiscountAmount  = decimal.Round(DiscountAmount, 2);
            DiscountedPrice = decimal.Round(DiscountedPrice.Value, 2);
            SalesTaxPercent = decimal.Round(SalesTaxPercent, 2);
            SalesTaxAmount  = decimal.Round(SalesTaxAmount, 2);
            FinalPrice      = decimal.Round(FinalPrice.Value, 2);
        }
Example #2
0
        protected override void GoEx()
        {
            A = InputParser.ConvertInputStringToDecimal(Input.A, "A", "A", false, null, null, true, false, false);
            B = InputParser.ConvertInputStringToDecimal(Input.B, "B", "B", false, null, null, false, false, false);
            C = InputParser.ConvertInputStringToDecimal(Input.C, "C", "C", false, null, null, true, false, false);
            D = InputParser.ConvertInputStringToDecimal(Input.D, "D", "D", false, null, null, false, false, false);

            int count = (A.HasValue ? 1 : 0) + (B.HasValue ? 1 : 0) + (C.HasValue ? 1 : 0) + (D.HasValue ? 1 : 0);

            if (count == 0)
            {
                throw new DwInputException(null, "No values were entered.  Please enter any three values.  The remaining value will be calculated.");
            }
            if (count == 1)
            {
                throw new DwInputException(null, "Only one value was entered.  Please enter any three values.  The remaining value will be calculated.");
            }
            if (count == 2)
            {
                throw new DwInputException(null, "Only two values were entered.  Please enter any three values.  The remaining value will be calculated.");
            }
            if (count == 4)
            {
                throw new DwInputException(null, "All four values were entered.  Please enter any three values.  The remaining value will be calculated.");
            }

            if (!A.HasValue)
            {
                A = B.Value * C.Value / D.Value;
                A = decimal.Round(A.Value, 6);
            }
            else if (!B.HasValue)
            {
                if (C.Value == 0M)
                {
                    throw new DwInputException("C", "If B is unset, then C must not be zero.");
                }
                B = A.Value * D.Value / C.Value;
                B = decimal.Round(B.Value, 6);
            }
            else if (!C.HasValue)
            {
                C = A.Value * D.Value / B.Value;
                C = decimal.Round(C.Value, 6);
            }
            else
            {
                if (A.Value == 0M)
                {
                    throw new DwInputException("A", "If D is unset, then A must not be zero.");
                }
                D = B.Value * C.Value / A.Value;
                D = decimal.Round(D.Value, 6);
            }
        }
Example #3
0
        protected override void GoEx()
        {
            if (string.IsNullOrWhiteSpace(Input.ScenarioId))
            {
                throw new DwLogicException("The scenario ID is missing.");
            }
            ScenarioId = Input.ScenarioId.Trim();
            Scenario   = GetScenario(ScenarioId);

            A = InputParser.ConvertInputStringToDecimal(Input.A, "A", "A", false, null, null, true, false, false);
            B = InputParser.ConvertInputStringToDecimal(Input.B, "B", "B", false, null, null, true, false, false);
            C = InputParser.ConvertInputStringToDecimal(Input.C, "C", "C", false, null, null, true, false, false);

            int count = (A.HasValue ? 1 : 0) + (B.HasValue ? 1 : 0) + (C.HasValue ? 1 : 0);

            if (count == 0)
            {
                throw new DwInputException(null, "No values were entered.  Please enter any two values.  The remaining value will be calculated.");
            }
            if (count == 1)
            {
                throw new DwInputException(null, "Only one value was entered.  Please enter any two values.  The remaining value will be calculated.");
            }
            if (count == 3)
            {
                throw new DwInputException(null, "All three values were entered.  Please enter any two values.  The remaining value will be calculated.");
            }

            if (!A.HasValue)
            {
                A = decimal.Round(Scenario.CalcA(B.Value, C.Value), 6);
            }
            else if (!B.HasValue)
            {
                B = decimal.Round(Scenario.CalcB(A.Value, C.Value), 6);
            }
            else
            {
                C = decimal.Round(Scenario.CalcC(A.Value, B.Value), 6);
            }
        }