Modules/EDMI_ClientSuite/UserManager/UserControlAssignment.vb
2019-02-19 16:58:01 +01:00

75 lines
3.3 KiB
VB.net

Imports DevExpress.XtraGrid.Views.Base
Public Class UserControlAssignment
Public Property TextParentList As String
Public Property TextAssignedToParent As String
Public Property TextNotAssignedToParent As String
Private _DragDropManager As ClassDragDrop
Private _ParentIdColumn As String
Private _ChildIdColumn As String
Private _ParentList As DataTable
Private _ChildList As DataTable
Private _AssignmentList As DataTable
Private Sub UserControlAssignment_Load(sender As Object, e As EventArgs) Handles Me.Load
_DragDropManager = New ClassDragDrop()
_DragDropManager.AddGridView(ViewAssignedToParent)
_DragDropManager.AddGridView(ViewNotAssignedToParent)
' Load text customizations
labelAssignedToParent.Text = TextAssignedToParent
labelNotAssignedToParent.Text = TextNotAssignedToParent
labelParentList.Text = TextParentList
' Load grid customizations
GridParentList = ClassUIUtils.ConfigureGridControlDefaults(GridParentList, [ReadOnly]:=True)
GridNotAssignedToParent = ClassUIUtils.ConfigureGridControlDefaults(GridNotAssignedToParent, [ReadOnly]:=True)
GridAssignedToParent = ClassUIUtils.ConfigureGridControlDefaults(GridAssignedToParent, [ReadOnly]:=True)
AddHandler ViewParentList.FocusedRowChanged, AddressOf ViewParentList_FocusedRowChanged
End Sub
Private Sub ViewParentList_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs)
Dim oRowHandle = e.FocusedRowHandle
Dim oParentRecordId = ViewParentList.GetRowCellValue(oRowHandle, ClassConstants.ATTRIBUTE_ID_COLUMN)
Dim oAssignedChildIds = From oRow In _AssignmentList.AsEnumerable()
Where oRow.Item(_ParentIdColumn) = oParentRecordId
Select oRow.Item(_ChildIdColumn)
Dim oAssignedChildren As EnumerableRowCollection(Of DataRow) = From oRow In _ChildList.AsEnumerable()
Where oAssignedChildIds.Contains(oRow.Item(ClassConstants.ATTRIBUTE_ID_COLUMN))
Dim oNotAssignedChildren As EnumerableRowCollection(Of DataRow) = From oRow In _ChildList.AsEnumerable()
Where Not oAssignedChildIds.Contains(oRow.Item(ClassConstants.ATTRIBUTE_ID_COLUMN))
GridAssignedToParent.DataSource = MaybeCopyToDataTable(oAssignedChildren)
GridNotAssignedToParent.DataSource = MaybeCopyToDataTable(oNotAssignedChildren)
End Sub
Private Function MaybeCopyToDataTable(RowCollection As EnumerableRowCollection(Of DataRow)) As DataTable
If RowCollection.Count > 0 Then
Return RowCollection.CopyToDataTable()
Else
Return New DataTable()
End If
End Function
Public Sub Init(ParentList As DataTable, ChildrenList As DataTable, AssignmentList As DataTable, ParentIdColumn As String, ChildIdColumn As String)
_ParentList = ParentList
_ChildList = ChildrenList
_AssignmentList = AssignmentList
_ParentIdColumn = ParentIdColumn
_ChildIdColumn = ChildIdColumn
' This will trigger FocusedRowChanged, needs to be last!!
GridParentList.DataSource = ParentList
End Sub
End Class