Пример #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
        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);
                }
            }
        }
Пример #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 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);
     }
 }
Пример #5
0
 public void AddRows(int row, int count)
 {
     if ((count > 0) && !this.Suspended)
     {
         if (this.Manager.GetExpression(new CalcRangeIdentity(row, 1, true)) == null)
         {
             CalcExpressionHelper.ValidateIntersectedArrayFormula(this.Manager, row, -1, 1, -1, true);
         }
         FormulaOperatorHelper.Insert(this._formulaOperatorSource, row, count, true, false, true, true);
     }
 }
Пример #6
0
 public void ReorderRows(int fromRow, int toRow, int rowCount)
 {
     if ((fromRow != toRow) && !this.Suspended)
     {
         if (((this.Manager.GetExpression(new CalcRangeIdentity(fromRow, rowCount, false)) == null) && this.Manager.IsIsIntersectantWithArrayFormula(new CalcRangeIdentity(fromRow, rowCount, true))) || ((this.Manager.GetExpression(new CalcRangeIdentity(toRow, rowCount, false)) == null) && this.Manager.IsIsIntersectantWithArrayFormula(new CalcRangeIdentity(toRow, rowCount, true))))
         {
             throw new InvalidOperationException(ResourceStrings.FormulaChangePartOfArrayFormulaError);
         }
         FormulaOperatorHelper.Reorder(this._formulaOperatorSource, this.Storage, fromRow, toRow, rowCount, true, true, true);
     }
 }
Пример #7
0
 public void RemoveColumns(int column, int count)
 {
     if ((count > 0) && !this.Suspended)
     {
         if (this.Manager.GetExpression(new CalcRangeIdentity(column, count, false)) == null)
         {
             CalcExpressionHelper.ValidateIntersectedArrayFormula(this.Manager, -1, column, -1, count, false);
         }
         FormulaOperatorHelper.Remove(this._formulaOperatorSource, column, count, false, false, true, true);
     }
 }
Пример #8
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);
        }
Пример #9
0
        public static void Clear(CalcCalculationManager mgr, CalcLocalIdentity id)
        {
            Dictionary <CalcCellIdentity, CalcExpression>  dictionary;
            Dictionary <CalcRangeIdentity, CalcExpression> dictionary2;

            FormulaOperatorHelper.GetAllContainsIds(mgr, id, out dictionary, out dictionary2);
            foreach (CalcCellIdentity identity in dictionary.Keys)
            {
                mgr.ClearExpression(identity);
                mgr.Invalidate(identity, false);
            }
            foreach (CalcRangeIdentity identity2 in dictionary2.Keys)
            {
                mgr.ClearExpression(identity2);
                mgr.Invalidate(identity2, false);
            }
        }
Пример #10
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);
            }
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
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);
                    }
                }
            }
        }
Пример #14
0
        public void RemoveDataValidation(int row, int column)
        {
            CalcLocalIdentity actualId = FormulaOperatorHelper.Indexs2Identity(row, column, row, column);

            base.RemoveConditionals(actualId, null);
        }
Пример #15
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));
 }