-
Notifications
You must be signed in to change notification settings - Fork 0
/
Default.aspx.cs
109 lines (97 loc) · 5.37 KB
/
Default.aspx.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
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
using System;
using System.Collections.Generic;
namespace WebApplication1 {
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DevExpress.DataAccess.Sql.SqlDataSource sqlDataSource = GenerateSqlDataSource();
DevExpress.DataAccess.ObjectBinding.ObjectDataSource objDataSource = GenerateObjectDataSource();
DevExpress.DataAccess.EntityFramework.EFDataSource efDataSource = GenerateEFDataSource();
DevExpress.DataAccess.Excel.ExcelDataSource excelDataSource = GenerateExcelDataSource();
DevExpress.DataAccess.Json.JsonDataSource jsonDataSource = GenerateJsonDataSource();
ASPxReportDesigner1.DataSources.Add(sqlDataSource.Name, sqlDataSource);
ASPxReportDesigner1.DataSources.Add(objDataSource.Name, objDataSource);
ASPxReportDesigner1.DataSources.Add(efDataSource.Name, efDataSource);
ASPxReportDesigner1.DataSources.Add(excelDataSource.Name, excelDataSource);
ASPxReportDesigner1.DataSources.Add(jsonDataSource.Name, jsonDataSource);
ASPxReportDesigner1.OpenReport("XtraReportTest");
}
private DevExpress.DataAccess.Json.JsonDataSource GenerateJsonDataSource()
{
DevExpress.DataAccess.Json.JsonDataSource jsonDataSource = new DevExpress.DataAccess.Json.JsonDataSource();
jsonDataSource.Name = "CustomJsonDataSource";
var uri = new System.Uri("~/App_Data/nwind.json", System.UriKind.Relative);
jsonDataSource.JsonSource = new DevExpress.DataAccess.Json.UriJsonSource(uri);
jsonDataSource.Fill();
return jsonDataSource;
}
private DevExpress.DataAccess.Excel.ExcelDataSource GenerateExcelDataSource()
{
DevExpress.DataAccess.Excel.ExcelDataSource excelDS = new DevExpress.DataAccess.Excel.ExcelDataSource();
excelDS.FileName = Server.MapPath("App_Data/Categories.xlsx");
excelDS.Name = "CustomExcelDataSource";
DevExpress.DataAccess.Excel.ExcelWorksheetSettings excelWorksheetSettings1 = new DevExpress.DataAccess.Excel.ExcelWorksheetSettings() { CellRange = null, WorksheetName = "Sheet" };
DevExpress.DataAccess.Excel.ExcelSourceOptions excelSourceOptions1 = new DevExpress.DataAccess.Excel.ExcelSourceOptions(excelWorksheetSettings1) { SkipEmptyRows = true, SkipHiddenColumns = true, SkipHiddenRows = true, UseFirstRowAsHeader = true };
excelDS.SourceOptions = excelSourceOptions1;
DevExpress.DataAccess.Excel.FieldInfo fieldInfo1 = new DevExpress.DataAccess.Excel.FieldInfo() { Name = "CategoryID", Type = typeof(double) };
DevExpress.DataAccess.Excel.FieldInfo fieldInfo2 = new DevExpress.DataAccess.Excel.FieldInfo() { Name = "CategoryName", Type = typeof(string) };
DevExpress.DataAccess.Excel.FieldInfo fieldInfo3 = new DevExpress.DataAccess.Excel.FieldInfo() { Name = "Description", Type = typeof(string) };
excelDS.Schema.AddRange(new DevExpress.DataAccess.Excel.FieldInfo[] {
fieldInfo1,
fieldInfo2,
fieldInfo3
});
excelDS.RebuildResultSchema();
return excelDS;
}
private DevExpress.DataAccess.EntityFramework.EFDataSource GenerateEFDataSource()
{
DevExpress.DataAccess.EntityFramework.EFDataSource efds = new DevExpress.DataAccess.EntityFramework.EFDataSource();
efds.Name = "CustomEntityFrameworkDataSource";
efds.ConnectionParameters = new DevExpress.DataAccess.EntityFramework.EFConnectionParameters();
efds.ConnectionParameters.ConnectionStringName = "NorthwindEntitiesConnString";
efds.ConnectionParameters.Source = typeof(Models.NorthwindEntities);
return efds;
}
private DevExpress.DataAccess.Sql.SqlDataSource GenerateSqlDataSource()
{
DevExpress.DataAccess.Sql.SqlDataSource ds =
new DevExpress.DataAccess.Sql.SqlDataSource("localhost_Northwind_Connection");
ds.Name = "CustomSqlDataSource";
// Create an SQL query to access the Products table.
DevExpress.DataAccess.Sql.CustomSqlQuery query = new DevExpress.DataAccess.Sql.CustomSqlQuery();
query.Name = "customQuery1";
query.Sql = "SELECT * FROM Products";
ds.Queries.Add(query);
ds.RebuildResultSchema();
return ds;
}
private DevExpress.DataAccess.ObjectBinding.ObjectDataSource GenerateObjectDataSource()
{
DevExpress.DataAccess.ObjectBinding.ObjectDataSource objds = new DevExpress.DataAccess.ObjectBinding.ObjectDataSource();
objds.BeginInit();
objds.Name = "CustomObjectDataSource";
objds.DataSource = typeof(ItemList);
objds.Constructor = new DevExpress.DataAccess.ObjectBinding.ObjectConstructorInfo();
objds.EndInit();
return objds;
}
}
#region Object Data Source
public class ItemList : List<Item>
{
public ItemList()
{
for (int i = 0; i < 10; i++)
{
Add(new Item() { Name = i.ToString() });
}
}
}
public class Item
{
public string Name { get; set; }
}
#endregion
}