Private Function CreateOlapReport() As OlapReport
Dim olapReport As New OlapReport() With { _
.Name = "Default Report" _
}
olapReport.CurrentCubeName = "Adventure Works"
Dim measureElement As New MeasureElements()
measureElement.Elements.Add(New MeasureElement() With { _
.UniqueName = "[Measures].[Customer Count]" _
})
Dim dimensionElementRow As New DimensionElement()
dimensionElementRow.Name = "Date"
dimensionElementRow.AddLevel("Fiscal", "Fiscal Year")
olapReport.SeriesElements.Add(dimensionElementRow)
olapReport.CategoricalElements.Add(measureElement)
Return olapReport
End Function |
olapReport.SlicerRangeFilters.AddRange(getUserCountriesFilter())
Private Function getCountriesOfCurrentUser(user As User) As IList(Of Country)
Dim returnCountries As IList(Of Country) = New List(Of Country)
Dim countryDao As ICountryDao = DaoFactory.GetCountryDao
returnCountries.Add(countryDao.GetById(1, False)) 'Germany
returnCountries.Add(countryDao.GetById(1039, False)) 'Canada
Return returnCountries
End Function
C#(Inside Service):
Public Function NodeDropped(ByVal action As String, ByVal dropType As String, ByVal nodeInfo As String, ByVal olapReport As String, ByVal clientReports As String) As Dictionary(Of String, Object) Implements IOlapClientService.NodeDropped
Dim DataManager As New OlapDataManager(connectionString)
DataManager.SetCurrentReport(OLAPUTILS.Utils.DeserializeOlapReport(olapReport))
DataManager.Reports = olapClientHelper.DeserializedReports(clientReports)
'Temporary Solution
Dim dict As Dictionary(Of String, Object) = olapClientHelper.GetJsonData(action, DataManager, dropType, nodeInfo)
Dim nodeInfomation = nodeInfo.Split(New String() {"-"}, StringSplitOptions.RemoveEmptyEntries)
If dropType.Equals("TreeNode") AndAlso nodeInfomation(1).Equals("[Customer]") Then 'You can set the dimension name here to exclude its members
Dim currentReport = OLAPUTILS.Utils.DeserializeOlapReport(dict("UpdatedReport").ToString())
Dim reportCollection = olapClientHelper.DeserializedReports(dict("ClientReports").ToString())
currentReport = FilterReport(nodeInfo, currentReport)
For i As Integer = 0 To reportCollection.Count - 1
If reportCollection(i).Name.Equals(currentReport.Name) Then
reportCollection(i) = currentReport
Exit For
End If
Next
dict("ClientReports") = Syncfusion.Olap.Common.Common.SerializeObject(Of OlapReportCollection)(reportCollection).Compress()
dict("UpdatedReport") = OLAPUTILS.Utils.SerializeOlapReport(currentReport)
End If
Return dict
End Function
Public Function FilterReport(nodeInfo As String, currentReport As OlapReport) As OlapReport
Dim nodeInfomation = nodeInfo.Split(New String() {"-"}, StringSplitOptions.RemoveEmptyEntries)
Dim axis = nodeInfomation(2).ToLower()
If userName.Equals("abc") Then
' for user "abc" we have exclude the member "Canada" from the dimension "Customer".
If axis = "categorical" Then
For Each item In currentReport.CategoricalElements
If (TypeOf item.ElementValue Is DimensionElement) AndAlso TryCast(item.ElementValue, DimensionElement).UniqueName.ToLower() = nodeInfomation(1).ToLower() Then
Dim excludeDimensionElement As New DimensionElement()
excludeDimensionElement.Name = item.ElementValue.Name
excludeDimensionElement.AddLevel(TryCast(item.ElementValue, DimensionElement).HierarchyName, TryCast(item.ElementValue, DimensionElement).Hierarchy.LevelElements(0).Name)
excludeDimensionElement.Hierarchy.LevelElements(TryCast(item.ElementValue, DimensionElement).Hierarchy.LevelElements(0).Name).Add(New MemberElement() With { _
.Name = "Canada", _
.UniqueName = "[Customer].[Customer Geography].[Country].&[Canada]" _
})
item.ExcludedElementValue = excludeDimensionElement
End If
Next
ElseIf axis = "series" Then
For Each item In currentReport.SeriesElements
If (TypeOf item.ElementValue Is DimensionElement) AndAlso TryCast(item.ElementValue, DimensionElement).UniqueName.ToLower() = nodeInfomation(1).ToLower() Then
Dim excludeDimensionElement As New DimensionElement()
excludeDimensionElement.Name = item.ElementValue.Name
excludeDimensionElement.AddLevel(TryCast(item.ElementValue, DimensionElement).HierarchyName, TryCast(item.ElementValue, DimensionElement).Hierarchy.LevelElements(0).Name)
excludeDimensionElement.Hierarchy.LevelElements(TryCast(item.ElementValue, DimensionElement).Hierarchy.LevelElements(0).Name).Add(New MemberElement() With { _
.Name = "Canada", _
.UniqueName = "[Customer].[Customer Geography].[Country].&[Canada]" _
})
item.ExcludedElementValue = excludeDimensionElement
End If
Next
End If
ElseIf userName.Equals("xyz") Then
' for user "xyz" we have exclude the member "France" from the dimension "Customer".
If axis = "categorical" Then
For Each item In currentReport.CategoricalElements
If (TypeOf item.ElementValue Is DimensionElement) AndAlso TryCast(item.ElementValue, DimensionElement).UniqueName.ToLower() = nodeInfomation(1).ToLower() Then
Dim excludeDimensionElement As New DimensionElement()
excludeDimensionElement.Name = item.ElementValue.Name
excludeDimensionElement.AddLevel(TryCast(item.ElementValue, DimensionElement).HierarchyName, TryCast(item.ElementValue, DimensionElement).Hierarchy.LevelElements(0).Name)
excludeDimensionElement.Hierarchy.LevelElements(TryCast(item.ElementValue, DimensionElement).Hierarchy.LevelElements(0).Name).Add(New MemberElement() With { _
.Name = "France", _
.UniqueName = "[Customer].[Customer Geography].[Country].&[France]" _
})
item.ExcludedElementValue = excludeDimensionElement
End If
Next
ElseIf axis = "series" Then
For Each item In currentReport.SeriesElements
If (TypeOf item.ElementValue Is DimensionElement) AndAlso TryCast(item.ElementValue, DimensionElement).UniqueName.ToLower() = nodeInfomation(1).ToLower() Then
Dim excludeDimensionElement As New DimensionElement()
excludeDimensionElement.Name = item.ElementValue.Name
excludeDimensionElement.AddLevel(TryCast(item.ElementValue, DimensionElement).HierarchyName, TryCast(item.ElementValue, DimensionElement).Hierarchy.LevelElements(0).Name)
excludeDimensionElement.Hierarchy.LevelElements(TryCast(item.ElementValue, DimensionElement).Hierarchy.LevelElements(0).Name).Add(New MemberElement() With { _
.Name = "France", _
.UniqueName = "[Customer].[Customer Geography].[Country].&[France]" _
})
item.ExcludedElementValue = excludeDimensionElement
End If
Next
End If
End If
Return currentReport
End Function
|