Code Implementation
Dashboard.aspx
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Dashboard.aspx.vb" Inherits="Dashboard" %>
<!DOCTYPE html>
<html>
<head>
<title>Dashboard</title>
<link rel="stylesheet" href="styles.css" />
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #f0f4f8;
margin: 0;
padding: 0;
}
.container {
max-width: 900px;
margin: 40px auto;
background: white;
padding: 30px 40px;
box-shadow: 0 8px 16px rgba(0,0,0,0.1);
border-radius: 12px;
}
h2 {
text-align: center;
color: #333;
margin-bottom: 30px;
}
.welcome {
font-size: 1.2rem;
font-weight: 600;
color: #007ACC;
margin-bottom: 25px;
text-align: center;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
gap: 20px;
}
.card-btn {
background-color: #007ACC;
color: white;
border: none;
padding: 18px 0;
border-radius: 10px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
box-shadow: 0 5px 15px rgba(0, 122, 204, 0.3);
transition: background-color 0.3s ease, transform 0.2s ease;
text-align: center;
text-decoration: none;
display: inline-block;
}
.card-btn:hover {
background-color: #005a99;
transform: translateY(-3px);
}
.logout-btn {
background-color: #d9534f !important;
box-shadow: 0 5px 15px rgba(217, 83, 79, 0.4) !important;
}
.logout-btn:hover {
background-color: #b52b27 !important;
}
</style>
</head>
<body>
<form runat="server">
<div class="container">
<h2>Employee Payroll System Dashboard</h2>
<div class="welcome">Welcome, <asp:Label ID="lblUser" runat="server" /></div>
<div class="grid">
<asp:Button CssClass="card-btn" Text="Register Employee" PostBackUrl="Register.aspx" runat="server" />
<asp:Button CssClass="card-btn" Text="Payments" PostBackUrl="Payments.aspx" runat="server" />
<asp:Button CssClass="card-btn" Text="Leaves" PostBackUrl="Leaves.aspx" runat="server" />
<asp:Button CssClass="card-btn" Text="Salary Slip" PostBackUrl="SalarySlip.aspx" runat="server" />
<asp:Button ID="btnLogout" CssClass="card-btn logout-btn" Text="Logout" OnClick="btnLogout_Click" runat="server" />
</div>
</div>
</form>
</body>
</html>
Dashboard.aspx.vb
Partial Class Dashboard
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Session("username") Is Nothing Then
Response.Redirect("Login.aspx")
Else
lblUser.Text = Session("username").ToString()
End If
End Sub
Protected Sub btnLogout_Click(sender As Object, e As EventArgs)
Session.Abandon()
Response.Redirect("Login.aspx")
End Sub
End Class
Register.aspx
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Register.aspx.vb" Inherits="Register" %>
<!DOCTYPE html>
<html>
<head>
<title>Register Employee - EPS</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<form id="form1" runat="server" style="max-width: 500px; margin:auto; padding:20px; border:1px solid #ccc; border-radius: 5px;">
<h2>Register Employee</h2>
<asp:Label ID="lblMessage" runat="server" CssClass="message" /><br />
<asp:TextBox ID="txtName" runat="server" Placeholder="Full Name" CssClass="inputField" />
<asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtName" ErrorMessage="Name required" ForeColor="Red" Display="Dynamic" /><br /><br />
<asp:TextBox ID="txtEmail" runat="server" Placeholder="Email Address" CssClass="inputField" />
<asp:RequiredFieldValidator ID="rfvEmail" runat="server" ControlToValidate="txtEmail" ErrorMessage="Email required" ForeColor="Red" Display="Dynamic" />
<asp:RegularExpressionValidator ID="revEmail" runat="server" ControlToValidate="txtEmail" ErrorMessage="Invalid email format" ValidationExpression="^\S+@\S+\.\S+$" ForeColor="Red" Display="Dynamic" /><br /><br />
<asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" Rows="3" Placeholder="Address" CssClass="inputField" /><br /><br />
<asp:TextBox ID="txtPhone" runat="server" Placeholder="Phone Number" CssClass="inputField" />
<asp:RequiredFieldValidator ID="rfvPhone" runat="server" ControlToValidate="txtPhone" ErrorMessage="Phone required" ForeColor="Red" Display="Dynamic" /><br /><br />
<asp:TextBox ID="txtDOJ" runat="server" TextMode="Date" CssClass="inputField" />
<asp:RequiredFieldValidator ID="rfvDOJ" runat="server" ControlToValidate="txtDOJ" ErrorMessage="Date of Joining required" ForeColor="Red" Display="Dynamic" /><br /><br />
<asp:DropDownList ID="ddlDepartment" runat="server" CssClass="inputField" AppendDataBoundItems="true">
<asp:ListItem Text="-- Select Department --" Value="0" />
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvDept" runat="server" ControlToValidate="ddlDepartment" InitialValue="0" ErrorMessage="Please select a department" ForeColor="Red" Display="Dynamic" /><br /><br />
<asp:Button ID="btnRegister" runat="server" Text="Register" OnClick="btnRegister_Click" CssClass="button" />
<asp:Button ID="btnBack" runat="server" Text="Back to Dashboard" CssClass="button" PostBackUrl="Dashboard.aspx" Style="margin-left:10px;" CausesValidation="False"/>
</form>
</body>
</html>
Register.aspx.vb
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class Register
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadDepartments()
End If
End Sub
Private Sub LoadDepartments()
Dim connStr As String = ConfigurationManager.ConnectionStrings("SqlConn").ConnectionString
Using conn As New SqlConnection(connStr)
Dim query As String = "SELECT DeptID, DeptName FROM Departments"
Dim cmd As New SqlCommand(query, conn)
Try
conn.Open()
ddlDepartment.DataSource = cmd.ExecuteReader()
ddlDepartment.DataTextField = "DeptName"
ddlDepartment.DataValueField = "DeptID"
ddlDepartment.DataBind()
Catch ex As Exception
lblMessage.Text = "Could not load departments."
lblMessage.ForeColor = Drawing.Color.Red
End Try
End Using
End Sub
Protected Sub btnRegister_Click(sender As Object, e As EventArgs)
If String.IsNullOrWhiteSpace(txtName.Text) OrElse _
String.IsNullOrWhiteSpace(txtEmail.Text) OrElse _
String.IsNullOrWhiteSpace(txtPhone.Text) OrElse _
String.IsNullOrWhiteSpace(txtDOJ.Text) OrElse _
ddlDepartment.SelectedValue = "0" Then
lblMessage.Text = "Please fill all required fields and select a department."
lblMessage.ForeColor = Drawing.Color.Red
Return
End If
Dim dojDate As Date
If Not Date.TryParse(txtDOJ.Text, dojDate) Then
lblMessage.Text = "Please enter a valid Date of Joining."
lblMessage.ForeColor = Drawing.Color.Red
Return
End If
Dim deptId As Integer = Integer.Parse(ddlDepartment.SelectedValue)
Dim connStr As String = ConfigurationManager.ConnectionStrings("SqlConn").ConnectionString
Try
Using conn As New SqlConnection(connStr)
conn.Open()
Dim query As String = "INSERT INTO Employees (FullName, Email, Address, Phone, DOJ, DeptID) " & _
"VALUES (@name, @email, @address, @phone, @doj, @deptId)"
Using cmd As New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@name", txtName.Text.Trim())
cmd.Parameters.AddWithValue("@email", txtEmail.Text.Trim())
cmd.Parameters.AddWithValue("@address", txtAddress.Text.Trim())
cmd.Parameters.AddWithValue("@phone", txtPhone.Text.Trim())
cmd.Parameters.AddWithValue("@doj", dojDate)
cmd.Parameters.AddWithValue("@deptId", deptId)
Dim rows = cmd.ExecuteNonQuery()
If rows > 0 Then
lblMessage.Text = "Employee registered successfully!"
lblMessage.ForeColor = Drawing.Color.Green
ClearForm()
Else
lblMessage.Text = "Registration failed. Try again."
lblMessage.ForeColor = Drawing.Color.Red
End If
End Using
End Using
Catch ex As Exception
lblMessage.Text = "Error: " & ex.Message
lblMessage.ForeColor = Drawing.Color.Red
End Try
End Sub
Private Sub ClearForm()
txtName.Text = ""
txtEmail.Text = ""
txtAddress.Text = ""
txtPhone.Text = ""
txtDOJ.Text = ""
ddlDepartment.SelectedIndex = 0
End Sub
Protected Sub btnBack_Click(sender As Object, e As EventArgs)
Response.Redirect("~/Project/Dashboard.aspx")
End Sub
End Class
Salary Slip.aspx
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="SalarySlip.aspx.vb" Inherits="SalarySlip" %>
<!DOCTYPE html>
<html>
<head>
<title>Salary Slip</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<form runat="server">
<div class="container">
<h2>View Salary Slip</h2>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="validation-summary" HeaderText="Please fix the following:" ForeColor="Red" />
<asp:TextBox ID="txtEmpID" runat="server" Placeholder="Employee ID" CssClass="textbox" />
<asp:RequiredFieldValidator ID="rfvEmpID" runat="server" ControlToValidate="txtEmpID" ErrorMessage="Employee ID is required." ForeColor="Red" Display="Dynamic" />
<br /><br />
<asp:Button ID="btnView" runat="server" Text="View Slip" OnClick="btnView_Click" CssClass="button" />
<asp:GridView ID="gvSlip" runat="server" AutoGenerateColumns="False" CssClass="salaryslip-table" GridLines="None"
HeaderStyle-CssClass="gv-header"
RowStyle-CssClass="gv-row"
AlternatingRowStyle-CssClass="gv-alt" ShowHeaderWhenEmpty="True" EmptyDataText="No records found.">
<Columns>
<asp:BoundField DataField="NAME" HeaderText="Employee Name" />
<asp:BoundField DataField="Month" HeaderText="Month" />
<asp:BoundField DataField="Year" HeaderText="Year" />
<asp:BoundField DataField="BasicSalary" HeaderText="Basic Salary" DataFormatString="{0:C}" HtmlEncode="false" />
<asp:BoundField DataField="TotalPay" HeaderText="Total Pay" DataFormatString="{0:C}" HtmlEncode="false" />
</Columns>
</asp:GridView>
<asp:Button ID="btnBack" runat="server" Text="Back to Dashboard" PostBackUrl="Dashboard.aspx" CssClass="button" />
</div>
</form>
</body>
</html>
Salary Slip.aspx.vb
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class SalarySlip
Inherits System.Web.UI.Page
Protected Sub btnView_Click(sender As Object, e As EventArgs)
Dim empID As String = txtEmpID.Text.Trim()
If String.IsNullOrEmpty(empID) Then Return
Dim connStr As String = ConfigurationManager.ConnectionStrings("SqlConn").ConnectionString
Using conn As New SqlConnection(connStr)
Try
conn.Open()
Dim query As String = "SELECT e.FullName AS NAME, p.Month, p.Year, p.BasicSalary, p.TotalPay " & _
"FROM Payments p INNER JOIN Employees e ON p.EmpID = e.EmpID " & _
"WHERE p.EmpID = @eid " & _
"ORDER BY p.Year DESC, p.Month DESC"
Dim cmd As New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@eid", empID)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
da.Fill(dt)
gvSlip.DataSource = dt
gvSlip.DataBind()
Catch ex As Exception
' Handle error
' lblMessage.Text = "Error: " & ex.Message
End Try
End Using
End Sub
End Class
Payments.aspx
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Payments.aspx.vb" Inherits="Payments" %>
<!DOCTYPE html>
<html>
<head>
<title>Employee Payments</title>
<link rel="stylesheet" href="styles.css" />
<style>
.error { color: red; margin-bottom: 10px; }
.success { color: green; margin-bottom: 10px; }
input[type=text] { width: 100%; padding: 8px; box-sizing: border-box; }
.button { padding: 8px 15px; margin-right: 10px; }
</style>
</head>
<body>
<form runat="server">
<div style="width: 400px; margin: auto;">
<h3>Add Payment</h3>
<asp:Label ID="lblMessage" runat="server"></asp:Label>
<asp:TextBox ID="txtEmpID" runat="server" Placeholder="Employee ID (numeric)" MaxLength="10" /><br /><br />
<asp:TextBox ID="txtMonth" runat="server" Placeholder="Month (e.g., January)" MaxLength="20" /><br /><br />
<asp:TextBox ID="txtYear" runat="server" Placeholder="Year (numeric)" MaxLength="4" /><br /><br />
<asp:TextBox ID="txtBasic" runat="server" Placeholder="Basic Salary (decimal)" MaxLength="15" /><br /><br />
<asp:TextBox ID="txtTotal" runat="server" Placeholder="Total Pay (decimal)" MaxLength="15" /><br /><br />
<asp:Button ID="btnAddPay" runat="server" Text="Add Payment" CssClass="button" OnClick="btnAddPay_Click" />
<asp:Button ID="btnBack" runat="server" Text="Back to Dashboard" PostBackUrl="Dashboard.aspx" CssClass="button" />
</div>
</form>
</body>
</html>
Payments.aspx.vb
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Data
Partial Class Payments
Inherits System.Web.UI.Page
Protected Sub btnAddPay_Click(sender As Object, e As EventArgs)
If Not ValidateInputs() Then Exit Sub
Dim connStr As String = ConfigurationManager.ConnectionStrings("SqlConn").ConnectionString
Using conn As New SqlConnection(connStr)
Try
conn.Open()
' ✅ Check if Employee exists
Dim checkEmpQuery As String = "SELECT COUNT(1) FROM Employees WHERE EmpID = @eid"
Using checkCmd As New SqlCommand(checkEmpQuery, conn)
checkCmd.Parameters.Add("@eid", SqlDbType.Int).Value = Convert.ToInt32(txtEmpID.Text.Trim())
Dim exists As Integer = Convert.ToInt32(checkCmd.ExecuteScalar())
If exists = 0 Then
lblMessage.Text = "Error: Employee ID does not exist."
lblMessage.CssClass = "error"
Exit Sub
End If
End Using
' ✅ Insert into Payments table
Dim insertQuery As String = "INSERT INTO Payments (EmpID, Month, Year, BasicSalary, TotalPay) " &
"VALUES (@eid, @month, @year, @basicSalary, @totalPay)"
Using cmd As New SqlCommand(insertQuery, conn)
cmd.Parameters.Add("@eid", SqlDbType.Int).Value = Convert.ToInt32(txtEmpID.Text.Trim())
cmd.Parameters.Add("@month", SqlDbType.NVarChar, 20).Value = txtMonth.Text.Trim()
cmd.Parameters.Add("@year", SqlDbType.Int).Value = Convert.ToInt32(txtYear.Text.Trim())
cmd.Parameters.Add("@basicSalary", SqlDbType.Decimal).Value = Convert.ToDecimal(txtBasic.Text.Trim())
cmd.Parameters.Add("@totalPay", SqlDbType.Decimal).Value = Convert.ToDecimal(txtTotal.Text.Trim())
cmd.ExecuteNonQuery()
End Using
lblMessage.Text = "✅ Payment record added successfully."
lblMessage.CssClass = "success"
ClearFields()
Catch ex As Exception
lblMessage.Text = "❌ Error: " & ex.Message
lblMessage.CssClass = "error"
End Try
End Using
End Sub
Private Function ValidateInputs() As Boolean
lblMessage.Text = ""
lblMessage.CssClass = ""
Dim eid As Integer
Dim yr As Integer
Dim bs As Decimal
Dim tp As Decimal
If String.IsNullOrWhiteSpace(txtEmpID.Text) OrElse Not Integer.TryParse(txtEmpID.Text.Trim(), eid) Then
lblMessage.Text = "Please enter a valid Employee ID (numeric)."
lblMessage.CssClass = "error"
Return False
End If
If String.IsNullOrWhiteSpace(txtMonth.Text) Then
lblMessage.Text = "Please enter the Month."
lblMessage.CssClass = "error"
Return False
End If
If String.IsNullOrWhiteSpace(txtYear.Text) OrElse Not Integer.TryParse(txtYear.Text.Trim(), yr) Then
lblMessage.Text = "Please enter a valid Year (numeric)."
lblMessage.CssClass = "error"
Return False
End If
If String.IsNullOrWhiteSpace(txtBasic.Text) OrElse Not Decimal.TryParse(txtBasic.Text.Trim(), bs) Then
lblMessage.Text = "Please enter a valid Basic Salary (decimal)."
lblMessage.CssClass = "error"
Return False
End If
If String.IsNullOrWhiteSpace(txtTotal.Text) OrElse Not Decimal.TryParse(txtTotal.Text.Trim(), tp) Then
lblMessage.Text = "Please enter a valid Total Pay (decimal)."
lblMessage.CssClass = "error"
Return False
End If
Return True
End Function
Private Sub ClearFields()
txtEmpID.Text = ""
txtMonth.Text = ""
txtYear.Text = ""
txtBasic.Text = ""
txtTotal.Text = ""
End Sub
End Class
Login.aspx
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Login.aspx.vb" Inherits="Login" %>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<form runat="server">
<div style="text-align:center;">
<h2>Login to Employee Payroll System</h2>
<asp:TextBox ID="txtUsername" runat="server" Placeholder="Username" /><br /><br />
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Placeholder="Password" /><br /><br />
<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" CssClass="button" />
<p>Username: payrollAdmin, Password: SecurePass2025!</p>
</div>
</form>
</body>
</html>
Login.aspx.vb
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class Login
Inherits System.Web.UI.Page
Protected Sub btnLogin_Click(sender As Object, e As EventArgs)
Dim username As String = txtUsername.Text.Trim()
Dim password As String = txtPassword.Text.Trim()
Dim connStr As String = ConfigurationManager.ConnectionStrings("SqlConn").ConnectionString
Dim query As String = "SELECT COUNT(*) FROM Users WHERE Username = @username AND Password = @password"
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@username", username)
cmd.Parameters.AddWithValue("@password", password)
Try
conn.Open()
Dim userCount As Integer = Convert.ToInt32(cmd.ExecuteScalar())
If userCount > 0 Then
Session("username") = username
Response.Redirect("Dashboard.aspx")
Else
Response.Write("<script>alert('Invalid credentials. Please try again.');</script>")
End If
Catch ex As Exception
Response.Write("<script>alert('Database error: " & ex.Message & "');</script>")
End Try
End Using
End Using
End Sub
End Class
Leaves.aspx
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Leaves.aspx.vb" Inherits="Leaves" %>
<!DOCTYPE html>
<html>
<head>
<title>Leave Records</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<form runat="server">
<div style="width:500px; margin:auto;">
<h3>Record Leave</h3>
<asp:TextBox ID="txtEmpID" runat="server" Placeholder="Employee ID" /><br /><br />
<asp:TextBox ID="txtLeaveType" runat="server" Placeholder="Leave Type" /><br /><br />
<asp:TextBox ID="txtLeaveDate" runat="server" TextMode="Date" /><br /><br />
<asp:TextBox ID="txtDays" runat="server" Placeholder="Number of Days" /><br /><br />
<asp:Button ID="btnLeave" runat="server" Text="Record Leave" OnClick="btnLeave_Click" CssClass="button" /><br /><br />
<asp:Button ID="btnBack" runat="server" Text="Back to Dashboard" PostBackUrl="Dashboard.aspx" CssClass="button" /><br /><br />
<asp:Label ID="lblMessage" runat="server" /><br /><br />
<h4>Existing Leave Records</h4>
<asp:GridView ID="gvLeaves" runat="server" AutoGenerateColumns="True" />
</div>
</form>
</body>
</html>
Leaves.aspx.vb
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class Leaves
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Session("username") Is Nothing Then
Response.Redirect("Login.aspx")
End If
If Not IsPostBack Then
LoadLeaveRecords()
End If
End Sub
Protected Sub btnLeave_Click(sender As Object, e As EventArgs)
Dim empID As Integer
Dim leaveType As String = txtLeaveType.Text.Trim()
Dim leaveDate As DateTime
Dim days As Integer
If Not Integer.TryParse(txtEmpID.Text.Trim(), empID) OrElse String.IsNullOrEmpty(leaveType) _
OrElse Not DateTime.TryParse(txtLeaveDate.Text, leaveDate) _
OrElse Not Integer.TryParse(txtDays.Text, days) OrElse days <= 0 Then
lblMessage.ForeColor = Drawing.Color.Red
lblMessage.Text = "Please fill in all fields with valid data."
Return
End If
Dim connStr As String = ConfigurationManager.ConnectionStrings("SqlConn").ConnectionString
Using conn As New SqlConnection(connStr)
Dim query As String = "INSERT INTO Leaves (EmpID, LeaveType, LeaveDate, NumDays) VALUES (@EmpID, @LeaveType, @LeaveDate, @NumDays)"
Using cmd As New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@EmpID", empID)
cmd.Parameters.AddWithValue("@LeaveType", leaveType)
cmd.Parameters.AddWithValue("@LeaveDate", leaveDate)
cmd.Parameters.AddWithValue("@NumDays", days)
conn.Open()
cmd.ExecuteNonQuery()
End Using
End Using
lblMessage.ForeColor = Drawing.Color.Green
lblMessage.Text = "Leave recorded successfully!"
' Clear form
txtEmpID.Text = ""
txtLeaveType.Text = ""
txtLeaveDate.Text = ""
txtDays.Text = ""
' Refresh GridView
LoadLeaveRecords()
End Sub
Private Sub LoadLeaveRecords()
Dim connStr As String = "workstation id=ShaheenaDatabase.mssql.somee.com;packet size=4096;user id=Shaheena_SQLLogin_4;pwd=6qg31vdupf;data source=ShaheenaDatabase.mssql.somee.com;persist security info=False;initial catalog=ShaheenaDatabase;TrustServerCertificate=True"
Using conn As New SqlConnection(connStr)
Dim query As String = "SELECT L.LeaveID, E.FullName, L.LeaveType, L.LeaveDate, L.NumDays " &
"FROM Leaves L " &
"JOIN Employees E ON L.EmpID = E.EmpID"
Using cmd As New SqlCommand(query, conn)
Using adapter As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
adapter.Fill(dt)
gvLeaves.DataSource = dt
gvLeaves.DataBind()
End Using
End Using
End Using
End Sub
End Class