-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmDeleteStaff.frm
More file actions
570 lines (543 loc) · 19.1 KB
/
frmDeleteStaff.frm
File metadata and controls
570 lines (543 loc) · 19.1 KB
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
VERSION 5.00
Object = "{CFC13920-9EF4-11D0-B72F-0000C04D4C0A}#6.0#0"; "mswless.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmDeleteStaff
BorderStyle = 1 'Fixed Single
Caption = "Delete Employee"
ClientHeight = 8130
ClientLeft = 45
ClientTop = 390
ClientWidth = 7695
HelpContextID = 20
Icon = "frmDeleteStaff.frx":0000
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 8130
ScaleWidth = 7695
StartUpPosition = 2 'CenterScreen
Begin VB.CheckBox chkFilters
Caption = "Show filters"
BeginProperty Font
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 4320
TabIndex = 11
Top = 1200
Width = 2895
End
Begin VB.Frame frameFilters
BorderStyle = 0 'None
Height = 4935
Left = 360
TabIndex = 1
Top = 1800
Width = 6975
Begin VB.Frame pnlResults
Caption = "Results"
Height = 3015
Left = 120
TabIndex = 9
Top = 1800
Width = 6735
Begin MSComctlLib.ListView lstResults
Height = 2655
Left = 240
TabIndex = 10
Top = 240
Width = 6255
_ExtentX = 11033
_ExtentY = 4683
View = 3
LabelWrap = -1 'True
HideSelection = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
NumItems = 4
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
Key = "colName"
Text = "DNI"
Object.Width = 2646
EndProperty
BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 1
Key = "colLastName"
Text = "Name"
Object.Width = 2646
EndProperty
BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 2
Key = "colDNI"
Text = "Last Name"
Object.Width = 2999
EndProperty
BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 3
Key = "colRole"
Text = "Role"
Object.Width = 2646
EndProperty
End
End
Begin VB.Frame pnlFilters
Caption = "Filters"
Height = 1575
Left = 120
TabIndex = 2
Top = 0
Width = 6735
Begin VB.ComboBox cmbLastName
BeginProperty Font
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 390
ItemData = "frmDeleteStaff.frx":3AFA
Left = 240
List = "frmDeleteStaff.frx":3AFC
Style = 2 'Dropdown List
TabIndex = 4
Top = 960
Width = 2655
End
Begin VB.CommandButton cmdResetFilters
Caption = "Reset Filters"
BeginProperty Font
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 4200
TabIndex = 3
Top = 240
Width = 2055
End
Begin MSWLess.WLCombo cmbRole
Height = 390
Left = 3960
TabIndex = 6
ToolTipText = "Manufacturer"
Top = 960
Width = 2535
_ExtentX = 4471
_ExtentY = 688
_Version = 393216
Style = 2
ListCount = -19436
Text = "cmbRole"
ForeColor = -2147483640
BackColor = -2147483643
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
List = "frmDeleteStaff.frx":3AFE
End
Begin VB.Label Label1
Caption = "Last Name"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 240
TabIndex = 8
Top = 720
Width = 2535
End
Begin VB.Label Label2
Caption = "Role"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 3960
TabIndex = 7
Top = 720
Width = 2535
End
Begin MSWLess.WLCheck chkUseAllFilters
Height = 375
Left = 240
TabIndex = 5
Top = 240
Width = 2655
_ExtentX = 4683
_ExtentY = 661
_Version = 393216
Caption = "Use all filters?"
ForeColor = -2147483630
BackColor = -2147483633
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
End
End
Begin MSWLess.WLCommand btnDelete
Height = 975
Left = 2520
TabIndex = 14
Top = 6960
Width = 2535
_ExtentX = 4471
_ExtentY = 1720
_Version = 393216
Caption = "&Delete"
ForeColor = -1
BackColor = -2147483633
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 14.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLCombo cmbFullName
Height = 390
Left = 360
TabIndex = 12
ToolTipText = "Manufacturer"
Top = 1200
Width = 3135
_ExtentX = 5530
_ExtentY = 688
_Version = 393216
Style = 2
ListCount = -19396
Text = "cmbFullName"
ForeColor = -2147483640
BackColor = -2147483643
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
List = "frmDeleteStaff.frx":3B1A
End
Begin VB.Label Label6
Caption = "Employee Full Name"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 360
TabIndex = 13
Top = 960
Width = 3135
End
Begin VB.Label lblTitle
Alignment = 2 'Center
Caption = "Staff"
BeginProperty Font
Name = "Javanese Text"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 240
TabIndex = 0
Top = 0
Width = 7215
End
End
Attribute VB_Name = "frmDeleteStaff"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub btnDelete_Click()
Dim userDNI As String
Dim IsFullNameDuplicated As Boolean
If cmbFullName.ListIndex <> -1 Then
If MsgBox("Are you sure you want to delete the user '" _
& cmbFullName.Text & "'?", vbExclamation + vbYesNo) = vbYes Then
userDNI = GetUserDNI(IsFullNameDuplicated)
If IsFullNameDuplicated Then
MsgBox "There are more than 1 user with this name." & vbCrLf & _
"Please use the filters to select the right user", vbInformation, "Information"
Exit Sub
Else
If IsUserLastAdministrator Then
MsgBox "User can't be deleted because there are no more Administrators", vbCritical, "Erorr"
Else
ExecuteSQL "Select * from Staff where DNI = '" & userDNI & "'"
rs.Fields!Available = False
rs.Fields!Role_ID = 4
rs.Update
MsgBox "User deleted successfully!", vbInformation, "Information"
LoadFullNames
End If
End If
End If
ElseIf lstResults.ListItems.Count > 0 And Not lstResults.SelectedItem Is Nothing Then
If MsgBox("Are you sure you want to delete the user '" _
& GetUserFullName(lstResults.SelectedItem.Text) & "'?", vbExclamation + vbYesNo) = vbYes Then
If IsUserLastAdministrator Then
MsgBox "User can't be deleted because there are no more Administrators", vbCritical, "Erorr"
Else
ExecuteSQL "Select * from Staff where DNI = '" & lstResults.SelectedItem & "'"
rs.Fields!Available = False
rs.Fields!Role_ID = 4
rs.Update
MsgBox "User deleted successfully!", vbInformation, "Information"
LoadLastNames
LoadRoles
cmdResetFilters_Click
End If
End If
Else
MsgBox "Select an user to delete it", vbInformation, "Information"
End If
End Sub
Function IsUserLastAdministrator() As Boolean
Dim result As Boolean
result = False
ExecuteSQL2 "Select * from Staff where Role_ID = 3"
If rs2.RecordCount = 1 Then
result = True
End If
IsUserLastAdministrator = result
End Function
Function GetUserDNI(ByRef IsFullNameDuplicated As Boolean) As String
Dim dividedName As Variant
dividedName = Split(cmbFullName.Text, " ")
ExecuteSQL2 "Select * from Staff where Staff_Name = '" & dividedName(0) & "' and Staff_LastName = '" & dividedName(1) & "'"
If rs2.RecordCount > 1 Then
IsFullNameDuplicated = True
Exit Function
End If
GetUserDNI = rs2.Fields!DNI
End Function
Function GetUserFullName(UserDNI As String) As String
Dim fullName As String
ExecuteSQL2 "Select * from Staff where DNI = '" & UserDNI & "'"
fullName = rs2.Fields!Staff_Name & " " & rs2.Fields!Staff_LastName
GetUserFullName = fullName
End Function
Private Sub chkFilters_Click()
If chkFilters.value <> 0 Then
frameFilters.Enabled = True
frameFilters.Visible = True
Me.Height = 8715
btnDelete.Top = 6960
cmbFullName.Enabled = False
cmbFullName.ListIndex = -1
Else
frameFilters.Enabled = False
frameFilters.Visible = False
Me.Height = 4000
btnDelete.Top = 2000
cmbFullName.Enabled = True
End If
End Sub
Private Sub chkUseAllFilters_Click()
LoadLastNames
LoadRoles
End Sub
Private Sub cmbLastName_Click()
If chkUseAllFilters.value = wlUnchecked Then
LoadRoles
Else
If cmbRole.Text = "" Then LoadRoles cmbLastName.Text
End If
ShowResults cmbLastName, cmbRole
End Sub
Private Sub cmbRole_Click()
If chkUseAllFilters.value = wlUnchecked Then
LoadLastNames
Else
If cmbLastName.Text = "" Then LoadLastNames cmbRole.Text
End If
ShowResults cmbLastName, cmbRole
End Sub
Private Sub cmdResetFilters_Click()
LoadLastNames
LoadRoles
lstResults.ListItems.Clear
End Sub
Private Sub Form_Load()
LoadFullNames
LoadLastNames
LoadRoles
frameFilters.Enabled = False
frameFilters.Visible = False
Me.Height = 4000
btnDelete.Top = 2000
VerifyCurrentRole
End Sub
Sub VerifyCurrentRole()
If frmMain.CurrentUserRoleID = 1 Then
MsgBox "The current user does not have permission to delete employees", vbInformation, "Information"
btnDelete.Enabled = False
End If
End Sub
Sub LoadFullNames()
Dim FullName As String
ExecuteSQL "Select * from Staff where Available = True order by Staff_LastName asc"
cmbFullName.Clear
While Not rs.EOF
FullName = rs.Fields!Staff_Name & " " & rs.Fields!Staff_LastName
cmbFullName.AddItem FullName
rs.MoveNext
Wend
End Sub
Sub LoadLastNames(Optional Role As String)
Dim query As String
Dim value As String
If chkUseAllFilters.value <> 0 Then
CreateQuery query, , Role
ExecuteSQL query
cmbLastName.Clear
While Not rs.EOF
value = rs.Fields!Staff_LastName
If Not ExistsInCombo(value, cmbLastName) Then
cmbLastName.AddItem (value)
End If
rs.MoveNext
Wend
Else
cmbLastName.Clear
cmbLastName.AddItem "A-E"
cmbLastName.AddItem "F-J"
cmbLastName.AddItem "K-O"
cmbLastName.AddItem "P-T"
cmbLastName.AddItem "U-Z"
End If
End Sub
Sub LoadRoles(Optional lastName As String)
Dim query As String
Dim value As String
If chkUseAllFilters.value <> 0 Then
CreateQuery query, lastName
ExecuteSQL query
cmbRole.Clear
While Not rs.EOF
value = GetRoleName(rs.Fields!Role_ID)
If Not ExistsInCombo(value, , cmbRole) Then
cmbRole.AddItem value
End If
rs.MoveNext
Wend
Else
cmbRole.Clear
cmbRole.AddItem "Seller"
cmbRole.AddItem "Manager"
cmbRole.AddItem "Administrator"
End If
End Sub
Function GetRoleName(RoleID As Integer) As String
ExecuteSQL2 "Select * from Role where ID = " & RoleID
GetRoleName = rs2.Fields!Role
End Function
Function GetRoleID(RoleName As String) As Integer
ExecuteSQL2 "Select * from Role where Role = '" & RoleName & "'"
GetRoleID = rs2.Fields!ID
End Function
Sub CreateQuery(ByRef queryOut As String, Optional lastName As String, Optional Role As String)
queryOut = "Select * from Staff where Available = True"
If Not lastName = "" Then GetLastNameQuery queryOut, lastName
If Not Role = "" Then queryOut = queryOut & " and Role_ID = " & GetRoleID(Role)
End Sub
Sub ShowResults(Optional lastName As String, Optional Role As String)
Dim li As ListItem
Dim RoleName As String
Dim query As String
On Error GoTo DoNothing
CreateQuery query, lastName, Role
ExecuteSQL query
lstResults.ListItems.Clear
While Not rs.EOF
Set li = lstResults.ListItems.Add(, , rs.Fields!DNI)
li.SubItems(1) = rs.Fields!Staff_Name
li.SubItems(2) = rs.Fields!Staff_LastName
RoleName = GetRoleName(rs.Fields!Role_ID)
li.SubItems(3) = RoleName
rs.MoveNext
Wend
Exit Sub
DoNothing:
Exit Sub
End Sub
Sub GetLastNameQuery(ByRef queryOut, lastName As String)
Dim Initials As Variant
Dim SearchedCharacter As String
If Len(lastName) = 3 And InStr(1, lastName, "-", vbTextCompare) = 2 Then
Initials = Split(lastName, "-")
queryOut = queryOut & " and Staff_LastName >= '" & Initials(0) & "' and Staff_LastName <= '" & Initials(1) & "'"
Else
queryOut = queryOut & " and Staff_LastName = '" & lastName & "'"
End If
End Sub