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); } } }
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); } }
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); } }
public void InsertSheet(IList sources) { foreach (object obj2 in sources) { ICalcSource source = obj2 as ICalcSource; if (source != null) { CalcCalculationManager mgr = this.Manager.Service.GetCalculationManager(source, null, true); if (mgr != null) { foreach (CalcLocalIdentity identity in mgr.Graph.GetAllSheetRangeIdentities()) { CalcExpression expr = mgr.GetExpression(identity); CalcExpressionHelper.SetExpression(mgr, identity, expr, true); } } } } }
public void SetExpression(CalcLocalIdentity id, CalcExpression expr) { CalcExpressionHelper.SetExpression(this.Manager, id, expr, null); }