CellSet 遍历

CellSet 结构:

查询MDX:

SELECT  
NON EMPTY {{  {{ {{ {{  {{ AddCalculatedMembers([店铺.店铺ID].[店铺ID].Members)}}  }} }} }}  
 }}  
DIMENSION PROPERTIES MEMBER_TYPE
, [店铺.店铺ID].[店铺ID].[国家], [店铺.店铺ID].[店铺ID].[区域], 
[店铺.店铺ID].[店铺ID].[省份], [店铺.店铺ID].[店铺ID].[店铺名称]

 ON ROWS ,
  {{   [Measures].[终端销售数量],[measures].[终端销售生意额],[measures].[终端销售吊牌额]
       }}

   ON COLUMNS
FROM [RegentCube] 
 where  [日期].[年周].[].&[2015].[第01周]

 

C#遍历:

    int pos = 0;
        foreach (Position py in cellSet.Axes[1].Positions)
        {
            dr = dt.NewRow();

            //维度描述列数据
            int cols = 0;
            for (int i = 0; i < py.Members.Count; i++)
            {
                if (i == 0)
                {
                    for (int w = 1; w < py.Members[0].MemberProperties.Count; w++)
                    {
                        dr[cols] = py.Members[0].MemberProperties[w].Value;
                        cols++;
                    }
                }
                else
                {
                    dr[cols] = py.Members[i].Caption;
                    cols++;
                }
            }

            //数据列
            for (int x = 1; x <= cellSet.Axes[0].Positions.Count; x++)
            {
                dr[x + cols - 1] = cellSet[pos++].Value;
            }
            dt.Rows.Add(dr);
        }
      var  model = dt.AsEnumerable().Select(r => new
        {
            销售数 = string.IsNullOrWhiteSpace(r["终端销售数量"].ToString()) ? 0 : Convert.ToInt32(r["终端销售数量"]),
            生意额 = string.IsNullOrWhiteSpace(r["终端销售生意额"].ToString()) ? 0 : Convert.ToDouble(r["终端销售生意额"]),
            吊牌额 = string.IsNullOrWhiteSpace(r["终端销售吊牌额"].ToString()) ? 0 : Convert.ToDouble(r["终端销售吊牌额"]),
            国家 = r["Dimension0"],
            省份 = r["Dimension1"],
            城市 = r["Dimension2"],
            店铺名称 = r["Dimension3"]
        });

 

posted @ 2015-04-08 15:11  Rain520  阅读(550)  评论(0编辑  收藏  举报