Reconfigure for GIT
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
' Developer Express Code Central Example:
|
||||
' How to populate a List View with data from a LINQ query
|
||||
'
|
||||
' See the http://www.devexpress.com/scid=K18107 KB Article for more information.
|
||||
'
|
||||
' You can find sample updates and versions for different programming languages here:
|
||||
' http://www.devexpress.com/example=E859
|
||||
|
||||
' Developer Express Code Central Example:
|
||||
' How to populate the list view with data from a LINQ query
|
||||
'
|
||||
' See the http://www.devexpress.com/scid=K18107 KB Article for more information.
|
||||
'
|
||||
' You can find sample updates and versions for different programming languages here:
|
||||
' http://www.devexpress.com/example=E859
|
||||
|
||||
|
||||
Imports Microsoft.VisualBasic
|
||||
Imports System
|
||||
Imports DevExpress.ExpressApp
|
||||
Imports DevExpress.ExpressApp.SystemModule
|
||||
|
||||
Namespace Dennis.Linq
|
||||
Public Class DisableActionsLinqListViewController
|
||||
Inherits ViewController
|
||||
Private Const DefaultReason As String = "LinqListViewController is active"
|
||||
Protected Overloads Overrides Sub OnActivated()
|
||||
MyBase.OnActivated()
|
||||
Dim flag As Boolean = Not View.Id.EndsWith(LinqCollectionSource.DefaultSuffix)
|
||||
Frame.GetController(Of ListViewProcessCurrentObjectController)().Active(DefaultReason) = flag
|
||||
Frame.GetController(Of DeleteObjectsViewController)().Active(DefaultReason) = flag
|
||||
Frame.GetController(Of NewObjectViewController)().Active(DefaultReason) = flag
|
||||
Frame.GetController(Of FilterController)().Active(DefaultReason) = flag
|
||||
End Sub
|
||||
Protected Overloads Overrides Sub OnDeactivated()
|
||||
MyBase.OnDeactivated()
|
||||
Frame.GetController(Of ListViewProcessCurrentObjectController)().Active.RemoveItem(DefaultReason)
|
||||
Frame.GetController(Of DeleteObjectsViewController)().Active.RemoveItem(DefaultReason)
|
||||
Frame.GetController(Of NewObjectViewController)().Active.RemoveItem(DefaultReason)
|
||||
Frame.GetController(Of FilterController)().Active.RemoveItem(DefaultReason)
|
||||
End Sub
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,5 @@
|
||||
Imports DevExpress.ExpressApp.Model
|
||||
Public Interface IModelListViewLinq
|
||||
Inherits IModelNode
|
||||
Property XPQueryMethod() As String
|
||||
End Interface
|
||||
@@ -0,0 +1,77 @@
|
||||
' Developer Express Code Central Example:
|
||||
' How to populate a List View with data from a LINQ query
|
||||
'
|
||||
' See the http://www.devexpress.com/scid=K18107 KB Article for more information.
|
||||
'
|
||||
' You can find sample updates and versions for different programming languages here:
|
||||
' http://www.devexpress.com/example=E859
|
||||
|
||||
' Developer Express Code Central Example:
|
||||
' How to populate the list view with data from a LINQ query
|
||||
'
|
||||
' See the http://www.devexpress.com/scid=K18107 KB Article for more information.
|
||||
'
|
||||
' You can find sample updates and versions for different programming languages here:
|
||||
' http://www.devexpress.com/example=E859
|
||||
|
||||
|
||||
Imports Microsoft.VisualBasic
|
||||
Imports System
|
||||
Imports System.Linq
|
||||
Imports DevExpress.Xpo
|
||||
Imports System.Collections
|
||||
Imports System.ComponentModel
|
||||
Imports DevExpress.ExpressApp
|
||||
Imports DevExpress.ExpressApp.DC
|
||||
Imports DevExpress.Data.Filtering
|
||||
Imports DevExpress.ExpressApp.Xpo
|
||||
|
||||
Namespace Dennis.Linq
|
||||
Public Class LinqCollectionSource
|
||||
Inherits CollectionSourceBase
|
||||
Public Const DefaultSuffix As String = "_Linq"
|
||||
Private collectionCore As IBindingList
|
||||
Private objectTypeInfoCore As ITypeInfo
|
||||
Public Function ConvertQueryToCollection(ByVal sourceQuery As IQueryable) As IList
|
||||
collectionCore = New BindingList(Of Object)()
|
||||
For Each item In sourceQuery
|
||||
collectionCore.Add(item)
|
||||
Next item
|
||||
Return collectionCore
|
||||
End Function
|
||||
Private queryCore As IQueryable = Nothing
|
||||
Protected Sub New(ByVal objectSpace As IObjectSpace, ByVal mode As CollectionSourceMode)
|
||||
MyBase.New(objectSpace, mode)
|
||||
End Sub
|
||||
Protected Sub New(ByVal objectSpace As IObjectSpace)
|
||||
MyBase.New(objectSpace)
|
||||
End Sub
|
||||
Public Sub New(ByVal objectSpace As IObjectSpace, ByVal objectType As Type, ByVal query As IQueryable)
|
||||
MyBase.New(objectSpace)
|
||||
objectTypeInfoCore = XafTypesInfo.Instance.FindTypeInfo(objectType)
|
||||
queryCore = query
|
||||
End Sub
|
||||
Public Property Query() As IQueryable
|
||||
Get
|
||||
Return queryCore
|
||||
End Get
|
||||
Set(ByVal value As IQueryable)
|
||||
queryCore = value
|
||||
End Set
|
||||
End Property
|
||||
Protected Overrides Function CreateCollection() As Object
|
||||
CType(Query, XPQueryBase).Session = TryCast(ObjectSpace, XPObjectSpace).Session
|
||||
Return ConvertQueryToCollection(Query)
|
||||
End Function
|
||||
Public Overrides Function IsObjectFitForCollection(ByVal obj As Object) As Boolean?
|
||||
Return collectionCore.Contains(obj)
|
||||
End Function
|
||||
Protected Overrides Sub ApplyCriteriaCore(ByVal criteria As CriteriaOperator)
|
||||
End Sub
|
||||
Public Overrides ReadOnly Property ObjectTypeInfo() As ITypeInfo
|
||||
Get
|
||||
Return objectTypeInfoCore
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,109 @@
|
||||
' Developer Express Code Central Example:
|
||||
' How to populate a List View with data from a LINQ query
|
||||
'
|
||||
' See the http://www.devexpress.com/scid=K18107 KB Article for more information.
|
||||
'
|
||||
' You can find sample updates and versions for different programming languages here:
|
||||
' http://www.devexpress.com/example=E859
|
||||
|
||||
' Developer Express Code Central Example:
|
||||
' How to populate the list view with data from a LINQ query
|
||||
'
|
||||
' See the http://www.devexpress.com/scid=K18107 KB Article for more information.
|
||||
'
|
||||
' You can find sample updates and versions for different programming languages here:
|
||||
' http://www.devexpress.com/example=E859
|
||||
|
||||
|
||||
Imports Microsoft.VisualBasic
|
||||
Imports System
|
||||
Imports System.Linq
|
||||
Imports DevExpress.Xpo
|
||||
Imports System.Reflection
|
||||
Imports DevExpress.ExpressApp
|
||||
Imports System.Collections.Generic
|
||||
Imports SISBusiness.Module.Dennis.Linq
|
||||
|
||||
|
||||
Public NotInheritable Class LinqCollectionSourceHelper
|
||||
Private Sub New()
|
||||
End Sub
|
||||
Public Shared Sub CreateCustomCollectionSource(ByVal sender As Object, ByVal e As CreateCustomCollectionSourceEventArgs)
|
||||
Dim listViewInfo As IModelListViewLinq = TryCast((CType(sender, XafApplication)).FindModelView(e.ListViewID), IModelListViewLinq)
|
||||
If listViewInfo Is Nothing Then
|
||||
Return
|
||||
End If
|
||||
If String.IsNullOrEmpty(listViewInfo.XPQueryMethod) Then
|
||||
Return
|
||||
End If
|
||||
Dim query As IQueryable = LinqCollectionSourceHelper.InvokeMethod(e.ObjectType, listViewInfo.XPQueryMethod, (CType(e.ObjectSpace, Xpo.XPObjectSpace)).Session)
|
||||
If query Is Nothing Then
|
||||
Return
|
||||
End If
|
||||
e.CollectionSource = New LinqCollectionSource(e.ObjectSpace, e.ObjectType, query)
|
||||
End Sub
|
||||
Public Shared Function GetXPQueryMethods(ByVal type As Type) As String()
|
||||
Dim names As New List(Of String)()
|
||||
Dim methods() As MethodInfo = type.GetMethods(System.Reflection.BindingFlags.Public Or System.Reflection.BindingFlags.Static)
|
||||
For Each mi As MethodInfo In methods
|
||||
If IsCompatibleMethod(mi) Then
|
||||
names.Add(mi.Name)
|
||||
End If
|
||||
Next mi
|
||||
Return names.ToArray()
|
||||
End Function
|
||||
Public Shared Function IsCompatibleMethod(ByVal mi As MethodInfo) As Boolean
|
||||
Dim pis() As ParameterInfo = mi.GetParameters()
|
||||
Return mi.ReturnType IsNot Nothing AndAlso GetType(IQueryable).IsAssignableFrom(mi.ReturnType) AndAlso pis.Length = 1 AndAlso pis(0).ParameterType.IsAssignableFrom(GetType(Session))
|
||||
End Function
|
||||
Public Shared Function InvokeMethod(ByVal type As Type, ByVal name As String, ByVal session As Session) As IQueryable
|
||||
Dim method As MethodInfo = FindMethod(type, name)
|
||||
If method Is Nothing Then
|
||||
Return Nothing
|
||||
End If
|
||||
Return CType(method.Invoke(Nothing, New Object() {session}), IQueryable)
|
||||
End Function
|
||||
Private Shared Function FindMethod(ByVal type As Type, ByVal name As String) As MethodInfo
|
||||
Dim methods() As MethodInfo = type.GetMethods(System.Reflection.BindingFlags.Public Or System.Reflection.BindingFlags.Static)
|
||||
For Each mi As MethodInfo In methods
|
||||
If mi.Name = name AndAlso IsCompatibleMethod(mi) Then
|
||||
Return mi
|
||||
End If
|
||||
Next mi
|
||||
Return Nothing
|
||||
End Function
|
||||
Public Shared Function GetDisplayableProperties(ByVal type As Type, ByVal name As String) As String()
|
||||
Dim method As MethodInfo = FindMethod(type, name)
|
||||
If method Is Nothing Then
|
||||
Return Nothing
|
||||
End If
|
||||
For Each attribute As CustomQueryPropertiesAttribute In method.GetCustomAttributes(GetType(CustomQueryPropertiesAttribute), False)
|
||||
If attribute.Name = "DisplayableProperties" Then
|
||||
Return attribute.Value.Split(";"c)
|
||||
End If
|
||||
Next attribute
|
||||
Return Nothing
|
||||
End Function
|
||||
End Class
|
||||
<AttributeUsage(AttributeTargets.Method)> _
|
||||
Public NotInheritable Class CustomQueryPropertiesAttribute
|
||||
Inherits Attribute
|
||||
Private theName As String
|
||||
Private theValue As String
|
||||
Public ReadOnly Property Name() As String
|
||||
Get
|
||||
Return theName
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property Value() As String
|
||||
Get
|
||||
Return theValue
|
||||
End Get
|
||||
End Property
|
||||
Public Sub New(ByVal theName As String, ByVal theValue As String)
|
||||
Me.theName = theName
|
||||
Me.theValue = theValue
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
Imports DevExpress.ExpressApp.Model
|
||||
Imports DevExpress.ExpressApp.Model.Core
|
||||
Imports DevExpress.ExpressApp.Model.NodeGenerators
|
||||
|
||||
Public Class ModelListViewLinqColumnsNodesGeneratorUpdater
|
||||
Inherits ModelNodesGeneratorUpdater(Of ModelListViewColumnsNodesGenerator)
|
||||
Public Overrides Sub UpdateNode(ByVal node As ModelNode)
|
||||
Dim linqViewInfo As IModelListViewLinq = TryCast(node.Parent, IModelListViewLinq)
|
||||
If linqViewInfo IsNot Nothing AndAlso (Not String.IsNullOrEmpty(linqViewInfo.XPQueryMethod)) Then
|
||||
Dim listViewInfo As IModelListView = CType(linqViewInfo, IModelListView)
|
||||
Dim columns() As String = LinqCollectionSourceHelper.GetDisplayableProperties(listViewInfo.ModelClass.TypeInfo.Type, linqViewInfo.XPQueryMethod)
|
||||
If columns IsNot Nothing Then
|
||||
If listViewInfo.Columns Is Nothing Then
|
||||
listViewInfo.AddNode(Of IModelColumns)("Columns")
|
||||
End If
|
||||
Dim i As Integer = listViewInfo.Columns.Count
|
||||
Do While i > 0
|
||||
i -= 1
|
||||
Dim col As IModelColumn = listViewInfo.Columns.Item(i)
|
||||
If Array.IndexOf(columns, col.Id) < 0 Then
|
||||
'listViewInfo.Columns.Remove(col)
|
||||
End If
|
||||
Loop
|
||||
For Each column As String In columns
|
||||
Dim col As IModelColumn = listViewInfo.Columns.GetNode(column)
|
||||
If col Is Nothing Then
|
||||
col = listViewInfo.Columns.AddNode(Of IModelColumn)(column)
|
||||
col.PropertyName = column
|
||||
End If
|
||||
Next column
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
End Class
|
||||
@@ -0,0 +1,27 @@
|
||||
Imports DevExpress.ExpressApp.Model
|
||||
Imports DevExpress.ExpressApp.Model.Core
|
||||
Imports DevExpress.ExpressApp.Model.NodeGenerators
|
||||
Imports SISBusiness.Module.Dennis.Linq
|
||||
|
||||
Public Class ModelListViewLinqNodesGeneratorUpdater
|
||||
Inherits ModelNodesGeneratorUpdater(Of ModelViewsNodesGenerator)
|
||||
Public Overrides Sub UpdateNode(ByVal node As ModelNode)
|
||||
For Each classInfo As IModelClass In node.Application.BOModel
|
||||
If classInfo.TypeInfo.IsPersistent Then
|
||||
If (Not String.IsNullOrEmpty(classInfo.Name)) Then
|
||||
For Each method As String In LinqCollectionSourceHelper.GetXPQueryMethods(classInfo.TypeInfo.Type)
|
||||
Dim id As String = String.Format("{0}_{1}{2}", ModelListViewNodesGenerator.GetListViewId(classInfo.TypeInfo.Type), method, LinqCollectionSource.DefaultSuffix)
|
||||
Dim listViewInfo As IModelListView = node.Application.Views.GetNode(id)
|
||||
If listViewInfo Is Nothing Then
|
||||
listViewInfo = node.AddNode(Of IModelListView)(id)
|
||||
End If
|
||||
listViewInfo.ModelClass = classInfo
|
||||
If TryCast(listViewInfo, IModelListViewLinq) IsNot Nothing Then
|
||||
CType(listViewInfo, IModelListViewLinq).XPQueryMethod = method
|
||||
End If
|
||||
Next method
|
||||
End If
|
||||
End If
|
||||
Next classInfo
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user