예제 #1
0
        public void SPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Cell c = (Cell)sender;

            if (e.PropertyName == "Text")
            {
                try
                {
                    //removedep(c);
                    getCellValue(c);
                }
                catch (Exception ex)
                {
                }
                CellPropertyChanged?.Invoke(sender, new PropertyChangedEventArgs("Value"));
            }
            else if (e.PropertyName == "Value")
            {
                try
                {
                    cascading(c);
                }
                catch (Exception ex)
                {
                }
                CellPropertyChanged?.Invoke(sender, new PropertyChangedEventArgs("Value"));
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPropChanged(object sender, PropertyChangedEventArgs e)
        {
            Cell c = sender as Cell; // makes the sender into a cell and setting a temp value for it

            if (e.PropertyName == "Text")
            {
                UpdateCell(c);
            }
            CellPropertyChanged?.Invoke(sender, new PropertyChangedEventArgs("Value")); // this is to check if there is an inputted value and will check if there is a property changed
        }
 /// post: Updates the value of the cell by checking the text
 /// object sender - a reference to the control/object that raised the event
 /// PropertyChangedEventArgs e - calls e that contains the property change event data
 private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "Text")
     {
         if (!((Cell)sender).Text.StartsWith("=")) //6b
         {
             ((Cell)sender).Value = ((Cell)sender).Text;
         }
         else //6c
         {
             string formula = ((Cell)sender).Text.Substring(1); // these three lines is pulling value from another cell by reading in the cell number (ie. "A5") (6c.2)
             int    column  = Convert.ToInt16(formula[0]) - 'A';
             int    row     = Convert.ToInt16(formula.Substring(1)) - 1;
             ((Cell)sender).Value = (GetCell(row, column)).Value;
         }
     }
     CellPropertyChanged?.Invoke(sender, new PropertyChangedEventArgs("Value")); // if PropertyName is Value, update value of cell (6a)
 }
 public void SPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "Text")
     {
         if (!((Cell)sender).setText.StartsWith("="))
         {
             ((Cell)sender).Value = ((Cell)sender).setText;
         }
         else
         {
             string equation = ((Cell)sender).setText.Substring(1);
             int    column   = Convert.ToInt16(equation[0]) - 'A';
             int    row      = Convert.ToInt16(equation.Substring(1)) - 1;
             ((Cell)sender).Value = (GetCell(row, column)).Value;
         }
     }
     CellPropertyChanged?.Invoke(sender, new PropertyChangedEventArgs("Value"));
 }
예제 #5
0
 private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "Text")
     {
         if (!((Cell)sender).Text.StartsWith("="))
         {
             ((Cell)sender).Value = ((Cell)sender).Text;
         }
         else
         {
             string formula = ((Cell)sender).Text.Substring(1);
             int    column  = Convert.ToInt16(formula[0]) - 'A';
             int    row     = Convert.ToInt16(formula.Substring(1)) - 1;
             ((Cell)sender).Value = (GetCell(row, column)).Value;
         }
     }
     CellPropertyChanged?.Invoke(sender, new PropertyChangedEventArgs("Value"));
 }
예제 #6
0
        private void Spreadsheet_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            //from crandall

            if (e.PropertyName == "Text")
            {
                if (!((Cell)sender).Text.StartsWith("="))
                {
                    ((Cell)sender).Value = ((Cell)sender).Text;
                }
                else if (((Cell)sender).Text.StartsWith("="))
                {
                    string str    = ((Cell)sender).Text.Substring(1); //starts at position 1 if there is
                    int    column = Convert.ToInt16(str[0]) - 'A';
                    Int32.TryParse(((Cell)sender).Text.Substring(1), out int row);
                    ((Cell)sender).Value = (GetCell(column, row)).Value;
                }
            }

            CellPropertyChanged?.Invoke(sender, new PropertyChangedEventArgs("Value"));
        }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPropChanged(object sender, PropertyChangedEventArgs e)
        {
            Cell c = sender as Cell; // makes the sender into a cell and setting a temp value for it

            if (e.PropertyName == "Text")
            {
                if (c.Text.StartsWith("=")) // checks if the text starts with an '='
                {
                    // formula for copying the cell
                    string incel = c.Text.Substring(1);
                    int    col   = Convert.ToInt16(incel[0]) - 'A';
                    int    row   = Convert.ToInt16(incel.Substring(1)) - 1;
                    c.Value = (GetCell(row, col)).Value;
                }
                else
                {
                    c.Value = c.Text;
                }
            }
            CellPropertyChanged?.Invoke(sender, new PropertyChangedEventArgs("Value")); // this is to check if there is an inputted value and will check if there is a property changed
        }
