-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.cs
89 lines (81 loc) · 3.84 KB
/
Code.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
namespace SqlDataSourceSnippets
{
public class Code
{
SqlDataSource DataSource { get; set; }
void SqlDataSourceInitialization()
{
//1)
var myConnectionName = "Northwind_Connection";
SqlDataSource DataSource = new SqlDataSource(myConnectionName);
//2)
//MsSqlConnectionParameters connectionParameters = new MsSqlConnectionParameters(".", "NWind", null, null, MsSqlAuthorizationType.Windows);
//SqlDataSource ds1 = new SqlDataSource(connectionParameters);
}
void SelectQueryCreation()
{
SelectQuery query = SelectQueryFluentBuilder
.AddTable("Categories")
.SelectColumn("CategoryName")
.GroupBy("CategoryName")
.Join("Products", "CategoryID")
.SelectColumn("ProductName", AggregationType.Count, "ProductCount")
.SortBy("ProductName", AggregationType.Count, System.ComponentModel.ListSortDirection.Descending)
.GroupFilter("[ProductCount] > 7")
.Build("Categories");
DataSource.Queries.Add(query);
QueryParameterInitialization(query);
}
void StoredProcedureInitialization()
{
StoredProcQuery spQuery = new StoredProcQuery("StoredProcedure", "stored_procedure_name");
spQuery.Parameters.Add(new QueryParameter("@First", typeof(int), 0));
spQuery.Parameters.Add(new QueryParameter("@Second", typeof(string), "Value"));
spQuery.Parameters.Add(new QueryParameter("@Third", typeof(string), "Value"));
DataSource.Queries.Add(spQuery);
}
void QueryParameterInitialization(SelectQuery query)
{
QueryParameter parameter = new QueryParameter()
{
Name = "catID",
Type = typeof(DevExpress.DataAccess.Expression),
Value = new DevExpress.DataAccess.Expression("[Parameters.catID]", typeof(System.Int32))
};
query.Parameters.Add(parameter);
query.FilterString = "CategoryID = ?catID";
}
void CustomSqlQueryInitialization()
{
CustomSqlQuery query = new CustomSqlQuery();
query.Name = "CustomQuery";
query.Sql = "Select top 10 * from Products";
DataSource.Queries.Add(query);
}
void RelationshipInitialization()
{
SelectQuery categories = SelectQueryFluentBuilder.AddTable("Categories").SelectAllColumns().Build("Categories");
SelectQuery products = SelectQueryFluentBuilder.AddTable("Products").SelectAllColumns().Build("Products");
DataSource.Queries.AddRange(new SqlQuery[] { categories, products });
DataSource.Relations.Add(new MasterDetailInfo("Categories", "Products", "CategoryID", "CategoryID"));
}
public static SqlDataSource CreateSqlDataSource()
{
MsSqlConnectionParameters connectionParameters = new MsSqlConnectionParameters(".", "NorthWind", null, null, MsSqlAuthorizationType.Windows);
var sqlDataSource = new SqlDataSource(connectionParameters) { Name = "Sql_Categories" };
var categoriesQuery = SelectQueryFluentBuilder.AddTable("Categories").
SelectAllColumnsFromTable().
Build("Categories");
sqlDataSource.Queries.Add(categoriesQuery);
sqlDataSource.RebuildResultSchema();
return sqlDataSource;
}
}
}