Ejemplo n.º 1
0
        /// <summary>
        /// Name:DetermineCellValue
        /// Description:Determines if the text written in the cell is a formula or if its just a text
        /// </summary>
        /// <param name="cell">the cell that you inputed text in</param>
        private void DetermineCellValue(Cell cell)
        {
            BaseCell determineCell = cell as BaseCell;
            string   cellName      = determineCell.ColIndex.ToString() + determineCell.RowIndex.ToString();

            if (determineCell.Text[0] == '=' && determineCell.Text.Length > 1)
            {
                double         varValue;
                string         text          = determineCell.Text.Substring(1);
                ExpressionTree determineTree = new ExpressionTree(text);
                string[]       variables     = determineTree.GetVariable();
                foreach (string name in variables)
                {
                    Cell varCell = this.GetCell(name);
                    if (name == cellName)
                    {
                        determineCell.SetVal("ERROR: REFRENCING SELF");
                        this.CellPropertyChanged(cell, new PropertyChangedEventArgs("Value Property Changed"));
                        return;
                    }
                    else if (double.TryParse(varCell.Value, out varValue))
                    {
                        determineTree.SetVariable(name, varValue);
                    }
                    else
                    {
                        determineTree.SetVariable(name, 0);
                    }
                }

                determineCell.SetVal(determineTree.Evaluate().ToString());
                this.CellPropertyChanged(cell, new PropertyChangedEventArgs("Value Property Changed"));
            }
            else if (!string.IsNullOrWhiteSpace(determineCell.Text))
            {
                determineCell.SetVal(determineCell.Text);
                this.CellPropertyChanged(cell, new PropertyChangedEventArgs("Value Property Changed"));
            }
            else
            {
                determineCell.SetVal(string.Empty);
                this.CellPropertyChanged(cell, new PropertyChangedEventArgs("Value Property Changed"));
            }

            if (this.refrenceDictionary.ContainsKey(cellName))
            {
                foreach (string cells in this.refrenceDictionary[cellName])
                {
                    this.DetermineCellValue(this.GetCell(cells));
                }
            }
        }
Ejemplo n.º 2
0
        public Spreadsheet(int color, int row = 50, int col = 26)
        {
            cellCollection = new Cell[row, col];

            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    cellCollection[r, c] = new Cell(color, r, c);
                    cellCollection[r, c].PropertyChanged += OnPropertyChangedEventHandler;
                }
            }

            tree = new ExpressionTree(ref cellCollection);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Name:PropertyChanged
        /// Description:property changed function checks if the cell is = or not and if its = 'it knows that its pointing to something else
        /// </summary>
        /// <param name="sender">object( the cell)</param>
        /// <param name="e">event argument</param>
        public void PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Text Property Changed")
            {
                BaseCell baseCell = sender as BaseCell;
                string   name     = baseCell.ColIndex.ToString() + baseCell.RowIndex.ToString();

                this.DeleteRefrence(name);

                if (baseCell.Text != string.Empty && baseCell.Text[0] == '=' && baseCell.Text.Length > 1)
                {
                    ExpressionTree tree = new ExpressionTree(baseCell.Text.Substring(1));
                    this.SetRefrence(name, tree.GetVariable());
                }

                this.DetermineCellValue(sender as Cell);
            }
        }