-
Notifications
You must be signed in to change notification settings - Fork 6
/
MainWindow.xaml.vb
58 lines (52 loc) · 2.59 KB
/
MainWindow.xaml.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
Imports XPOIssues.Issues
Imports DevExpress.Data.Filtering
Imports DevExpress.Xpo
Imports System.Linq
Imports DevExpress.Xpf.Grid
Imports DevExpress.Mvvm.Xpf
Imports System
Imports System.Collections
Class MainWindow
Public Sub New()
InitializeComponent()
Dim properties = New ServerViewProperty() {
New ServerViewProperty("Subject", SortDirection.None, New OperandProperty("Subject")),
New ServerViewProperty("UserId", SortDirection.None, New OperandProperty("UserId")),
New ServerViewProperty("Created", SortDirection.None, New OperandProperty("Created")),
New ServerViewProperty("Votes", SortDirection.None, New OperandProperty("Votes")),
New ServerViewProperty("Priority", SortDirection.None, New OperandProperty("Priority")),
New ServerViewProperty("Oid", SortDirection.Ascending, New OperandProperty("Oid"))
}
Dim source = New XPInstantFeedbackView(GetType(Issue), properties, Nothing)
AddHandler source.ResolveSession, Sub(o, e) e.Session = New Session()
grid.ItemsSource = source
LoadLookupData()
End Sub
Private Sub LoadLookupData()
Dim session = New Session()
usersLookup.ItemsSource = session.Query(Of User).OrderBy(Function(user) user.Oid).[Select](Function(user) New With {
.Id = user.Oid,
.Name = user.FirstName & " " + user.LastName
}).ToArray()
End Sub
Private Sub OnDataSourceRefresh(ByVal sender As Object, ByVal e As DataSourceRefreshEventArgs)
LoadLookupData()
End Sub
Private Sub OnCreateEditEntityViewModel(ByVal sender As Object, ByVal e As CreateEditItemViewModelArgs)
Dim unitOfWork = New UnitOfWork()
Dim item = If(e.IsNewItem, New Issue(unitOfWork), unitOfWork.GetObjectByKey(Of Issue)(e.Key))
e.ViewModel = New EditItemViewModel(item, New EditIssueInfo(unitOfWork, CType(usersLookup.ItemsSource, IList)), dispose:=Sub() unitOfWork.Dispose(), title:=If(e.IsNewItem, "New ", "Edit ") & NameOf(Issue))
End Sub
Private Sub OnValidateRow(ByVal sender As Object, ByVal e As EditFormRowValidationArgs)
Dim unitOfWork = CType(e.EditOperationContext, EditIssueInfo).UnitOfWork
unitOfWork.CommitChanges()
End Sub
Private Sub OnValidateRowDeletion(ByVal sender As Object, ByVal e As EditFormValidateRowDeletionArgs)
Using unitOfWork = New UnitOfWork()
Dim key = CInt(e.Keys.[Single]())
Dim item = unitOfWork.GetObjectByKey(Of Issue)(key)
unitOfWork.Delete(item)
unitOfWork.CommitChanges()
End Using
End Sub
End Class