Articles in this section
Category / Section

How to create multiple OLAP Controls on the same Silverlight page sharing same Data Provider with different Data Managers

1 min read

We can able to add multiple OLAP Controls in the same Silverlight page which shares the same Data Provider with different Data Managers. This can be achieved by adding the OlapGrid, OlapChart and OlapClient control in same Silverlight page and binding the OlapData to each one of them one by one.

 

Steps to achieve

  1. Create a Silverlight project along with Web project.
  2. Create a WCF service as OlapManager.svc.
  3. Inherit the newly added WCF service with the IOlapDataProvider and explicitly implement the IOlapDataProvider. The connection to the database is done with the help of the WCF service. 
  4. Add the OlapGrid, OlapChart and OlapClient controls in the MainPage.xaml.
  5. Please refer the below code snippet for sharing the same DataProvider with different Data Managers for binding the OlapData to OlapGrid, OlapChart and OlapClient Control.

The following codes should be added in MainPage.xaml.cs

C#

 
  #region Private variables

        public IOlapDataProvider dataProvider;
 
        #endregion
 
        public MainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
            this.Dispatcher.BeginInvoke((Action)delegate
            {
                this.olapChart.Loaded += new RoutedEventHandler(OlapChart_Loaded);
                this.OlapClient1.Loaded += new RoutedEventHandler(OlapClientWindow_Loaded);
            });
           
        }
 
        void OlapChart_Loaded(object sender, RoutedEventArgs e)
        {
            OlapDataManager chartOlapDataManager = new OlapDataManager();
            chartOlapDataManager.DataProvider = dataProvider;
            chartOlapDataManager.SetCurrentReport(CreateOlapReport());
            this.olapChart.OlapDataManager = chartOlapDataManager;
        }
    
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            //// Initialize the service connection
            this.InitializeConnection();
            OlapDataManager gridOlapDataManager = new OlapDataManager();
            gridOlapDataManager.DataProvider = dataProvider;
            /// Sets the Current Report
            gridOlapDataManager.SetCurrentReport(CreateOlapReport());
            ////Tag the OnError for OlapDataManager
            gridOlapDataManager.OnError += new OlapDataManager.EventHandler(olapDataManager_OnError);
            this.olapGrid.OlapDataManager = gridOlapDataManager;
 
            this.OlapClient1.OlapGrid.GridLineStroke = new SolidColorBrush(Color.FromArgb(Byte.Parse("FF", System.Globalization.NumberStyles.HexNumber), Byte.Parse("2F", System.Globalization.NumberStyles.HexNumber), Byte.Parse("5B", System.Globalization.NumberStyles.HexNumber), Byte.Parse("B7", System.Globalization.NumberStyles.HexNumber)));
        }
 
        /// <summary>
        /// Handles the OnError event of the olapDataManager control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Syncfusion.OlapSilverlight.Manager.OlapDataManager.ErrorEventArgs"/> instance containing the event data.</param>
        private void olapDataManager_OnError(object sender, OlapDataManager.ErrorEventArgs e)
        {
            this.Dispatcher.BeginInvoke((Action)delegate
            {
                Syncfusion.Windows.Tools.Controls.WindowControl.ShowAlert("Exception Message: " + e.Message + "\nException Stack trace:\n" + e.ExceptionObject.StackTrace, "Error from Service", Syncfusion.Windows.Tools.Controls.DialogIcon.Error, Syncfusion.Windows.Tools.Controls.DialogButton.OK, null, Syncfusion.Windows.Tools.Controls.AnimationType.Zoom);
            });
        }
 
        private void OlapClientWindow_Loaded(object sender, RoutedEventArgs e)
        {
            OlapDataManager clientOlapDataManager = new OlapDataManager();
            clientOlapDataManager.DataProvider = dataProvider;
            clientOlapDataManager.SetCurrentReport(CreateOlapReport());
            this.OlapClient1.OlapDataManager = clientOlapDataManager;
            ////Tag the Axis Element Builder's Mouse Left button up events
            this.OlapClient1.AxisElementBuilderColumn.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(AxisElementBuilder_MouseLeftButtonUp);
            this.OlapClient1.AxisElementBuilderRow.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(AxisElementBuilder_MouseLeftButtonUp);
            this.OlapClient1.AxisElementBuilderSlicer.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(AxisElementBuilder_MouseLeftButtonUp);
        }
 
        /// <summary>
        /// Handles the MouseLeftButtonUp event of the AxisElementBuilder control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        private void AxisElementBuilder_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            ListBox listBox = sender as ListBox;
            if (listBox.Items.Count > 0)
            {
                bool measureItem = listBox.Items.Cast<MetaTreeNode>().Where(i => i.Description.Equals("Measures")).Any();
                if (measureItem)
                {
                    if ((listBox as AxisElementBuilder).Axis == AxisPosition.Categorical || (listBox as AxisElementBuilder).Axis == AxisPosition.Series)
                    {
                        this.OlapClient1.AxisElementBuilderColumn.IsEnabled = false;
                        this.OlapClient1.AxisElementBuilderRow.IsEnabled = false;
                        this.OlapClient1.AxisElementBuilderSlicer.IsEnabled = true;
                    }
                    else if ((listBox as AxisElementBuilder).Axis == AxisPosition.Slicer)
                    {
                        this.OlapClient1.AxisElementBuilderColumn.IsEnabled = true;
                        this.OlapClient1.AxisElementBuilderRow.IsEnabled = true;
                        this.OlapClient1.AxisElementBuilderSlicer.IsEnabled = false;
                    }
                }
            }
        }
 
        void InitializeConnection()
        {
            Binding customBinding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement { MaxReceivedMessageSize = 2147483647 });
            EndpointAddress address = new EndpointAddress(new Uri(App.Current.Host.Source.ToString() + "../../../../Services/OlapManager.svc/binary"));
            ChannelFactory<IOlapDataProvider> clientChannel = new ChannelFactory<IOlapDataProvider>(customBinding, address);
            dataProvider = clientChannel.CreateChannel();
        }
 
        private OlapReport CreateOlapReport()
        {
            OlapReport olapReport = new OlapReport { Name = "Sales Report" };
            olapReport.CurrentCubeName = "Adventure Works";
 
            DimensionElement dimensionElementColumn = new DimensionElement();
            //Specifying the Name for the Dimension Element
            dimensionElementColumn.Name = "Customer";
 
            dimensionElementColumn.HierarchyName = "Customer Geography";
            dimensionElementColumn.AddLevel("Customer Geography", "Country");
 
            MeasureElements measureElementColumn = new MeasureElements();
            measureElementColumn.Elements.Add(new MeasureElement { Name = "Internet Sales Amount" });
 
            DimensionElement dimensionElementRow = new DimensionElement();
            //Specifying the Dimension Name
            dimensionElementRow.Name = "Date";
 
            //Adding the level element along with the Hierarchy Name
            dimensionElementRow.AddLevel("Fiscal", "Fiscal Year");
 
            olapReport.CategoricalElements.Add(new Item { ElementValue = dimensionElementColumn });
 
            ///Adding Measure Element
            olapReport.CategoricalElements.Add(new Item { ElementValue = measureElementColumn });
            /// Adding Column Members
            ///Adding Row Members
            olapReport.SeriesElements.Add(new Item { ElementValue = dimensionElementRow });
 
            return olapReport;
        }
 

 

 

 

Figure: OlapGrid, OlapChart and OlapClient appear in same page with same DataProvider

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied