Tải bản đầy đủ (.doc) (9 trang)

Tài liệu Bài thực hành số 6: ADO, Phân trang với Recordseự doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (389.79 KB, 9 trang )

Bài thực hành số 6: ADO, Phân trang với Recordset
1. Tạo CSDL HOSO.MDB và thiết kế các bảng dữ liệu có cấu trúc như sau:
Tạo quan hệ giữa 2 bảng như sau:


2. Thiết kế trang DEFAULT.ASP cho phép hiển thị các thông tin về sinh viên như sau:
Chú ý:
- Sử dụng kỹ thuật phân trang
- Các chức năng ADD, EDIT, DELETE để thực hiên các chức năng thêm mới, sửa, xóa các
bản ghi
- Nhấn vào Mã SV cho phép liên kết đến trang xem tổng hợp thông tin cá nhân về SV đó
(Ví dụ: Profile.asp)
GV: LÊ ANH TÚ - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên
1
Bảng Sinhvien
Bảng Tinh
Bài thực hành số 6: ADO, Phân trang với Recordset
3. Yêu cầu thiết giao diện các trang thêm mới và sửa như sau:
- Giao diện cập nhật SV mới

- Giao diện thay đổi thông tin cá nhân 1 SV đã nhập

MÃ NGUỒN MẦU
File Connection.inc
<%
FilePath=Server.Mappath("Hoso.mdb")
Set Conn=Server.CreateObject("ADODB.COnnection")
StrConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath
Conn.Open strConn
Set RS=Server.CreateObject("ADODB.Recordset")
%>


File Default.asp
<!--#include file=Connection.inc-->
<%
'Su dung Query trong Access de tao xau truy van nhu duoi day
StrSQL="SELECT SinhVien.*, [Tinh].[Tentinh] FROM Tinh INNER JOIN SinhVien ON [Tinh].
[MaTinh]=[SinhVien].[MaTinh];"
'Dat thuoc tinh cho RS co kha nang phan trang
RS.CursorLocation=3
RS.Pagesize=3
RS.Open StrSQL,Conn,0,1
'Xac dinh trang hien thoi
Session("CurrenPage")=1
If request("PageID")<>"" then
Session("CurrenPage")=Cint(request("PageID"))
End if
GV: LÊ ANH TÚ - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên
2
Bài thực hành số 6: ADO, Phân trang với Recordset
If not(RS.eof or RS.bof) then
RS.Absolutepage=Session("CurrenPage")
End if
%>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Phân trang với RS</title>
</head>

<body>
<p align="center"><b>DANH SACH SINH VIEN </b></p>
<form method="POST" action="Xuly_Default.asp">
<b>Page <%=Session("CurrenPage")%> of <%=RS.PageCount%></b>
<table border="0" width="100%">
<tr>
<td>STT</td>
<td>Sửa</td>
<td>Xóa</td>
<td>Mã SV</td>
<td>Họ và tên</td>
<td>Giới tính</td>
<td>Tuổi</td>
<td>Ngày vào đoàn</td>
<td>Tên Tỉnh</td>
<td>Sở thích</td>
</tr>
<%
i=RS.Pagesize*(Session("CurrenPage")-1)
While not RS.eof and RS.AbsolutePage=Session("CurrenPage")
i=i+1
%>
<tr>
<td><%=i%></td>
<td><input type="radio" value=<%=RS.Fields("MaSV")%> checked name="RdoSua"></td>
<td><input type="checkbox" name="chkXoa" value=<%=RS.Fields("MaSV")%>></td>
<td>
<a href=Profile.asp?MaSV_ID=<%=RS.Fields("MaSV")%>><%=RS.Fields("MaSV")%></a>
</td>
<td><%=RS.Fields("Hoten")%></td>