예제 #8
0
        private void Spreadsheet_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var cell = (SpreadsheetCell)sender; //casts the sending object as a SpreadsheetCell

            if (e.PropertyName == "Text")
            {
                string text = cell.Text;
                if (text == string.Empty) //if there is no text
                {
                    cell.SetValue(string.Empty);
                    // clears all of this cells references
                    foreach (SpreadsheetCell cellReference in cell.ReferencedCells.ToList())
                    {
                        cellReference.ValueChanged -= cell.OnValueChanged; // unsubsribes from the cell
                        cell.RemoveReferenceToCell(cellReference);         //removes it from the list
                    }
                }
                else if (text.Length == 1)
                {
                    cell.SetValue(text);
                }
                else if (Regex.Match(text, @"=[A-Z]\d+\z").Success) //matches if there is only a single reference with no operators
                {
                    // Removes all references to other cells
                    SpreadsheetCell           referencedCell        = GetCell(text.Substring(1)) as SpreadsheetCell;
                    HashSet <SpreadsheetCell> senderReferencedCells = cell.ReferencedCells;
                    if (senderReferencedCells.Count > 0)
                    {
                        foreach (SpreadsheetCell cellReference in senderReferencedCells.ToList()) // all the cells that were referenced previously but are no longer being referenced.
                        {
                            referencedCell.ValueChanged -= cell.OnValueChanged;                   // unsubsribes from the cell
                            cell.RemoveReferenceToCell(referencedCell);
                        }
                    }

                    //adds a reference to the cell in its text
                    cell.SetValue(referencedCell.Value);
                    cell.AddReferenceToCell(referencedCell);
                    referencedCell.ValueChanged += cell.OnValueChanged;
                }
                else if (text[0] == '=')
                {
                    try
                    {
                        cell.SetValue(CalculateValue(cell.Text, cell)); //updates cell value if it needs to be
                    }
                    catch                                               //Kind of the nuclear option but there are so many exception types to handle one by one.
                    {
                        cell.SetValue("#REF!");
                    }
                }
                else
                {
                    cell.SetValue(cell.Text);
                }
            }
            else //dont really need this. But going to keep it to keep track of value/text changes in the future.
            {
                cell.SetValue(cell.Text);
            }

            CellPropertyChanged?.Invoke(sender, e); //fancy way to only call if CellPropertyChanged isnt null
        }
 void OnCellPropertyChanged(object sender, CellPropertyChangedEventArgs e)
 {
     CellPropertyChanged?.Invoke(sender, e);
 }
예제 #10
0
 //Notify all subscribers that the property has changed (e.g. form1 --> dataGridview1)
 private void NotifyPropertyChanged(object sender, string propertyName)
 {
     CellPropertyChanged?.Invoke(sender, new PropertyChangedEventArgs(propertyName));
 }
 //Event used to alert UI-layer code to update the content of a cell
 public void NotifyCellPropertyChanged(AbstractCell cell)
 {
     CellPropertyChanged?.Invoke(cell, new PropertyChangedEventArgs("Cell"));
 }
예제 #12
0
 public void NotifyCellPropertyChanged(Cell cell)
 {
     CellPropertyChanged?.Invoke(this, new PropertyChangedEventArgs(cell.RowIndex.ToString() + "," + cell.ColumnIndex.ToString()));
 }
예제 #13
0
 void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     CellPropertyChanged?.Invoke(sender, new CellPropertyChangedEventArgs(e.PropertyName, this));
 }
