次の方法で共有


階層表現 (テーブル)

階層は、高度なドリル アップおよびドリル ダウン操作をエンド ユーザーに提供するメカニズムです。

階層表現

テーブル オブジェクト モデルにおける階層は、ユーザーが選択した値に基づいて属性間を移動するためのナビゲーション パスです。

AMO における階層

AMO を使用してテーブル モデル テーブルを管理する場合、AMO 内の階層に一対一で対応するオブジェクトは存在しません。AMO では、階層が Hierarchy オブジェクトによって表されます。

次のコード スニペットでは、階層を既存のテーブル モデルに渡す方法を示します。 このコードでは、AMO データベース オブジェクトである newDatabase と、AMO キューブ オブジェクトである modelCube が存在していることを前提としています。

        private void addHierarchy(
                            AMO.Database newDatabase
                         ,  AMO.Cube modelCube
                         ,  string tableName
                         ,  string hierarchyName
                         ,  string levelsText
                     )
        {
            //Validate input
            if (string.IsNullOrEmpty(hierarchyName) || string.IsNullOrEmpty(levelsText))
            {
                MessageBox.Show(String.Format("Hierarchy Name or Layout must be provided."), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!overwriteHierarchy.Checked && newDatabase.Dimensions[tableName].Hierarchies.Contains(hierarchyName))
            {
                MessageBox.Show(String.Format("Hierarchy already exists.\nGive a new name or enable overwriting"), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                if (newDatabase.Dimensions[tableName].Hierarchies.Contains(hierarchyName))
                {
                    //Hierarchy exists... deleting it to write it later
                    newDatabase.Dimensions[tableName].Hierarchies.Remove(hierarchyName, true);
                    newDatabase.Dimensions[tableName].Update(AMO.UpdateOptions.AlterDependents);
                }
                AMO.Hierarchy currentHierarchy = newDatabase.Dimensions[tableName].Hierarchies.Add(hierarchyName, hierarchyName);
                currentHierarchy.AllMemberName = string.Format("(All of {0})", hierarchyName);
                //Parse hierarchyLayout
                using (StringReader levels = new StringReader(levelsText))
                {
                    //Each line:
                    //  must come with: The columnId of the attribute in the dimension --> this represents the SourceAttributeID
                    //  optional: A display name for the Level (if this argument doesn't come the default is the SourceAttributeID)
                    string line;
                    while ((line = levels.ReadLine()) != null)
                    {
                        if (string.IsNullOrEmpty(line) || string.IsNullOrWhiteSpace(line)) continue;
                        line = line.Trim();
                        string[] hierarchyData = line.Split(',');
                        if (string.IsNullOrEmpty(hierarchyData[0])) continue; //first argument cannot be empty or blank, 
                                                                              //assume is a blank line and ignore it
                        string levelSourceAttributeID = hierarchyData[0].Trim();
                        string levelID = (hierarchyData.Length > 1 && !string.IsNullOrEmpty(hierarchyData[1])) ? hierarchyData[1].Trim() : levelSourceAttributeID;
                        currentHierarchy.Levels.Add(levelID).SourceAttributeID = levelSourceAttributeID;
                    }
                }
                newDatabase.Dimensions[tableName].Update(AMO.UpdateOptions.AlterDependents);

            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("Error creating hierarchy [{0}].\nError message: {1}", newHierarchyName.Text, ex.Message), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                if (newDatabase.Dimensions[tableName].Hierarchies.Contains(hierarchyName))
                {
                    //Hierarchy was created but exception prevented complete hierarchy to be written... deleting incomplete hierarchy
                    newDatabase.Dimensions[tableName].Hierarchies.Remove(hierarchyName, true);
                    newDatabase.Dimensions[tableName].Update(AMO.UpdateOptions.AlterDependents);
                }

            }
            newDatabase.Dimensions[tableName].Process(AMO.ProcessType.ProcessFull);
            modelCube.MeasureGroups[tableName].Process(AMO.ProcessType.ProcessFull);
        }

AMO2Tabular サンプル

AMO を使用して階層表現の作成と操作を行う方法については、AMO to Tabular サンプルのソース コードを参照してください。特に、ソース ファイル "AddHierarchies.cs" の内容に注意してください。 このサンプルは、Codeplex でダウンロードできます。 このコードに関する重要な注意事項: このコードは、ここで説明する論理的概念を補足するためにのみ提供されています。運用環境では使用しないでください。教育目的以外の目的にも使用しないでください。