Пример #1
0
 public void Sort(IDictionary <int, int> movedRows)
 {
     if (movedRows.Count != 0)
     {
         ChangingContext context = new ChangingContext();
         foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair in this.Storage)
         {
             CalcCellIdentity identity = pair.Key as CalcCellIdentity;
             if (identity != null)
             {
                 int num2;
                 int rowIndex = identity.RowIndex;
                 if (movedRows.TryGetValue(rowIndex, out num2))
                 {
                     if (!context.ChangedFormulas.ContainsKey(identity))
                     {
                         context.ChangedFormulas[identity] = null;
                     }
                     if (num2 >= 0)
                     {
                         CalcCellIdentity identity2 = new CalcCellIdentity(num2, identity.ColumnIndex);
                         CalcExpression   expr      = pair.Value;
                         int?maxColCount            = null;
                         expr = new ReferenceValidateVisitor(new int?(this.RowCount - 1), maxColCount).Visit(expr, num2, identity.ColumnIndex);
                         context.ChangedFormulas[identity2] = new Tuple <CalcLocalIdentity, CalcExpression>(identity, expr);
                     }
                 }
             }
         }
         FormulaOperatorHelper.UpdataChangings(this._formulaOperatorSource, context);
     }
 }
Пример #2
0
 static void InvalidateNode(IFormulaOperatorSource mgr, ChangingContext context, CalcNode node)
 {
     using (Dictionary <CalcNode, CalcNode> .Enumerator enumerator = node.Dependents.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             CalcLocalIdentity id = enumerator.Current.Key.Id as CalcLocalIdentity;
             if ((id != null) && (node.Source == mgr.Source))
             {
                 if (!context.ChangingIdentities.ContainsKey(id) && (mgr.GetExpression(id) != null))
                 {
                     context.InvalidateFormula(mgr, id);
                 }
             }
             else if (id != null)
             {
                 IFormulaOperatorSource externalManager = mgr.GetExternalManager(node.Source);
                 if ((externalManager != null) && (externalManager.GetExpression(id) != null))
                 {
                     context.InvalidateFormula(externalManager, id);
                 }
             }
         }
     }
 }
Пример #3
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);
            }
        }
Пример #4
0
        public void Move(SpreadCalcAxialManager src, int fromRow, int fromColumn, int toRow, int toColumn, int rowCount, int columnCount)
        {
            CalcCalculationManager sourceMgr = (src == null) ? this.Manager : src.Manager;
            ChangingContext        context   = new ChangingContext();
            Dictionary <CalcLocalIdentity, CalcExpression> formulas = this.GetFormulaIds(fromRow, fromColumn, rowCount, columnCount, sourceMgr, context, true);
            int sourceRowCount    = (src == null) ? this.RowCount : src.RowCount;
            int sourceColumnCount = (src == null) ? this.ColumnCount : src.ColumnCount;

            FormulaClipboardHelper.Save(sourceMgr, this.Manager, context, sourceRowCount, sourceColumnCount, fromRow, fromColumn, toRow, toColumn, rowCount, columnCount, rowCount, columnCount, formulas, true, true);
        }
Пример #5
0
        static void GetInvalidFormulas(IFormulaOperatorSource mgr, ChangingContext context)
        {
            HashSet <CalcNode> arrayFormulaNodes = new HashSet <CalcNode>();

            foreach (CalcLocalIdentity identity in context.ChangingIdentities.Keys)
            {
                CalcNode node = mgr.GetNode(identity);
                if ((node != null) && (node.Dependents != null))
                {
                    GetChangedDependents(mgr, context, node, arrayFormulaNodes, null, null);
                }
            }
        }
Пример #6
0
        public static void Remove(IFormulaOperatorSource mgr, int index, int count, bool row, bool isFullBand = false, bool updateDependents = true, bool updateNames = true)
        {
            ChangingContext context = new ChangingContext();
            RemoveVisitor   visitor = new RemoveVisitor(index, count, row, isFullBand, null);

            GetChangingIds(mgr, row, context, visitor, updateDependents);
            GetInvalidFormulas(mgr, context);
            if (updateNames)
            {
                UpdataCustomnNames(mgr, visitor);
            }
            visitor.CurrentCalcSource = mgr.Source;
            UpdataInvalidFormula(mgr, context, visitor);
        }
