C1WPF制作OLAP Cube瀏覽工具


       經過前期一段時間對WPF的學習了解,相信大家對WPF有了一定的了解。今天我們一起來了解使用Component One(簡稱C1)的WPF控件制作CUBE瀏覽工具。其實這個OLAP控件官方已經有了很詳細的示例。

下面是C1的WPF版所有的控件信息:

 

所有WPF控件信息:

 

OLAP組件:

 

        不管官方介紹有多好,我們還是要自己體驗了控件使用才能知道到底好不好用,我們開始創建項目。

1、新建WPF項目,名稱CubeAnalysis,引入C1控件

 

2、 在UI界面中先要引入C1的引用xmlns:olap="clr-namespace:C1.WPF.Olap;assembly=C1.WPF.Olap.4" xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"   

3、在UI界面中調用OLAP控件

 

界面代碼如下:

 1 <Window x:Class="CubeAnalysis.MainWindow"
 2 
 3         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 4 
 5         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowState="Maximized"
 6 
 7         Title="MainWindow" Height="350" Width="525" xmlns:olap="clr-namespace:C1.WPF.Olap;assembly=C1.WPF.Olap.4" xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml">
 8 
 9     <Grid x:Name="LayoutRoot">
10 
11         <Grid.RowDefinitions>
12 
13             <RowDefinition Height="Auto" />
14 
15             <RowDefinition />
16 
17         </Grid.RowDefinitions>
18 
19  
20 
21         <StackPanel Orientation="Horizontal" Grid.ColumnSpan="2">
22 
23             <TextBlock Text="C1.WPF.Olap: Cube Analysis" VerticalAlignment="Center" Margin="10,5" FontSize="18" FontWeight="Bold" />
24 
25             <Button Content="更新" Margin="10,5" Width="80" Click="Button_Click" />
26 
27             <Button Content="取消更新" Margin="10,5" Width="120" Click="Button_Click_1" />
28 
29         </StackPanel>
30 
31  
32 
33         <olap:C1OlapPage x:Name="_c1OlapPage" Grid.Row="1" />
34 
35  
36 
37         <StackPanel x:Name="info" Grid.Row="1" Visibility="Collapsed" HorizontalAlignment="Center" VerticalAlignment="Center">
38 
39             <c1:C1ProgressBar x:Name="progress" Width="250" Height="20" />
40 
41             <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
42 
43                 <TextBlock HorizontalAlignment="Center" Text="Loading" Margin="0,4,4,0" FontSize="12" FontWeight="Bold"/>
44 
45                 <TextBlock x:Name="txt" HorizontalAlignment="Center" Margin="0,4,0,0" FontSize="12" FontWeight="Bold"/>
46 
47             </StackPanel>
48 
49         </StackPanel>
50 
51     </Grid>
52 
53 </Window>
View Code

 

4、后端加載數據連接cube,只需要使用ConnectCube函數即可解決多維數據集獲取問題。

后台代碼如下:

  1 using System;
  2 
  3 using System.Collections.Generic;
  4 
  5 using System.Linq;
  6 
  7 using System.Text;
  8 
  9 using System.Windows;
 10 
 11 using System.Windows.Controls;
 12 
 13 using System.Windows.Data;
 14 
 15 using System.Windows.Documents;
 16 
 17 using System.Windows.Input;
 18 
 19 using System.Windows.Media;
 20 
 21 using System.Windows.Media.Imaging;
 22 
 23 using System.Windows.Navigation;
 24 
 25 using System.Windows.Shapes;
 26 
 27 /*************作者:黃昏前黎明后***************************************************
 28 
 29 *   作者:黃昏前黎明后
 30 
 31 *   CLR版本:4.0.30319.42000
 32 
 33 *   創建時間:2018-04-18 13:12:57
 34 
 35 *   命名空間:CubeAnalysis
 36 
 37 *   唯一標識:57a428fc-1bad-4455-ae05-2b591db69167
 38 
 39 *   機器名稱:HLPC
 40 
 41 *   聯系人郵箱:hl@cn-bi.com
 42 
 43 *
 44 
 45 *   描述說明:
 46 
 47 *   修改歷史:
 48 
 49  
 50 
 51 *****************************************************************/
 52 
 53 namespace CubeAnalysis
 54 
 55 {
 56 
 57     /// <summary>
 58 
 59     /// Interaction logic for MainWindow.xaml
 60 
 61     /// </summary>
 62 
 63     public partial class MainWindow : Window
 64 
 65     {
 66 
 67         public MainWindow()
 68 
 69         {
 70 
 71             InitializeComponent();
 72 
 73  
 74 
 75             //綁定OLAP數據源
 76 
 77             _c1OlapPage.Loaded += (s, ea) =>
 78 
 79             {
 80 
 81                 //准備連接數據源和cube名稱
 82 
 83                 string connectionString = @"Data Source=HLPC;Initial Catalog=AdventureWorksDW2014Multidimensional-EE";
 84 
 85  
 86 
 87                 string cubeName = "Adventure Works";
 88 
 89                 try
 90 
 91                 {
 92 
 93                     _c1OlapPage.OlapPanel.ConnectCube(cubeName, connectionString);
 94 
 95  
 96 
 97                     ////默認顯示數據
 98 
 99                     var olap = _c1OlapPage.OlapEngine;
100 
101                     olap.BeginUpdate();
102 
103                     olap.ColumnFields.Add("Color");
104 
105                     olap.RowFields.Add("Category");
106 
107                     olap.ValueFields.Add("Order Count");
108 
109                     olap.EndUpdate();
110 
111                 }
112 
113                 catch (Exception ex)
114 
115                 {
116 
117                     MessageBox.Show(ex.Message);
118 
119                 }
120 
121               
122 
123                 _c1OlapPage.OlapEngine.Updated += (s1, e) =>
124 
125                 {
126 
127                     _c1OlapPage.OlapGrid.Opacity = 1;
128 
129                     info.Visibility = Visibility.Collapsed;
130 
131                 };
132 
133                 //進度條處理
134 
135                 _c1OlapPage.OlapEngine.UpdateProgressChanged += (s1, e) =>
136 
137                 {
138 
139                     _c1OlapPage.OlapGrid.Opacity = 0.4;
140 
141                     info.Visibility = Visibility.Visible;
142 
143                     progress.Value = (int)e.ProgressPercentage;
144 
145                     txt.Text = e.ProgressPercentage.ToString() + " %";
146 
147                 };
148 
149             };
150 
151         }
152 
153  
154 
155         void Button_Click(object sender, RoutedEventArgs e)
156 
157         {
158 
159             // 刷新
160 
161             _c1OlapPage.OlapPanel.OlapEngine.Update();
162 
163         }
164 
165  
166 
167         private void Button_Click_1(object sender, RoutedEventArgs e)
168 
169         {
170 
171             // 取消更新
172 
173             _c1OlapPage.OlapPanel.OlapEngine.CancelUpdate();
174 
175         }
176 
177     }
178 
179 }
View Code

5、運行結果:

 

       看到這個結果,是不是感覺使用C1WPF控件構建OLAP服務很簡單很方便。其實這個只是最基本的控件,還可以制作自定義界面的,讓頁面布局更方便自己的使用習慣。可以輕松實現下圖效果:

 

圖形瀏覽:

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM