Exemple #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);
     }
 }
Exemple #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);
            }
        }
Exemple #3
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);
            }
        }