예제 #1
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;

                if (baseCell.CellText[0] == '=')
                {
                    string text = baseCell.CellText.Substring(1);
                    int    tempCol, tempRow;

                    if (text.Length > 2)
                    {
                        tempCol = text[0] - 65;
                        text    = text.Substring(1);
                        int.TryParse(text, out tempRow);
                        tempRow--;
                    }
                    else if (text.Length == 2)
                    {
                        tempCol = text[0] - 65;
                        tempRow = text[1] - 49;
                    }
                    else
                    {
                        tempCol = -1;
                        tempRow = -1;
                    }

                    Cell tempCell = this.GetCell(tempRow, tempCol);

                    if (sender != null)
                    {
                        baseCell.SetVal(tempCell.CellText);
                        this.CellPropertyChanged(sender, new PropertyChangedEventArgs("Value Property Changed"));
                    }
                    else
                    {
                        baseCell.SetVal("null");
                        this.CellPropertyChanged(sender, new PropertyChangedEventArgs("Value Property Changed"));
                    }
                }
                else if (string.IsNullOrWhiteSpace(baseCell.CellText))
                {
                    baseCell.SetVal(string.Empty);
                    this.CellPropertyChanged(sender, new PropertyChangedEventArgs("Value Property Changed"));
                }
                else
                {
                    baseCell.SetVal(baseCell.CellText);
                    this.CellPropertyChanged(sender, new PropertyChangedEventArgs("Value Property Changed"));
                }
            }
        }
예제 #2
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));
                }
            }
        }