Tài liệu Bài thực hành số 5: Báo điện tử ppt

10 739 3
Tài liệu Bài thực hành số 5: Báo điện tử ppt

Đang tải... (xem toàn văn)

Thông tin tài liệu

Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset 1. Taoh CSDL HOSO.MDB và thiết kế bảng dữ liệu BAIVIET có cấu trúc như sau: 2. Thiết kế trang Default.asp cho phép hiển thị bảng BAIVIET theo dạng trang báo điện tử như sau: - Nếu người dùng nhấn liên kết Viết bài sẽ cho phép chuyển đến trang cap_nhat_bai_viet.asp để viết một bài mới - Nếu người dùng nhấn liên kết Quản trị bài viết sẽ cho phép chuyển đến trang Quan_tri_bai_viet.asp cho phép thêm mới, xoá, sửa các bài đã viết GV: LÊ ANH - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên 1 Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset 3. Thiết kế trang cap_nhat_bai_viet.asp như sau: Ghi chú: Giả sử các file ảnh đã có sẵn trong thư mục gốc của ứng dụng web. Tại mục Tên file ảnh chỉ cần nhập tên file (không cần nhập đường dẫn) ví dụ: Picture1.jpg 4. Thiết kế trang Quan_tri_bai_viet.asp như sau: - Nếu người dùng đánh dấu chọn một số bài viết nào đó và nhấn nút xoá thì các bài viết được chọn sẽ bị xoá khỏi CSDL - Nếu nhấn vào tiêu đề của bài viết (tại trang quản trị) sẽ cho phép sửa nội dung bài viết (chuyển đến trang SuaBaiviet.asp) GV: LÊ ANH - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên 2 Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset 5. Thiết kế trang SuaBaiviet.asp như sau: THAM KHẢO MÃ NGUỒN CÁC FILE ASP NHƯ SAU Connection.inc <% StrConn="Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & server.mappath("Hoso.mdb") Set conn=Server.CreateObject("ADODB.Connection") Conn.open StrConn Set RS=server.CreateObject("ADODB.Recordset") %> Default.asp <!--#include file=connection.inc--> <% StrSQL="Select * from Baiviet" rs.cursorLocation=3 rs.Pagesize=3 rs.open strSQL,conn,0,1 if request("ViewPage")<>"" then Session("CurrentPage")=cint(request("ViewPage")) else Session("CurrentPage")=cint(Session("CurrentPage"))+Request("Page") end if if cint(session("CurrentPage"))<1 then session("CurrentPage")=1 end if if cint(session("CurrentPage"))>rs.pagecount then session("CurrentPage")=rs.pagecount end if if not rs.eof then rs.absolutePage=session("CurrentPage") GV: LÊ ANH - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên 3 Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset 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>New Page 1</title> </head> <body> <table border="0" width="722" height="1"> <tr> <td width="672" colspan="3" bgcolor="#000080" height="1"><b><font size="7">&nbsp;</font><font size="6"> <font color="#FFFF00">TIN TUC NEWS</font></font></b></td> </tr> <tr> <td width="672" colspan="3" height="16" bgcolor="#00FFFF"> <b><font color="#0000FF">Trang <%=Session("CurrentPage")%>/<%=rs.pagecount %></font></b> <b><font color="#0000FF"> <a href="cap_nhat_bai_viet.asp" target="_blank">Viet bai&nbsp;</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="Quan_tri_bai_viet.asp" target="_blank">Quan tri bai da viet</a></font></b> </td> </tr> <% while not rs.eof and rs.absolutePage=session("CurrentPage") %> <tr> <td width="672" colspan="3" height="16" bgcolor="#C0C0C0"> <b> <a href=NDChitiet.asp?IDBaiviet=<%=rs.fields("Mabaiviet")%> target="_blank"><font color="#0000FF"><%=rs.fields("Tieude")%></font></a> </b> </td> </tr> <tr> <td width="102" height="21"> <img border="0" src=<%=server.mappath(rs.fields("FileAnh"))%> width="112" height="109"></td> <td width="564" height="21" colspan="2"><%=rs.fields("NDTomTat")%></td> </tr> <tr> <td width="672" colspan="3" height="21"> <p align="right"> GV: LÊ ANH - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên 4 Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset <i><font color="#0000FF"> <a href=NDChitiet.asp?IDBaiviet=<%=rs.fields("Mabaiviet")%> target="_blank">Chi tiet .</a> </font></i></td> </tr> <% rs.movenext wend %> <tr> <td width="102"> <%if cint(session("CurrentPage"))>1 then%> <a href=default.asp?Page=-1>Trang truoc</a> <%end if%> </td> <td width="130"> <% if (cint(session("CurrentPage"))+2)<=rs.pagecount then for i=cint(session("CurrentPage")) to cint(session("CurrentPage"))+2 'response.write " " %> &nbsp;&nbsp;<a href=default.asp?ViewPage=<%=i%>> <%=i%> </a> <% next else for i=cint(session("CurrentPage")) to rs.pagecount 'response.write " ; " %> &nbsp;&nbsp;<a href=default.asp?ViewPage=<%=i%>> <%=i%> </a> <% next end if %> &nbsp;&nbsp; . </td> <td width="428"> <%if cint(session("CurrentPage"))<Rs.PageCount then%> <a href=default.asp?Page=1>Trang sau</a> <% end if rs.close %> </td> </tr> </table> </body> </html> GV: LÊ ANH - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên 5 Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset Cap_nhat_bai_viet.asp <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>CAP NHAT BAI VIET</title> </head> <body> <form method="POST" action="Xuly_Capnhatbaiviet.asp"> <p> <b>CAP NHAT BAI VIET</b></p> <table border="1" width="71%"> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Tieu de</b></td> <td width="72%" bgcolor="#C0C0C0"><input type="text" name="txtTieude" size="55"></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Noi dung tom tat</b></td> <td width="72%" bgcolor="#C0C0C0"><textarea rows="5" name="txtaNDTomtat" cols="41"></textarea></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Noi dung chi tiet</b></td> <td width="72%" bgcolor="#C0C0C0"><textarea rows="5" name="txtaNDChitiet" cols="41"></textarea></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Ten file anh </b></td> <td width="72%" bgcolor="#C0C0C0"><input type="text" name="txtTenfileanh" size="55"></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Tac gia</b></td> <td width="72%" bgcolor="#C0C0C0"><input type="text" name="txtTacgia" size="55"></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Ngay viet</b></td> <td width="72%" bgcolor="#C0C0C0"><input type="text" name="txtNgayviet" size="17" value=<%=date()%>></td> </tr> </table> <blockquote> <blockquote> <p> <input type="submit" value=" Ghi " name="CmdGhi">&nbsp;&nbsp; GV: LÊ ANH - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên 6 Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset &nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" value="Nhaplai" name="cmdNhaplai"></p> </blockquote> </blockquote> </form> </body> </html> Xuly_Capnhatbaiviet.asp <!--#include file=connection.inc--> <% StrSQL="Select * from Baiviet" rs.open strSQL,Conn,1,3 rs.addnew rs.fields("tieude")=request.form("txttieude") rs.fields("NDTomtat")=request.form("txtaNDTomtat") rs.fields("NDChitiet")=request.form("txtaNDChitiet") rs.fields("fileanh")=request.form("txttenfileanh") rs.fields("tacgia")=request.form("txttacgia") rs.fields("ngayviet")=cdate(request.form("txtngayviet")) rs.update rs.close response.redirect("quan_tri_bai_viet.asp") %> Quan_tri_bai_viet.asp <!--#include file=connection.inc--> <% StrSQL="Select * from Baiviet" 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>QUAN TRI BAI VIET</title> </head> <body> <form method="POST" action="Xuly_quantri.asp"> <p align="center"><b><font size="5">QUAN TRI BAI VIET</font></b></p> <table border="1" width="100%"> <tr> <td width="1%" align="center" bgcolor="#008080"><b><input type="submit" value="Xoa" name="cmdXoa"></b></td> <td width="42%" align="center" bgcolor="#008080"><b>Tieu de</b></td> GV: LÊ ANH - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên 7 Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset <td width="23%" align="center" bgcolor="#008080"><b>Tac gia</b></td> <td width="11%" align="center" bgcolor="#008080"><b>Ngay viet</b></td> </tr> <% while not rs.eof %> <tr> <td width="1%" align="center" bgcolor="#C0C0C0"><p align="center"> <input type="checkbox" name="chkXoa" value=<%=rs.fields("Mabaiviet")%>> </td> <td width="42%"><a href=SuaBaiviet.asp?MaBai=<%=rs.fields("Mabaiviet")%>> < %=rs.fields("tieude")%> </a></td> <td width="23%"><%=rs.fields("Tacgia")%></td> <td width="11%" align="center"><%=rs.fields("Ngayviet")%></td> </tr> <% rs.movenext wend rs.close %> </table> <p><a href="cap_nhat_bai_viet.asp" target="_blank">Viet bai moi</a></p> </form> </body> </html> Xuly_quantri.asp <!--#include file=connection.inc--> <% IF request.form("cmdXoa")<>"" THEN for i=1 to request.form("chkXoa").count if request.form("chkXoa")(i)<>"" then strSQL="Select * from Baiviet where mabaiviet=" & cint(request.form("chkXoa")(i)) rs.open strsQL,Conn,1,3 rs.delete rs.close End if next response.redirect("quan_tri_bai_viet.asp") END IF %> SuaBaiviet.asp <!--#include file=connection.inc--> <% session("Mabai")=request("Mabai") StrSQL="Select * from Baiviet where Mabaiviet=" & request("Mabai") rs.open strSQL,Conn GV: LÊ ANH - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên 8 Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset %> <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>CAP NHAT BAI VIET</title> </head> <body> <form method="POST" action="Xuly_Suabaiviet.asp"> <p> <b>SUA BAI VIET</b></p> <table border="1" width="71%"> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Ma bai viet</b></td> <td width="72%" bgcolor="#C0C0C0"><%=rs.fields("Mabaiviet")%></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Tieu de</b></td> <td width="72%" bgcolor="#C0C0C0"><input type="text" name="txtTieude" size="55" value=<%="'" & rs.fields("Tieude") & "'"%>></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Noi dung tom tat</b></td> <td width="72%" bgcolor="#C0C0C0"> <textarea rows="5" name="txtaNDTomtat" cols="41"><%=rs.fields("NDTomtat") %></textarea></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Noi dung chi tiet</b></td> <td width="72%" bgcolor="#C0C0C0"> <textarea rows="5" name="txtaNDChitiet" cols="41"><%=rs.fields("NDChitiet") %></textarea></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Ten file anh </b></td> <td width="72%" bgcolor="#C0C0C0"><input type="text" name="txtTenfileanh" size="55" value=<%=rs.fields("FileAnh")%>></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Tac gia</b></td> <td width="72%" bgcolor="#C0C0C0"><input type="text" name="txtTacgia" size="55" value=<%="'"&rs.fields("Tacgia")&"'"%>></td> </tr> <tr> <td width="28%" bgcolor="#C0C0C0"><b>Ngay viet</b></td> <td width="72%" bgcolor="#C0C0C0"><input type="text" name="txtNgayviet" size="17" value=<%=rs.fields("Ngayviet")%>></td> </tr> GV: LÊ ANH - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên 9 Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset </table> <blockquote> <blockquote> <p> <input type="submit" value=" Ghi " name="CmdGhi">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; </p> </blockquote> </blockquote> </form> </body> </html> Xuly_Suabaiviet.asp <!--#include file=connection.inc--> <% StrSQL="Select * from Baiviet where Mabaiviet=" & session("Mabai") rs.open strSQL,Conn,1,3 rs.fields("tieude")=request.form("txttieude") rs.fields("NDTomtat")=request.form("txtaNDTomtat") rs.fields("NDChitiet")=request.form("txtaNDChitiet") rs.fields("fileanh")=request.form("txttenfileanh") rs.fields("tacgia")=request.form("txttacgia") rs.fields("ngayviet")=cdate(request.form("txtngayviet")) rs.update rs.close response.redirect("quan_tri_bai_viet.asp") %> GV: LÊ ANH - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên 10 . Bài thực hành số 5: Báo điện tử ADO, Phân trang với Recordset 1. Taoh CSDL HOSO.MDB và thiết kế bảng dữ liệu BAIVIET có cấu trúc. dung bài viết (chuyển đến trang SuaBaiviet.asp) 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ố 5: Báo điện tử

Ngày đăng: 25/12/2013, 23:18

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan