-
Notifications
You must be signed in to change notification settings - Fork 0
/
DirWindow.vb
297 lines (208 loc) · 8.93 KB
/
DirWindow.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
''' <summary>Shows the UMSWEB Directory</summary>
Public Class DirWindow
'--------------------------------[Variables]--------------------------------
''' <summary>Mode of this directory window</summary>
Private ReadOnly mode As DirectoryMode
''' <summary>Different modes for the directory window</summary>
Public Enum DirectoryMode As Integer
Login
SendMoney
Checkbook
End Enum
Private DirectoryArray() As String
Private ServerMSG As String
Public Commit As Boolean = False
Public MyReturn As String = ""
''' <summary>Structure to hold directory items</summary>
Public Structure DirectoryItem
Public ID As String
Public Name As String
Public Category As Integer
End Structure
Public DirectoryUsers() As DirectoryItem
'--------------------------------[Initialization]--------------------------------
Public Sub New(Mode As DirectoryMode)
InitializeComponent()
Me.mode = Mode
End Sub
Private Sub LoadingTime() Handles Me.Load
Select Case mode
Case DirectoryMode.Login
BankGroupBox.Enabled = False
SelectButton.Visible = False
OKButton.Visible = True
CheckbookOK.Visible = False
Case DirectoryMode.SendMoney
BankGroupBox.Enabled = True
SelectButton.Visible = True
OKButton.Visible = False
CheckbookOK.Visible = False
Case DirectoryMode.Checkbook
BankGroupBox.Enabled = False
SelectButton.Visible = False
OKButton.Visible = False
CheckbookOK.Visible = True
End Select
LoadingLabel.Text = "Loading..."
DirectoryView.Items.Clear()
DirectoryView.Visible = False
End Sub
Private Sub Showtime() Handles Me.Shown
RefreshNotice.Show()
BackgroundWorker1.RunWorkerAsync()
End Sub
'--------------------------------[Buttons]--------------------------------
''' <summary>Handles the OK action during Login Mode</summary>
Private Sub ViBELoginOK() Handles OKButton.Click
If HasUserSelected() Then
Commit = True
MyReturn = DirectoryView.SelectedItems(0).Text
Close()
End If
End Sub
''' <summary>Handles the OK action during SendMoney Mode</summary>
Private Sub SendMonetOK() Handles SelectButton.Click
If HasUserSelected() Then
Dim Bank As String = "NO"
If UMSNBRButton.Checked Then Bank = "UMSNB"
If GBANKRButton.Checked Then Bank = "GBANK"
If RIVERRButton.Checked Then Bank = "RIVER"
If Bank = "NO" Then
MsgBox("Please select a destination bank", vbCritical, "ViBE")
Exit Sub
End If
Commit = True
MyReturn = DirectoryView.SelectedItems(0).Text & "\" & Bank
Close()
End If
End Sub
''' <summary>Handles the OK action during Checkbook Mode</summary>
Private Sub CheckbookOK_Click() Handles CheckbookOK.Click
If HasUserSelected() Then
Commit = True
''57174: Igtampe
MyReturn = DirectoryView.SelectedItems(0).Text & ":" & DirectoryView.SelectedItems(0).SubItems(1).Text
Close()
End If
End Sub
Private Sub Nevermind() Handles NoNoButton.Click
Close()
End Sub
''' <summary>If we're in sendmoney mode, this directory window will grab the info of the selected user</summary>
Private Sub HeDidAClick() Handles DirectoryView.SelectedIndexChanged
Dim Selectedindex As Integer
Try
Selectedindex = DirectoryView.SelectedIndices(0)
Catch
Exit Sub
End Try
If mode = DirectoryMode.SendMoney Then
UMSNBRButton.Enabled = False
GBANKRButton.Enabled = False
RIVERRButton.Enabled = False
SelectButton.Enabled = False
NoNoButton.Enabled = False
DirectoryView.Enabled = False
SearchBox.Enabled = False
Dim INFO() As String
INFO = CoreCommands.UserInfo(DirectoryView.SelectedItems(0).Text).Split(",")
If INFO(0) = 1 Then UMSNBRButton.Enabled = True Else UMSNBRButton.Enabled = False
If INFO(2) = 1 Then GBANKRButton.Enabled = True Else GBANKRButton.Enabled = False
If INFO(4) = 1 Then RIVERRButton.Enabled = True Else RIVERRButton.Enabled = False
SelectButton.Enabled = True
NoNoButton.Enabled = True
DirectoryView.Enabled = True
SearchBox.Enabled = True
End If
End Sub
'--------------------------------[Background Worker]--------------------------------
''' <summary>Gets the directory from the server</summary>
Private Sub GetDirBW() Handles BackgroundWorker1.DoWork
ServerMSG = GetDirectory()
DirectoryArray = ServerMSG.Split(",")
Dim N As Integer
Dim StringProcessor() As String
ReDim DirectoryUsers(DirectoryArray.Count - 1)
For N = 0 To DirectoryArray.Count - 1
StringProcessor = DirectoryArray(N).Split(":")
DirectoryUsers(N).ID = StringProcessor(0)
DirectoryUsers(N).Name = StringProcessor(1)
If DirectoryUsers(N).Name.EndsWith(" (Corp.)") Then
DirectoryUsers(N).Name = DirectoryUsers(N).Name.Replace(" (Corp.)", "")
DirectoryUsers(N).Category = 1
ElseIf DirectoryUsers(N).Name.EndsWith(" (Gov.)") Then
DirectoryUsers(N).Name = DirectoryUsers(N).Name.Replace(" (Gov.)", "")
DirectoryUsers(N).Category = 2
Else
DirectoryUsers(N).Category = 0
End If
Next
End Sub
''' <summary>Populates the listview and prepares the form for presentation</summary>
Private Sub DoneGettingDir() Handles BackgroundWorker1.RunWorkerCompleted
RefreshNotice.Close()
PopulateListview()
DirectoryView.Visible = True
LoadingLabel.Text = DirectoryArray.Count & " Users registered"
End Sub
'--------------------------------[Other Functions]--------------------------------
''' <summary>Populate the listview</summary>
''' <param name="SearchItem"> find this item or items containing this </param>
Sub PopulateListview(Optional ByVal SearchItem As String = "")
'Clears and sets up the directory listview
Dim I As Integer
DirectoryView.Clear()
DirectoryView.View = View.Details
DirectoryView.Columns.Add("ID")
DirectoryView.Columns.Item(0).Width = 60
DirectoryView.Columns.Add("Name")
DirectoryView.Columns.Item(1).Width = 200
DirectoryView.MultiSelect = False
DirectoryView.FullRowSelect = True
DirectoryView.HideSelection = False
DirectoryView.Groups.Add(New ListViewGroup("Personal Accounts", HorizontalAlignment.Left))
DirectoryView.Groups.Add(New ListViewGroup("Corporate Accounts", HorizontalAlignment.Left))
DirectoryView.Groups.Add(New ListViewGroup("Government and Non-Taxed Accoutns", HorizontalAlignment.Left))
'Adds the users
For I = 0 To DirectoryUsers.Count - 1
Dim CLVI As ListViewItem
If Not String.IsNullOrWhiteSpace(SearchItem) Then
'Search Mode
If DirectoryUsers(I).Name.ToLower.Contains(SearchItem.ToLower) Or DirectoryUsers(I).ID.Contains(SearchItem) Then
CLVI = New ListViewItem With {.Text = DirectoryUsers(I).ID}
CLVI.SubItems.Add(DirectoryUsers(I).Name)
CLVI.Group = DirectoryView.Groups(DirectoryUsers(I).Category)
DirectoryView.Items.Add(CLVI)
End If
Else
'Non-Search Mode
CLVI = New ListViewItem With {.Text = DirectoryUsers(I).ID}
CLVI.SubItems.Add(DirectoryUsers(I).Name)
CLVI.Group = DirectoryView.Groups(DirectoryUsers(I).Category)
DirectoryView.Items.Add(CLVI)
End If
Next
End Sub
''' <summary>Repopulates the listview when the searchbox is changed</summary>
Sub RePopulateListView() Handles SearchBox.TextChanged
If Not String.IsNullOrEmpty(SearchBox.Text) Then
PopulateListview(SearchBox.Text)
Else
PopulateListview()
End If
End Sub
''' <summary>Verifies if a user from the directory is selected</summary>
Private Function HasUserSelected()
Dim Selectedindex As Integer
Try
Selectedindex = DirectoryView.SelectedIndices(0)
Catch
Return False
End Try
If Selectedindex = -1 Then
MsgBox("Please select a User", vbCritical, "ViBE")
Return False
End If
Return True
End Function
End Class