0% found this document useful (0 votes)
4 views11 pages

Program Source Code

The document contains source code for a login and staff management system using Visual Basic and an OleDb database connection. It includes functionalities for user login, staff record management (adding, updating, deleting, and searching), and loading staff data into a grid view. The code handles various events and user interactions to facilitate staff management operations.

Uploaded by

obi joseph
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views11 pages

Program Source Code

The document contains source code for a login and staff management system using Visual Basic and an OleDb database connection. It includes functionalities for user login, staff record management (adding, updating, deleting, and searching), and loading staff data into a grid view. The code handles various events and user interactions to facilitate staff management operations.

Uploaded by

obi joseph
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PROGRAM SOURCE CODE

Imports System.Data.OleDb
Public Class frmLogin

Private Sub Login()


Try
sqL = "SELECT * FROM Users WHERE Username = '" & txtUser.Text & "'
AND pwd = '" & txtPwd.Text & "'"
ConnDB()
cmd = New OleDbCommand(sqL, conn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read = True Then
frmMain.lblEmployeeNo.Text = "Welcome " & dr("Username")
frmMain.lblEmployeeNo.Visible = True
frmMain.LogoutMenuItem.Visible = True
txtUser.Text = ""
txtPwd.Text = ""
Me.Close()
Else
MsgBox("Incorrect username or password!",
MsgBoxStyle.Critical, "Login")
txtPwd.Focus()
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnLogin.Click
Login()
End Sub

Private Sub txtUser_GotFocus(ByVal sender As Object, ByVal e As


System.EventArgs) Handles txtUser.GotFocus
AcceptButton = btnLogin
End Sub

Private Sub txtPwd_GotFocus(ByVal sender As Object, ByVal e As


System.EventArgs) Handles txtPwd.GotFocus
AcceptButton = btnLogin
End Sub
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btncancel.Click

If MsgBox("Are you sure you want to close?", MsgBoxStyle.YesNo, "Close


Window") = MsgBoxResult.Yes Then
End
End If
txtUser.Focus()
End Sub

Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
frmUsers.ShowDialog()
End Sub
End Class

Imports System.Data.OleDb
Public Class frmStaff
Public adding As Boolean
Public updating As Boolean
Public search As Boolean

Private Sub GetStaffID()


Try
sqL = "SELECT StaffID FROM Staff Order By StaffID Desc"
ConnDB()
cmd = New OleDbCommand(sqL, conn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read = True Then
txtStaffID.Text = dr(0) + 1
Else
txtStaffID.Text = 1
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub

Private Sub AddStaff()


'State, LGA, Nationality, Dob, AdminMode, Session, Department, Level,
Nokname, Noktel
'" & state.Text & "', '" & lga.Text & "', '" & country.Text & "', '" &
Dob.Text & "', '" & Cmbmode.Text & "', '" & Cmbsession.Text & "', '" &
dept.Text & "', '" & Cmblevel.Text & "', '" & nokname.Text & "', '" &
noktel.Text & "'
Try
sqL = "INSERT INTO Staff(Lastname, Firstname, MI, Address,
ContactNo, [Position], State, LGA, Nationality, Dob, AdminMode, Ses,
Department, Lev, Nokname, Noktel) VALUES('" & _
txtLastname.Text & "', '" & txtFirstname.Text & "', '" &
txtMI.Text & "', '" & txtAddress.Text & "', '" & txtContactNo.Text & "', '" &
txtPosition.Text & "', '" & state.Text _
& "', '" & lga.Text & "', '" & country.Text & "', '" & Dob.Text &
"', '" & Cmbmode.Text & "', '" & Cmbsession.Text & "', '" & dept.Text & "', '"
& Cmblevel.Text & "', '" & nokname.Text & "', '" & noktel.Text & "')"
ConnDB()
cmd = New OleDbCommand(sqL, conn)
Dim i As Integer
i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("Student Added", MsgBoxStyle.Information, "Add
Student")
Else
MsgBox("Failed to Add Student", MsgBoxStyle.Critical, "Add
Student")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub

Private Sub UpdateStaff()


If btnUpdate.Text = "Update" Then
Try
sqL = "Update Staff SET Lastname ='" & txtLastname.Text & "',
Firstname = '" & txtFirstname.Text & "', MI = '" & _
txtMI.Text & "', Address= '" & txtAddress.Text & "', ContactNo
= '" & txtContactNo.Text & "', [Position] = '" & _
txtPosition.Text & "', State = '" & state.Text & "', LGA = '"
& lga.Text & "', Nationality = '" & country.Text & _
"', Dob = '" & Dob.Text & "', AdminMode = '" & Cmbmode.Text &
"', Ses = '" & Cmbsession.Text _
& "', Department = '" & dept.Text & "', Lev = '" &
Cmblevel.Text & "', Nokname = '" & nokname.Text _
& "', Noktel = '" & noktel.Text & "' WHERE StaffID = " &
txtStaffID.Text & ""
ConnDB()
cmd = New OleDbCommand(sqL, conn)
Dim i As Integer
i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("Staff Updated", MsgBoxStyle.Information, "Update
Staff")
Else
MsgBox("Failed in updating staff", MsgBoxStyle.Critical,
"Update Staff")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
ElseIf btnUpdate.Text = "Delete" Then
If MsgBox("Are you sure you want delete Record?",
MsgBoxStyle.YesNo, "Delete Student") = MsgBoxResult.Yes Then
DeleteUser()
Else
Exit Sub
End If

End If
End Sub

Private Sub GetStaffRecord()


Try
sqL = "SELECT * From Staff WHERE StaffID = " & txtStaffID.Text &
""
ConnDB()
cmd = New OleDbCommand(sqL, conn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read = True Then
txtLastname.Text = dr("Lastname")
txtFirstname.Text = dr("Firstname")
txtMI.Text = dr("MI")
txtAddress.Text = dr("Address")
txtContactNo.Text = dr("ContactNo")
txtPosition.Text = dr("Position")
state.Text = dr("State")
lga.Text = dr("LGA")
country.Text = dr("Nationality")
Dob.Text = dr("Dob")
Cmbmode.Text = dr("AdminMode")
Cmbsession.Text = dr("Ses")
dept.Text = dr("Department")
Cmblevel.Text = dr("Lev")
nokname.Text = dr("Nokname")
noktel.Text = dr("Noktel")

End If

Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub
Private Sub DeleteUser()
Try
sqL = "DELETE FROM Staff Where StaffID = " & txtStaffID.Text & ""
ConnDB()
cmd = New OledbCommand(sqL, conn)
Dim i As Integer
i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("Record Deleted", MsgBoxStyle.Information, "Delete
Student")
Else
MsgBox("Failed in Deleting User")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub

Private Sub CLearFields()


txtStaffID.Text = ""
txtLastname.Text = ""
txtFirstname.Text = ""
txtMI.Text = ""
txtAddress.Text = ""
txtContactNo.Text = ""
txtPosition.Text = ""
state.Text = ""
lga.Text = ""
country.Text = ""
Dob.Text = ""
Cmbmode.Text = ""
Cmbsession.Text = ""
dept.Text = ""
Cmblevel.Text = ""
nokname.Text = ""
noktel.Text = ""
End Sub

Private Sub EnabledText()


txtStaffID.Enabled = True
txtLastname.Enabled = True
txtFirstname.Enabled = True
txtMI.Enabled = True
txtAddress.Enabled = True
txtContactNo.Enabled = True
txtPosition.Enabled = True
state.Enabled = True
lga.Enabled = True
country.Enabled = True
Dob.Enabled = True
Cmbmode.Enabled = True
Cmbsession.Enabled = True
dept.Enabled = True
Cmblevel.Enabled = True
nokname.Enabled = True
noktel.Enabled = True
End Sub
Private Sub DisabledText()
txtStaffID.Enabled = False
txtLastname.Enabled = False
txtFirstname.Enabled = False
txtMI.Enabled = False
txtAddress.Enabled = False
txtContactNo.Enabled = False
txtPosition.Enabled = False
state.Enabled = False
lga.Enabled = False
country.Enabled = False
Dob.Enabled = False
Cmbmode.Enabled = False
Cmbsession.Enabled = False
dept.Enabled = False
Cmblevel.Enabled = False
nokname.Enabled = False
noktel.Enabled = False
End Sub

Private Sub EnabledButton()


btnAdd.Enabled = True
btnUpdate.Enabled = True
btnSearch.Enabled = True
btnClose.Enabled = True

btnSave.Enabled = False
btnCancel.Enabled = False
End Sub

Private Sub DisabledButton()


btnAdd.Enabled = False
btnUpdate.Enabled = False
btnSearch.Enabled = False
btnClose.Enabled = False

btnSave.Enabled = True
btnCancel.Enabled = True
End Sub

Private Sub frmStaff_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
DisabledText()
EnabledButton()
End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnAdd.Click
adding = True
updating = False

EnabledText()
CLearFields()
DisabledButton()
GetStaffID()
txtLastname.Focus()
txtStaffID.Enabled = False
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnUpdate.Click
If txtStaffID.Text = "" Then
MsgBox("Please select record to update", MsgBoxStyle.Information,
"Update Record")
Exit Sub
End If
If btnUpdate.Text = "Delete" Then
btnSave.Text = "Confirm"
End If
adding = False
updating = True
EnabledText()
DisabledButton()
txtLastname.Focus()
txtStaffID.Enabled = False
End Sub

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSearch.Click
search = True
frmLoadStaff.ShowDialog()
End Sub

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnClose.Click
CLearFields()
Me.Close()
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnSave.Click
If adding = True Then
AddStaff()
DisabledText()
EnabledButton()
CLearFields()
Else
UpdateStaff()
DisabledText()
EnabledButton()
CLearFields()
End If
End Sub

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnCancel.Click
DisabledText()
EnabledButton()
CLearFields()
End Sub

Private Sub txtStaffID_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtStaffID.TextChanged
If search = True Then
GetStaffRecord()
search = False
End If

End Sub
Private Sub Cmbmode_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Cmbmode.SelectedIndexChanged

End Sub

Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object,


ByVal e As System.Windows.Forms.DateRangeEventArgs)

End Sub

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles GroupBox1.Enter

End Sub

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Dob.ValueChanged

End Sub
End Class

Imports System.Data.OleDb
Public Class frmLoadStudent

Private Sub LoadStudent()


Try
sqL = "SELECT StaffID, Lastname & ', ' & Firstname as StaffName,
MI, Address, ContactNo, [Position], State, Ses, Department, FeePaid FROM
Staff"
ConnDB()
cmd = New OleDbCommand(sqL, conn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dgw.Rows.Clear()
Do While dr.Read = True
dgw.Rows.Add(dr(0), dr(1), dr(2), dr(3), dr(4), dr(5), dr(6),
dr(7), dr(8), dr(9))
Loop
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub

Private Sub SearchStudent()


Try
sqL = "SELECT StaffID, Lastname & ', ' & Firstname as StaffName,
MI, Address, ContactNo, [Position], State, Ses, Department, FeePaid FROM Staff
WHERE Lastname LIKE '" & TextBox1.Text & "%'"
ConnDB()
cmd = New OleDbCommand(sqL, conn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dgw.Rows.Clear()
Do While dr.Read = True
dgw.Rows.Add(dr(0), dr(1), dr(2), dr(3), dr(4), dr(5), dr(6),
dr(7), dr(8), dr(9))
Loop
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub

Private Sub dgw_CellDoubleClick(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles dgw.CellDoubleClick

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox1.TextChanged
SearchStudent()
End Sub

Private Sub frmLoadCustomer_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
LoadStudent()
End Sub
End Class

You might also like