Esempio n. 1
0
        public static void Save(CalcCalculationManager sourceMgr, CalcCalculationManager targetMgr, ChangingContext context, int sourceRowCount, int sourceColumnCount, int fromRow, int fromColumn, int toRow, int toColumn, int fromRowCount, int fromColumnCount, int toRowCount, int toColumnCount, Dictionary <CalcLocalIdentity, CalcExpression> formulas, bool offsetSelf, bool updataDependens)
        {
            Dictionary <CalcLocalIdentity, CalcExpression> dictionary3;

            if (context == null)
            {
                context = new ChangingContext();
            }
            GetDependentsFromulas(sourceMgr, targetMgr, context, fromRow, fromColumn, toRow, toColumn, fromRowCount, formulas, fromColumnCount, offsetSelf, updataDependens);
            Dictionary <CalcCellIdentity, CalcExpression>  cellFormulas  = new Dictionary <CalcCellIdentity, CalcExpression>();
            Dictionary <CalcRangeIdentity, CalcExpression> rangeFormulas = new Dictionary <CalcRangeIdentity, CalcExpression>();

            foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair in formulas)
            {
                if (pair.Key is CalcCellIdentity)
                {
                    cellFormulas[pair.Key as CalcCellIdentity] = pair.Value;
                }
                else if (pair.Key is CalcRangeIdentity)
                {
                    rangeFormulas[pair.Key as CalcRangeIdentity] = pair.Value;
                }
            }
            GetTargetFormulas(sourceMgr, targetMgr, sourceRowCount, sourceColumnCount, fromRow, fromColumn, toRow, toColumn, fromRowCount, fromColumnCount, toRowCount, toColumnCount, cellFormulas, rangeFormulas, offsetSelf, out dictionary3);
            ReferenceValidateVisitor visitor = new ReferenceValidateVisitor(new int?(sourceRowCount - 1), new int?(sourceColumnCount - 1));

            Clear(targetMgr, FormulaOperatorHelper.Indexs2Identity(toRow, toColumn, (toRow + toRowCount) - 1, (toColumn + toColumnCount) - 1));
            foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair2 in dictionary3)
            {
                if (pair2.Value == null)
                {
                    targetMgr.ClearExpression(pair2.Key);
                }
                else
                {
                    int            num;
                    int            num2;
                    int            num3;
                    int            num4;
                    CalcExpression expr = pair2.Value;
                    FormulaOperatorHelper.Identity2Indexs(pair2.Key, out num, out num2, out num3, out num4);
                    num  = (num < 0) ? 0 : num;
                    num2 = (num2 < 0) ? 0 : num2;
                    num3 = (num3 < 0) ? 0 : num3;
                    num4 = (num4 < 0) ? 0 : num4;
                    expr = visitor.Visit(expr, num, num2);
                    if (expr is CalcSharedExpression)
                    {
                        expr = visitor.Visit(expr, num3, num4);
                    }
                    bool?isArrayFormula = null;
                    CalcExpressionHelper.SetExpression(targetMgr, pair2.Key, expr, isArrayFormula);
                }
                targetMgr.Invalidate(pair2.Key, false);
            }
        }
Esempio n. 2
0
 public void AddDataValidation(int row, int column, DataValidator validator)
 {
     IConditionalFormula[] formulaConditions = validator.FormulaConditions;
     if ((formulaConditions != null) && (formulaConditions.Length != 0))
     {
         CalcLocalIdentity          actualId = FormulaOperatorHelper.Indexs2Identity(row, column, row, column);
         List <IConditionalFormula> list     = new List <IConditionalFormula>();
         list.AddRange(formulaConditions);
         base.AddConditionals(actualId, (ICollection <IConditionalFormula>)list);
     }
 }