예제 #14
0
        //Defining Response behaviour to CellPropertyChanged event.
        //If the cell Text changes, then the cell is recalculated.
        private void OnCellPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            SCell target = (SCell)sender;

            int[] newcell = { target.RowIndex, target.ColumnIndex };
            bool  flag    = false;

            foreach (int[] location in ChangedCells)
            {
                flag = location.SequenceEqual(newcell);
                if (flag == true)
                {
                    break;
                }
            }

            if (flag == false)
            {
                ChangedCells.Add(newcell);
            }



            string temp = "";

            //if the target text has been set before and starts with '='...
            if (e.PropertyName == "Text" && target.Text != null && target.Text != "" && target.Text[0] == '=')
            {
                //just grab the rest of the string...
                for (int i = 1; i < target.Text.Length; i++)
                {
                    temp += target.Text[i].ToString();
                }
                //... and set the target cell's value to it

                string[] parts    = target.Eqn.Shunt(temp).Split(' ');
                bool     equation = true;

                //Checking to see if it is a valid equation. looks for non-value, non-variable, and non-operator parts
                foreach (string part in parts)
                {
                    if (equation == true && (Regex.Match(part, @"(^[+,\-,/,*]$)").Success || Regex.Match(part, @"(^\d+\.?\d*$)").Success || (Regex.Match(part, @"(^[A-Z{1}][\d+])").Success) && !Regex.Match(part, @"(\W)").Success))
                    {
                        equation = true;
                    }
                    else
                    {
                        equation = false;
                    }
                }

                if (equation == true)
                {
                    //prepare target:

                    //Removing all subscriptions. Subscriptions to referenced cells are (re)added later.
                    foreach (ExpTree.ExpTree.Var variable in target.Eqn.GetRegi())
                    {
                        int row = Int32.Parse(variable.Name[1].ToString()) - 1;
                        int col = variable.Name[0] - 65;

                        //unsubscribing to referenced cell's event:
                        SpreadS[row, col].AlertValChange -= target.OnAlertCellValueChange;
                    }

                    //rebuilding target cell's equation
                    target.Eqn.Rebuild(temp);

                    //~*~* MaTh *~*~

                    //target.Eqn.Expression = temp;
                    target.Value = target.Eqn.Evald().ToString();

                    //setting variables in target cell to values in respective cells, if there are any
                    foreach (ExpTree.ExpTree.Var variable in target.Eqn.GetRegi())
                    {
                        int row = Int32.Parse(variable.Name.Substring(1)) - 1;
                        int col = variable.Name[0] - 65;

                        //subscribing to referenced cell's event for when just the value changes
                        SpreadS[row, col].AlertValChange += target.OnAlertCellValueChange;

                        //Checking to see if referenced cell is valid for an equation input
                        if (SpreadS[row, col].Value == null || !IsEqn(SpreadS[row, col].Eqn.Expression) || !Double.TryParse(SpreadS[row, col].Value, out double num))
                        {
                            target.Value = "#REFF!";
                        }
                        else
                        {
                            target.Eqn.SetVar(variable.Name, Double.Parse(SpreadS[row, col].Value));
                            target.Value = target.Eqn.Evald().ToString();
                        }
                    }
                }
                else
                {
                    target.Value = target.Text;
                }
            }
            //...otherwise just set the target cell's value to it
            else if (e.PropertyName == "Text")
            {
                if (Double.TryParse(target.Text, out double num))
                {
                    target.Eqn.Expression = num.ToString();
                }
                target.Value = target.Text;
            }

            // finally, fire off CellPropertyChanged event
            CellPropertyChanged?.Invoke(target, e);
        }
예제 #15
0
파일: Spreadsheet.cs 프로젝트: sl8rw/CS321
        private void Spreadsheet_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            //from crandall

            rmDep((Cell)sender);
            if (e.PropertyName == "Text")
            {
                changedCells.Add((Cell)sender);

                if (!((Cell)sender).Text.StartsWith("="))
                {
                    ((Cell)sender).Value = ((Cell)sender).Text;
                }
                else
                {
                    var expression = ((Cell)sender).Text;  //this will get the expression
                    try
                    {
                        var     subExp       = expression.Substring(1);
                        ExpTree ssExpression = new ExpTree(subExp);
                        DefineVars(ssExpression);
                        ((Cell)sender).Value = ssExpression.Eval().ToString();
                        if (((Cell)sender).Value == "NaN")
                        {
                            ((Cell)sender).Value = expression;
                            ((Cell)sender).Value = GetCell(expression.Substring(1)).Value;
                            CellPropertyChanged.Invoke(sender,
                                                       new PropertyChangedEventArgs("Value"));
                        }

                        addDep((Cell)sender, ssExpression.varNameList);
                    }
                    catch

                    {
                        //we are concerned with #REF
                        try
                        {
                            var ssExpression = new ExpTree(((Cell)sender).Text.Substring(1).ToUpper());
                            ((Cell)sender).Value = "#REF";
                            CellPropertyChanged.Invoke(sender,
                                                       new PropertyChangedEventArgs("Value"));
                            addDep((Cell)sender, ssExpression.varNameList);
                        }
                        catch
                        {
                            //need to check if there is an = operator without any following
                            ((Cell)sender).Value = "#REF";
                            CellPropertyChanged.Invoke(sender,
                                                       new PropertyChangedEventArgs("Value"));
                        }

                        ((Cell)sender).Value = "#REF";
                        CellPropertyChanged.Invoke(sender,
                                                   new PropertyChangedEventArgs("Value"));
                    }
                }
            }

            if (cellDependency.ContainsKey((Cell)sender))
            {
                updateDep((Cell)sender);
            }
            CellPropertyChanged.Invoke(sender,
                                       new PropertyChangedEventArgs("Value"));
        }