예제 #1
0
파일: CalcNode.cs 프로젝트: Daoting/dt
        private static void ExpandSharedFormulaDependency(CalcService service, CalcGraph graph, List <CalcNode> searchingDepends, List <SharedFormulaDirtyItem> sharedDirtyItmes, CalcNode rangeIntersected, CalcLocalIdentity currentId)
        {
            CalcRangeIdentity identity = currentId as CalcRangeIdentity;
            CalcRangeIdentity id       = rangeIntersected.Id as CalcRangeIdentity;

            if ((!object.ReferenceEquals(id, null) && (rangeIntersected.Dependents != null)) && ((rangeIntersected.Dependents.Count > 0) && ShouldExpand(graph, id)))
            {
                foreach (KeyValuePair <CalcNode, CalcNode> pair in rangeIntersected.Dependents)
                {
                    List <CalcLocalIdentity> list;
                    CalcRangeIdentity        rangeId = pair.Key.Id as CalcRangeIdentity;
                    if ((rangeId == null) || !graph.IsSharedFormula(rangeId))
                    {
                        goto Label_019E;
                    }
                    if ((currentId == rangeId) || ((identity != null) && (identity.IsFullRow || identity.IsFullColumn)))
                    {
                        searchingDepends.Add(pair.Key);
                        continue;
                    }
                    SharedFormulaDirtyItem dirtyItem = null;
                    if (pair.Key.DirtyItem != null)
                    {
                        if (pair.Key.DirtyItem is SharedFormulaDirtyItem)
                        {
                            dirtyItem = pair.Key.DirtyItem as SharedFormulaDirtyItem;
                            if (!dirtyItem.IsFullRangeDirty)
                            {
                                goto Label_0136;
                            }
                        }
                        continue;
                    }
                    dirtyItem = new SharedFormulaDirtyItem(service, graph.Manager.Source, rangeId, graph.GetNode(rangeId));
                    graph.GetNode(rangeId).DirtyItem = dirtyItem;
Label_0136:
                    list = GetDepIdsInSharedFormulaRange(graph.Manager, rangeId, currentId);
                    if ((list.Count == 1) && (list[0] == rangeId))
                    {
                        dirtyItem.IsFullRangeDirty = true;
                        searchingDepends.Add(graph.GetNode(rangeId));
                    }
                    else
                    {
                        dirtyItem.DirtySubIds2.AddRange(list);
                        if (dirtyItem.DirtySubIds2.Count > 0)
                        {
                            sharedDirtyItmes.Add(dirtyItem);
                        }
                    }
                    continue;
Label_019E:
                    searchingDepends.Add(pair.Key);
                }
            }
            else
            {
                searchingDepends.Add(rangeIntersected);
            }
        }
예제 #2
0
        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);
        }