예제 #1
0
        private void EvalCell(Cell cell)
        {
            InstanciateCell mCell = cell as InstanciateCell;

            // if the string is empty
            if (string.IsNullOrEmpty(mCell.Text))
            {
                mCell.SetVal("");
                CellPropertyChanged(cell, new PropertyChangedEventArgs("Value"));
            }
            // if it an equation
            else if (mCell.Text[0] == '=' && mCell.Text.Length > 1)
            {
                // remove =
                string exp = mCell.Text.Substring(1);
                SpreadsheetEngine.ExpTree mExp = new SpreadsheetEngine.ExpTree(exp);
                string[] arrayVars             = mExp.getVars();

                foreach (string v in arrayVars)
                {
                    if (GetCell(v) == null)
                    {
                        mCell.SetVal("Bad Ref");
                        CellPropertyChanged(cell, new PropertyChangedEventArgs("Value"));

                        break;
                    }
                    // attempt at setting variable to value
                    SetExpVar(mExp, v);
                }
                mCell.SetVal(mExp.Eval().ToString());
                CellPropertyChanged(cell, new PropertyChangedEventArgs("Value"));
            }
            // not an expression
            else
            {
                mCell.SetVal(mCell.Text);
                CellPropertyChanged(cell, new PropertyChangedEventArgs("Value"));
            }

            // evaluate dependencies
            if (depDict.ContainsKey(mCell.Name))
            {
                foreach (string name in depDict[mCell.Name])
                {
                    Eval(name);
                }
            }
        }