Mini Kabibi Habibi
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.ServiceModel.DomainServices.Client
Imports System.Windows
Imports DevExpress.Xpf.DemoBase.Web
Imports DevExpress.Xpf.DemoBase.Web.Services
Namespace GridDemo
Partial Public Class RIAServices
Inherits GridDemoModule
Private domainContext As New NWindDomainContext()
Public Sub New()
InitializeComponent()
DataContext = domainContext
LoadDataSource()
End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
LoadDataSource()
End Sub
Private Sub LoadDataSource()
grid.Columns.Clear()
grid.ItemsSource = SelectSource(TryCast(listBoxEdit.EditValue, String))
End Sub
Private Function SelectSource(ByVal tableName As String) As IEnumerable
Select Case tableName
Case "Invoices"
Return GetSource(Of Invoices)(Function() domainContext.GetInvoicesQuery())
Case "Customers"
Return GetSource(Of Customers)(Function() domainContext.GetCustomersQuery())
Case "Employees"
Return GetSource(Of Employees)(Function() domainContext.GetEmployeesQuery())
Case "Products"
Return GetSource(Of Products)(Function() domainContext.GetProductsQuery())
Case Else
Throw New NotImplementedException()
End Select
End Function
Private Function GetSource(Of T As Entity)(ByVal getQuery As Func(Of EntityQuery(Of T))) As IEnumerable
Dim loadOperation As LoadOperation(Of T) = domainContext.Load(Of T)(getQuery(), New Action(Of LoadOperation(Of T))(AddressOf OnCompleted), Nothing)
Return loadOperation.Entities
End Function
Private Sub OnCompleted(ByVal op As LoadOperation)
If op.HasError Then
MessageBox.Show("Connection could not be established." & Environment.NewLine & op.Error.Message, "Connection Error", MessageBoxButton.OK)
op.MarkErrorAsHandled()
End If
End Sub
End Class
End Namespace