private void LoadMeasuresXandY(OlapControl grid, List <Measure> assignedMeasures)
        {
            if (!string.IsNullOrEmpty(AxesLayout.XMeasure))
            {
                var m = grid.Measures.Find(AxesLayout.XMeasure);
                if (m != null)
                {
                    grid.Pivoting(m, LayoutArea.laColumn, null, LayoutArea.laNone);
                    assignedMeasures.Remove(m);
                }
            }

            if (AxesLayout.YMeasures != null)
            {
                foreach (var gm in AxesLayout.YMeasures)
                {
                    gm.Restore(grid, assignedMeasures);
                }
            }
        }
        private void LoadMeasures(OlapControl grid)
        {
            var cMs = new List <Measure>();

            if (AxesLayout != null && AxesLayout.Measures != null)
            {
                for (var i = 0; i < AxesLayout.Measures.Length; i++)
                {
                    var SM = AxesLayout.Measures[i];
                    var m  = grid.Measures.Find(SM.UniqueName);

                    if (m == null && !string.IsNullOrEmpty(SM.Expression))
                    {
                        m               = grid.Measures.AddCalculatedMeasure(SM.DisplayName, "", "", SM.UniqueName, true);
                        m.Expression    = SM.Expression;
                        m.DefaultFormat = SM.DefaultFormat;
                    }

                    if (m != null)
                    {
                        m.Expression    = SM.Expression;
                        m.VisibleInTree = SM.VisibleInTree;

                        if (string.IsNullOrEmpty(SM.DefaultFormat))
                        {
                            m.FDefaultFormat_ = m.CubeMeasure == null ? "" : m.CubeMeasure.DefaultFormat;
                        }
                        else
                        {
                            m.FDefaultFormat_ = SM.DefaultFormat;
                        }

                        m.Visible = SM.Visible;

                        foreach (var sm in m.ShowModes.ToArray())
                        {
                            try
                            {
                                if (sm.Visible)
                                {
                                    sm.Visible = false;
                                }
                            }
                            catch (Exception e)
                            {
                            }
                        }

                        if (SM.ActiveModes != null)
                        {
                            foreach (var s in SM.ActiveModes)
                            {
                                var sm = m.ShowModes.Find(s);
                                if (sm != null)
                                {
                                    sm.Visible = true;
                                }
                            }
                        }

                        if (SM.ActiveShowModes != null)
                        {
                            foreach (var assm in SM.ActiveShowModes)
                            {
                                var sm = m.ShowModes.Find(assm);
                                if (sm != null)
                                {
                                    sm.Visible = true;
                                }
                            }
                        }

                        if (SM.Intelligences != null)
                        {
                            for (var ii = 0; ii < SM.Intelligences.Length; ii++)
                            {
                                var hi = grid.Dimensions.FindHierarchy(SM.IntelligenceParents[ii]);
                                if (hi != null)
                                {
                                    hi.InitHierarchy(0);
                                    foreach (var ti in hi.Intelligence)
                                    {
                                        if (ti.Expression == SM.Intelligences[ii])
                                        {
                                            ti.AddMeasure(m);
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        var b = m.ShowModes.Any(sm => sm.fVisible);

                        if (!b)
                        {
                            m.ShowModes[0].fVisible = true;
                        }

                        if (SM.Filter != null)
                        {
                            m.fFilter = new MeasureFilter(m, SM.Filter.Condition, SM.Filter.FirstValue,
                                                          SM.Filter.SecondFalue)
                            {
                                RestrictsTo = SM.Filter.RestrictsTo
                            }
                        }
                        ;
                        else
                        {
                            m.fFilter = null;
                        }

                        m.RestoreAfterSerialization(grid);
                        var mm = grid.Measures.Level.FindMember(SM.UniqueName);
                        grid.Measures.Level.Members.MoveMember(mm, i);
                    }

                    if (m != null && !string.IsNullOrEmpty(m.Expression))
                    {
                        cMs.Add(m);
                    }
                }
                if (grid.CellsetMode == CellsetMode.cmChart)
                {
                    foreach (var m in grid.Measures)
                    {
                        if (!m.Visible)
                        {
                            continue;
                        }
                        if (!m.IsActive)
                        {
                            grid.Pivoting(m, LayoutArea.laRow, null, LayoutArea.laNone);
                        }
                    }
                    grid.ChartsType = ChartsType;
                    TrendDeSerialize(grid);
                }
            }
        }
        private void LoadHierarchies(OlapControl grid, List <Measure> assignedMeasures)
        {
            if (Hierarchies == null)
            {
                return;
            }

            foreach (var H in Hierarchies)
            {
                var h = grid.Dimensions.FindHierarchy(H.UniqueName);
                if (h != null)
                {
                    H.Restore(h);
                }
            }

            foreach (var s in AxesLayout.RowHierarchies)
            {
                var h = grid.Dimensions.FindHierarchy(s);
                if (h != null)
                {
                    grid.PivotingLast(h, LayoutArea.laRow);
                }
            }

            foreach (var s in AxesLayout.ColumnHierarchies)
            {
                var H = grid.Dimensions.FindHierarchy(s);
                if (H != null)
                {
                    grid.PivotingLast(H, LayoutArea.laColumn);
                }
            }
            //if (olap.OlapDocumentMode == OlapDocumentMode.MDI && (olap.AllowShareFilter == false))
            {
                foreach (var s in AxesLayout.PageHierarchies)
                {
                    var H = grid.Dimensions.FindHierarchy(s);
                    if (H != null)
                    {
                        grid.PivotingLast(H, LayoutArea.laPage);
                    }
                }
            }

            if (AxesLayout.DetailsHierarchies != null)
            {
                foreach (var s in AxesLayout.DetailsHierarchies)
                {
                    var h = grid.Dimensions.FindHierarchy(s);
                    if (h != null)
                    {
                        grid.PivotingLast(h, LayoutArea.laDetails);
                    }
                }
            }

            if (!string.IsNullOrEmpty(AxesLayout.ColorAxis)) // && grid.CellsetMode == CellsetMode.cmChart)
            {
                var m = grid.Measures.Find(AxesLayout.ColorAxis);
                if (m != null)
                {
                    grid.Pivoting(m, LayoutArea.laColor, null, LayoutArea.laNone);
                    assignedMeasures.Remove(m);
                }
                else
                {
                    var h = grid.Dimensions.FindHierarchy(AxesLayout.ColorAxis);
                    if (h != null)
                    {
                        grid.PivotingFirst(h, LayoutArea.laColor);
                    }
                }
            }

            if (!string.IsNullOrEmpty(AxesLayout.ColorForeAxis) && grid.CellsetMode == CellsetMode.cmGrid)
            {
                var m = grid.Measures.Find(AxesLayout.ColorForeAxis);
                if (m != null)
                {
                    grid.Pivoting(m, LayoutArea.laColorFore, null, LayoutArea.laNone);
                    assignedMeasures.Remove(m);
                }
                else
                {
                    var h = grid.Dimensions.FindHierarchy(AxesLayout.ColorForeAxis);
                    if (h != null)
                    {
                        grid.PivotingFirst(h, LayoutArea.laColorFore);
                    }
                }
            }

            if (!string.IsNullOrEmpty(AxesLayout.SizeAxis))
            {
                var m = grid.Measures.Find(AxesLayout.SizeAxis);
                if (m != null)
                {
                    grid.Pivoting(m, LayoutArea.laSize, null, LayoutArea.laNone);
                    assignedMeasures.Remove(m);
                }
                else
                {
                    var h = grid.Dimensions.FindHierarchy(AxesLayout.SizeAxis);
                    if (h != null)
                    {
                        grid.PivotingFirst(h, LayoutArea.laSize);
                    }
                }
            }
            if (!string.IsNullOrEmpty(AxesLayout.ShapeAxis))
            {
                var h = grid.Dimensions.FindHierarchy(AxesLayout.ShapeAxis);
                if (h != null)
                {
                    grid.PivotingFirst(h, LayoutArea.laShape);
                }
            }

            if (!string.IsNullOrEmpty(AxesLayout.XMeasure))
            {
                var m = grid.Measures.Find(AxesLayout.XMeasure);
                if (m != null)
                {
                    grid.Pivoting(m, LayoutArea.laColumn, null, LayoutArea.laNone);
                }
            }

            if (AxesLayout.YMeasures != null)
            {
                grid.AxesLayout.fYAxisMeasures.Clear();

                foreach (var gm in AxesLayout.YMeasures)
                {
                    gm.Restore(grid, assignedMeasures);
                }
            }

#pragma warning disable 612,618
            if (AxesLayout.OpenendNodes != null)
            {
                var on = new Dictionary <string, PossibleDrillActions>(AxesLayout.OpenendNodes.Length);
                for (var i = 0; i < AxesLayout.OpenendNodes.Length; i++)
                {
                    on.Add(AxesLayout.OpenendNodes[i], AxesLayout.OpenendActions[i]);
                }
#pragma warning restore 612,618
                grid.FCellSet.ApplyOpenedNodes(on);
            }
            if (AxesLayout.Drills != null)
            {
                foreach (var s in AxesLayout.Drills)
                {
                    var da = DrillAction.FromString(grid, s);
                    if (da != null)
                    {
                        grid.CellSet.FDrillActions.Add(da);
                    }
                }
            }
        }