コード例 #1
0
        public void Swap(int fromRow, int fromColumn, int toRow, int toColumn, int rowCount, int columnCount)
        {
            Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > dictionary  = this.GetAllFromulas(fromRow, fromColumn, rowCount, columnCount);
            Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > dictionary2 = this.GetAllFromulas(toRow, toColumn, rowCount, columnCount);
            int rowOffset    = toRow - fromRow;
            int columnOffset = toColumn - fromColumn;

            this.Clear(fromRow, fromColumn, rowCount, columnCount);
            this.Clear(toRow, toColumn, rowCount, columnCount);
            MoveVisitor visitor = new MoveVisitor(new CellRange(fromRow, fromColumn, rowCount, columnCount), rowOffset, columnOffset, this._sheetRowCount, this._sheetColumnCount, false, null, false, null, false);

            using (Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > .ValueCollection.Enumerator enumerator = dictionary.Values.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    foreach (ConditionalGraph.ConditionalIdentity identity in enumerator.Current)
                    {
                        CalcExpression expr = visitor.Visit(identity.Expression, toRow, toColumn);
                        ((IFormulaOperatorSource)this).SetExpression(identity, expr);
                    }
                }
            }
            visitor = new MoveVisitor(new CellRange(toRow, toColumn, rowCount, columnCount), -rowOffset, -columnOffset, this._sheetRowCount, this._sheetColumnCount, false, null, false, null, true);
            using (Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > .ValueCollection.Enumerator enumerator3 = dictionary2.Values.GetEnumerator())
            {
                while (enumerator3.MoveNext())
                {
                    foreach (ConditionalGraph.ConditionalIdentity identity2 in enumerator3.Current)
                    {
                        CalcExpression expression2 = visitor.Visit(identity2.Expression, fromRow, fromColumn);
                        ((IFormulaOperatorSource)this).SetExpression(identity2, expression2);
                    }
                }
            }
        }
コード例 #2
0
        public void OffsetFormulasWhileCopy(Worksheet src, int fromRow, int fromColumn, int toRow, int toColumn, int rowCount, int columnCount, Dictionary <Tuple <int, int>, DataValidator> copiedValidators)
        {
            DataValidationConditionalGraph graph = null;

            rowCount    = (rowCount <= 0) ? 0 : rowCount;
            columnCount = (columnCount <= 0) ? 0 : columnCount;
            int num = toRow - fromRow;

            foreach (KeyValuePair <Tuple <int, int>, DataValidator> pair in copiedValidators)
            {
                int                   rowOffset         = num + (((pair.Key.Item1 - toRow) / rowCount) * rowCount);
                int                   columnOffset      = num + (((pair.Key.Item2 - toColumn) / columnCount) * columnCount);
                MoveVisitor           visitor           = new MoveVisitor(new CellRange(fromRow, fromColumn, rowCount, columnCount), rowOffset, columnOffset, graph._sheetRowCount, graph._sheetColumnCount, false, null, false, null, true);
                IConditionalFormula[] formulaConditions = pair.Value.FormulaConditions;
                if ((formulaConditions != null) && (formulaConditions.Length != 0))
                {
                    foreach (IConditionalFormula formula in formulaConditions)
                    {
                        CalcExpression expr = graph.Formula2Expression(formula.Formula, toRow, toColumn);
                        expr            = visitor.Visit(expr, toRow, toColumn);
                        formula.Formula = graph.Expression2Formula(expr, toRow, toColumn);
                    }
                }
            }
        }
コード例 #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);
        }
コード例 #4
0
        public void Move(Worksheet src, int fromRow, int fromColumn, int toRow, int toColumn, int rowCount, int columnCount)
        {
            DataValidationConditionalGraph graph = null;
            Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > dictionary = this.GetAllFromulas(fromRow, fromColumn, rowCount, columnCount);

            this.Clear(fromRow, fromColumn, rowCount, columnCount);
            graph.Clear(toRow, toColumn, rowCount, columnCount);
            MoveVisitor visitor = new MoveVisitor(new CellRange(fromRow, fromColumn, rowCount, columnCount), toRow - fromRow, toColumn - fromColumn, graph._sheetRowCount, graph._sheetColumnCount, false, null, false, null, false);

            using (Dictionary <CalcLocalIdentity, List <ConditionalGraph.ConditionalIdentity> > .ValueCollection.Enumerator enumerator = dictionary.Values.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    foreach (ConditionalGraph.ConditionalIdentity identity in enumerator.Current)
                    {
                        CalcExpression expr = visitor.Visit(identity.Expression, toRow, toColumn);
                        ((IFormulaOperatorSource)graph).SetExpression(identity, expr);
                    }
                }
            }
        }
