-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmCreateNewStaff.frm
586 lines (564 loc) · 18.7 KB
/
frmCreateNewStaff.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
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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
VERSION 5.00
Object = "{CFC13920-9EF4-11D0-B72F-0000C04D4C0A}#6.0#0"; "mswless.ocx"
Object = "{C932BA88-4374-101B-A56C-00AA003668DC}#1.1#0"; "MSMASK32.OCX"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form frmCreateNewStaff
BorderStyle = 1 'Fixed Single
Caption = "Create New Employee"
ClientHeight = 6090
ClientLeft = 45
ClientTop = 390
ClientWidth = 7710
HelpContextID = 20
Icon = "frmCreateNewStaff.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6090
ScaleWidth = 7710
StartUpPosition = 2 'CenterScreen
Begin MSComCtl2.DTPicker dtDateBirth
Height = 495
Left = 360
TabIndex = 4
Top = 3120
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
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
CustomFormat = "MM/dd/yyyy"
Format = 141361155
CurrentDate = 44707
End
Begin MSMask.MaskEdBox txtDNI
Height = 495
Left = 360
TabIndex = 2
ToolTipText = "DNI of the new employee"
Top = 2160
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
MaxLength = 9
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
Format = "#########"
PromptChar = "_"
End
Begin MSMask.MaskEdBox txtPhoneNumber
Height = 495
Left = 4200
TabIndex = 3
ToolTipText = "Phone number of the new employee"
Top = 2160
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
MaxLength = 8
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
Format = "####-####"
PromptChar = "_"
End
Begin MSWLess.WLCommand btnCreate
Height = 975
Left = 960
TabIndex = 8
Top = 4920
Width = 2535
_ExtentX = 4471
_ExtentY = 1720
_Version = 393216
Caption = "&Create"
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 btnReset
Height = 975
Left = 4200
TabIndex = 9
Top = 4920
Width = 2535
_ExtentX = 4471
_ExtentY = 1720
_Version = 393216
Caption = "&Reset"
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.WLText txtPassword
Height = 495
Left = 4200
TabIndex = 7
ToolTipText = "Password to enter the application"
Top = 4080
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
PasswordChar = "*"
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
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
Begin MSWLess.WLText txtUsername
Height = 495
Left = 360
TabIndex = 6
ToolTipText = "Username to enter the application"
Top = 4080
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
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
Begin MSWLess.WLCombo cmbRole
Height = 390
Left = 4200
TabIndex = 5
ToolTipText = "Role of the new employee"
Top = 3120
Width = 3135
_ExtentX = 5530
_ExtentY = 688
_Version = 393216
Style = 2
ListCount = -300
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 = "frmCreateNewStaff.frx":3AFA
End
Begin VB.Label Label5
Caption = "Date of birth"
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 = 15
Top = 2880
Width = 1215
End
Begin VB.Label lblPhoneNumber
Caption = "Phone Number"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 4200
TabIndex = 14
Top = 1920
Width = 1215
End
Begin MSWLess.WLText txtLastName
Height = 495
Left = 4200
TabIndex = 1
ToolTipText = "Last name of the new employee"
Top = 1200
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
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
Begin MSWLess.WLText txtName
Height = 495
Left = 360
TabIndex = 0
ToolTipText = "Name of the new employee"
Top = 1200
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
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
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 = 10
Top = 0
Width = 7215
End
Begin VB.Label lblName
Caption = "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 = 11
Top = 960
Width = 1215
End
Begin VB.Label lblLastName
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 = 4200
TabIndex = 12
Top = 960
Width = 1215
End
Begin VB.Label lblDNI
Caption = "DNI"
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 = 1920
Width = 1215
End
Begin VB.Label lblRole
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 = 4200
TabIndex = 16
Top = 2880
Width = 1215
End
Begin VB.Label lblUsername
Caption = "Username"
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 = 17
Top = 3840
Width = 1215
End
Begin VB.Label lblPassword
Caption = "Password"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 4200
TabIndex = 18
Top = 3840
Width = 1215
End
End
Attribute VB_Name = "frmCreateNewStaff"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public PreviousDNI As String, PreviousUsername As String
Dim AlreadyMarked As Boolean
Private Sub btnCreate_Click()
On Error GoTo ErrHandler
If IsInformationValid Then
If btnCreate.Caption = "&Create" Then
ExecuteSQL "Select * from Staff where DNI = '" & Replace(txtDNI.Text, "-", "") & "'"
ExecuteSQL2 "Select * from Staff where Username = '" & txtUsername & "'"
If Not rs.EOF Then
MsgBox "DNI already exists", vbCritical, "Error"
Exit Sub
ElseIf Not rs2.EOF Then
MsgBox "Username already exists", vbCritical, "Error"
Exit Sub
End If
rs.AddNew
MsgBox "New user added successfully!", vbOKOnly, "Information"
ElseIf btnCreate.Caption = "&Update" Then
ExecuteSQL "Select * from Staff where DNI = '" & PreviousDNI & "'"
If UserExists(Replace(txtDNI.Text, "-", ""), txtUsername) Then Exit Sub
MsgBox "User updated successfully!", vbOKOnly, "Information"
End If
Else
MsgBox "Fill all the required spaces in the form", vbInformation, "Information"
CheckEmptyText
AlreadyMarked = True
Exit Sub
End If
rs!Staff_Name = txtName
rs!Staff_LastName = txtLastName
rs!DNI = Replace(txtDNI.Text, "-", "")
rs!Phone_Number = Replace(txtPhoneNumber.Text, "-", "")
rs!DateBirth = dtDateBirth
rs!Role_ID = GetRoleID
rs!UserName = txtUsername
rs!Password = txtPassword
rs!Available = True
rs!PreviousRole_ID = GetRoleID
rs.Update
AlreadyMarked = False
RemoveMark Me
ClearForm
Exit Sub
ErrHandler:
MsgBox "There was an error during the operation", vbCritical, "Error"
Exit Sub
End Sub
Function UserExists(UserDNI As String, UserName As String) As Boolean
Dim result As Boolean
ExecuteSQL2 "Select * from Staff where DNI = '" & UserDNI & "'"
ExecuteSQL3 "Select * from Staff where Username = '" & UserName & "'"
If UserDNI = PreviousDNI And UserName = PreviousUsername Then
result = False
ElseIf Not rs2.EOF And UserDNI <> PreviousDNI Then
MsgBox "DNI already exists!", vbCritical, "Error"
result = True
ElseIf Not rs3.EOF And UserName <> PreviousUsername Then
MsgBox "Username already exists!", vbCritical, "Error"
result = True
End If
UserExists = result
End Function
Sub CheckEmptyText()
AddRequiredMark lblName, vbRed, txtName
AddRequiredMark lblLastName, vbRed, txtLastName
AddRequiredMark lblDNI, vbRed, txtDNI
AddRequiredMark lblPhoneNumber, vbRed, txtPhoneNumber
AddRequiredMark lblRole, vbRed, cmbRole
AddRequiredMark lblUsername, vbRed, txtUsername
AddRequiredMark lblPassword, vbRed, txtPassword
End Sub
Function GetRoleID() As Integer
ExecuteSQL2 "Select * from Role where Role = '" & cmbRole.Text & "'"
GetRoleID = rs2.Fields!ID
End Function
Private Sub btnReset_Click()
ClearForm
End Sub
Sub ClearForm()
RemoveMark Me
AlreadyMarked = False
txtName.Text = ""
txtLastName.Text = ""
txtDNI.Text = ""
txtPhoneNumber.Text = ""
dtDateBirth.value = DateTime.Date
cmbRole.ListIndex = -1
txtUsername.Text = ""
txtPassword.Text = ""
End Sub
Function IsInformationValid() As Boolean
If txtName.Text <> "" And txtLastName.Text <> "" And txtDNI.Text <> "" And _
txtPhoneNumber.Text <> "" And txtUsername.Text <> "" And _
txtPassword.Text <> "" And cmbRole.ListIndex <> -1 Then
IsInformationValid = True
Else
IsInformationValid = False
End If
End Function
Private Sub Form_Load()
dtDateBirth.value = DateTime.Date
LoadRoles
VerifyCurrentRole
End Sub
Sub VerifyCurrentRole()
If frmMain.CurrentUserRoleID = 1 Then
MsgBox "The current user does not have permission to add or modify employees information", vbInformation, "Information"
btnCreate.Enabled = False
End If
End Sub
Sub LoadRoles()
ExecuteSQL "Select * from Role Where ID <> 4"
cmbRole.Clear
While Not rs.EOF
cmbRole.AddItem (rs.Fields!Role)
rs.MoveNext
Wend
End Sub
Private Sub txtDNI_GotFocus()
If txtDNI.Text <> "" Then txtDNI.Text = Replace(txtDNI.Text, "-", "")
End Sub
Private Sub txtDNI_KeyPress(KeyAscii As Integer)
VerifyChar KeyAscii
If Len(txtDNI) = 9 And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Sub VerifyChar(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And Not KeyAscii = 8 Then
KeyAscii = 0
MsgBox "Enter only numeric characters!", vbInformation, "Information"
End If
End Sub
Public Sub txtDNI_LostFocus()
txtDNI.Text = Format(txtDNI.Text, "#-####-####")
End Sub
Private Sub txtPhoneNumber_GotFocus()
If txtPhoneNumber.Text <> "" Then txtPhoneNumber.Text = Replace(txtPhoneNumber.Text, "-", "")
End Sub
Private Sub txtPhoneNumber_KeyPress(KeyAscii As Integer)
If Len(txtPhoneNumber) = 8 And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Public Sub txtPhoneNumber_LostFocus()
txtPhoneNumber.Text = Format(txtPhoneNumber.Text, "####-####")
End Sub