/// <summary>
        /// Run formula and apply to passed cell.
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        public Boolean Run(SheetCell cell)
        {
            Boolean returnValue             = default(Boolean);
            FormulaExecutionContext context = default(FormulaExecutionContext);

            try
            {
                //validate settings determined at runtime
                if (!this.Complete())
                {
                    throw new ApplicationException(String.Format("{0}", this.ErrorMessage));
                }

                //run operation
                context = new FormulaExecutionContext(this, cell);
                cell.ValueChangingProgrammatically = true;
                //TODO:invoke with parameter list
                cell.Value = this.Delegate.DynamicInvoke(new ParameterExpression[] { /*Expression.Parameter(typeof(float), "p")*/ }).ToString(); //AssignerOperand.Evaluate(context).ToString();
                //TODO:mvoe this or something like it to wwhere formula is changed.
                //cell.Value = AssignerOperand.Evaluate(context).ToString();
                cell.ValueChangingProgrammatically = false;

                returnValue = true;
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
                cell.ValueChangingProgrammatically = false;
                throw;
            }
            return(returnValue);
        }
Пример #2
0
        /// <summary>
        /// Evaluate the operand. Must return the literal value.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Single Evaluate(FormulaExecutionContext context)
        {
            Single returnValue = default(Single);

            try
            {
                returnValue = _Value;
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                throw;
            }
            return(returnValue);
        }
        /// <summary>
        /// The operation's OperandBase implementation is invoked here.
        /// </summary>
        /// <param name="dictionary"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public OperandBase Run(Dictionary <String, OperandBase> dictionary, FormulaExecutionContext context)
        {
            OperandBase returnValue = default(OperandBase);

            try
            {
                returnValue = functorOperandBase(dictionary, context);
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                throw;
            }
            return(returnValue);
        }
Пример #4
0
        /// <summary>
        /// Evaluate the operand. Must process the address reference and find a single sheet cell.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Single Evaluate(FormulaExecutionContext context)
        {
            Single returnValue = default(Single);
            List <CategoryItem> assignerCellCriteria = default(List <CategoryItem>);
            List <SheetCell>    formulaSearchResults = default(List <SheetCell>);
            Sheet sheet = default(Sheet);

            try
            {
                //locate parent sheet, containing cells
                sheet = context.ExecutingFormula.Parent;
                if (sheet == null)
                {
                    throw new ApplicationException(String.Format("Unable to find parent sheet for formula: '{0}'", context.ExecutingFormula.Value));
                }

                //select all criteria in assignee cell EXCEPT those categories defined for assigner in the formula criteria.
                assignerCellCriteria = context.AssigneeCell.CategoryItems.Except(_Value, new EqualityComparerOfT <CategoryItem>((x, y) => x.Parent == y.Parent)).ToList <CategoryItem>();
                //add formula criteria to produce a complete set of criteria for an assigner cell.
                assignerCellCriteria.AddRange(_Value);


                //run assigner criteria
                formulaSearchResults = Sheet.GetCellsWhereAllSearchCategoryItemsMatchAnyInGivenCell(sheet.Cells.ToList <SheetCell>(), assignerCellCriteria);
                if ((formulaSearchResults == null) || (formulaSearchResults.Count == 0))
                {
                    throw new ApplicationException(String.Format("Unable to find assigner cell for parent sheet for formula '{0}'", context.ExecutingFormula.Value));
                }
                if (formulaSearchResults.Count > 1)
                {
                    throw new ApplicationException(String.Format("Too many results found for assigner cell for parent sheet for formula '{0}'", context.ExecutingFormula.Value));
                }

                //retrieve value from single cell in results
                returnValue = Single.Parse(formulaSearchResults[0].Value);
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                throw;
            }
            return(returnValue);
        }
        /// <summary>
        /// Run operation on child operands. Must pass through sheet cell and formula to child operands that may need to do cell lookups.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Single Run(FormulaExecutionContext context)
        {
            Single      returnValue     = default(Single);
            OperandBase operationResult = default(OperandBase);

            try
            {
                //The operand (of type OperandOperation) that contains this operation will have its Evaluate() called; Evaluate() will call this operation's Run().
                operationResult = Operator.Run(this.Operands, context);

                returnValue = operationResult.Evaluate(context);
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                throw;
            }
            return(returnValue);
        }
Пример #6
0
 public abstract Single Evaluate(FormulaExecutionContext context);
 /// <summary>
 /// Run operation on child operands. Must pass through sheet cell and formula to child operands that may need to do cell lookups.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public abstract Single Run(FormulaExecutionContext context);