-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfrmUserDetails.frm
740 lines (718 loc) · 23.3 KB
/
frmUserDetails.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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
VERSION 5.00
Begin VB.Form frmUserDetails
Appearance = 0 'Flat
BackColor = &H00E0E0E0&
BorderStyle = 0 'None
ClientHeight = 8595
ClientLeft = 14865
ClientTop = 1005
ClientWidth = 13365
FillStyle = 0 'Solid
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 8595
ScaleWidth = 13365
StartUpPosition = 1 'CenterOwner
Begin VB.ComboBox cboUserRole
BeginProperty Font
Name = "Arial"
Size = 20.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 600
Left = 3360
Style = 2 'Dropdown List
TabIndex = 13
Top = 4320
Width = 6975
End
Begin VB.Frame fraContainer1
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 7215
Left = 360
TabIndex = 6
Top = 1080
Width = 12615
Begin VB.Frame fraButton2
Appearance = 0 'Flat
BackColor = &H00B7D736&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 735
Left = 9360
MousePointer = 99 'Custom
TabIndex = 17
Top = 6000
Width = 2775
Begin VB.Label lblButton2
Alignment = 2 'Center
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "BUTTON LABEL 2"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 300
Left = 225
TabIndex = 18
Top = 240
Width = 2235
End
End
Begin VB.OptionButton optActive
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "No"
BeginProperty Font
Name = "Arial"
Size = 20.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 600
Index = 1
Left = 5400
TabIndex = 16
Top = 4200
Value = -1 'True
Width = 1215
End
Begin VB.OptionButton optActive
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Yes"
BeginProperty Font
Name = "Arial"
Size = 20.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 600
Index = 0
Left = 3000
TabIndex = 15
Top = 4200
Width = 1215
End
Begin VB.Frame fraButton1
Appearance = 0 'Flat
BackColor = &H00B7D736&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 735
Left = 5280
MousePointer = 99 'Custom
TabIndex = 9
Top = 6000
Width = 2775
Begin VB.Label lblButton1
Alignment = 2 'Center
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "BUTTON LABEL 1"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 300
Left = 225
TabIndex = 2
Top = 240
Width = 2235
End
End
Begin VB.TextBox txtUserName
BeginProperty Font
Name = "Arial"
Size = 20.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00404040&
Height = 615
IMEMode = 3 'DISABLE
Left = 3000
MaxLength = 20
TabIndex = 1
Top = 2280
Width = 6975
End
Begin VB.TextBox txtUserID
BeginProperty Font
Name = "Arial"
Size = 20.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00404040&
Height = 615
Left = 3000
MaxLength = 20
TabIndex = 0
Top = 1320
Width = 6975
End
Begin VB.Frame fraContainerTitle1
Appearance = 0 'Flat
BackColor = &H00C0FFFF&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 735
Left = 0
TabIndex = 7
Top = 0
Width = 12615
Begin VB.Label lblContainerTitle1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "CONTAINER TITLE 1"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00404040&
Height = 300
Left = 240
TabIndex = 8
Top = 240
Width = 2565
End
End
Begin VB.Label Label4
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "LABEL 4"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00404040&
Height = 300
Left = 960
TabIndex = 14
Top = 4200
Width = 1080
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "LABEL 3"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00404040&
Height = 300
Left = 960
TabIndex = 12
Top = 3240
Width = 1080
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "LABEL 2"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00404040&
Height = 300
Left = 960
TabIndex = 11
Top = 2280
Width = 1080
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "LABEL 1"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00404040&
Height = 300
Left = 960
TabIndex = 10
Top = 1320
Width = 1080
End
End
Begin VB.Frame fraTitle
BackColor = &H8000000D&
BorderStyle = 0 'None
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 0
TabIndex = 3
Top = 0
Width = 13365
Begin VB.Label lblX
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BackStyle = 0 'Transparent
Caption = "x"
BeginProperty Font
Name = "Arial"
Size = 21.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 615
Left = 12730
TabIndex = 5
Top = 0
Width = 615
End
Begin VB.Shape shpX
BorderColor = &H000000FF&
FillColor = &H000000FF&
FillStyle = 0 'Solid
Height = 615
Left = 12750
Top = 0
Width = 615
End
Begin VB.Label lblTitle
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "APPLICATION TITLE"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 300
Left = 240
TabIndex = 4
Top = 240
Width = 2535
End
End
End
Attribute VB_Name = "frmUserDetails"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim strAppDataPath As String
Dim strAppDataFile As String
Dim strUserID As String
Dim strUserName As String
Dim strUserRole As String
Dim strActive As String
Dim strSalt As String
Dim strPassword As String
Dim MoveStartX As Single
Dim MoveStartY As Single
Dim MoveEndX As Single
Dim MoveEndY As Single
Private Sub Form_Initialize()
Me.Icon = LoadResPicture("APPICON", vbResIcon)
End Sub
Private Sub Form_Load()
Me.Caption = "USER DETAILS"
lblTitle.Caption = Me.Caption
Label1.Caption = "USER ID"
Label2.Caption = "USER NAME"
Label3.Caption = "USER ROLE"
Label4.Caption = "ACTIVE"
lblButton1.Caption = "UPDATE"
lblButton2.Caption = "SECRET"
With cboUserRole
.AddItem "Admin"
.AddItem "Manager"
.AddItem "User"
End With
LoadMousePointer
SetContainerTitle
End Sub
Private Sub LoadMousePointer()
On Error Resume Next
fraButton1.MouseIcon = LoadPicture(App.Path & "\Resources\Icon\hand.ico")
fraButton2.MouseIcon = LoadPicture(App.Path & "\Resources\Icon\hand.ico")
End Sub
Private Sub SetContainerTitle()
lblContainerTitle1.Caption = "USER DETAILS"
End Sub
Private Sub fraButton1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With fraButton1
.BackColor = &HE0E0E0
End With
With lblButton1
.ForeColor = &H404040
End With
End Sub
Private Sub fraButton2_Click()
If txtUserID.Text = "" Then
MsgBox "User ID is empty!", vbExclamation, "User ID"
Exit Sub
End If
With frmUserUpdateSaltPassword
.Show
.LoadCombo
.cboUserID.Text = txtUserID.Text
End With
Unload Me
End Sub
Private Sub fraContainer1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With fraButton1
.BackColor = &HB7D736
End With
With lblButton1
.ForeColor = &HFFFFFF
End With
End Sub
Private Sub fraTitle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
GetMouseMove Button, X, Y
End Sub
Private Sub fraTitle_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetMouseMove Button, X, Y
End Sub
Private Sub fraButton1_Click()
If txtUserID.Text = "" Then
MsgBox "User ID is empty!", vbExclamation, "User ID"
Exit Sub
End If
If FindUser Then
UpdateUser
Else
AddUser
End If
End Sub
Private Sub lblButton1_Click()
fraButton1_Click
End Sub
Private Sub lblButton2_Click()
fraButton2_Click
End Sub
Private Sub lblTitle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
GetMouseMove Button, X, Y
End Sub
Private Sub lblTitle_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetMouseMove Button, X, Y
End Sub
Private Sub GetMouseMove(Button As Integer, X As Single, Y As Single)
MoveStartX = X
MoveStartY = Y
End Sub
Private Sub SetMouseMove(Button As Integer, X As Single, Y As Single)
MoveEndX = X - MoveStartX
MoveEndY = Y - MoveStartY
If Button = 1 Then
Me.Left = Me.Left + MoveEndX
Me.Top = Me.Top + MoveEndY
End If
End Sub
Private Sub lblX_Click()
Unload Me
frmUsers.Show
End Sub
Public Sub PopulateValues(strUserID As String)
Dim DB As New OmlDatabase
Dim SB As New OmlSQLBuilder
Dim rst As ADODB.Recordset
On Error GoTo Catch
strAppDataPath = App.Path & "\Storage\"
strAppDataFile = "Data.mdb"
DB.DataPath = strAppDataPath
DB.DataFile = strAppDataFile
'DB.DataPassword = ""
DB.OpenMdb
If DB.ErrorDesc <> "" Then
MsgBox "Error: " & DB.ErrorDesc, vbExclamation, "Open Database"
Exit Sub
End If
'strSQL = "SELECT"
'strSQL = strSQL & " UserID,"
'strSQL = strSQL & " UserName,"
'strSQL = strSQL & " UserRole,"
'strSQL = strSQL & " Active"
'strSQL = strSQL & " FROM Users"
'strSQL = strSQL & " WHERE ID = " & strUserID
SB.SELECT_
SB.SQL "UserID"
SB.SQL "UserName"
SB.SQL "UserRole"
SB.SQL "Active", 0
SB.FROM "Users"
SB.WHERE_Long "ID", CLng(strUserID)
Set rst = DB.OpenRs(SB.Text)
If DB.ErrorDesc <> "" Then
MsgBox "Error: " & DB.ErrorDesc, vbExclamation, "Query Database"
Exit Sub
End If
If Not rst.EOF Then
txtUserID.Text = rst!UserID
txtUserName.Text = rst!UserName
cboUserRole.Text = rst!UserRole
If rst!Active Then
optActive(0).Value = True
Else
optActive(1).Value = True
End If
txtUserID.Enabled = False
With txtUserName
.SelStart = Len(.Text)
.SelLength = 0
End With
Else
txtUserID.Text = ""
txtUserName.Text = ""
cboUserRole.ListIndex = -1
optActive(1).Value = True ' Default = No
With txtUserID
.Enabled = True
.SetFocus
End With
End If
DB.CloseRs rst
DB.CloseMdb
Exit Sub
Catch:
MsgBox Err.Number & " - " & Err.Description, vbExclamation, "PopulateValues"
DB.CloseRs rst
DB.CloseMdb
End Sub
Private Function FindUser() As Boolean
Dim DB As New OmlDatabase
Dim SB As New OmlSQLBuilder
Dim rst As ADODB.Recordset
On Error GoTo Catch
strAppDataPath = App.Path & "\Storage\"
strAppDataFile = "Data.mdb"
DB.DataPath = strAppDataPath
DB.DataFile = strAppDataFile
'DB.DataPassword = ""
DB.OpenMdb
If DB.ErrorDesc <> "" Then
MsgBox "Error: " & DB.ErrorDesc, vbExclamation, "Open Database"
Exit Function
End If
strUserID = Trim(txtUserID.Text)
'strSQL = "SELECT ID"
'strSQL = strSQL & " FROM Users"
'strSQL = strSQL & " WHERE UserID = '" & strUserID & "'"
SB.SELECT_ID "Users"
SB.WHERE_Text "UserID", strUserID
Set rst = DB.OpenRs(SB.Text)
If DB.ErrorDesc <> "" Then
MsgBox "Error: " & DB.ErrorDesc, vbExclamation, "Query Database"
Exit Function
End If
If Not rst.EOF Then
FindUser = True
Else
FindUser = False
End If
DB.CloseRs rst
DB.CloseMdb
Exit Function
Catch:
MsgBox Err.Number & " - " & Err.Description, vbExclamation, "FindUser"
DB.CloseRs rst
DB.CloseMdb
FindUser = False
End Function
Private Sub AddUser()
Dim DB As New OmlDatabase
Dim SB As New OmlSQLBuilder
On Error GoTo Catch
strAppDataPath = App.Path & "\Storage\"
strAppDataFile = "Data.mdb"
DB.DataPath = strAppDataPath
DB.DataFile = strAppDataFile
'DB.DataPassword = ""
DB.OpenMdb
If DB.ErrorDesc <> "" Then
MsgBox "Error: " & DB.ErrorDesc, vbExclamation, "Open Database"
Exit Sub
End If
strUserID = Trim(txtUserID.Text)
strUserName = Trim(txtUserName.Text)
strUserRole = cboUserRole.Text
If optActive(0).Value = True Then
strActive = "Yes"
Else
strActive = "No"
End If
strSalt = GenerateSalt("SECRET") ' default
strPassword = strUserID ' default
strPassword = MD5(strPassword & strSalt)
'strSQL = "INSERT INTO Users"
'strSQL = strSQL & " (UserID,"
'strSQL = strSQL & " UserName,"
'strSQL = strSQL & " UserRole,"
'strSQL = strSQL & " Salt,"
'strSQL = strSQL & " UserPassword,"
'strSQL = strSQL & " Active)"
'strSQL = strSQL & " VALUES"
'strSQL = strSQL & " ('" & strUserID & "',"
'strSQL = strSQL & " '" & strUserName & "',"
'strSQL = strSQL & " '" & strUserRole & "',"
'strSQL = strSQL & " '" & strSalt & "',"
'strSQL = strSQL & " '" & strPassword & "',"
'strSQL = strSQL & " " & strActive & ")"
SB.INSERT "Users"
SB.SOB "UserID"
SB.SQL "UserName"
SB.SQL "UserRole"
SB.SQL "Salt"
SB.SQL "UserPassword"
SB.SCB "Active"
SB.VALUES
SB.VOB strUserID
SB.VTX strUserName
SB.VTX strUserRole
SB.VTX strSalt
SB.VTX strPassword
SB.VCB strActive, 0
DB.Execute SB.Text
If DB.ErrorDesc <> "" Then
MsgBox "Error: " & DB.ErrorDesc, vbExclamation, "Add User"
Exit Sub
End If
MsgBox "User added", vbInformation, "Add User"
DB.CloseMdb
Exit Sub
Catch:
MsgBox Err.Number & " - " & Err.Description, vbExclamation, "AddUser"
DB.CloseMdb
End Sub
Private Sub UpdateUser()
Dim DB As New OmlDatabase
Dim SB As New OmlSQLBuilder
On Error GoTo Catch
strAppDataPath = App.Path & "\Storage\"
strAppDataFile = "Data.mdb"
DB.DataPath = strAppDataPath
DB.DataFile = strAppDataFile
'DB.DataPassword = ""
DB.OpenMdb
If DB.ErrorDesc <> "" Then
MsgBox "Error: " & DB.ErrorDesc, vbExclamation, "Open Database"
Exit Sub
End If
strUserID = Trim(txtUserID.Text)
strUserName = Trim(txtUserName.Text)
strUserRole = cboUserRole.Text
'If optActive(0).Value = True Then
' strActive = "Yes"
'Else
' strActive = "No"
'End If
'strSQL = "UPDATE Users SET"
'strSQL = strSQL & " UserName = '" & strUserName & "',"
'strSQL = strSQL & " UserRole = '" & strUserRole & "',"
'strSQL = strSQL & " Active = " & strActive
'strSQL = strSQL & " WHERE UserID = '" & strUserID & "'"
SB.UPDATE "Users"
SB.UTX "UserName", strUserName
SB.UTX "UserRole", strUserRole
SB.UYN "Active", optActive(0).Value, 0
SB.WHERE_Text "UserID", strUserID
DB.Execute SB.Text
If DB.ErrorDesc <> "" Then
MsgBox "Error: " & DB.ErrorDesc, vbExclamation, "Update User"
Exit Sub
End If
MsgBox "User updated", vbInformation, "Update User"
DB.CloseMdb
Exit Sub
Catch:
MsgBox Err.Number & " - " & Err.Description, vbExclamation, "UpdateUser"
DB.CloseMdb
End Sub
Private Function GenerateSalt(ByVal strPlain As String) As String
' A better way is to generate a random string for salt
GenerateSalt = MD5(strPlain)
End Function