dxstanley
/
treelist-how-to-load-data-from-a-database-in-virtual-mode-and-implement-drag-and-drop-e4837
Public
forked from DevExpress-Examples/asp-net-mvc-treelist-virtual-mode-and-drag-and-drop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreeListVirtualModeHelper.vb
62 lines (57 loc) · 2.1 KB
/
TreeListVirtualModeHelper.vb
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
Imports Microsoft.VisualBasic
Imports DevExpress.Web.ASPxTreeList
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Web
Namespace Q515371.Models
Public Class TreeListVirtualModeHelper
' Fields...
Private Shared nwd As New NorthwindDataContext()
Public Shared Sub VirtualModeCreateChildren(ByVal e As TreeListVirtualModeCreateChildrenEventArgs)
Dim parentEmployee As Employee = TryCast(e.NodeObject, Employee)
If parentEmployee Is Nothing Then
e.Children = nwd.Employees.Where(Function(empl) empl.ReportsTo Is Nothing).ToList()
Else
e.Children = ( _
From empl In nwd.Employees _
Where empl.ReportsTo.Equals(parentEmployee.EmployeeID) _
Select empl).ToList()
End If
End Sub
Public Shared Sub VirtualModeNodeCreating(ByVal e As TreeListVirtualModeNodeCreatingEventArgs)
Dim empl As Employee = TryCast(e.NodeObject, Employee)
If empl Is Nothing Then
Return
End If
e.NodeKeyValue = empl.EmployeeID
Dim childEmployeeCount As Integer = nwd.Employees.Where(Function(x) x.ReportsTo.Equals(empl.EmployeeID)).ToList().Count
e.IsLeaf = Not(childEmployeeCount > 0)
e.SetNodeValue("FirstName", empl.FirstName)
e.SetNodeValue("LastName", empl.LastName)
e.SetNodeValue("Address", empl.Address)
e.SetNodeValue("City", empl.City)
e.SetNodeValue("HireDate", empl.HireDate)
e.SetNodeValue("BirthDate", empl.BirthDate)
e.SetNodeValue("ReportsTo", empl.ReportsTo)
e.SetNodeValue("Title", empl.Title)
End Sub
Public Shared Sub MoveNode(ByVal EmployeeID As Integer, ByVal ReportsTo? As Integer)
Dim newParentID As Integer = Convert.ToInt32(ReportsTo)
Dim empl As Employee = GetEmployee(EmployeeID)
If empl.EmployeeID = newParentID Then
Return
End If
If newParentID = 0 Then
empl.ReportsTo = Nothing
Else
empl.ReportsTo = newParentID
End If
nwd.SubmitChanges()
End Sub
Private Shared Function GetEmployee(ByVal EmployeeID As Integer) As Employee
Return nwd.Employees.Where(Function(x) x.EmployeeID = EmployeeID).FirstOrDefault()
End Function
End Class
End Namespace