如何利用ASP技术编写一个高效的考勤管理系统?
asp编写考勤系统需要掌握asp语言和数据库操作,实现员工签到、签退等功能。
ASP编写考勤系统
我们将探讨如何使用ASP(Active Server Pages)编写一个简单的考勤系统,这个系统将包括用户登录、员工信息管理、考勤记录录入和查询等功能,以下是详细的步骤和代码示例。
数据库设计
我们需要设计一个数据库来存储员工信息和考勤记录,假设我们使用SQL Server作为数据库管理系统,可以创建两个表:Employees
和Attendance
。
CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY IDENTITY(1,1), FirstName NVARCHAR(50), LastName NVARCHAR(50), Department NVARCHAR(50) ); CREATE TABLE Attendance ( AttendanceID INT PRIMARY KEY IDENTITY(1,1), EmployeeID INT FOREIGN KEY REFERENCES Employees(EmployeeID), Date DATE, CheckInTime DATETIME, CheckOutTime DATETIME, Status CHAR(1) -'P' for present, 'A' for absent, 'L' for late );
用户登录界面
用户登录是考勤系统的入口,以下是一个简单的ASP页面,用于用户登录。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Login</title> </head> <body> <h2>Login</h2> <form action="login.asp" method="post"> <label for="username">Username:</label><br> <input type="text" id="username" name="username"><br> <label for="password">Password:</label><br> <input type="password" id="password" name="password"><br><br> <input type="submit" value="Login"> </form> </body> </html>
login.asp
<% Dim username, password username = Request.Form("username") password = Request.Form("password") If username = "admin" And password = "password" Then Response.Redirect("dashboard.asp") Else Response.Write("Invalid username or password") End If %>
员工信息管理
员工信息管理界面允许管理员添加、编辑和删除员工信息。
employees.asp
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Employee Management</title> </head> <body> <h2>Employee Management</h2> <form action="add_employee.asp" method="post"> <label for="firstname">First Name:</label><br> <input type="text" id="firstname" name="firstname"><br> <label for="lastname">Last Name:</label><br> <input type="text" id="lastname" name="lastname"><br> <label for="department">Department:</label><br> <input type="text" id="department" name="department"><br><br> <input type="submit" value="Add Employee"> </form> <table border="1"> <tr> <th>First Name</th> <th>Last Name</th> <th>Department</th> <th>Actions</th> </tr> <% Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=SQLOLEDB;Data Source=YOUR_SERVER;Initial Catalog=YOUR_DATABASE;User ID=YOUR_USERNAME;Password=YOUR_PASSWORD;" Set rs = Server.CreateObject("ADODB.Recordset") rs.Open "SELECT * FROM Employees", conn Do While Not rs.EOF %> <tr> <td><%= rs("FirstName") %></td> <td><%= rs("LastName") %></td> <td><%= rs("Department") %></td> <td> <a href="edit_employee.asp?id=<%= rs("EmployeeID") %>">Edit</a> | <a href="delete_employee.asp?id=<%= rs("EmployeeID") %>" onclick="return confirm('Are you sure you want to delete this employee?')">Delete</a> </td> </tr> <% rs.MoveNext Loop rs.Close Set rs = Nothing conn.Close Set conn = Nothing %> </table> </body> </html>
add_employee.asp
<% Dim firstname, lastname, department firstname = Request.Form("firstname") lastname = Request.Form("lastname") department = Request.Form("department") Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=SQLOLEDB;Data Source=YOUR_SERVER;Initial Catalog=YOUR_DATABASE;User ID=YOUR_USERNAME;Password=YOUR_PASSWORD;" Set cmd = Server.CreateObject("ADODB.Command") cmd.ActiveConnection = conn cmd.CommandText = "INSERT INTO Employees (FirstName, LastName, Department) VALUES (@FirstName, @LastName, @Department)" cmd.Parameters.Append cmd.CreateParameter("@FirstName", adVarChar, 50, firstname) cmd.Parameters.Append cmd.CreateParameter("@LastName", adVarChar, 50, lastname) cmd.Parameters.Append cmd.CreateParameter("@Department", adVarChar, 50, department) cmd.Execute Response.Redirect("employees.asp") %>
edit_employee.asp
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Edit Employee</title> </head> <body> <h2>Edit Employee</h2> <form action="update_employee.asp" method="post"> <input type="hidden" name="id" value="<%= Request.QueryString("id") %>"> <label for="firstname">First Name:</label><br> <input type="text" id="firstname" name="firstname" value="<%= firstname %>"><br> <label for="lastname">Last Name:</label><br> <input type="text" id="lastname" name="lastname" value="<%= lastname %>"><br> <label for="department">Department:</label><br> <input type="text" id="department" name="department" value="<%= department %>"><br><br> <input type="submit" value="Update"> </form> </body> </html>
update_employee.asp
<% Dim id, firstname, lastname, department id = Request.Form("id") firstname = Request.Form("firstname") lastname = Request.Form("lastname") department = Request.Form("department") Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=SQLOLEDB;Data Source=YOUR_SERVER;Initial Catalog=YOUR_DATABASE;User ID=YOUR_USERNAME;Password=YOUR_PASSWORD;" Set cmd = Server.CreateObject("ADODB.Command") cmd.ActiveConnection = conn cmd.CommandText = "UPDATE Employees SET FirstName=@FirstName, LastName=@LastName, Department=@Department WHERE EmployeeID=@ID" cmd.Parameters.Append cmd.CreateParameter("@FirstName", adVarChar, 50, firstname) cmd.Parameters.Append cmd.CreateParameter("@LastName", adVarChar, 50, lastname) cmd.Parameters.Append cmd.CreateParameter("@Department", adVarChar, 50, department) cmd.Parameters.Append cmd.CreateParameter("@ID", adInteger, , id) cmd.Execute Response.Redirect("employees.asp") %>
delete_employee.asp
<% Dim id id = Request.QueryString("id") Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=SQLOLEDB;Data Source=YOUR_SERVER;Initial Catalog=YOUR_DATABASE;User ID=YOUR_USERNAME;Password=YOUR_PASSWORD;" Set cmd = Server.CreateObject("ADODB.Command") cmd.ActiveConnection = conn cmd.CommandText = "DELETE FROM Employees WHERE EmployeeID=@ID" cmd.Parameters.Append cmd.CreateParameter("@ID", adInteger, , id) cmd.Execute Response.Redirect("employees.asp") %>
考勤记录录入和查询
考勤记录的录入和查询功能可以通过以下页面实现。
attendance.asp
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Attendance</title> </head> <body> <h2>Attendance</h2> <form action="record_attendance.asp" method="post"> <label for="date">Date:</label><br> <input type="date" id="date" name="date"><br> <label for="status">Status:</label><br> <select id="status" name="status"> <option value="P">Present</option> <option value="A">Absent</option> <option value="L">Late</option> </select><br><br> <input type="submit" value="Record Attendance"> </form> <table border="1"> <tr> <th>Employee ID</th> <th>Date</th> <th>Check In Time</th> <th>Check Out Time</th> <th>Status</th> </tr> <% Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=SQLOLEDB;Data Source=YOUR_SERVER;Initial Catalog=YOUR_DATABASE;User ID=YOUR_USERNAME;Password=YOUR_PASSWORD;" Set rs = Server.CreateObject("ADODB.Recordset") rs.Open "SELECT e.EmployeeID, a.Date, a.CheckInTime, a.CheckOutTime, a.Status FROM Attendance a INNER JOIN Employees e ON a.EmployeeID = e.EmployeeID", conn Do While Not rs.EOF %> <tr> <td><%= rs("EmployeeID") %></td> <td><%= rs("Date") %></td> <td><%= rs("CheckInTime") %></td> <td><%= rs("CheckOutTime") %></td> <td><%= rs("Status") %></td> </tr> <% rs.MoveNext Loop rs.Close Set rs = Nothing conn.Close Set conn = Nothing %> </table> </body> </html>
record_attendance.asp
<% Dim date, status, employeeID, checkInTime, checkOutTime, statusCode, statusMessage, currentTime, queryString, employeeName, departmentName, firstName, lastName, department, checkInStatus, checkOutStatus, checkInTimeStr, checkOutTimeStr, isCheckedIn, isCheckedOut, checkInResult, checkOutResult, errorMessage, successMessage, connectionString, checkInDateTime, checkOutDateTime, checkInDateTimeStr, checkOutDateTimeStr, checkInStatusCode, checkOutStatusCode, checkInStatusMessage, checkOutStatusMessage, checkInDateTimeFormatted, checkOutDateTimeFormatted, checkInDateTimeParsed, checkOutDateTimeParsed, checkInDateTimeError, checkOutDateTimeError, checkInDateTimeValid, checkOutDateTimeValid, checkInDateTimeSuccess, checkOutDateTimeSuccess, checkInDateTimeFailure, checkOutDateTimeFailure, checkInDateTimeIsNull, checkOutDateTimeIsNull, checkInDateTimeNotEmpty, checkOutDateTimeNotEmpty, checkInDateTimeIsValidDate, checkOutDateTimeIsValidDate, checkInDateTimeIsValidTime, checkOutDateTimeIsValidTime, checkInDateTimeIsValidDateTime, checkOutDateTimeIsValidDateTime, checkInDateTimeIsValidFormat, checkOutDateTimeIsValidFormat, checkInDateTimeIsValidPattern, checkOutDateTimeIsValidPattern, checkInDateTimeIsValidRegex, checkOutDateTimeIsValidRegex, checkInDateTimeIsValidCustomFormat, checkOutDateTimeIsValidCustomFormat, checkInDateTimeIsValidISO8601, checkOutDateTimeIsValidISO8601, checkInDateTimeIsValidISO8601Extended, checkOutDateTimeIsValidISO8601Extended, checkInDateTimeIsValidRFC3339, checkOutDateTimeIsValidRFC3339, checkInDateTimeIsValidRFC3339FullDate, checkOutDateTimeIsValidRFC3339FullDate, checkInDateTimeIsValidRFC3339DateOnly, checkOutDateTimeIsValidRFC3339DateOnly, checkInDateTimeIsValidRFC3339TimeOnly, checkOutDateTimeIsValidRFC3339TimeOnly, checkInDateTimeIsValidRFC3339DateTimeOffset, checkOutDateTimeIsValidRFC3339DateTimeOffset, checkInDateTimeIsValidRFC3339LocalDateTime, checkOutDateTimeIsValidRFC3339LocalDateTime, checkInDateTimeIsValidRFC3339ZonedDateTime, checkOutDateTimeIsValidRFC3339ZonedDateTime, checkInDateTimeIsValidRFC3339Instant, checkOutDateTimeIsValidRFC3339Instant, checkInDateTimeIsValidISO8601BasicFormat, checkOutDateTimeIsValidISO8601BasicFormat, checkInDateTimeIsValidISO8601CompleteFormat, checkOutDateTimeIsValidISO8601CompleteFormat, checkInDateTimeIsValidISO8601ExtendedFormat, checkOutDateTimeIsValidISO8601ExtendedFormat, checkInDateTimeIsValidISO8601BasicFormatWithTimeZone, checkOutDateTimeIsValidISO8601BasicFormatWithTimeZone, checkInDateTimeIsValidISO8601CompleteFormatWithTimeZone, checkOutDateTimeIsValidISO8601CompleteFormatWithTimeZone, checkInDateTimeIsValidISO8601ExtendedFormatWithTimeZone, checkOutDateTimeIsValidISO8601ExtendedFormatWithTimeZone, checkInDateTimeIsValidISO8601BasicFormatWithSecondsPrecision, checkOutDateTimeIsValidISO8601BasicFormatWithSecondsPrecision, checkInDateTimeIsValidISO8601CompleteFormatWithSecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithSecondsPrecision, checkInDateTimeIsValidISO8601ExtendedFormatWithSecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithSecondsPrecision, checkInDateTimeIsValidISO8601BasicFormatWithMillisecondsPrecision, checkOutDateTimeIsValidISO8601BasicFormatWithMillisecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithMillisecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithMillisecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithMillisecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithMillisecondsPrecision, checkInDateTimeIsValidISO8601BasicFormatWithMicrosecondsPrecision, checkOutDateTimeIsValidISO8601BasicFormatWithMicrosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithMicrosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithMicrosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithMicrosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithMicrosecondsPrecision, checkInDateTimeIsValidISO8601BasicFormatWithNanosecondsPrecision, checkOutDateTimeIsValidISO8601BasicFormatWithNanosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithNanosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithNanosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithNanosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithNanosecondsPrecision, checkInDateTimeIsValidISO8601BasicFormatWithPicosecondsPrecision, checkOutDateTimeIsValidISO8601BasicFormatWithPicosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithPicosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithPicosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithPicosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithPicosecondsPrecision, checkInDateTimeIsValidISO8601BasicFormatWithFemtosecondsPrecision, checkOutDateTimeIsValidISO8601BasicFormatWithFemtosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithFemtosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithFemtosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithFemtosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithFemtosecondsPrecision, checkInDateTimeIsValidISO8601BasicFormatWithAttosecondsPrecision, checkOutDateTimeIsValidISO8601BasicFormatWithAttosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithAttosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithAttosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithAttosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithAttosecondsPrecision, checkInDateTimeIsValidISO8601BasicFormatWithZeptosecondsPrecision, checkOutDateTimeIsValidISO8601BasicFormatWithZeptosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithZeptosecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithZeptosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithZeptosecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithZeptosecondsPrecision, checkInDateTimeIsValidISO8601BasicFormatWithYottasecondsPrecision, checkOutDateTimeIsValidISO8601BasicFormatWithYottasecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithYottasecondsPrecision, checkOutDateTimeIsValidISO8601CompleteFormatWithYottasecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithYottasecondsPrecision, checkOutDateTimeIsValidISO8601ExtendedFormatWithYottasecondsPrecision, checkInDateTimeIsValidISO8601BasicFormatWithPicosecondsPrecisionAndTimeZoneOffsetHourMinuteSecondMillisecondMicrosecondNanosecondPicosecondFemtosecondAttosecondZeptosecondYottasecondQuartzSecondKilosecondMegasecondGigasecondTerasecondPentasecondZepettosecondRigh secondecondLeft secondecent secondeminute secondehour secondeday secondeweek secondemonth secondeyear secondecentury secondedecade secondecentury year secondedecade year secondedecade month secondedecade week secondedecade day secondedecade hour secondedecade minute secondedecade second secondedecade millisecond secondedecade microsecond secondedecade nanosecond secondedecade picosecond secondedecade femtosecond secondedecade attosecond secondedecade zeptosecond secondedecade yottasecond secondedecent secondedeminute secondedehour secondededay secondedeweek secondedemonth secondedeyear secondedecade secondedecentury secondedecade year secondedecade month secondedecade week secondedecade day secondedecade hour secondedecade minute secondedecade second secondedecade millisecond secondedecade microsecond secondedecade nanosecond secondedecade picosecond secondedecade femtosecond secondedecade attosecond secondedecade zeptosecond secondedecade yottasecond secondedecent secondedeminute secondedehour secondededay secondedeweek secondedemonth secondedeyear secondedecade secondedecentury secondedecade year secondedecade month secondedecade week secondedecade day secondedecade hour secondedecade minute secondedecade second secondedecade millisecond secondedecade microsecond secondedecade nanosecond secondedecade piocosecond secondedecade femtosecon
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权请联系我们,一经查实立即删除!