The IDimSelection interface is used to work with selection of dictionaries.
The following comparison selections are available for dictionary selection: comparison for equality and inequality. These comparison types can be applied for:
Comparison by Selection.
Comparison with Number. It is performed by element key in dictionary.
Comparison with Row. It is performed by row view of element key in dictionary.
See below examples of various options of selection comparison.
Executing the example requires that the repository contains table dictionaries with the COUNTRY_OLD and COUNTRY_NEW identifiers. The COUNTRY_OLD dictionary contains Russia, Germany, France elements and the COUNTRY_NEW dictionary contains the Russia, Germany, France, Italy elements.
Add links to the Dimensions, Metabase system assemblies.
Comparison for equality and inequality
Complete comparison of dictionaries selection is executed. Comparison results are displayed to the console window.
Sub EqualityInequality;
Var
mb: IMetabase;
CountryOld, CountryNew: IDimInstance;
SelCountryOld, SelCountryNew: IDimSelection;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get dictionaries
CountryOld := mb.ItemById("COUNTRY_OLD").Open(Null) As IDimInstance;
CountryNew := mb.ItemById("COUNTRY_NEW").Open(Null) As IDimInstance;
// Create dictionary selection
SelCountryOld := CountryOld.CreateSelection;
SelCountryNew := CountryNew.CreateSelection;
// Select all dictionary elements
SelCountryOld.SelectAll;
SelCountryNew.SelectAll;
// Display element selection to the console window
Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "':");
Debug.WriteLine(" " + SelCountryOld.ToString);
Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "':");
Debug.WriteLine(" " + SelCountryNew.ToString);
// Execute comparison for equality and display results to the console window
If SelCountryOld = SelCountryNew
Then Debug.WriteLine("Selection of dictionaries is equal");
Else Debug.WriteLine("Selection of dictionaries is different");
End If;
// Compare for inequality and display results to the console window
If SelCountryOld <> SelCountryNew
Then Debug.WriteLine("Selection of dictionaries is different");
Else Debug.WriteLine("Selection of dictionaries is equal");
End If;
End Sub EqualityInequality;
Imports Prognoz.Platform.Interop.Dimensions;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
CountryOld, CountryNew: IDimInstance;
SelCountryOld, SelCountryNew: IDimSelection;
Begin
// Get current repository
mb := Params.Metabase;
// Get dictionaries
CountryOld := mb.ItemById["COUNTRY_OLD"].Open(Null) As IDimInstance;
CountryNew := mb.ItemById["COUNTRY_NEW"].Open(Null) As IDimInstance;
// Create dictionary selection
SelCountryOld := CountryOld.CreateSelection();
SelCountryNew := CountryNew.CreateSelection();
// Select all dictionary elements
SelCountryOld.SelectAll();
SelCountryNew.SelectAll();
// Display element selection to the console window
System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "':");
System.Diagnostics.Debug.WriteLine(" " + SelCountryOld.ToString("", ",", False));
System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "':");
System.Diagnostics.Debug.WriteLine(" " + SelCountryNew.ToString("", ",", False));
// Compare for equality and display results to the console window
If SelCountryOld = SelCountryNew
Then System.Diagnostics.Debug.WriteLine("Selection of dictionaries is equal");
Else System.Diagnostics.Debug.WriteLine("Selection of dictionaries is different");
End If;
// Compare for inequality and display results to the console window
If SelCountryOld <> SelCountryNew
Then System.Diagnostics.Debug.WriteLine("Selection of dictionaries is different");
Else System.Diagnostics.Debug.WriteLine("Selection of dictionaries is equal");
End If;
End Sub;
Dictionary selection is compared with the number corresponding to the dictionary element key. Comparison results are displayed to the console window.
Sub CompareWithNumber;
Var
mb: IMetabase;
CountryOld, CountryNew: IDimInstance;
SelCountryOld, SelCountryNew: IDimSelection;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get dictionaries
CountryOld := mb.ItemById("COUNTRY_OLD").Open(Null) As IDimInstance;
CountryNew := mb.ItemById("COUNTRY_NEW").Open(Null) As IDimInstance;
// Create dictionary selection
SelCountryOld := CountryOld.CreateSelection;
SelCountryNew := CountryNew.CreateSelection;
// Select one of the dictionary elements
SelCountryOld.SelectElement(1, False);
SelCountryNew.SelectElement(2, False);
// Display element selection and keys of selected elements to the console window
Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "':");
Debug.WriteLine(" - element: '" + SelCountryOld.ToString + "', key: " +
CountryOld.Elements.Id(1));
Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "':");
Debug.WriteLine(" - element: '" + SelCountryNew.ToString + "', key: " +
CountryNew.Elements.Id(2));
// Compare selections with the number 1
If SelCountryOld.ToVariant = 1
Then Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "' is equal");
Else Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "' is different");
End If;
If SelCountryNew.ToVariant = 1
Then Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "' is equal");
Else Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "' is different");
End If;
End Sub CompareWithNumber;
Imports Prognoz.Platform.Interop.Dimensions;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
CountryOld, CountryNew: IDimInstance;
SelCountryOld, SelCountryNew: IDimSelection;
Begin
// Get current repository
mb := Params.Metabase;
// Get dictionaries
CountryOld := mb.ItemById["COUNTRY_OLD"].Open(Null) As IDimInstance;
CountryNew := mb.ItemById["COUNTRY_NEW"].Open(Null) As IDimInstance;
// Create dictionary selection
SelCountryOld := CountryOld.CreateSelection();
SelCountryNew := CountryNew.CreateSelection();
// Select one element from each dictionary
SelCountryOld.SelectElement(1, False);
SelCountryNew.SelectElement(2, False);
// Display selection of elements and keys of selected elements to the console window
System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "':");
System.Diagnostics.Debug.WriteLine(" - element: '" + SelCountryOld.ToString("", ",", False) + "', key: " +
CountryOld.Elements.Id[1]);
System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "':");
System.Diagnostics.Debug.WriteLine(" - element: '" + SelCountryNew.ToString("", ",", False) + "', key: " +
CountryNew.Elements.Id[2]);
// Compare selections with the number 1
If SelCountryOld.ToVariant() = (1 As object)
Then System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "' is equal");
Else System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "' is different");
End If;
If SelCountryNew.ToVariant() = (1 As object)
Then System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "' is equal");
Else System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "' is different");
End If;
End Sub;
Dictionary selection is compared with the row corresponding to the dictionary element key. Comparison results are displayed to the console window.
Sub CompareWithString;
Var
mb: IMetabase;
CountryOld, CountryNew: IDimInstance;
SelCountryOld, SelCountryNew: IDimSelection;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get dictionaries
CountryOld := mb.ItemById("COUNTRY_OLD").Open(Null) As IDimInstance;
CountryNew := mb.ItemById("COUNTRY_NEW").Open(Null) As IDimInstance;
// Create dictionary selection
SelCountryOld := CountryOld.CreateSelection;
SelCountryNew := CountryNew.CreateSelection;
// Select one element of each dictionary
SelCountryOld.SelectElement(1, False);
SelCountryNew.SelectElement(2, False);
// Display element selection and keys of selected elements to the console window
Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "':");
Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "':");
Debug.WriteLine(" - element: '" + SelCountryOld.ToString + "', key: " +
CountryOld.Elements.Id(1));
Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "':");
Debug.WriteLine(" - element: '" + SelCountryNew.ToString + "', key: " +
CountryNew.Elements.Id(2));
// Compare selections with the string 1
If SelCountryOld.ToVariant = "1"
Then Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "' is equal");
Else Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "' is different");
End If;
If SelCountryNew.ToVariant = "1"
Then Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "' is equal");
Else Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "' is different");
End If;
End Sub CompareWithString;
Imports Prognoz.Platform.Interop.Dimensions;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
CountryOld, CountryNew: IDimInstance;
SelCountryOld, SelCountryNew: IDimSelection;
Begin
// Get current repository
mb := Params.Metabase;
// Get dictionaries
CountryOld := mb.ItemById["COUNTRY_OLD"].Open(Null) As IDimInstance;
CountryNew := mb.ItemById["COUNTRY_NEW"].Open(Null) As IDimInstance;
// Create dictionary selection
SelCountryOld := CountryOld.CreateSelection();
SelCountryNew := CountryNew.CreateSelection();
// Select one element of each dictionary
SelCountryOld.SelectElement(1, False);
SelCountryNew.SelectElement(2, False);
// Display element selection and key of selected elements to the console window
System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "':");
System.Diagnostics.Debug.WriteLine(" - element: '" + SelCountryOld.ToString("", ",", False) + "', key: " +
CountryOld.Elements.Id[1]);
System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "':");
System.Diagnostics.Debug.WriteLine(" - element: '" + SelCountryNew.ToString("", ",", False) + "', key: " +
CountryNew.Elements.Id[2]);
// Compare selections with the string 1
If SelCountryOld.ToVariant() = ("1" As object)
Then System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "' is equal");
Else System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryOld.Name + "' is different");
End If;
If SelCountryNew.ToVariant() = ("1" As object)
Then System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "' is equal");
Else System.Diagnostics.Debug.WriteLine("Dictionary selection '" + CountryNew.Name + "' is different");
End If;
End Sub;
See also: