-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDefault.aspx.cs
More file actions
120 lines (98 loc) · 6.07 KB
/
Default.aspx.cs
File metadata and controls
120 lines (98 loc) · 6.07 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.Web.Hosting;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using DevExpress.DataAccess.DataFederation;
using DevExpress.DataAccess.Excel;
using DevExpress.DataAccess.Json;
using DevExpress.DataAccess.Sql;
namespace AspNetWebFormsDataFederation {
public partial class Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
DashboardFileStorage dashboardFileStorage = new DashboardFileStorage("~/App_Data/Dashboards");
ASPxDashboard1.SetDashboardStorage(dashboardFileStorage);
// Uncomment this string to allow end users to create new data sources based on predefined connection strings.
//ASPxDashboard1.SetConnectionStringsProvider(new DevExpress.DataAccess.Web.ConfigFileConnectionStringsProvider());
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
// Configures an SQL data source.
DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("SQL Data Source", "NWindConnectionString");
SelectQuery query = SelectQueryFluentBuilder
.AddTable("Orders")
.SelectAllColumnsFromTable()
.Build("SQL Orders");
sqlDataSource.Queries.Add(query);
// Configures an Object data source.
DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source");
objDataSource.DataId = "odsInvoices";
// Configures an Excel data source.
DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource("Excel Data Source");
excelDataSource.ConnectionName = "excelSales";
excelDataSource.FileName = HostingEnvironment.MapPath(@"~/App_Data/SalesPerson.xlsx");
excelDataSource.SourceOptions = new ExcelSourceOptions(new ExcelWorksheetSettings("Data"));
// Configures a JSON data source.
DashboardJsonDataSource jsonDataSource = new DashboardJsonDataSource("JSON Data Source");
jsonDataSource.ConnectionName = "jsonCategories";
Uri fileUri = new Uri(HostingEnvironment.MapPath(@"~/App_Data/Categories.json"), UriKind.RelativeOrAbsolute);
jsonDataSource.JsonSource = new UriJsonSource(fileUri);
// Registers a Federated data source.
dataSourceStorage.RegisterDataSource("federatedDataSource", CreateFederatedDataSource(sqlDataSource,
excelDataSource, objDataSource, jsonDataSource).SaveToXml());
ASPxDashboard1.SetDataSourceStorage(dataSourceStorage);
}
protected void ASPxDashboard1_ConfigureDataConnection(object sender, ConfigureDataConnectionWebEventArgs e) {
if (e.ConnectionName == "excelSales") {
(e.ConnectionParameters as ExcelDataSourceConnectionParameters).FileName = HostingEnvironment.MapPath(@"~/App_Data/SalesPerson.xlsx");
} else if (e.ConnectionName == "jsonCategories") {
e.ConnectionParameters = new JsonSourceConnectionParameters() {
JsonSource = new UriJsonSource(new Uri(HostingEnvironment.MapPath(@"~/App_Data/Categories.json"), UriKind.RelativeOrAbsolute))
};
}
}
protected void DataLoading(object sender, DataLoadingWebEventArgs e) {
if(e.DataId == "odsInvoices") {
e.Data = Invoices.CreateData();
}
}
private static DashboardFederationDataSource CreateFederatedDataSource(DashboardSqlDataSource sqlDS,
DashboardExcelDataSource excelDS, DashboardObjectDataSource objDS, DashboardJsonDataSource jsonDS) {
DashboardFederationDataSource federationDataSource = new DashboardFederationDataSource("Federated Data Source");
Source sqlSource = new Source("sqlSource", sqlDS, "SQL Orders");
Source excelSource = new Source("excelSource", excelDS, "");
Source objectSource = new Source("objectSource", objDS, "");
SourceNode jsonSourceNode = new SourceNode(new Source("json", jsonDS, ""));
// Join
SelectNode joinQuery =
sqlSource.From()
.Select("OrderDate", "ShipCity", "ShipCountry")
.Join(excelSource, "[excelSource.OrderID] = [sqlSource.OrderID]")
.Select("CategoryName", "ProductName", "Extended Price")
.Join(objectSource, "[objectSource.Country] = [excelSource.Country]")
.Select("Country", "UnitPrice")
.Build("Join query");
federationDataSource.Queries.Add(joinQuery);
// Union and UnionAll
UnionNode queryUnionAll = sqlSource.From().Select("OrderID", "OrderDate").Build("OrdersSqlite")
.UnionAll(excelSource.From().Select("OrderID", "OrderDate").Build("OrdersExcel"))
.Build("OrdersUnionAll");
queryUnionAll.Alias = "Union query";
UnionNode queryUnion = sqlSource.From().Select("OrderID", "OrderDate").Build("OrdersSqlite")
.Union(excelSource.From().Select("OrderID", "OrderDate").Build("OrdersExcel"))
.Build("OrdersUnion");
queryUnion.Alias = "UnionAll query";
federationDataSource.Queries.Add(queryUnionAll);
federationDataSource.Queries.Add(queryUnion);
// Transformation
TransformationNode unfoldNode = new TransformationNode(jsonSourceNode) {
Alias = "Unfold",
Rules = { new TransformationRule { ColumnName = "Products", Alias = "Product", Unfold = true, Flatten = false } }
};
TransformationNode unfoldFlattenNode = new TransformationNode(jsonSourceNode) {
Alias = "Unfold and Flatten",
Rules = { new TransformationRule { ColumnName = "Products", Unfold = true, Flatten = true } }
};
federationDataSource.Queries.Add(unfoldNode);
federationDataSource.Queries.Add(unfoldFlattenNode);
return federationDataSource;
}
}
}