IDimHierarchies.Add

Fore Syntax

Add(Dimension: IDimensionModel): IDimHierarchy;

Fore.NET Syntax

Add(Dimension: Prognoz.Platform.Interop.Dimensions.IDimensionModel): Prognoz.Platform.Interop.Dimensions.IDimHierarchy;

Parameters

Dimension. Model of the dictionary used as an alternative hierarchy source.

Description

The Add method adds alternative hierarchy to collection.

Comments

To delete alternative hierarchy from collection, use the IDimHierarchies.Remove method.

Fore Example

Executing the example requires that the repository contains dictionaries with the TB_BASE and TB_ALT identifiers. The TB_BASE dictionary is considered as the main one, the TB_ALT dictionary is considered as a dictionary for alternative hierarchy. There should also be a form containing the Button component with the Button1» identifier, the DimensionTree component with the DimensionTree1 identifier, and the UiDimension component with the UiDimension1 identifier, which is a data source for the DimensionTree1 component. Specify the TB_BASE dictionary as a data source for the UiDimension1 component. The example is a handler of the OnClick event for the Button1 component.

Add a link to the Metabase system assembly.

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    Mb: IMetabase;
    OriginalModelObj: IMetabaseObject;
    OriginalModel, AlternateModel: IDimensionModel;
    Hierarchies: IDimHierarchies;
    Alt_Hierarchy: IDimHierarchy;
    Origin_Attributes, Alt_Attributes: IDimAttributes;
    Origin_Attr, Alt_Attr: IDimAttribute;
    dimInstance: IDimInstance;
    Hs_Instance: IDimHierarchiesInstance;
    H_Inst: IDimHierarchyInstance;
    dimSel: IDimSelection;
    i: Integer;
Begin
    Mb := MetabaseClass.Active;
    OriginalModelObj := Mb.ItemById(
"TB_BASE").Edit;
    OriginalModel := OriginalModelObj 
As IDimensionModel;
    AlternateModel := Mb.ItemById(
"TB_ALT").Bind As IDimensionModel;
    Hierarchies := OriginalModel.Hierarchies;
    Hierarchies.Clear;
    
// Determine index containing keys of elements for alternative hierarchy
    Hierarchies.OriginalIndex := OriginalModel.Indexes.PrimaryIndex;
    // Add source of alternative hierarchy
    Alt_Hierarchy := Hierarchies.Add(AlternateModel);
    
// Determine index containing keys for comparing elements of main and alternative dictionary
    Alt_Hierarchy.SourceIndex := AlternateModel.Indexes.PrimaryIndex;
    Origin_Attributes := OriginalModel.Attributes;
    Alt_Attributes := AlternateModel.Attributes;
    
// Link attributes of original dimension with attributes from source of alternative hierarchy
    For i := 0 To Origin_Attributes.Count - 1 Do
        Origin_Attr := Origin_Attributes.FindById(
"NAME");
        Alt_Attr := Alt_Attributes.FindById(
"NAME");
        Alt_Hierarchy.SourceAttribute(Origin_Attr) := Alt_Attr;
    
End For;
    OriginalModelObj.Save;
    
// Change main hierarchy for alternative
    dimInstance := OriginalModelObj.Open(NullAs IDimInstance;
    Hs_Instance := dimInstance.Hierarchies;
    
If Hs_Instance.Count > 0 Then
        H_Inst := Hs_Instance.Item(
0);
        dimSel := DimensionTree1.Selection;
        dimSel.Hierarchy := H_Inst;
    
End If;
End Sub Button1OnClick;

After executing the example alternative hierarchy is added and set for the basic dictionary.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore Example. Use Fore.NET analogs instead of Fore components.

Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Dimensions;

Private Sub button1_Click(sender: System.Object; e: System.EventArgs);
Var
    Mb: IMetabase;
    OriginalModelObj: IMetabaseObject;
    OriginalModel, AlternateModel: IDimensionModel;
    Hierarchies: IDimHierarchies;
    Alt_Hierarchy: IDimHierarchy;
    Origin_Attributes, Alt_Attributes: IDimAttributes;
    Origin_Attr, Alt_Attr: IDimAttribute;
    dimInstance: IDimInstance;
    Hs_Instance: IDimHierarchiesInstance;
    H_Inst: IDimHierarchyInstance;
    dimSel: IDimSelection;
    i: integer;
Begin
    Mb:=Self.Metabase;
    OriginalModelObj := Mb.ItemById("TB_BASE").Edit;
    OriginalModel := OriginalModelObj As IDimensionModel;
    AlternateModel := Mb.ItemById("TB_ALT").Bind As IDimensionModel;
    Hierarchies := OriginalModel.Hierarchies;
    Hierarchies.Clear();
    // Determine index, containing keys of elements for alternative hierarchy
    Hierarchies.OriginalIndex := OriginalModel.Indexes.PrimaryIndex;
    // Add source alternative hierarchy
    Alt_Hierarchy := Hierarchies.Add(AlternateModel);
    // Determine index containing keys for comparing elements of main and alternative dictionary
    Alt_Hierarchy.SourceIndex := AlternateModel.Indexes.PrimaryIndex;
    Origin_Attributes := OriginalModel.Attributes;
    Alt_Attributes := AlternateModel.Attributes;
    // Link attributes of original dimension with attributes from source of alternative hierarchy
    For i := 0 To Origin_Attributes.Count - 1 Do
        Origin_Attr := Origin_Attributes.FindById("NAME");
        Alt_Attr := Alt_Attributes.FindById("NAME");
        Alt_Hierarchy.SourceAttribute[Origin_Attr] := Alt_Attr;
    End For;
    OriginalModelObj.Save();
    // Change main hierarchy for alternative
    dimInstance := OriginalModelObj.Open(NullAs IDimInstance;
    Hs_Instance := dimInstance.Hierarchies;
    If Hs_Instance.Count > 0 Then
        H_Inst := Hs_Instance.Item[0];
        dimSel := dimensionTreeNet1.Selection;
        dimSel.Hierarchy := H_Inst;
    End If;
End Sub;

See also:

IDimHierarchies