Пример #7
0
        public static void UpdataChangings(IFormulaOperatorSource manager, ChangingContext context)
        {
            Dictionary <CalcLocalIdentity, Tuple <CalcLocalIdentity, CalcExpression> > changedFormulas = context.ChangedFormulas;
            Dictionary <IFormulaOperatorSource, Dictionary <CalcLocalIdentity, Tuple <CalcLocalIdentity, CalcExpression> > > extChangedFormulas = context.ExtChangedFormulas;

            foreach (CalcLocalIdentity identity in changedFormulas.Keys)
            {
                manager.ClearExpression(identity);
            }
            foreach (KeyValuePair <IFormulaOperatorSource, Dictionary <CalcLocalIdentity, Tuple <CalcLocalIdentity, CalcExpression> > > pair in extChangedFormulas)
            {
                foreach (CalcLocalIdentity identity2 in pair.Value.Keys)
                {
                    pair.Key.ClearExpression(identity2);
                }
            }
            foreach (KeyValuePair <CalcLocalIdentity, Tuple <CalcLocalIdentity, CalcExpression> > pair2 in changedFormulas)
            {
                if (pair2.Value != null)
                {
                    CalcLocalIdentity id = pair2.Key;
                    manager.SetExpression(id, pair2.Value.Item2);
                    context.InvalidateFormula(manager, id);
                }
            }
            foreach (KeyValuePair <IFormulaOperatorSource, Dictionary <CalcLocalIdentity, Tuple <CalcLocalIdentity, CalcExpression> > > pair3 in extChangedFormulas)
            {
                foreach (KeyValuePair <CalcLocalIdentity, Tuple <CalcLocalIdentity, CalcExpression> > pair4 in pair3.Value)
                {
                    if (pair4.Value != null)
                    {
                        CalcLocalIdentity identity4 = pair4.Key;
                        pair3.Key.SetExpression(identity4, pair4.Value.Item2);
                        context.InvalidateFormula(pair3.Key, identity4);
                    }
                }
            }
            foreach (KeyValuePair <IFormulaOperatorSource, Dictionary <CalcLocalIdentity, CalcLocalIdentity> > pair5 in context.InvalidateIdentities)
            {
                foreach (KeyValuePair <CalcLocalIdentity, CalcLocalIdentity> pair6 in pair5.Value)
                {
                    if (pair6.Value != null)
                    {
                        CalcLocalIdentity identity5 = pair6.Key;
                        pair5.Key.Invalidate(identity5, false);
                    }
                }
            }
        }
Пример #8
0
        public static void Reorder(IFormulaOperatorSource mgr, ICalcStorage <CalcLocalIdentity, CalcExpression> calcStorage, int from, int to, int count, bool row, bool updateDependents = true, bool updateNames = true)
        {
            ChangingContext context = new ChangingContext();
            ReorderVisitor  visitor = new ReorderVisitor(from, to, count, row, false, null);

            GetChangingIds(mgr, row, context, visitor, updateDependents);
            if (updateDependents)
            {
                GetInvalidFormulas(mgr, context);
            }
            if (updateNames)
            {
                UpdataCustomnNames(mgr, visitor);
            }
            visitor.CurrentCalcSource = mgr.Source;
            UpdataInvalidFormula(mgr, context, visitor);
        }
Пример #9
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);
        }
