예제 #1
0
 private bool IsHierarchyInLevels(Hierarchy h, List <Level> levels)
 {
     foreach (var l in levels)
     {
         if (l.Hierarchy == h)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #2
0
        private void RetrieveLine2_MSAS(
            Dictionary <Level, HashSet <Member> > src, Line ALine, Hierarchy intelligenceh, StringBuilder WHERE,
            List <long> idxmul, List <Level> idxlevels, MOlapCube cube,
            ref StringBuilder WITH, List <Hierarchy> sources,
            string MeasureName, ref StringBuilder SELECT, ref long idx, ref StringBuilder SUBCUBE)
        {
            //DebugLogging.WriteLine("MdEngine.RetrieveLine2_MSAS(aline={0})", ALine.ToString());

            var single         = true;
            var subcubeCounter = 0;
            var lh             = new List <Hierarchy>(2);

            if (cube.Is2000)
            {
                WHERE.Append(MeasureName);

                foreach (var h in sources) // visual totals
                {
                    if (h.Filtered)
                    {
                        cube.MakeVisualTotals(h, WITH);
                        lh.Add(h);
                    }
                }
            }
            else
            {
                if (ALine.Measure.IsKPI)
                {
                    switch (ALine.fMode.Mode)
                    {
                    case MeasureShowModeType.smKPIValue:
                    case MeasureShowModeType.smSpecifiedByEvent:
                        WHERE.Append("KPIValue");
                        break;

                    case MeasureShowModeType.smKPIGoal:
                        WHERE.Append("KPIGoal");
                        break;

                    case MeasureShowModeType.smKPIStatus:
                        WHERE.Append("KPIStatus");
                        break;

                    case MeasureShowModeType.smKPITrend:
                        WHERE.Append("KPITrend");
                        break;

                    case MeasureShowModeType.smKPIWeight:
                        WHERE.Append("KPIWeight");
                        break;
                    }
                    WHERE.Append("(\"");
                    WHERE.Append(ALine.Measure.UniqueName);
                    WHERE.Append("\")");
                }
                else
                {
                    WHERE.Append(MeasureName);
                }
            }

            var lh2     = new List <Hierarchy>();
            var singles = new SortedList <string, Member>();

            foreach (var h in FGrid.FFilteredHierarchies) // subcube filtered
            {
                Member m     = null;
                var    _done = false;

                if (cube.Is2000)
                {
                    if (lh.Contains(h))
                    {
                        continue; // already processed (visualtotals)
                    }
                    foreach (var probe in src)
                    {
                        bool ss;
                        if (probe.Key.Hierarchy == h)
                        {
                            _done = true;
                            cube.MakeWhere(h, WITH, WHERE, probe.Value, out ss);
                            single = single && ss;
                            if (single && probe.Value.Count == 1)
                            {
                                if (m != null)
                                {
                                    single = false;
                                }
                                else
                                {
                                    m = probe.Value.First();
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (h.RetrieveFilteredMember() != null && !IsHierarchyInLevels(h, ALine.Levels))
                    {
                        foreach (var probe in src)
                        {
                            if (probe.Key.Hierarchy == h)
                            {
                                cube.MakeWhere(h, WITH, WHERE, probe.Value, out single);
                                if (single)
                                {
                                    var m1 = probe.Value.First();
                                    singles.Add(h.UniqueName, m1);
                                    if (h == intelligenceh && WITH.ToString().Contains("{0}"))
                                    {
                                        // sets restriction member to the intelligence script
                                        WITH = new StringBuilder(WITH.ToString().Replace("{0}", m.UniqueName));
                                    }
                                }
                                lh2.Add(h);
                                break;
                            }
                        }
                    }
                }

                if (cube.Is2000)
                {
                    if (!_done)
                    {
                        cube.MakeWhere(h, WITH, WHERE, null, out single);
                    }

                    if (single)
                    {
                        singles.Add(h.UniqueName, m);
                        if (h == intelligenceh && WITH.ToString().Contains("{0}"))
                        {
                            WITH = new StringBuilder(WITH.ToString().Replace("{0}", m.UniqueName));
                        }
                    }
                    lh2.Add(h);
                }
                else
                {
                    if (lh2.Contains(h))
                    {
                        continue;
                    }

                    if (SUBCUBE == null)
                    {
                        SUBCUBE = new StringBuilder("SELECT ");
                    }
                    if (subcubeCounter > 0)
                    {
                        SUBCUBE.Append(",");
                        SUBCUBE.AppendLine();
                    }
                    SUBCUBE.Append("{");
                    //SUBCUBE.Append(cube.DoSubcubeFilter(h, m));
                    SUBCUBE.Append(cube.DoSubcubeFilter(h, null));
                    SUBCUBE.Append("} ON ");
                    SUBCUBE.Append(subcubeCounter++);
                    lh2.Add(h);
                }
            }

            string contextsubcube = null;

            if (cube.Is2000)
            {
                foreach (var probe in src) // apply other restrictions
                {
                    if (probe.Value.Count > 1 || probe.Key.Hierarchy == null)
                    {
                        continue;
                    }

                    if (!lh2.Contains(probe.Key.Hierarchy))
                    {
                        if (sources.Contains(probe.Key.Hierarchy) &&
                            (!ALine.Levels.Contains(probe.Key) ||
                             probe.Key.Hierarchy.Origin == HierarchyOrigin.hoParentChild))
                        {
                            continue;
                        }

                        if (probe.Key.Hierarchy.Origin == HierarchyOrigin.hoParentChild)
                        {
                            if (probe.Value.Count == 1 && ALine.Levels.Contains(probe.Key))
                            {
                                if (probe.Value.First().Depth == ALine.fDepthes[ALine.Levels.IndexOf(probe.Key)] - 1)
                                {
                                    continue;
                                }
                            }
                        }

                        if (src.Keys.Any(item => item.Hierarchy == probe.Key.Hierarchy && item.Index > probe.Key.Index))
                        {
                            continue;
                        }

                        cube.MakeWhere(probe.Key.Hierarchy, WITH, WHERE, probe.Value, out single);
                        if (!single)
                        {
                            continue;
                        }
                    }
                    if (!singles.ContainsKey(probe.Key.Hierarchy.UniqueName) && probe.Value.Count == 1)
                    {
                        singles.Add(probe.Key.Hierarchy.UniqueName, probe.Value.First());
                        if (probe.Key.Hierarchy == intelligenceh && WITH.ToString().Contains("{0}"))
                        {
                            WITH = new StringBuilder(WITH.ToString().Replace("{0}", probe.Value.First().UniqueName));
                        }
                    }
                    idx += probe.Value.First().ID *ALine.Multipliers[ALine.Levels.IndexOf(probe.Key)];
                }
            }
            else
            {
                contextsubcube = cube.GetContextFilterSubcube(FGrid);

                if (SUBCUBE != null)
                {
                    SUBCUBE.AppendLine();
                    SUBCUBE.Append("FROM ");
                    SUBCUBE.Append(contextsubcube);
                }
            }

            // make crossjoin
            var b = false;

            for (var i = 0; i < ALine.Levels.Count; i++)
            {
                var l = ALine.Levels[i];

                if (singles.ContainsKey(l.Hierarchy.UniqueName))
                {
                    continue;
                }
                idxlevels.Add(l);
                idxmul.Add(ALine.Multipliers[ALine.Levels.IndexOf(l)]);
                if (b)
                {
                    SELECT.Append("*");
                }

                var me = new HashSet <Member>();
                foreach (var probe in src)
                {
                    if (probe.Key.Hierarchy == l.Hierarchy)
                    {
                        me = probe.Value;
                        break;
                    }
                }
                SELECT.Append(cube.MakeCrossjoin(l, WITH, me, ALine.fDepthes[i]));
                if (l.Hierarchy == intelligenceh && WITH.ToString().Contains("{0}"))
                {
                    // sets "currentmember" for the crossjoin hierarchy to the intelligence script
                    WITH = new StringBuilder(WITH.ToString().Replace("{0}", l.Hierarchy.UniqueName + ".CURRENTMEMBER"));
                }
                b = true;
            }

            if (idxlevels.Count == 0)
            {
                SELECT = new StringBuilder("SELECT ");
            }
            else
            {
                if (cube.MDXCellsetThreshold > 0 && cube.Is2000 == false)
                {
                    SELECT.Append("}), "
                                  + cube.MDXCellsetThreshold
                                  + ")} DIMENSION PROPERTIES MEMBER_TYPE ON 0 ");
                }
                else
                {
                    SELECT.Append("} DIMENSION PROPERTIES MEMBER_TYPE ON 0 ");
                }
            }

            if (cube.Is2000)
            {
                SELECT.AppendLine();
                SELECT.Append("FROM ");
                SELECT.Append(cube.ApplySubcubeFilter());
                SELECT.AppendLine();

                WHERE.Append(")");
            }
            else
            {
                if (SUBCUBE == null)
                {
                    SELECT.Append("FROM ");
                    SELECT.Append(contextsubcube);
                }
                else
                {
                    SELECT.Append("FROM (");
                    SELECT.Append(SUBCUBE);
                    SELECT.Append(")");
                }
                SELECT.AppendLine();

                WHERE.Append(")");
            }
        }