Exemplo n.º 1
0
        /// Uses the provided price guides to compute the price according to the formula.
        /// <param name="priceGuides">Row from the priceGuides table containing guides for the card for which to evaluate this formula.
        /// If this formula UsesPriceGuides, must be set to contain all the columns, otherwise exception is thrown.</param>
        /// <param name="currentPrice">Our current sale price of the card (can be used as a guide).</param>
        /// <returns>The final price this formula evaluates to. NaN if the necessary guides are not found.</returns>
        public double Evaluate(DataRow priceGuides, double currentPriceSingle)
        {
            double term;

            foreach (var guideTerm in guidesToResolve)
            {
                if (guideTerm.Value == "CURRENT")
                {
                    term = currentPriceSingle;
                }
                else
                {
                    term = MKMHelpers.ConvertDoubleAnySep(priceGuides[guideTerm.Value].ToString());
                }
                if (double.IsNaN(term))
                {
                    return(term);
                }
                operands[guideTerm.Key] = term;
            }
            double val = operands[0];

            for (int i = 0; i < operators.Count; i++)
            {
                val = operators[i](val, operands[i + 1]);
            }
            return(val);
        }
Exemplo n.º 2
0
        /// Converts the operand to number or price guide and stores it
        /// <param name="operand">Trimmed string representation of the operand.</param>
        /// <returns>False if the parsing failed.</returns>
        private bool parseAndAddOperand(string operand)
        {
            double number = MKMHelpers.ConvertDoubleAnySep(operand);

            if (double.IsNaN(number))
            {
                foreach (var guide in MKMHelpers.PriceGuides)
                {
                    if (guide.Value.Code == operand)
                    {
                        guidesToResolve.Add(new KeyValuePair <int, string>(operands.Count, operand));
                        operands.Add(-9999);
                        return(true);
                    }
                }
            }
            else
            {
                operands.Add(number);
                return(true);
            }
            return(false);
        }