예제 #1
0
        public void RemoveSheet(IList sources, ICalcSource replacedSource)
        {
            ICalcSource currentSource = this.Manager.Source;
            Dictionary <CalcCalculationManager, Dictionary <CalcLocalIdentity, CalcExpression> > dictionary = new Dictionary <CalcCalculationManager, Dictionary <CalcLocalIdentity, CalcExpression> >();

            foreach (object obj2 in sources)
            {
                ICalcSource source = obj2 as ICalcSource;
                if (source != null)
                {
                    CalcCalculationManager manager = this.Manager.Service.GetCalculationManager(source, null, true);
                    if (manager != null)
                    {
                        foreach (CalcLocalIdentity identity in manager.Graph.GetAllSheetRangeIdentities())
                        {
                            CalcNode node = manager.Graph.GetNode(identity);
                            if (node.Precedents != null)
                            {
                                using (List <CalcNode> .Enumerator enumerator3 = node.Precedents.GetEnumerator())
                                {
                                    while (enumerator3.MoveNext())
                                    {
                                        if (enumerator3.Current.Source == currentSource)
                                        {
                                            Dictionary <CalcLocalIdentity, CalcExpression> dictionary2;
                                            if (!dictionary.TryGetValue(manager, out dictionary2))
                                            {
                                                dictionary2         = new Dictionary <CalcLocalIdentity, CalcExpression>();
                                                dictionary[manager] = dictionary2;
                                            }
                                            dictionary2[identity] = manager.GetExpression(identity);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            RemoveSheetVisitor visitor = new RemoveSheetVisitor(currentSource, replacedSource);

            foreach (KeyValuePair <CalcCalculationManager, Dictionary <CalcLocalIdentity, CalcExpression> > pair in dictionary)
            {
                CalcCalculationManager mgr = pair.Key;
                foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair2 in pair.Value)
                {
                    int num;
                    int num2;
                    int num3;
                    int num4;
                    mgr.ClearExpression(pair2.Key);
                    FormulaOperatorHelper.Identity2Indexs(pair2.Key, out num, out num2, out num3, out num4);
                    CalcExpression expr = visitor.Visit(pair2.Value, num, num2);
                    CalcExpressionHelper.SetExpression(mgr, pair2.Key, expr, true);
                    mgr.Invalidate(pair2.Key, false);
                }
            }
        }
예제 #2
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);
            }
        }
예제 #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 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);
            }
        }