Beispiel #1
0
        public override object Parse(MathCell ownerMathCell)
        {
            string formula = ownerMathCell.DereferencedFormula =
                ownerMathCell.Formula = RemoveRedundantZeroes(ownerMathCell);

            if (AddressesHandler.HasAnyAddress(formula))
            {
                int i = 0;
                while (AddressesHandler.HasAnyAddress(formula)) // While formula contains any reference
                {
                    MathCell refCell    = ownerMathCell.References[i];
                    string   refAddress = refCell.OwnAddress;

                    if (refCell.Value == null)
                    {
                        refCell.EvaluateFormula();
                    }

                    string refValue = refCell.Value.ToString();
                    if (string.IsNullOrEmpty(refValue))
                    {
                        ownerMathCell.DereferencedFormula = formula = formula.Replace(refAddress, "0");
                    }
                    ownerMathCell.DereferencedFormula = formula = formula.Replace(refAddress, refValue);

                    ++i;
                }
            }

            return(base.Parse(ownerMathCell));
        }
Beispiel #2
0
        public MathCell GetMathCell(string address)
        {
            var(rowIndex, colIndex) = AddressesHandler.GetIndexes(address);
            MathCell mCell = (MathCell)OwnerGrid.dataGridView[colIndex, rowIndex].Tag;

            return(mCell);
        }
Beispiel #3
0
        public override object Parse(MathCell ownerMathCell)
        {
            ownerMathCell.ResetReferences();

            string formula = ownerMathCell.Formula;

            if (AddressesHandler.HasAnyAddress(formula))
            {
                List <string> formulaReferences = AddressesHandler.GetAddresses(formula);
                for (int i = 0; i < formulaReferences.Count; ++i)
                {
                    string reference = formulaReferences[i];

                    MathCell refCell =
                        MathCellsProvider.GetInstance.GetMathCell(reference);

                    if (!ownerMathCell.References.Contains(refCell))
                    {
                        ownerMathCell.InsertReference(refCell);
                    }

                    if (!refCell.Dependents.Contains(ownerMathCell))
                    {
                        refCell.InsertDependent(ownerMathCell);
                    }
                }
            }

            return(base.Parse(ownerMathCell));
        }
Beispiel #4
0
        private static string RemoveRedundantZeroes(MathCell ownerMathCell)
        {
            string        formula = ownerMathCell.Formula;
            List <string> oldAdr  = AddressesHandler.GetAddresses(formula);

            const string pattern = @"0+(?=(0|[1-9]))";

            for (int i = 0; i < oldAdr.Count; ++i)
            {
                string updStr = Regex.Replace(oldAdr[i], pattern, "", RegexOptions.Compiled);
                formula = ownerMathCell.Formula.Replace(oldAdr[i], updStr);
            }
            return(formula);
        }
Beispiel #5
0
        private static bool HasInvalidIndexing(string formula)
        {
            List <string> formulaAddresses = AddressesHandler.GetAddresses(formula);
            GridForm      ownerGrid        = MathCellsProvider.GetInstance.OwnerGrid;

            foreach (string address in formulaAddresses)
            {
                var(rowIndex, colIndex) = AddressesHandler.GetIndexes(address);
                if (rowIndex >= ownerGrid.dataGridView.RowCount || colIndex >= ownerGrid.dataGridView.ColumnCount)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #6
0
        public override object Parse(MathCell ownerMathCell)
        {
            // Removes spaces for proper parsing
            string formula = ownerMathCell.Formula = RemoveSpaces(ownerMathCell.Formula);

            List <string> refAddresses = AddressesHandler.GetAddresses(formula);

            if (refAddresses.Count != 0 && formula.First() != '=')
            {
                ownerMathCell.ResetReferences();
                throw new InvalidReferenceFormat();
            }

            if (string.IsNullOrEmpty(formula) || formula.First() != '=')
            {
                ownerMathCell.ResetReferences();
                return(formula);
            }

            return(base.Parse(ownerMathCell)); // Proceed
        }
Beispiel #7
0
        public void ShiftReferences()
        {
            List <string> updatedReferences = AddressesHandler.GetAddresses(References);
            List <string> oldReferences     = AddressesHandler.GetAddresses(Formula);

            try
            {
                for (int i = 0; i < oldReferences.Count; ++i)
                {
                    if (oldReferences[i] != "RC" && oldReferences[i] != updatedReferences[i])
                    {
                        Formula = Formula.Replace(oldReferences[i], updatedReferences[i]);
                    }
                }
            }
            catch (ArgumentException ae)
            {
                MessageBox.Show(ae.Message, "Error in references shifting",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }