Skip to content

Commit 401d431

Browse files
authored
Merge pull request #3 from SyncfusionExamples/MySQL
added MySQL samples
2 parents ba9f570 + 5e2b4df commit 401d431

File tree

167 files changed

+77782
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+77782
-44
lines changed

Binding MS SQL database using CustomAdaptor/Blazor Web app/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL/Components/Pages/Home.razor

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,32 @@
6767
public override async Task<object> ReadAsync(DataManagerRequest DataManagerRequest, string Key = null)
6868
{
6969
IEnumerable<Order> DataSource = await OrderService.GetOrdersAsync();
70-
// Handling Searching in Custom Adaptor.
70+
// Handling Searching in CustomAdaptor.
7171
if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0)
7272
{
7373
// Searching
7474
DataSource = DataOperations.PerformSearching(DataSource, DataManagerRequest.Search);
7575
}
76-
// Handling Filtering in Custom Adaptor.
76+
// Handling Filtering in CustomAdaptor.
7777
if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0)
7878
{
7979
// Filtering
8080
DataSource = DataOperations.PerformFiltering(DataSource, DataManagerRequest.Where, DataManagerRequest.Where[0].Operator);
8181
}
82-
// Handling Sorting in Custom Adaptor.
82+
// Handling Sorting in CustomAdaptor.
8383
if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0)
8484
{
8585
// Sorting
8686
DataSource = DataOperations.PerformSorting(DataSource, DataManagerRequest.Sorted);
8787
}
88-
int count = DataSource.Cast<Order>().Count();
89-
// Handling Aggregates in Custom Adaptor.
88+
int TotalRecordsCount = DataSource.Cast<Order>().Count();
89+
// Handling Aggregates in CustomAdaptor.
9090
IDictionary<string, object> Aggregates = null;
9191
if (DataManagerRequest.Aggregates != null) // Aggregation
9292
{
9393
Aggregates = DataUtil.PerformAggregation(DataSource, DataManagerRequest.Aggregates);
9494
}
95-
// Handling Paging in Custom Adaptor. For example, Skip is 0 and Take is equal to page size for first page.
95+
// Handling Paging in CustomAdaptor. For example, Skip is 0 and Take is equal to page size for first page.
9696
if (DataManagerRequest.Skip != 0)
9797
{
9898
//Paging
@@ -102,7 +102,7 @@
102102
{
103103
DataSource = DataOperations.PerformTake(DataSource, DataManagerRequest.Take);
104104
}
105-
// Handling Grouping in Custom Adaptor.
105+
// Handling Grouping in CustomAdaptor.
106106
DataResult DataObject = new DataResult();
107107
if (DataManagerRequest.Group != null)
108108
{
@@ -113,19 +113,19 @@
113113
ResultData = DataUtil.Group<Order>(ResultData, group, DataManagerRequest.Aggregates, 0, DataManagerRequest.GroupByFormatter);
114114
}
115115
DataObject.Result = ResultData;
116-
DataObject.Count = count;
116+
DataObject.Count = TotalRecordsCount;
117117
//If both Grouping and Aggregate is enabled
118118
if (DataManagerRequest.Aggregates != null)
119119
{
120120
DataObject.Aggregates = Aggregates;
121121
}
122-
//Here RequiresCount is passed from the control side itself, where ever the ondemand data fetching is needed then the RequiresCount is set as true in component side itself.
123-
// In the above case we are using Paging so datas are loaded in ondemand bases whenever the next page is clicked in DataGrid side.
122+
//Here RequiresCount is passed from the control side itself, where ever the on-demand data fetching is needed then the RequiresCount is set as true in component side itself.
123+
// In the above case we are using paging so datas are loaded in on-demand bases whenever the next page is clicked in DataGrid side.
124124
return DataManagerRequest.RequiresCounts ? DataObject : (object)ResultData;
125125
}
126-
//Here RequiresCount is passed from the control side itself, where ever the ondemand data fetching is needed then the RequiresCount is set as true in component side itself.
127-
// In the above case we are using Paging so datas are loaded in ondemand bases whenever the next page is clicked in DataGrid side.
128-
return DataManagerRequest.RequiresCounts ? new DataResult() { Result = DataSource, Count = count, Aggregates = Aggregates } : (object)DataSource;
126+
//Here RequiresCount is passed from the control side itself, where ever the on-demand data fetching is needed then the RequiresCount is set as true in component side itself.
127+
// In the above case we are using paging so datas are loaded in on-demand bases whenever the next page is clicked in DataGrid side.
128+
return DataManagerRequest.RequiresCounts ? new DataResult() { Result = DataSource, Count = TotalRecordsCount, Aggregates = Aggregates } : (object)DataSource;
129129
}
130130

131131
/// <summary>
@@ -170,6 +170,43 @@
170170
await OrderService.RemoveOrderAsync(Value as int?);
171171
return Value;
172172
}
173+
174+
/// <summary>
175+
/// /// Batchupdate (Insert, Update, Delete) a collection of data items from the data collection.
176+
/// </summary>
177+
/// <param name="DataManager">The DataManager is a data management component used for performing data operations in application.</param>
178+
/// <param name="Changed">The Changed specifies the collection of record updated in batch mode which needs to be updated from the grid record.</param>
179+
/// <param name="Added">The Added specifies the collection of record inserted in batch mode which needs to be inserted from the grid record.</param>
180+
/// <param name="Deleted">The Deleted specifies the collection of record deleted in batch mode which needs to be removed from the grid record.</param>
181+
/// <param name="KeyField">The KeyField specifies the field name of the primary column.</param>
182+
/// <param name="Key">An optional parameter that can be used to perform additional data operations.</param>
183+
/// <param name="DropIndex">An optional parameter that can be used to perform row drag and drop operation.</param>
184+
/// <returns>Returns the removed data item.</returns>
185+
public override async Task<object> BatchUpdateAsync(DataManager DataManager, object Changed, object Added, object Deleted, string KeyField, string Key, int? DropIndex)
186+
{
187+
if (Changed != null)
188+
{
189+
foreach (var record in (IEnumerable<Order>)Changed)
190+
{
191+
await OrderService.UpdateOrderAsync(record as Order);
192+
}
193+
}
194+
if (Added != null)
195+
{
196+
foreach (var record in (IEnumerable<Order>)Added)
197+
{
198+
await OrderService.AddOrderAsync(record as Order);
199+
}
200+
}
201+
if (Deleted != null)
202+
{
203+
foreach (var record in (IEnumerable<Order>)Deleted)
204+
{
205+
await OrderService.RemoveOrderAsync((record as Order).OrderID);
206+
}
207+
}
208+
return Key;
209+
}
173210
}
174211
}
175212

Binding MS SQL database using CustomAdaptor/Blazor Web app/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL/Data/OrderData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public async Task<List<Order>> GetOrdersAsync()
2121
Connection.Open();
2222
// Using SqlDataAdapter, process the query string and fill the data into the dataset
2323
Adapter.Fill(Data);
24-
//Cast the data fetched from Adapter to List<T>
24+
//Cast the data fetched from SqlDataAdapter to List<T>
2525
Orders = Data.Tables[0].AsEnumerable().Select(r => new Order
2626
{
2727
OrderID = r.Field<int>("OrderID"),

Binding MS SQL database using CustomAdaptor/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# blazor-grid-mssql-connectivity-using-custom-adaptor
1+
# Blazor Grid Microsoft SQL Server connectivity using CustomAdaptor
2+
23
A project that enables data binding and CRUD action handling in the Syncfusion Blazor DataGrid to a Microsoft SQL Server using CustomAdaptor feature of the Grid.
34

45
## Steps to run the sample

Binding MS SQL database using UrlAdaptor/Blazor WASM app/MyWebService/MyWebService/Controllers/GridController.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@ public class GridController : ControllerBase
2121
public object Post([FromBody] DataManagerRequest DataManagerRequest)
2222
{
2323
IEnumerable<Order> DataSource = GetOrderData();
24-
// Handling Searching in Url Adaptor.
24+
// Handling Searching in UrlAdaptor.
2525
if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0)
2626
{
2727
// Searching
2828
DataSource = DataOperations.PerformSearching(DataSource, DataManagerRequest.Search);
2929
}
30-
// Handling Filtering in Url Adaptor.
30+
// Handling Filtering in UrlAdaptor.
3131
if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0)
3232
{
3333
// Filtering
3434
DataSource = DataOperations.PerformFiltering(DataSource, DataManagerRequest.Where, DataManagerRequest.Where[0].Operator);
3535
}
36-
// Handling Sorting in Url Adaptor.
36+
// Handling Sorting in UrlAdaptor.
3737
if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0)
3838
{
3939
// Sorting
4040
DataSource = DataOperations.PerformSorting(DataSource, DataManagerRequest.Sorted);
4141
}
42-
int count = DataSource.Cast<Order>().Count();
43-
// Handling Aggregation in Url Adaptor.
42+
int TotalRecordsCount = DataSource.Cast<Order>().Count();
43+
// Handling Aggregation in UrlAdaptor.
4444
IDictionary<string, object> Aggregates = null;
4545
if (DataManagerRequest.Aggregates != null) // Aggregation
4646
{
4747
Aggregates = DataUtil.PerformAggregation(DataSource, DataManagerRequest.Aggregates);
4848
}
49-
// Handling Paging in Url Adaptor.
49+
// Handling Paging in UrlAdaptor.
5050
if (DataManagerRequest.Skip != 0)
5151
{
5252
// Paging
@@ -58,7 +58,7 @@ public object Post([FromBody] DataManagerRequest DataManagerRequest)
5858
}
5959
//Here RequiresCount is passed from the control side itself, where ever the ondemand data fetching is needed then the RequiresCount is set as true in component side itself.
6060
// In the above case we are using Paging so data are loaded in ondemand bases whenever the next page is clicked in DataGrid side.
61-
return new { result = DataSource, count = count, aggregates = Aggregates };
61+
return new { result = DataSource, count = TotalRecordsCount, aggregates = Aggregates };
6262
}
6363
[Route("api/[controller]")]
6464
public List<Order> GetOrderData()
@@ -76,7 +76,7 @@ public List<Order> GetOrderData()
7676
// Using SqlDataAdapter, process the query string and fill the data into the dataset
7777
DataAdapter.Fill(DataTable);
7878
sqlConnection.Close();
79-
//Cast the data fetched from Adaptor to List<T>
79+
//Cast the data fetched from SqlDataAdapter to List<T>
8080
var DataSource = (from DataRow Data in DataTable.Rows
8181
select new Order()
8282
{
@@ -162,7 +162,7 @@ public void Delete([FromBody] CRUDModel<Order> Value)
162162
[HttpPost]
163163
[Route("api/Grid/Batch")]
164164
/// <summary>
165-
/// Batch update (Insert, Update, Delete) a collection of data item from the data collection.
165+
/// Batch update (Insert, Update, Delete) a collection of data items from the data collection.
166166
/// </summary>
167167
/// <param name="CRUDModel<T>">The set of information along with details about the CRUD actions to be executed from the database.</param>
168168
/// <returns>Returns void</returns>
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
# blazor-grid-mssql-connectivity-using-url-adaptor
1+
# Blazor DataGrid Microsoft SQL Server connectivity using UrlAdaptor
2+
23
A project that enables data binding and CRUD action handling in the Syncfusion Blazor DataGrid to a Microsoft SQL Server using UrlAdaptor feature.
34

45
## Steps to run the sample
56

6-
1. Download or unzip the project
7+
1. Download or unzip the project
78

89
2. This project consist of two applications so open and run both MyWebService and GridWASM_MSSQL_UrlAdaptor projects in Visual Studio 2022
910

10-
2. Open ServerExplorer tab in Visual Studio of MyWebService project.
11+
3. Open ServerExplorer tab in Visual Studio of MyWebService project.
1112

12-
3. Add NORTHWND.MDF database located in the App_Data folder of MyWebService project into the application.
13+
4. Add NORTHWND.MDF database located in the App_Data folder of MyWebService project into the application.
1314

14-
4. Replace connected database's connectionstring in GridController.cs file in Controllers folder.
15+
5. Replace connected database's connectionstring in GridController.cs file in Controllers folder.
1516

16-
5. Run the application
17+
6. Run the application

Binding MS SQL database using UrlAdaptor/Blazor Web app/Grid_MSSQL/Grid_MSSQL/Grid_MSSQL/Controllers/GridController.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,32 @@ public class GridController : ControllerBase
2424
public object Post([FromBody] DataManagerRequest DataManagerRequest)
2525
{
2626
IEnumerable<Order> DataSource = GetOrderData();
27-
// Handling Searching in Url Adaptor.
27+
// Handling Searching in UrlAdaptor.
2828
if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0)
2929
{
3030
// Searching
3131
DataSource = DataOperations.PerformSearching(DataSource, DataManagerRequest.Search);
3232
}
33-
// Handling Filtering in Url Adaptor.
33+
// Handling Filtering in UrlAdaptor.
3434
if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0)
3535
{
3636
// Filtering
3737
DataSource = DataOperations.PerformFiltering(DataSource, DataManagerRequest.Where, DataManagerRequest.Where[0].Operator);
3838
}
39-
// Handling Sorting in Url Adaptor.
39+
// Handling Sorting in UrlAdaptor.
4040
if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0)
4141
{
4242
// Sorting
4343
DataSource = DataOperations.PerformSorting(DataSource, DataManagerRequest.Sorted);
4444
}
45-
int count = DataSource.Cast<Order>().Count();
46-
// Handling Aggregation in Url Adaptor.
45+
int TotalRecordsCount = DataSource.Cast<Order>().Count();
46+
// Handling Aggregation in UrlAdaptor.
4747
IDictionary<string, object> Aggregates = null;
4848
if (DataManagerRequest.Aggregates != null) // Aggregation
4949
{
5050
Aggregates = DataUtil.PerformAggregation(DataSource, DataManagerRequest.Aggregates);
5151
}
52-
// Handling paging in Url Adaptor.
52+
// Handling paging in UrlAdaptor.
5353
if (DataManagerRequest.Skip != 0)
5454
{
5555
// Paging
@@ -61,7 +61,7 @@ public object Post([FromBody] DataManagerRequest DataManagerRequest)
6161
}
6262
//Here RequiresCount is passed from the control side itself, where ever the ondemand data fetching is needed then the RequiresCount is set as true in component side itself.
6363
// In the above case we are using Paging so data are loaded in ondemand bases whenever the next page is clicked in DataGrid side.
64-
return new { result = DataSource, count = count };
64+
return new { result = DataSource, count = TotalRecordsCount };
6565
}
6666
[Route("api/[controller]")]
6767
public List<Order> GetOrderData()
@@ -77,7 +77,7 @@ public List<Order> GetOrderData()
7777
// Using SqlDataAdapter, process the query string and fill the data into the dataset
7878
DataAdapter.Fill(DataTable);
7979
sqlConnection.Close();
80-
//Cast the data fetched from Adaptor to List<T>
80+
//Cast the data fetched from SqlDataAdapter to List<T>
8181
var DataSource = (from DataRow Data in DataTable.Rows
8282
select new Order()
8383
{
@@ -153,7 +153,7 @@ public void Delete([FromBody] CRUDModel<Order> Value)
153153
[HttpPost]
154154
[Route("api/Grid/Batch")]
155155
/// <summary>
156-
/// Batch update (Insert, Update, Delete) a collection of data item from the data collection.
156+
/// Batch update (Insert, Update, Delete) a collection of data items from the data collection.
157157
/// </summary>
158158
/// <param name="CRUDModel<T>">The set of information along with details about the CRUD actions to be executed from the database.</param>
159159
/// <returns>Returns void</returns>

Binding MS SQL database using UrlAdaptor/Blazor Web app/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# blazor-grid-mssql-connectivity-using-url-adaptor
1+
# Blazor DataGrid Microsoft SQL Server connectivity using UrlAdaptor
2+
23
A project that enables data binding and CRUD action handling in the Syncfusion Blazor DataGrid to a Microsoft SQL Server using UrlAdaptor feature.
34

45
## Steps to run the sample
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34525.116
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grid_MySQL", "Grid_MySQL\Grid_MySQL\Grid_MySQL.csproj", "{ADBACDFB-124F-4938-AABB-6AC1BA645F72}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grid_MySQL.Client", "Grid_MySQL\Grid_MySQL.Client\Grid_MySQL.Client.csproj", "{F11A0E8A-139E-4EC4-89B5-4477D0F0DDBC}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{ADBACDFB-124F-4938-AABB-6AC1BA645F72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{ADBACDFB-124F-4938-AABB-6AC1BA645F72}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{ADBACDFB-124F-4938-AABB-6AC1BA645F72}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{ADBACDFB-124F-4938-AABB-6AC1BA645F72}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{F11A0E8A-139E-4EC4-89B5-4477D0F0DDBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{F11A0E8A-139E-4EC4-89B5-4477D0F0DDBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{F11A0E8A-139E-4EC4-89B5-4477D0F0DDBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{F11A0E8A-139E-4EC4-89B5-4477D0F0DDBC}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {DB5C8E3B-2684-4F7E-931C-7726F7F5A388}
30+
EndGlobalSection
31+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
8+
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.1" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@page "/counter"
2+
@rendermode InteractiveAuto
3+
4+
<PageTitle>Counter</PageTitle>
5+
6+
<h1>Counter</h1>
7+
8+
<p role="status">Current count: @currentCount</p>
9+
10+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
11+
12+
@code {
13+
private int currentCount = 0;
14+
15+
private void IncrementCount()
16+
{
17+
currentCount++;
18+
}
19+
}

0 commit comments

Comments
 (0)