Point of Sale Tutorial Part 8 – Code in User Account and Main Form

 This series of tutorial is finally done!

Option Explicit

Private Sub mDesignation_Click()
frmAddDesig.Show
End Sub

Private Sub mClose_Click()
End
End Sub

Private Sub mItemCategory_Click()
frmPCategoryAE.Show
End Sub

Private Sub mLogout_Click()
Unload Me
frmLogin.Show
End Sub

Private Sub mPLookUp_Click()
frmLookUp.Show 1
End Sub

Private Sub mPOS_Click()
frmPOS.Show vbModal
End Sub

Private Sub mProductMaster_Click()
frmProductAE.Show 1
End Sub

Private Sub mSuppliers_Click()
frmSupplierAE.Show 1
End Sub

Private Sub mUserDesig_Click()
frmAddDesig.Show 1
End Sub

Private Sub mUsers_Click()
frmUAccount.Show 1
End Sub




Option Explicit
Public UserOptions

Private Sub cmdAddDesignation_Click()
frmAddDesig.Show 1
End Sub

Private Sub cmdClear_Click()
dtCreate.Value = Date
cboDesignation.Text = ""
ClearTextBox frmUAccount
End Sub


Private Sub cmdDelete_Click()
If UserOptions = vbNullString Then
MsgBox "Please choose a record in the record to Delete.", vbExclamation, "Warning!"
Exit Sub
Else
Set rs = New ADODB.Recordset
rs.Open "Select * from UserAccount where Username='" & UserOptions & "'", cn, adOpenKeyset, adLockPessimistic
With rs
.Delete
Call LoadListviewUser
.Close
End With
Set rs = Nothing
MsgBox "Record Successfully Deleted!", vbInformation, "Success Deleted!"
ClearTextBox frmUAccount
cboDesignation.Text = ""

End If
UserOptions = ""
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub cmdNew_Click()

dtCreate.Enabled = True
txtUsername.Enabled = True
txtPassword.Enabled = True
txtConfirm.Enabled = True
txtName.Enabled = True
cboDesignation.Enabled = True
txtUsername.SetFocus
End Sub

Private Sub cmdSave_Click()
If txtUsername.Text = vbNullString _
Or txtPassword.Text = vbNullString _
Or txtConfirm.Text = vbNullString _
Or cboDesignation.Text = vbNullString _
Or txtName.Text = vbNullString _
Or dtCreate.Value = 0 Then
MsgBox "Please fill the text field.", vbCritical, "Error"
Exit Sub
ElseIf txtPassword.Text <> txtConfirm.Text Then
MsgBox "Your Password did not match, Please re-enter.", vbCritical, "Warning"
txtPassword.Text = ""
txtConfirm.Text = ""
txtPassword.SetFocus
Exit Sub
Else
Set rs = New ADODB.Recordset
rs.Open "Select * from UserAccount", cn, adOpenKeyset, adLockPessimistic
With rs
.AddNew
.Fields("Username") = txtUsername.Text
.Fields("Password") = txtPassword.Text
.Fields("Confirm") = txtConfirm.Text
.Fields("Designation") = cboDesignation.Text
.Fields("CName") = txtName.Text
.Fields("DateCreate") = dtCreate.Value
.Update
MsgBox "Record Successfully Saved!", vbInformation, "Success Saved!"
Call LoadListviewUser
.Close
End With
Set rs = Nothing
ClearTextBox frmUAccount
dtCreate.Value = Date
cboDesignation.Text = ""
Exit Sub
End If
End Sub


Private Sub cmdUpdate_Click()
If UserOptions = vbNullString Then
MsgBox "Please choose a record in the record to Update.", vbExclamation, "Warning!"
Exit Sub
Else
Set rs = New ADODB.Recordset
rs.Open "Select * from UserAccount where Username='" & UserOptions & "'", cn, adOpenDynamic, adLockOptimistic
With rs
!UserName = txtUsername.Text
!Password = txtPassword.Text
!Confirm = txtConfirm.Text
!Designation = cboDesignation.Text
!CName = txtName.Text
!DateCreate = dtCreate.Value
.Update
.Close
Call LoadListviewUser
End With
Set rs = Nothing
MsgBox "Record Successfully Updated!", vbInformation, "Success Updated!"
dtCreate.Value = Date
ClearTextBox frmUAccount
cboDesignation.Text = ""

End If
End Sub

Private Sub Form_Load()
dtCreate.Value = Date
dtCreate.Enabled = False
txtUsername.Enabled = False
txtPassword.Enabled = False
txtConfirm.Enabled = False
txtName.Enabled = False
cboDesignation.Enabled = False
Call Module2.Connect
Call Module2.LoadListviewUser
Call Module2.PopulateDesignation
End Sub

Private Sub lvAccount_Click()
On Error Resume Next
UserOptions = lvAccount.SelectedItem.SubItems(1)
txtUsername.Text = lvAccount.SelectedItem.SubItems(1)
txtPassword.Text = lvAccount.SelectedItem.SubItems(2)
txtConfirm.Text = lvAccount.SelectedItem.SubItems(3)
txtName.Text = lvAccount.SelectedItem.SubItems(4)
cboDesignation.Text = lvAccount.SelectedItem.SubItems(5)
dtCreate.Value = lvAccount.SelectedItem.SubItems(6)

dtCreate.Enabled = True
txtUsername.Enabled = True
txtPassword.Enabled = True
txtConfirm.Enabled = True
txtName.Enabled = True
cboDesignation.Enabled = True

Label18.Caption = "Selected Record: " & lvAccount.SelectedItem.Index & "/" & lvAccount.ListItems.Count
End Sub

Private Sub txtConfirm_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(LCase$(Chr$(KeyAscii)))
End Sub

Private Sub txtName_LostFocus()
txtName.Text = StrConv(txtName.Text, vbProperCase)
End Sub

Private Sub txtPassword_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(LCase$(Chr$(KeyAscii)))
End Sub

Private Sub txtUsername_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(LCase$(Chr$(KeyAscii)))
End Sub

And our series tutorial is done! Thank you for reading.
If you have any questions just post in the comment below :)

Happy Coding!

DOWNLOAD LINK:
https://mega.nz/#!9kgVQZrL!GDfuKK6ijsQOVTNlP_UyqDGMMrW0cn2zr5ViZu2K9Jk
Point of Sale Tutorial Part 8 – Code in User Account and Main Form Point of Sale Tutorial Part 8 – Code in User Account and Main Form Reviewed by code-dev on 12:27 AM Rating: 5

No comments:

Powered by Blogger.