Esempio n. 3
0
        static void GetDependentsFromulas(CalcCalculationManager sourceMgr, CalcCalculationManager targetMgr, ChangingContext context, int fromRow, int fromColumn, int toRow, int toColumn, int fromRowCount, Dictionary <CalcLocalIdentity, CalcExpression> formulas, int fromColumnCount, bool offsetSelf, bool updataDependens)
        {
            int rowOffset               = toRow - fromRow;
            int columnOffset            = toColumn - fromColumn;
            CalcLocalIdentity id        = FormulaOperatorHelper.Indexs2Identity(fromRow, fromColumn, (fromRow + fromRowCount) - 1, (fromColumn + fromColumnCount) - 1);
            CellRange         fromRange = new CellRange(fromRow, fromColumn, fromRowCount, fromColumnCount);
            MoveVisitor       visitor   = new MoveVisitor(fromRange, rowOffset, columnOffset, 0x7fffffff, 0x7fffffff, true, targetMgr.Source, sourceMgr != targetMgr, null, !offsetSelf);

            sourceMgr.Source.GetEvaluatorContext(new CalcCellIdentity(toRow, toColumn));
            new Dictionary <CalcIdentity, CalcIdentity>();
            CalcNode node = sourceMgr.Graph.GetNode(id);
            IFormulaOperatorSource   mgr  = new SpreadCalcAxialManager.FormulaOperatorSource(sourceMgr);
            List <CalcLocalIdentity> list = new List <CalcLocalIdentity>();
            HashSet <CalcNode>       arrayFormulaNodes = new HashSet <CalcNode>();

            if ((node != null) && updataDependens)
            {
                list = FormulaOperatorHelper.GetChangedDependents(mgr, context, node, arrayFormulaNodes, formulas, null);
            }
            if (offsetSelf && updataDependens)
            {
                foreach (CalcIdentity identity2 in sourceMgr.Graph.GetAllLocalIdentities())
                {
                    int num3;
                    int num4;
                    int num5;
                    int num6;
                    FormulaOperatorHelper.Identity2Indexs(identity2, out num3, out num4, out num5, out num6);
                    if ((((fromRow == -1) || (num3 >= fromRow)) && ((fromRow == -1) || (num5 < (fromRow + fromRowCount)))) && (((fromColumn == -1) || (num4 >= fromColumn)) && ((fromColumn == -1) || (num6 < (fromColumn + fromColumnCount)))))
                    {
                        CalcNode node2 = sourceMgr.Graph.GetNode(identity2);
                        if ((node2 != null) && (node2.Dependents != null))
                        {
                            list.AddRange((IEnumerable <CalcLocalIdentity>)FormulaOperatorHelper.GetChangedDependents(mgr, context, node2, arrayFormulaNodes, formulas, null));
                        }
                    }
                }
                visitor.CurrentCalcSource = sourceMgr.Source;
                foreach (CalcLocalIdentity identity3 in list)
                {
                    int            num7;
                    int            num8;
                    int            num9;
                    int            num10;
                    CalcExpression expr = formulas[identity3];
                    FormulaOperatorHelper.Identity2Indexs(identity3, out num7, out num8, out num9, out num10);
                    expr = visitor.Visit(expr, num7, num8);
                    formulas[identity3] = expr;
                }
            }
            FormulaOperatorHelper.UpdataInvalidFormula(mgr, context, visitor);
        }
Esempio n. 4
0
        public void Swap(int fromRow, int fromColumn, int toRow, int toColumn, int rowCount, int columnCount)
        {
            CalcLocalIdentity id = FormulaOperatorHelper.Indexs2Identity(fromRow, fromColumn, (fromRow + rowCount) - 1, (fromColumn + columnCount) - 1);
            Dictionary <CalcLocalIdentity, CalcExpression> allContainsIds = FormulaOperatorHelper.GetAllContainsIds(this.Manager, id);
            CalcLocalIdentity identity2 = FormulaOperatorHelper.Indexs2Identity(toRow, toColumn, (toRow + rowCount) - 1, (toColumn + columnCount) - 1);
            Dictionary <CalcLocalIdentity, CalcExpression> dictionary2 = FormulaOperatorHelper.GetAllContainsIds(this.Manager, identity2);

            foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair in allContainsIds)
            {
                this.Manager.ClearExpression(pair.Key);
            }
            foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair2 in dictionary2)
            {
                this.Manager.ClearExpression(pair2.Key);
            }
            int rowOffset = toRow - fromRow;
            int colOffset = toColumn - fromColumn;
            ReferenceValidateVisitor visitor = new ReferenceValidateVisitor(new int?(this.RowCount), new int?(this.ColumnCount));

            foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair3 in allContainsIds)
            {
                int num3;
                int num4;
                int num5;
                int num6;
                FormulaOperatorHelper.Identity2Indexs(pair3.Key, out num3, out num4, out num5, out num6);
                CalcLocalIdentity identity3 = Offset(pair3.Key, rowOffset, colOffset);
                bool?isArrayFormula         = null;
                CalcExpressionHelper.SetExpression(this.Manager, identity3, visitor.Visit(pair3.Value, num3 + rowOffset, num4 + colOffset), isArrayFormula);
                this.Manager.Invalidate(identity3, false);
            }
            foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair4 in dictionary2)
            {
                int num7;
                int num8;
                int num9;
                int num10;
                FormulaOperatorHelper.Identity2Indexs(pair4.Key, out num7, out num8, out num9, out num10);
                CalcLocalIdentity identity4 = Offset(pair4.Key, -rowOffset, -colOffset);
                bool?nullable2 = null;
                CalcExpressionHelper.SetExpression(this.Manager, identity4, visitor.Visit(pair4.Value, num7 - rowOffset, num8 - colOffset), nullable2);
                this.Manager.Invalidate(identity4, false);
            }
        }