Пример #10
0
        public static void UpdataInvalidFormula(IFormulaOperatorSource mgr, ChangingContext context, Dt.Cells.Data.ExpressionVisitor visitor)
        {
            foreach (KeyValuePair <CalcLocalIdentity, CalcLocalIdentity> pair in context.ChangingIdentities)
            {
                if (mgr.GetExpression(pair.Key) != null)
                {
                    mgr.ClearExpression(pair.Key);
                }
                else
                {
                    mgr.ClearNode(pair.Key);
                }
            }
            foreach (KeyValuePair <CalcLocalIdentity, Tuple <CalcLocalIdentity, CalcExpression> > pair2 in context.ChangedFormulas)
            {
                if (pair2.Value == null)
                {
                    mgr.ClearExpression(pair2.Key);
                }
                else
                {
                    int num;
                    int num2;
                    int num3;
                    int num4;
                    Identity2Indexs(GetActualId(pair2.Value.Item1), out num, out num2, out num3, out num4);
                    CalcExpression expr = visitor.Visit(pair2.Value.Item2, num, num2);
                    mgr.SetExpression(pair2.Key, expr);
                }
                context.InvalidateFormula(mgr, pair2.Key);
            }
            OperatorExpressionVisistorBase base2 = visitor as OperatorExpressionVisistorBase;

            if (base2 != null)
            {
                base2.CurrentCalcSource  = mgr.Source;
                base2.OffsetExternalOnly = true;
            }
            foreach (KeyValuePair <IFormulaOperatorSource, Dictionary <CalcLocalIdentity, Tuple <CalcLocalIdentity, CalcExpression> > > pair3 in context.ExtChangedFormulas)
            {
                foreach (KeyValuePair <CalcLocalIdentity, Tuple <CalcLocalIdentity, CalcExpression> > pair4 in pair3.Value)
                {
                    CalcLocalIdentity id = pair4.Key;
                    if (pair4.Value.Item2 == null)
                    {
                        pair3.Key.ClearExpression(id);
                    }
                    else
                    {
                        int num5;
                        int num6;
                        int num7;
                        int num8;
                        Identity2Indexs(GetActualId(pair4.Value.Item1), out num5, out num6, out num7, out num8);
                        CalcExpression expression2 = visitor.Visit(pair4.Value.Item2, num5, num6);
                        pair3.Key.SetExpression(id, expression2);
                    }
                    context.InvalidateFormula(pair3.Key, id);
                }
            }
            foreach (KeyValuePair <IFormulaOperatorSource, Dictionary <CalcLocalIdentity, CalcLocalIdentity> > pair5 in context.InvalidateIdentities)
            {
                List <CalcLocalIdentity> list = new List <CalcLocalIdentity>();
                foreach (KeyValuePair <CalcLocalIdentity, CalcLocalIdentity> pair6 in pair5.Value)
                {
                    if (pair6.Value != null)
                    {
                        list.Add(pair6.Key);
                    }
                }
                pair5.Key.Invalidate((IEnumerable <CalcLocalIdentity>)list, false);
            }
        }
Пример #11
0
 static void GetChangingIds(IFormulaOperatorSource mgr, bool row, ChangingContext context, OperatorExpressionVisistor visitor, bool updateDependents)
 {
     foreach (CalcLocalIdentity identity in mgr.GetAllLocalIdentities())
     {
         CalcIdentity id = identity;
         if (identity is ConditionalGraph.ConditionalIdentity)
         {
             ConditionalGraph.ConditionalIdentity identity3 = identity as ConditionalGraph.ConditionalIdentity;
             id = (identity3.OldActualIdentity != null) ? identity3.OldActualIdentity : identity3.ActualIdentity;
         }
         CalcNode node = mgr.GetNode(id);
         if ((node == null) || (node.OwnerNode == null))
         {
             CalcCellIdentity  identity4  = id as CalcCellIdentity;
             CalcRangeIdentity identity5  = id as CalcRangeIdentity;
             CalcExpression    expression = mgr.GetExpression(identity);
             CalcLocalIdentity identity6  = null;
             int oldStart = -2147483648;
             int oldEnd   = -2147483648;
             int newEnd   = -2147483648;
             if (identity4 != null)
             {
                 oldStart = row ? identity4.RowIndex : identity4.ColumnIndex;
             }
             else if (identity5 != null)
             {
                 if (identity5.IsFullRow && identity5.IsFullColumn)
                 {
                     identity6 = identity;
                     oldStart  = 0;
                 }
                 else if ((identity5.IsFullRow && !row) || (identity5.IsFullColumn && row))
                 {
                     if (node != null)
                     {
                         context.InvalidateFormula(mgr, identity5);
                     }
                     if (((node == null) || (node.Dependents == null)) || ((node.Dependents.Count == 0) || !updateDependents))
                     {
                         continue;
                     }
                     InvalidateNode(mgr, context, node);
                 }
                 else
                 {
                     oldStart = row ? identity5.RowIndex : identity5.ColumnIndex;
                     oldEnd   = row ? ((identity5.RowIndex + identity5.RowCount) - 1) : ((identity5.ColumnIndex + identity5.ColumnCount) - 1);
                 }
             }
             if (oldStart != -2147483648)
             {
                 if (identity6 == null)
                 {
                     int num2;
                     if (identity5 != null)
                     {
                         visitor.GetRangeOffset(oldStart, oldEnd, out num2, out newEnd);
                         if ((num2 == oldStart) && (newEnd == oldEnd))
                         {
                             continue;
                         }
                         if ((num2 == -2147483648) || (newEnd == -2147483648))
                         {
                             expression = null;
                         }
                         else if (identity5.IsFullRow && row)
                         {
                             identity6 = new CalcRangeIdentity(num2, (newEnd - num2) + 1, true);
                         }
                         else if (identity5.IsFullColumn && !row)
                         {
                             identity6 = new CalcRangeIdentity(num2, (newEnd - num2) + 1, false);
                         }
                         else if (row)
                         {
                             identity6 = new CalcRangeIdentity(num2, identity5.ColumnIndex, (newEnd - num2) + 1, identity5.ColumnCount);
                         }
                         else
                         {
                             identity6 = new CalcRangeIdentity(identity5.RowIndex, num2, identity5.RowCount, (newEnd - num2) + 1);
                         }
                     }
                     else if (identity4 != null)
                     {
                         visitor.GetCellOffset(oldStart, out num2);
                         if (num2 == oldStart)
                         {
                             continue;
                         }
                         if (num2 == -2147483648)
                         {
                             expression = null;
                         }
                         else if (identity4 != null)
                         {
                             identity6 = row ? new CalcCellIdentity(num2, identity4.ColumnIndex) : new CalcCellIdentity(identity4.RowIndex, num2);
                         }
                     }
                 }
                 context.ChangingIdentities[identity] = identity;
                 if (expression != null)
                 {
                     identity6 = (identity is ConditionalGraph.ConditionalIdentity) ? identity : identity6;
                     context.ChangedFormulas[identity6] = new Tuple <CalcLocalIdentity, CalcExpression>(identity, expression);
                 }
             }
         }
     }
 }
