Example #1
0
        /// <summary>
        /// If the formula parameter is null, throws an ArgumentNullException.
        ///
        /// Otherwise, if name is null or invalid, throws an InvalidNameException.
        ///
        /// Otherwise, if changing the contents of the named cell to be the formula would cause a
        /// circular dependency, throws a CircularException.  (No change is made to the spreadsheet.)
        ///
        /// Otherwise, the contents of the named cell becomes formula.  The method returns a
        /// Set consisting of name plus the names of all other cells whose value depends,
        /// directly or indirectly, on the named cell.
        ///
        /// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the
        /// set {A1, B1, C1} is returned.
        /// </summary>
        protected override ISet <string> SetCellContents(string name, Formula formula)
        {
            //hashset with all the variables for formula hashset
            HashSet <string> temp = new HashSet <string>(formula.GetVariables());

            //replacing all dependents of data with empty dependents
            DG.ReplaceDependents(name, temp);
            IEnumerable <string> recalculation = (GetCellsToRecalculate(name));
            //creating a new cell with string name as a parameter.
            Cell cell = new Cell(name);

            //setting contents to number.
            cell.setContent(formula);
            //storing cell with data and number in dictionary.
            Cells[name] = cell;
            //recalculating the name and storing it in result.
            //if set content is sucessfull setting changed to true.
            this.Changed = true;
            //looping through and using a calculateValue method to calculate string.
            foreach (string a in recalculation)
            {
                calculateValue(a);
            }

            //return the recalculated value.
            return(new HashSet <string>(recalculation));
        }
Example #2
0
        /// <summary>
        /// If name is null or invalid, throws an InvalidNameException.
        ///
        /// Otherwise, the contents of the named cell becomes number.  The method returns a
        /// set consisting of name plus the names of all other cells whose value depends,
        /// directly or indirectly, on the named cell.
        ///
        /// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the
        /// set {A1, B1, C1} is returned.
        /// </summary>
        protected override ISet <string> SetCellContents(string name, double number)
        {
            //if name is null we throw Invalidname Exception.

            HashSet <string> temp = new HashSet <string>();

            //replacing all dependents of data with empty dependents
            DG.ReplaceDependents(name, temp);
            IEnumerable <string> recalculation = (GetCellsToRecalculate(name));
            //Created a new cell with name.
            Cell cell = new Cell(name);

            //setting contents to number.
            cell.setContent(number);
            //storing cell with data and number in dictionary.
            Cells[name] = cell;
            //recalculating the name and storing it in result.

            //if set content is sucessfull setting changed to true.
            this.Changed = true;
            //looping through and using a calculateValue method to calculate string.
            foreach (string a in recalculation)
            {
                calculateValue(a);
            }
            //return the recalculated value.
            return(new HashSet <string>(recalculation));
        }
Example #3
0
        /// <summary>
        /// If text is null, throws an ArgumentNullException.
        ///
        /// Otherwise, if name is null or invalid, throws an InvalidNameException.
        ///
        /// Otherwise, the contents of the named cell becomes text.  The method returns a
        /// set consisting of name plus the names of all other cells whose value depends,
        /// directly or indirectly, on the named cell.
        ///
        /// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the
        /// set {A1, B1, C1} is returned.
        /// </summary>
        protected override ISet <string> SetCellContents(string name, string text)
        {
            //empty hashset
            HashSet <string> temp = new HashSet <string>();

            //replacing all dependents of data with empty dependents
            DG.ReplaceDependents(name, temp);
            IEnumerable <string> recalculation = (GetCellsToRecalculate(name));
            Cell cell = new Cell(name);

            //setting contents to number.
            cell.setContent(text);
            //storing cell with data and number in dictionary.
            Cells[name] = cell;

            //if set content is sucessfull setting changed to true.
            this.Changed = true;
            //looping through and using a calculateValue method to calculate string.
            foreach (string a in recalculation)
            {
                calculateValue(a);
            }
            //return the recalculated value.
            return(new HashSet <string>(recalculation));


            //when the text is empty string return a empty hashset.
        }
Example #4
0
        public IEnumerable <String> Remove(String name)
        {
            if (Cells.ContainsKey(name))
            {
                if (Cells[name] != null)
                {
                    HashSet <string> temp = new HashSet <string>();

                    //replacing all dependents of data with empty dependents
                    DG.ReplaceDependents(name, temp);
                    IEnumerable <string> recalculation = (GetCellsToRecalculate(name));
                    Cell cell = new Cell(name);
                    //setting contents to number.
                    cell.setContent("");
                    //storing cell with data and number in dictionary.
                    Cells[name] = cell;

                    //if set content is sucessfull setting changed to true.
                    this.Changed = true;
                    //looping through and using a calculateValue method to calculate string.
                    foreach (string a in recalculation)
                    {
                        calculateValue(a);
                    }
                    //return the recalculated value.
                    return(new HashSet <string>(recalculation));
                }
            }
            return(new HashSet <String>());
        }