<td width="6%" align="center">
<%
If RS.Fields("Gioitinh") then
Response.Write("Nam")
Else
Response.Write("Nu")
End if
%>
</td>
<td width="6%" align="center"><%=RS.Fields("Tuoi")%></td>
<td width="9%"><%=RS.Fields("NgayDoan")%></td>
<td width="10%"><%=RS.Fields("Tentinh")%></td>
<td width="29%"><%=RS.Fields("Sothich")%></td>
</tr>
GV: LÊ ANH TÚ - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên
3
Bài thực hành số 6: ADO, Phân trang với Recordset
<%
RS.MoveNext
Wend
%>
</table>
<table border="0" width="100%">
<tr>
<td width="23%">
<%If Session("CurrenPage")=1 then
Response.write("Back")
Else%>
<a href=Default.asp?PageID=<%=Session("CurrenPage")-1%>>Back</a>
<%End if%>

</td>
<td width="54%">
<p align="center">
<%
k1=Session("CurrenPage")-1
k2=Session("CurrenPage")+1
If k1<1 then k1=1
If k2>RS.PageCount then k2=RS.PageCount
For i=k1 to k2
Response.write (" ")
If i=Session("CurrenPage") then
Response.write(i)
Else%>
<a href=Default.asp?PageID=<%=i%>><%=i%></a>
<%End if
Next
%>
</td>
<td width="23%">
<p align="right">
<%If Session("CurrenPage")=RS.PageCount then
Response.write("Next")
Else%>
<a href=Default.asp?PageID=<%=Session("CurrenPage")+1%>>Next</a>
<%End if
RS.Close
%>
</td>
</tr>
</table>

<input type="submit" value="Add" name="cmdAdd">
<input type="submit" value="Edit" name="cmdEdit">
<input type="submit" value="Delete" name="cmdDelete">
</form>
</body>
</html>
File Xuly_Default.asp
<%
if request.form("cmdAdd")<>"" then
response.redirect("Them.asp")
end if
if request.form("cmdEdit")<>"" then
session("MaSV")=request.form("rdoSua")
response.redirect("Sua.asp")
end if
GV: LÊ ANH TÚ - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên
4
Bài thực hành số 6: ADO, Phân trang với Recordset
if request.form("cmdDelete")<>"" then
%>
<!--#include file=xoa.asp-->
<%
end if
%>
File Them.asp
<!--#include file=Connection.inc-->
<%
StrSQL="Select * from Tinh Order By Tentinh"
RS.Open StrSQL,Conn
%>

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Thêm mới SV</title>
</head>
<body>
<form method="POST" action="Xuly_them.asp">
<b>CẬP NHẬT SINH VIÊN</b>
<table border="0" width="61%">
<tr><td>Mã SV</td><input type="text" name="txtMaSV" size="12"></td></tr>
<tr><td>HỌ và tên</td><td><input type="text" name="txtHoten" size="30"></td></tr>
<tr>
<td>Giới tính</td>
<td><input type="radio" value="Nam" checked name="rdoGT">Nam
<input type="radio" name="rdoGT" value="Nu">Nữ
</td>
</tr> <tr><td>Tuổi</td><td><input type="text" name="txtTuoi" size="12"></td> </tr>
<tr> <td>Ngày vào đoàn</td>
<td>
<select size="1" name="optNgay">
<%For i=1 to 31%>
<option <%if i=day(date()) then%> selected <%End if%> value=<%=i%>><%=i%></option>
<%Next%>
</select>
<select size="1" name="optThang">
<%For i=1 to 12%>
<option <%if i=month(date()) then%> selected <%End if%> value=<%=i%>><%=i%></option>

<%Next%>
</select>
<select size="1" name="optNam">
<%For i=1970 to year(date())%>
<option selected value=<%=i%>><%=i%></option>
<%Next%>
</select></td>
</tr>
<tr>
<td>Tỉnh</td>
<td>
<select size="1" name="optTinh">
<%
While not Rs.eof
GV: LÊ ANH TÚ - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên
5

×