コード例 #5
0
        static void GetTargetFormulas(CalcCalculationManager sourceMgr, CalcCalculationManager targetMgr, int sourceRowCount, int sourceColumnCount, int fromRow, int fromColumn, int toRow, int toColumn, int fromRowCount, int fromColumnCount, int toRowCount, int toColumnCount, Dictionary <CalcCellIdentity, CalcExpression> cellFormulas, Dictionary <CalcRangeIdentity, CalcExpression> rangeFormulas, bool offsetSelf, out Dictionary <CalcLocalIdentity, CalcExpression> newExpressions)
        {
            MoveVisitor visitor;
            int         rowOffset    = toRow - fromRow;
            int         columnOffset = toColumn - fromColumn;
            CellRange   fromRange    = new CellRange(fromRow, fromColumn, fromRowCount, fromColumnCount);
            MoveVisitor visitor2     = new MoveVisitor(fromRange, rowOffset, columnOffset, sourceRowCount, sourceColumnCount, false, sourceMgr.Source, sourceMgr != targetMgr, null, !offsetSelf);

            newExpressions = new Dictionary <CalcLocalIdentity, CalcExpression>();
            if ((cellFormulas != null) && (cellFormulas.Count > 0))
            {
                for (int i = toRow; i < (toRow + toRowCount); i++)
                {
                    int rowIndex = ((i - toRow) % fromRowCount) + fromRow;
                    for (int j = toColumn; j < (toColumn + toColumnCount); j++)
                    {
                        int columnIndex           = ((j - toColumn) % fromColumnCount) + fromColumn;
                        CalcCellIdentity identity = new CalcCellIdentity(rowIndex, columnIndex);
                        CalcCellIdentity id       = new CalcCellIdentity(i, j);
                        if (cellFormulas.ContainsKey(identity))
                        {
                            CalcExpression expr = cellFormulas[identity];
                            if (!offsetSelf)
                            {
                                visitor = new MoveVisitor(fromRange, rowOffset, columnOffset, sourceRowCount, sourceColumnCount, false, sourceMgr.Source, false, null, true);
                                expr    = visitor.FirstVisit(expr, identity.RowIndex, identity.ColumnIndex);
                            }
                            else
                            {
                                expr = visitor2.Visit(expr, identity.RowIndex, identity.ColumnIndex);
                            }
                            newExpressions[id] = expr;
                        }
                        else if (targetMgr.GetExpression(id) != null)
                        {
                            newExpressions[id] = null;
                        }
                    }
                }
            }
            int num7 = (toRow + toRowCount) - 1;
            int num8 = (toColumn + toColumnCount) - 1;

            if ((rangeFormulas != null) && (rangeFormulas.Count > 0))
            {
                foreach (KeyValuePair <CalcRangeIdentity, CalcExpression> pair in rangeFormulas)
                {
                    int baseRow    = (pair.Key.RowIndex < 0) ? 0 : pair.Key.RowIndex;
                    int baseColumn = (pair.Key.ColumnIndex < 0) ? 0 : pair.Key.ColumnIndex;
                    if (!pair.Key.IsFullRow || !pair.Key.IsFullColumn)
                    {
                        if (pair.Key.IsFullColumn)
                        {
                            for (int k = toColumn; k <= num8; k += fromColumnCount)
                            {
                                int num12 = (k + pair.Key.ColumnCount) - 1;
                                num12 = (num12 > num8) ? (num8 - k) : num12;
                                CalcRangeIdentity identity3   = new CalcRangeIdentity((k + pair.Key.ColumnIndex) - fromColumn, (num12 - k) + 1, false);
                                CalcExpression    expression2 = pair.Value;
                                if (!offsetSelf)
                                {
                                    visitor     = new MoveVisitor(fromRange, 0, columnOffset, sourceRowCount, sourceColumnCount, false, sourceMgr.Source, sourceMgr != targetMgr, null, true);
                                    expression2 = visitor.Visit(expression2, baseRow, baseColumn);
                                }
                                else
                                {
                                    expression2 = visitor2.Visit(expression2, baseRow, baseColumn);
                                }
                                newExpressions[identity3] = expression2;
                            }
                        }
                        else if (pair.Key.IsFullRow)
                        {
                            for (int m = toRow; m <= num7; m += fromRowCount)
                            {
                                int num14 = (m + pair.Key.RowCount) - 1;
                                num14 = (num14 > num7) ? (num7 - m) : num14;
                                CalcRangeIdentity identity4   = new CalcRangeIdentity((m + pair.Key.RowIndex) - fromRow, (num14 - m) + 1, true);
                                CalcExpression    expression3 = pair.Value;
                                if (!offsetSelf)
                                {
                                    visitor     = new MoveVisitor(fromRange, rowOffset, 0, sourceRowCount, sourceColumnCount, false, sourceMgr.Source, sourceMgr != targetMgr, null, true);
                                    expression3 = visitor.Visit(expression3, baseRow, baseColumn);
                                }
                                else
                                {
                                    expression3 = visitor2.Visit(expression3, baseRow, baseColumn);
                                }
                                newExpressions[identity4] = expression3;
                            }
                        }
                        else
                        {
                            for (int n = toRow; n <= num7; n += fromRowCount)
                            {
                                int num16 = (n + pair.Key.RowCount) - 1;
                                num16 = (num16 > num7) ? (num7 - n) : num16;
                                for (int num17 = toColumn; num17 <= num8; num17 += fromColumnCount)
                                {
                                    int num18 = (num17 + pair.Key.ColumnCount) - 1;
                                    num18 = (num18 > num8) ? (num8 - num17) : num18;
                                    CalcRangeIdentity identity5   = new CalcRangeIdentity((n + pair.Key.RowIndex) - fromRow, (num17 + pair.Key.ColumnIndex) - fromColumn, (num16 - n) + 1, (num18 - num17) + 1);
                                    CalcExpression    expression4 = pair.Value;
                                    if (!offsetSelf)
                                    {
                                        expression4 = new MoveVisitor(fromRange, rowOffset, columnOffset, sourceRowCount, sourceColumnCount, false, sourceMgr.Source, sourceMgr != targetMgr, null, true).Visit(expression4, baseRow, baseColumn);
                                    }
                                    else
                                    {
                                        expression4 = visitor2.Visit(expression4, baseRow, baseColumn);
                                    }
                                    newExpressions[identity5] = expression4;
                                }
                            }
                        }
                    }
                }
            }
        }