Esempio n. 5
0
        Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > GetAllFromulas(int row, int col, int rowCount, int colCount)
        {
            Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > dictionary = new Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> >();

            rowCount = (rowCount <= 0) ? 1 : rowCount;
            colCount = (colCount <= 0) ? 1 : colCount;
            for (int i = 0; i < (row + rowCount); i++)
            {
                for (int j = 0; j < (col + colCount); j++)
                {
                    CalcLocalIdentity actualId = FormulaOperatorHelper.Indexs2Identity(i, j, i, j);
                    List <ConditionalGraph.ConditionalIdentity> formulas = base.GetFormulas(actualId);
                    if ((formulas != null) && (formulas.Count > 0))
                    {
                        dictionary[actualId] = formulas;
                    }
                }
            }
            return(dictionary);
        }
Esempio n. 6
0
        Dictionary <CalcLocalIdentity, CalcExpression> GetFormulaIds(int fromRow, int fromColumn, int rowCount, int columnCount, CalcCalculationManager sourceMgr, ChangingContext context, bool clearSource)
        {
            CalcLocalIdentity id = FormulaOperatorHelper.Indexs2Identity(fromRow, fromColumn, (fromRow + rowCount) - 1, (fromColumn + columnCount) - 1);
            Dictionary <CalcLocalIdentity, CalcExpression> allContainsIds = FormulaOperatorHelper.GetAllContainsIds(sourceMgr, id);

            if (clearSource)
            {
                foreach (CalcLocalIdentity identity2 in allContainsIds.Keys)
                {
                    if (sourceMgr == this.Manager)
                    {
                        context.ChangedFormulas[identity2] = null;
                    }
                    else
                    {
                        context.AddExtChangedFormula(new FormulaOperatorSource(sourceMgr), identity2, identity2, null);
                    }
                }
            }
            return(allContainsIds);
        }
Esempio n. 7
0
        public static void ValidateIntersectedArrayFormula(CalcCalculationManager mgr, int row, int column, int rowCount, int columnCount, bool isInsertRowOrColumn)
        {
            List <CalcRangeIdentity> list;
            List <CalcRangeIdentity> list2;
            CalcRangeIdentity        objA = FormulaOperatorHelper.Indexs2Identity(row, column, (row + rowCount) - 1, (column + columnCount) - 1) as CalcRangeIdentity;

            if (object.ReferenceEquals(objA, null))
            {
                objA = new CalcRangeIdentity(row, column, 1, 1);
            }
            mgr.GetArrayFormulaByRange(objA, out list, out list2);
            if ((list2 != null) && (list2.Count > 0))
            {
                foreach (CalcRangeIdentity identity2 in list2)
                {
                    if (!isInsertRowOrColumn || (((!identity2.IsFullRow && !objA.IsFullRow) || (identity2.RowIndex < row)) && ((!identity2.IsFullColumn && !objA.IsFullColumn) || (identity2.ColumnIndex < column))))
                    {
                        throw new InvalidOperationException(ResourceStrings.FormulaChangePartOfArrayFormulaError);
                    }
                }
            }
        }
Esempio n. 8
0
        public void RemoveDataValidation(int row, int column)
        {
            CalcLocalIdentity actualId = FormulaOperatorHelper.Indexs2Identity(row, column, row, column);

            base.RemoveConditionals(actualId, null);
        }
Esempio n. 9
0
 public void Clear(int row, int column, int rowCount, int columnCount)
 {
     row    = (rowCount <= 0) ? -1 : row;
     column = (columnCount <= 0) ? -1 : column;
     FormulaClipboardHelper.Clear(this.Manager, FormulaOperatorHelper.Indexs2Identity(row, column, (row + rowCount) - 1, (column + columnCount) - 1));
 }