Пример #12
0
        public static List <CalcLocalIdentity> GetChangedDependents(IFormulaOperatorSource mgr, ChangingContext context, CalcNode node, HashSet <CalcNode> arrayFormulaNodes, Dictionary <CalcLocalIdentity, CalcExpression> formulas1 = null, Dictionary <CalcLocalIdentity, CalcExpression> formulas2 = null)
        {
            List <CalcLocalIdentity> list = new List <CalcLocalIdentity>();

            if (node.Dependents != null)
            {
                CalcNode myOwnerNode;
                foreach (CalcNode ownerNode in node.Dependents.Keys)
                {
                    myOwnerNode = ownerNode;
                    if (ownerNode.OwnerNode != null)
                    {
                        myOwnerNode = ownerNode.OwnerNode;
                        if (arrayFormulaNodes.Contains(myOwnerNode) || (mgr.GetExpression(myOwnerNode.Id as CalcLocalIdentity) is CalcSharedExpression))
                        {
                            continue;
                        }
                        arrayFormulaNodes.Add(myOwnerNode);
                    }
                    CalcLocalIdentity id = myOwnerNode.Id as CalcLocalIdentity;
                    if ((id != null) && (myOwnerNode.Source == mgr.Source))
                    {
                        if (!context.ChangingIdentities.ContainsKey(id))
                        {
                            CalcExpression expression = mgr.GetExpression(id);
                            if (expression != null)
                            {
                                if (((formulas1 != null) && formulas1.ContainsKey(id)) || ((formulas2 != null) && formulas2.ContainsKey(id)))
                                {
                                    list.Add(id);
                                }
                                else
                                {
                                    context.ChangedFormulas[id] = new Tuple <CalcLocalIdentity, CalcExpression>(id, expression);
                                }
                            }
                        }
                    }
                    else if ((id != null) && ((myOwnerNode.Source != mgr.Source) || !context.ChangingIdentities.ContainsKey(id)))
                    {
                        IFormulaOperatorSource externalManager = mgr.GetExternalManager(myOwnerNode.Source);
                        if (externalManager != null)
                        {
                            CalcExpression expr = externalManager.GetExpression(id);
                            if (expr != null)
                            {
                                if (((formulas1 != null) && formulas1.ContainsKey(id)) || ((formulas2 != null) && formulas2.ContainsKey(id)))
                                {
                                    list.Add(id);
                                }
                                else
                                {
                                    context.AddExtChangedFormula(externalManager, id, id, expr);
                                }
                            }
                        }
                    }
                }
            }
            return(list);
        }
Пример #13
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);
        }