-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmViewStaff.frm
377 lines (361 loc) · 12.1 KB
/
frmViewStaff.frm
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
VERSION 5.00
Object = "{CFC13920-9EF4-11D0-B72F-0000C04D4C0A}#6.0#0"; "mswless.ocx"
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form frmViewStaff
BorderStyle = 1 'Fixed Single
Caption = "View Employees Details"
ClientHeight = 7770
ClientLeft = 45
ClientTop = 390
ClientWidth = 11940
HelpContextID = 30
Icon = "frmViewStaff.frx":0000
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 7770
ScaleWidth = 11940
StartUpPosition = 2 'CenterScreen
Begin MSFlexGridLib.MSFlexGrid gridResults
Height = 5415
Left = 360
TabIndex = 1
Top = 960
Width = 11175
_ExtentX = 19711
_ExtentY = 9551
_Version = 393216
FixedRows = 0
FixedCols = 0
AllowBigSelection= 0 'False
SelectionMode = 1
AllowUserResizing= 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
End
Begin MSWLess.WLCommand btnShowHiddenElements
Height = 975
Left = 960
TabIndex = 5
Top = 6600
Width = 1935
_ExtentX = 3413
_ExtentY = 1720
_Version = 393216
Caption = "&Show Deleted"
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.WLCommand btnExit
Height = 975
Left = 8880
TabIndex = 4
Top = 6600
Width = 1935
_ExtentX = 3413
_ExtentY = 1720
_Version = 393216
Caption = "E&xit"
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.WLCommand btnEdit
Height = 975
Left = 3600
TabIndex = 3
Top = 6600
Width = 1935
_ExtentX = 3413
_ExtentY = 1720
_Version = 393216
Caption = "&Edit"
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.WLCommand btnDelete
Height = 975
Left = 6240
TabIndex = 2
Top = 6600
Width = 1935
_ExtentX = 3413
_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 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 = 11415
End
End
Attribute VB_Name = "frmViewStaff"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim SelectedRow As Integer
Dim query As String
Private Sub btnExit_Click()
Unload Me
End Sub
Private Sub btnShowHiddenElements_Click()
If btnShowHiddenElements.Caption = "&Show Deleted" Then
query = "Select * from Staff where Available = False Order By Staff_LastName Asc"
FillGrid
btnShowHiddenElements.Caption = "Show &Both"
ElseIf btnShowHiddenElements.Caption = "Show &Both" Then
query = "Select * from Staff order by Staff_LastName asc"
FillGrid
btnShowHiddenElements.Caption = "&Hide Deleted"
ElseIf btnShowHiddenElements.Caption = "&Hide Deleted" Then
query = "Select * from Staff where Available = True Order By Staff_LastName Asc"
FillGrid
btnShowHiddenElements.Caption = "&Show Deleted"
End If
gridResults_SelChange
End Sub
Private Sub Form_Load()
query = "Select * from Staff where Available = True Order By Staff_LastName Asc"
FillGrid
gridResults_SelChange
End Sub
Sub FillGrid()
Dim RoleName As String
Dim value As String
gridResults.Clear
ExecuteSQL query
With gridResults
.Cols = 7
.FixedCols = 0
.Rows = 0
.AddItem "Name" & vbTab & "Last Name" & vbTab & "Identification Number" _
& vbTab & "Phone Number" & vbTab & "Date of Birth" & vbTab & "Role" _
& vbTab & "Username"
AutoFitRows
Dim i As Integer, j As Integer, k As Integer
i = 1
k = 0
If rs.RecordCount = 0 Then
.Rows = 2
.FixedRows = 1
.Row = 0
Exit Sub
End If
While Not rs.EOF
.Rows = .Rows + 1
For j = 1 To 7
value = rs.Fields(j)
If j = 1 Or j = 2 Then
.ColWidth(j - 1) = 1500
ElseIf j = 3 Then
value = Format(value, "#-####-####")
.ColWidth(j - 1) = 1600
ElseIf j = 4 Then
value = Format(value, "####-####")
.ColWidth(j - 1) = 1400
ElseIf j = 5 Then
value = Format(value, "MM/dd/YYYY")
.ColWidth(j - 1) = 1500
ElseIf j = 6 Then
RoleName = GetRoleName(rs.Fields(j))
value = RoleName
.ColWidth(j - 1) = 1500
End If
.TextMatrix(i, k) = value
k = k + 1
Next
rs.MoveNext
i = i + 1
k = 0
Wend
.FixedRows = 1
.AllowUserResizing = flexResizeColumns
'.Row = 0
End With
End Sub
Sub AutoFitRows()
Dim i As Integer
Dim Twips As Integer
With gridResults
For i = 0 To .Cols - 1
Twips = Me.TextWidth(.TextMatrix(0, i))
.ColWidth(i) = Twips * Me.gridResults.Font.Size / Me.Font.Size + 530 '* Screen.TwipsPerPixelX
Next i
End With
End Sub
Function GetRoleName(RoleID As Integer) As String
ExecuteSQL3 "Select * from Role where ID = " & RoleID
GetRoleName = rs3.Fields!Role
End Function
Function GetRoleIndex(RoleName As String, CreateUserForm As frmCreateNewStaff) As Integer
Dim i As Integer, value As Integer
For i = 0 To CreateUserForm.cmbRole.ListCount - 1
If CreateUserForm.cmbRole.List(i) = RoleName Then
value = i
Exit For
End If
Next i
GetRoleIndex = value
End Function
Function GetUserIndex(UserName As String, DeleteUserForm As frmDeleteStaff) As Integer
Dim i As Integer, value As Integer
For i = 0 To DeleteUserForm.cmbFullName.ListCount - 1
If DeleteUserForm.cmbFullName.List(i) = UserName Then
value = i
Exit For
End If
Next i
GetUserIndex = value
End Function
Private Sub gridResults_DblClick()
Dim SelectedUser As String
SelectedUser = Replace(gridResults.TextMatrix(gridResults.Row, 2), "-", "")
ExecuteSQL2 "Select * from Staff where DNI = '" & SelectedUser & "'"
If rs2.EOF Or rs2.RecordCount = 0 Then
MsgBox "Please select a valid item", vbCritical, "Error"
Exit Sub
End If
Dim RoleName As String
Dim RoleIndex As Integer
If btnEdit.Caption = "&Edit" Then
Dim f As frmCreateNewStaff
Set f = New frmCreateNewStaff
f.txtName = rs2.Fields!Staff_Name
f.txtLastName = rs2.Fields!Staff_LastName
f.txtDNI = rs2.Fields!DNI
f.txtPhoneNumber = rs2.Fields!Phone_Number
f.dtDateBirth = rs2.Fields!DateBirth
RoleName = GetRoleName(rs2.Fields!Role_ID)
RoleIndex = GetRoleIndex(RoleName, f)
f.cmbRole = f.cmbRole.List(RoleIndex)
f.txtUsername = rs2.Fields!UserName
f.PreviousDNI = rs2.Fields!DNI
f.PreviousUsername = rs2.Fields!UserName
f.btnCreate.Caption = "&Update"
f.btnReset.Enabled = False
f.txtDNI_LostFocus
f.txtPhoneNumber_LostFocus
f.Show vbModal, Me
ElseIf btnEdit.Caption = "&Restore user" Then
rs2.Fields!Available = True
rs2.Fields!Role_ID = rs2.Fields!PreviousRole_ID
rs2.Update
MsgBox "User restored successfully!", vbInformation, "Information"
'btnEdit.Caption = "&Edit"
'btnDelete.Enabled = True
End If
SelectedRow = gridResults.Row
FillGrid
SelectLastRow
End Sub
Private Sub gridResults_Click()
gridResults_SelChange
End Sub
Sub SelectLastRow()
If gridResults.Rows > SelectedRow Then
gridResults.Row = SelectedRow
Else
gridResults.Row = gridResults.Rows - 1
End If
End Sub
Private Sub btnDelete_Click()
Dim SelectedUser As String, UserIndex As Integer
SelectedUser = gridResults.TextMatrix(gridResults.Row, 0) & " " & gridResults.TextMatrix(gridResults.Row, 1)
Dim f As frmDeleteStaff
Set f = New frmDeleteStaff
UserIndex = GetUserIndex(SelectedUser, f)
f.cmbFullName = f.cmbFullName.List(UserIndex)
SelectedRow = gridResults.Row
f.Show vbModal, Me
FillGrid
SelectLastRow
End Sub
Private Sub btnEdit_Click()
gridResults_DblClick
End Sub
Private Sub gridResults_SelChange()
Dim CurrentEmployee As String
CurrentEmployee = gridResults.TextMatrix(gridResults.Row, 2)
If gridResults.Row > 0 And Not CurrentEmployee = "" And Not CurrentEmployee = "Identification Number" Then
Dim SelectedUser As String, currentBool As Boolean
SelectedUser = Replace(CurrentEmployee, "-", "")
If SelectedUser = "" Then Exit Sub
ExecuteSQL3 "Select * from Staff where DNI = '" & SelectedUser & "'"
currentBool = rs3.Fields!Available
If currentBool = False Then
btnEdit.Caption = "&Restore user"
btnDelete.Enabled = False
btnEdit.Enabled = True
ElseIf currentBool = True Then
btnEdit.Caption = "&Edit"
btnEdit.Enabled = True
btnDelete.Enabled = True
End If
Else
btnDelete.Enabled = False
btnEdit.Enabled = False
End If
End Sub