📄 friend.aspx
字号:
<%@ Page Language="VB" ContentType="text/html" debug="true" %>
<%@ Import Namespace="system.data" %>
<%@ Import Namespace="system.data.oledb" %>
<html>
<head>
<title>zsczsc</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="CSS.CSS" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#CCCCCC">
<form runat="server" name="myfrm" >
<table width="549" height="24" border="0" cellpadding="0" cellspacing="0" background="pic/002.png">
<tr>
<td><font color="#FFFFFF"><strong> 我的好友</strong>(以好友昵称拼音排序)</font></td>
</tr>
</table>
<table width="549" height="400" border="1" cellpadding="0" cellspacing="0" bordercolorlight="#008080" bordercolordark="#FFFFFF">
<tr>
<td valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="540" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"><table width="100%" border="0">
<tr>
<td> <img src="pic/images/icon_group.gif" width="15" height="15"><strong>发送信件</strong></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="32%"> <div align="right">我要发信给:</div></td>
<td width="50%">
<asp:dropdownlist DataTextField="fname" DataValueField="fid" runat="server" ID="zfrienddropdown" />
<asp:button ID="zsendmail" runat="server" Text="转向发送页" onclick="zsendto" />
</td>
<td width="18%"> </td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1">
<tr>
<td>
<table width="540" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> <img src="pic/images/icon_group.gif" width="15" height="15"><strong>添加好友</strong></td>
<td> </td>
<td><strong><img src="pic/images/icon_group.gif" width="15" height="15"> <font color="#FF0000"><a href="#" onClick="javascript:window.open('userlist.aspx','_blank','width=549,height=430')">用户(ID)列表</a></font></strong></td>
</tr>
<tr>
<td width="24%" height="17">
<div align="right">好友昵称:</div></td>
<td width="28%"> <asp:textbox BorderStyle="solid" BorderWidth="1" ID="znicename" runat="server" TextMode="SingleLine" /><asp:requiredfieldvalidator EnableClientScript="false" ControlToValidate="znicename" Display="Dynamic" ErrorMessage="用户昵称必须填写" ID="rznicename" runat="server" Text="*" /></td>
<td width="48%"><strong> <font color="#FF0000">
<asp:label ID="msg" runat="server"></asp:label>
</font></strong></td>
</tr>
<tr>
<td> <div align="right">好友 I D:</div></td>
<td> <asp:textbox BorderStyle="solid" BorderWidth="1" ID="zid" runat="server" TextMode="SingleLine" /><asp:requiredfieldvalidator ControlToValidate="zid" Display="Dynamic" EnableClientScript="false" ErrorMessage="用户ID必须填写" ID="rzid" runat="server" Text="*" />
</td>
<td><asp:button Font-Size="10" ID="zadd" runat="server" Text="添加" OnClick="zscaddfriend" /></td>
</tr>
</table></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="540" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
<tr bgcolor="#FFFFFF">
<td height="16"> <img src="pic/images/icon_group.gif" width="15" height="15"><strong>编辑好友</strong>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="16">
<asp:datagrid runat="server" ID="myfriend"
DataKeyField="id"
AutoGenerateColumns="false"
AllowPaging="true"
PageSize="10"
OnPageIndexChanged="zscpage"
OnEditCommand="zscedit"
OnDeleteCommand="zscdel"
OnCancelCommand="zsccanc"
OnUpdateCommand="zscsave"
BorderColor="#cccccc"
Width="100%"
HorizontalAlign="Center"
>
<headerstyle Font-Bold="true" HorizontalAlign="center" />
<itemstyle HorizontalAlign="center" />
<pagerstyle NextPageText="下一页" PrevPageText="上一页" HorizontalAlign="right" />
<columns>
<asp:boundcolumn DataField="fname" HeaderText="好友昵称" />
</columns>
<columns>
<asp:boundcolumn ReadOnly="true" DataField="fid" HeaderText="好友ID" />
</columns>
<columns>
<asp:editcommandcolumn HeaderText="编辑操作" ButtonType="linkbutton"
CancelText="取消" EditText="编辑" updateText="保存" />
</columns>
<columns>
<asp:templatecolumn HeaderText="删除操作">
<itemtemplate>
<asp:linkbutton runat="server" CommandName="delete" Text="删除" />
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<script language="VB" runat="server">
sub page_load(s as object,e as eventargs)
if not ispostback then
friend_list()
end if
end sub
sub friend_list()
'为当前用户的朋友绑定数据
dim uinfo()=session("lguinfo")
'获取当前用户登录的用户名
dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("office.mdb"))
conn.open()
dim objada as new oledbdataadapter("select * from friend where myid=" & uinfo(0),conn)
dim ds as new dataset()
objada.fill(ds,"friend")
myfriend.datasource=ds.tables("friend")
myfriend.databind()
zfrienddropdown.datasource=ds.tables("friend")
zfrienddropdown.databind()
'下拉列表框也绑定到该数据源
conn.close()
end sub
sub zscpage(s as object,e as DataGridPageChangedEventArgs)
'对下面的数据表格进行分页操作
s.currentpageindex=e.newpageindex
friend_list()
end sub
sub zscedit(s as object,e as DataGridCommandEventArgs)
'使数据表格进入编辑状态
s.edititemindex=e.item.itemindex
friend_list()
end sub
sub zsccanc(s as object,e as DataGridCommandEventArgs)
'使数据表格退出编辑状态
s.edititemindex=-1
friend_list()
end sub
sub zscsave(s as object,e as DataGridCommandEventArgs)
'在用户单击保存按钮时执行该过程,用来保存用户所做的修改
dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & server.MapPath("office.mdb"))
conn.open()
dim objcmd as new oledbcommand()
objcmd.connection=conn
objcmd.commandtext="update friend set fname=(?) where id=?"
dim zcell as tablecell=ctype(e.item.controls(0),tablecell)
'得到该行数据的第一个单元格
dim ztext as textbox=zcell.controls(0)
'得到第一个单元格中的第一个控件,即文本框控件
objcmd.parameters.add("@fname",oledbtype.char).value=ztext.text
objcmd.parameters.add("@id",oledbtype.integer).value=s.datakeys(e.item.itemindex)
objcmd.executenonquery()
conn.close()
s.edititemindex=-1
friend_list()
end sub
sub zscdel(s as object,e as DataGridCommandEventArgs)
'删除用户指定的朋友
dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("office.mdb"))
conn.open()
dim objcmd as new oledbcommand()
objcmd.connection=conn
objcmd.commandtext="delete from friend where id=" & s.datakeys(e.item.itemindex)
objcmd.executenonquery()
conn.close()
friend_list()
end sub
sub zscaddfriend(s as object,e as eventargs)
'添加好友到friend表
if not page.isvalid then exit sub
'因为本页有一个按钮用来回到docaddfile.aspx,如果启用客户端验证,则点击该按钮
'时也会检查数据输入的正确性,为了不让其检查数据的输入,在这里关闭了验证控件
'的客户端检查,此时,必须用page对象的isvalid手工判断数据验证是否已经完全通过
dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("office.mdb"))
conn.open()
dim objcmd as new oledbcommand()
objcmd.connection=conn
dim uinfo()=session("lguinfo")
objcmd.commandtext="select fid from friend where fid=" & zid.text & "and myid=" & uinfo(0)
'检查frind表中是否已经将该用户加为自己的好友。
dim objrd as oledbdatareader=objcmd.executereader()
if objrd.read() then
msg.text="该用户已经是您的好友,不能重复添加!"
else
objrd.close()
msg.text=""
objcmd.commandtext="insert into friend (fid,fname,myid) " & _
" values (?,?,?)"
objcmd.parameters.add("@fid",oledbtype.integer).value=zid.text
objcmd.parameters.add("@fname",oledbtype.char).value=znicename.text
objcmd.parameters.add("@myid",oledbtype.integer).value=uinfo(0)
objcmd.executenonquery()
end if
objrd.close()
conn.close()
friend_list()
end sub
sub zsendto(s as object,e as eventargs)
'接受用户从下拉列表框中选择的朋友,并向docaddfile.aspx传递参数fid,
if zfrienddropdown.items.count>0 then
response.redirect("docaddfile.aspx?zid=" & zfrienddropdown.selecteditem.value )
else
response.redirect("docaddfile.aspx")
end if
end sub
</script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -