-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDashboardConfig.cs
40 lines (33 loc) · 1.98 KB
/
DashboardConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Web.Hosting;
using System.Web.Routing;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using DevExpress.DashboardWeb.Mvc;
using DevExpress.DataAccess.Excel;
using DevExpress.DataAccess.Sql;
namespace MvcCustomController {
public class DashboardConfig {
public static void RegisterService(RouteCollection routes) {
routes.MapDashboardRoute("dashboardControl", "DefaultDashboard");
DashboardFileStorage dashboardFileStorage = new DashboardFileStorage("~/App_Data/Dashboards");
DashboardConfigurator.Default.SetDashboardStorage(dashboardFileStorage);
// Uncomment this string to allow end users to create new data sources based on predefined connection strings.
//DashboardConfigurator.Default.SetConnectionStringsProvider(new DevExpress.DataAccess.Web.ConfigFileConnectionStringsProvider());
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
// Registers an SQL data source.
DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "NWindConnectionString");
SelectQuery query = SelectQueryFluentBuilder
.AddTable("SalesPerson")
.SelectAllColumns()
.Build("Sales Person");
sqlDataSource.Queries.Add(query);
dataSourceStorage.RegisterDataSource("sqlDataSource", sqlDataSource.SaveToXml());
// Registers an Excel data source.
DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource("Excel Data Source");
excelDataSource.FileName = HostingEnvironment.MapPath(@"~/App_Data/Sales.xlsx");
excelDataSource.SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Sheet1"));
dataSourceStorage.RegisterDataSource("excelDataSource", excelDataSource.SaveToXml());
DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage);
}
}
}