0% found this document useful (0 votes)
3 views

PayrollSystem for VB.Net

The document outlines a payroll system implemented in Visual Basic, featuring a user interface for entering employee details and calculating net pay based on hours worked and hourly rates. It includes functionalities for adding, deleting, and clearing employee records, as well as searching for employees by name or ID. The code also handles input validation and updates the net pay dynamically as the user inputs data.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

PayrollSystem for VB.Net

The document outlines a payroll system implemented in Visual Basic, featuring a user interface for entering employee details and calculating net pay based on hours worked and hourly rates. It includes functionalities for adding, deleting, and clearing employee records, as well as searching for employees by name or ID. The code also handles input validation and updates the net pay dynamically as the user inputs data.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ARDEE JHADE B.

ORLANDA
SEDRIEL H. NAVASCA
BSIT-S-1A
COMPUTER PROGRAMMING 2
PAYROLL SYSTEM

INTERFACE:

CODE:
Public Class Form2

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load


AddHandler AdvancePayBox.TextChanged, AddressOf UpdateNetPay
AddHandler HourlyRateBox.TextChanged, AddressOf UpdateNetPay
AddHandler HoursWorkedBox.TextChanged, AddressOf UpdateNetPay
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
If String.IsNullOrWhiteSpace(EmployeeBox.Text) OrElse
String.IsNullOrWhiteSpace(IdBox.Text) OrElse
String.IsNullOrWhiteSpace(PositionBox.Text) OrElse
String.IsNullOrWhiteSpace(HoursWorkedBox.Text) OrElse
String.IsNullOrWhiteSpace(HourlyRateBox.Text) OrElse
String.IsNullOrWhiteSpace(AdvancePayBox.Text) Then
MessageBox.Show("Please fill in all fields except Net Pay!")
Return
End If

Dim hoursWorked As Double


Dim hourlyRate As Double
Dim advancePay As Double

If Not Double.TryParse(HoursWorkedBox.Text, hoursWorked) OrElse


Not Double.TryParse(HourlyRateBox.Text, hourlyRate) OrElse
Not Double.TryParse(AdvancePayBox.Text, advancePay) Then
MessageBox.Show("Please enter valid numbers for Hours Worked, Hourly
Rate, and Advance Pay!")
Return
End If

Dim grossPay As Double = hoursWorked * hourlyRate


Dim netPay As Double = grossPay - advancePay

DataGridView1.Rows.Add(EmployeeBox.Text, IdBox.Text, PositionBox.Text,


HoursWorkedBox.Text,
grossPay.ToString("C2"), advancePay.ToString("C2"),
netPay.ToString("C2"))

ClearFields()
End Sub

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles


btnDelete.Click
If DataGridView1.SelectedRows.Count > 0 Then
DataGridView1.Rows.RemoveAt(DataGridView1.SelectedRows(0).Index)
Else
MessageBox.Show("Please select a row to delete.")
End If
End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles


btnClear.Click
ClearFields()
End Sub

Private Sub ClearFields()


EmployeeBox.Clear()
IdBox.Clear()
PositionBox.Clear()
HoursWorkedBox.Clear()
NetPayBox.Clear()
HourlyRateBox.Clear()
AdvancePayBox.Clear()
End Sub
Private Sub UpdateNetPay(sender As Object, e As EventArgs)
Dim hoursWorked As Double
Dim hourlyRate As Double
Dim advancePay As Double

If Double.TryParse(HoursWorkedBox.Text, hoursWorked) AndAlso


Double.TryParse(HourlyRateBox.Text, hourlyRate) AndAlso
Double.TryParse(AdvancePayBox.Text, advancePay) Then

Dim grossPay As Double = hoursWorked * hourlyRate


Dim netPay As Double = grossPay - advancePay
NetPayBox.Text = netPay.ToString("C2")
Else
NetPayBox.Clear()
End If
End Sub

Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles


PictureBox2.Click
If String.IsNullOrWhiteSpace(SearchBar.Text) Then
MessageBox.Show("Please enter an Employee Name or ID to search.")
Return
End If

Dim found As Boolean = False


For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells(0).Value Is Nothing Then Continue For

If
row.Cells(0).Value.ToString().ToLower().Contains(SearchBar.Text.ToLower()) Or

row.Cells(1).Value.ToString().ToLower().Contains(SearchBar.Text.ToLower()) Then

Dim employeeName As String = row.Cells(0).Value.ToString()


Dim id As String = row.Cells(1).Value.ToString()
Dim position As String = row.Cells(2).Value.ToString()
Dim hoursWorked As String = row.Cells(3).Value.ToString()
Dim hourlyRate As String =
(Double.Parse(row.Cells(4).Value.ToString().Replace("₱", "").Replace(",", "")) /
Double.Parse(hoursWorked)).ToString("F2")
Dim advancePay As String =
row.Cells(5).Value.ToString().Replace("₱", "").Replace(",", "")
Dim netPay As String = row.Cells(6).Value.ToString()

Dim form3 As New Form3()


form3.DisplayEmployeeInfo(employeeName, id, position, hoursWorked,
hourlyRate, advancePay, netPay)
form3.Show()

found = True
Exit For
End If
Next

If Not found Then


MessageBox.Show("No matching employee found.")
ClearFields()
End If
End Sub

Private Sub SearchBar_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


SearchBar.KeyPress
If e.KeyChar = Convert.ToChar(Keys.Enter) Then
e.Handled = True
PictureBox2_Click(sender, e)
End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
Application.Exit()
End Sub
End Class

You might also like