/// <summary> /// Gets the value at specified position which indicated by <paramref name="id" />. /// </summary> /// <param name="id">A <see cref="T:Dt.CalcEngine.CalcIdentity" /> indicates the identity of a address.</param> /// <returns> /// An <see cref="T:System.Object" /> indicates the value. /// If the <paramref name="id" /> is not recognized, return <see cref="F:Dt.CalcEngine.CalcErrors.Reference" />. /// </returns> public virtual object GetValue(CalcIdentity id) { if (id is CalcExternalIdentity) { CalcExternalIdentity identity = id as CalcExternalIdentity; ICalcSource source = identity.Source; if (source != null) { CalcLocalIdentity identity3; CalcLocalIdentity identity2 = identity.ConvertToLocal(); if ((this.ArrayFormulaMode || (this.RowCount > 1)) || (this.ColumnCount > 1)) { identity3 = new CalcRangeIdentity(this.Row, this.Column, this.RowCount, this.ColumnCount); } else { identity3 = new CalcCellIdentity(this.Row, this.Column); } return(source.GetEvaluatorContext(identity3).GetValue(identity2)); } } else if ((this.Source != null) && (id is CalcLocalIdentity)) { CalcRangeIdentity objA = id as CalcRangeIdentity; if (object.ReferenceEquals(objA, null)) { return(this.Source.GetValue(id as CalcLocalIdentity)); } if (objA._isFullColumn && objA._isFullRow) { return(this.Source.GetValue(new CalcCellIdentity(this.Row, this.Column))); } if (objA._isFullColumn) { return(this.Source.GetValue(new CalcCellIdentity(this.Row, objA._columnIndex))); } if (objA._isFullRow) { return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, this.Column))); } if (((objA._rowCount == 1) && (objA._columnIndex <= this.Column)) && (this.Column < (objA._columnIndex + objA._columnCount))) { return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, this.Column))); } if (((objA._columnCount == 1) && (objA._rowIndex <= this.Row)) && (this.Row < (objA._rowIndex + objA._rowCount))) { return(this.Source.GetValue(new CalcCellIdentity(this.Row, objA._columnIndex))); } if ((objA._rowCount == 1) && (objA._columnCount == 1)) { return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, objA._columnIndex))); } return(CalcErrors.Value); } return(CalcErrors.Reference); }
internal bool EvaluateFormula(CalcCalculationManager mgr, DirtyItem dirtyItem) { CalcLocalIdentity id = dirtyItem.Id as CalcLocalIdentity; if (object.ReferenceEquals(id, null)) { return(false); } CalcExpression objA = mgr.GetExpression(id); if (object.ReferenceEquals(objA, null)) { return(false); } ICalcSource source = mgr.Source; Dictionary <CalcLocalIdentity, CalcExpression> dictionary = new Dictionary <CalcLocalIdentity, CalcExpression>(); if ((id is CalcRangeIdentity) && mgr.Graph.IsSharedFormula(id as CalcRangeIdentity)) { List <CalcLocalIdentity> dirtySubIds = new List <CalcLocalIdentity>(); SharedFormulaDirtyItem item = dirtyItem as SharedFormulaDirtyItem; if ((item != null) && !item.IsFullRangeDirty) { dirtySubIds = (dirtyItem as SharedFormulaDirtyItem).DirtySubIds; } else { dirtySubIds.Add(id); } foreach (CalcLocalIdentity identity3 in dirtySubIds) { int num; int num2; int num3; int num4; bool flag; CalcRangeIdentity identity4 = identity3 as CalcRangeIdentity; CalcReferenceHelper.Id2Range(source, identity3, out num, out num2, out num3, out num4, out flag); for (int i = num; i < (num + num3); i++) { for (int j = num2; j < (num2 + num4); j++) { if ((identity4 != null) && (identity4.IsFullRow || identity4.IsFullColumn)) { new FullBandMappingVisitor(identity4.IsFullRow, identity4.IsFullRow ? i : j).Visit(objA, 0, 0); } CalcCellIdentity identity5 = new CalcCellIdentity(i, j); CalcExpression expression = mgr.GetExpression(identity5); if (((expression != null) && (expression == objA)) && !mgr.Graph.IsIsIntersectantWithArrayFormula(identity5)) { dictionary[identity5] = objA; } } } } } else { dictionary.Add(id, objA); } foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair in dictionary) { id = pair.Key; object obj2 = mgr.Evaluator.Evaluate(pair.Value, source.GetEvaluatorContext(id)); while (!(id is CalcRangeIdentity) && ((obj2 is CalcReference) || (obj2 is CalcArray))) { if (obj2 is CalcReference) { obj2 = ExtractValueFromReference(id, obj2); } if (obj2 is CalcArray) { obj2 = (obj2 as CalcArray).GetValue(0); } } source.SetValue(id, obj2); } return(true); }