📄 viewfile.aspx
字号:
<%@ Page Language="VB" ContentType="text/html" debug="true" %>
<%@ Import Namespace="system.data" %>
<%@ Import Namespace="system.data.oledb" %>
<%@ Import Namespace="system.io" %>
<html>
<head>
<title>我的收藏</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">
<input type=hidden runat="server" id="zfilter">
<input type=hidden runat="server" id="deltedid">
<!--
此处用来保存要删除的记录的ID号,因为真正的删除操作并不是在DataGrid控件所的
ondelete事件所对应过程中删除的,而是通过一次中转达操作。
即ondelete事件中的删除过程,只是保存删除记录的ID,然后启动客户端的对话框,
当用户在对话框中选择确定删除时,就做真正删除操作。
所以,这里要求用一个变量来保存在ondelete事件中能得到的e.item.itemindex参数。
-->
<table width="549" height="22" border="0" cellpadding="0" cellspacing="0" background="pic/002.png">
<tr>
<td>
<table width="100%" height="0" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="51%"> <strong><font color="#FFFFFF"> 我的收藏夹</font></strong>
</td>
<td width="15%"><a href="addfile.aspx"><img src="pic/pag.gif" width="16" height="16" border="0" align="absbottom"> </a><strong><font color="#FFFFFF">添加文档</font></strong></td>
<td width="16%"><a href="fileshare/linkaddadmin.aspx"><img src="pic/shareforum.gif" width="16" height="16" border="0" align="absbottom"> </a><font color="#FFFFFF"><strong>发布共享</strong></font></td>
<td width="18%" valign="middle"><font color="#FFFFFF"><strong><a href="fileshare/fileselfedit.aspx"><img src="pic/delete.gif" width="16" height="16" border="0" align="absbottom"></a>删除共享</strong></font></td>
</tr>
</table></td>
</tr>
</table>
<a href="addfile.asp">
</a>
<table width="549" height="380" border="1" cellpadding="0" cellspacing="0" bordercolorlight="#008080" bordercolordark="#FFFFFF">
<tr>
<td width="727" height="74" valign="top" bgcolor="#FFFFFF">
<asp:datagrid runat="server" ID="mygrid"
DataKeyField="id"
AutoGenerateColumns="false"
AllowPaging="true"
PageSize="15"
OnPageIndexChanged="zscpage"
HorizontalAlign="Center"
Width="98%"
BorderColor="#cccccc"
OnEditCommand="zscedit"
OnCancelCommand="zsccancel"
OnUpdateCommand="zscupdate"
OnDeleteCommand="zscdel"
>
<headerstyle Font-Bold="true" HorizontalAlign="center" />
<pagerstyle Mode="numericpages" PageButtonCount="5" HorizontalAlign="right" />
<itemstyle HorizontalAlign="center" />
<columns>
<asp:templatecolumn ItemStyle-HorizontalAlign="left" HeaderText="文档描述">
<itemtemplate>
<img src="pic/images/icon_folder_open_topic.gif">
<a href='<%# session("downpath") & container.dataitem("myfilename") %>' target="_blank">
<%# container.dataitem("mytitle") %>
</a>
</itemtemplate>
<edititemtemplate>
<asp:textbox BorderStyle="solid" BorderWidth="1" Font-Size="10" ID="ztitle" runat="server" TextMode="SingleLine" Text='<%# container.dataitem("mytitle") %>' />
</edititemtemplate>
</asp:templatecolumn>
<asp:boundcolumn DataField="mydate" HeaderText="存档日期" DataFormatString="{0:d}" ReadOnly="true" />
<asp:boundcolumn DataField="sizeZ" HeaderText="文档大小" ReadOnly="true" />
<asp:templatecolumn HeaderText="操作">
<itemtemplate>
<a href='fileshare/linkaddadmin.aspx?zurl=<%# session("downpath") & container.dataitem("myfilename") %>'>发布</a>
<a href='viwefilelink.aspx?id=<%# container.dataitem("id") %>'>查看</a>
<asp:linkbutton runat="server" CommandName="edit" Text="编辑" />
<asp:linkbutton runat="server" CommandName="delete" Text="删除" />
</itemtemplate>
<edititemtemplate>
<asp:linkbutton runat="server" CommandName="update" Text="保存" />
<asp:linkbutton runat="server" CommandName="cancel" Text="取消" />
</edititemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
<asp:button runat="server" ID="zdeltrue" OnClick="zscdeltrue" BackColor="#FFFFFF" BorderColor="#FFFFFF" BorderStyle="None" EnableViewState="false" Text="" />
<asp:label runat="server" Visible="false" ID="showhidescript">
<!--
此处的层用来保存一个客户端脚本,该脚本出现提示框,让用户选择。
当用户选择确定时,会用代码使服务端的“按钮”执行单击操作。
该按钮即是zdeltrue按钮,该按钮对应的过程用来真正删除myfile中的数据。
当用户选择取消时,没有执行任何操作,(本想在用户选择取消时,用客户端
脚步使该层隐藏,但后来发现,实现不了。
-->
<script language="JavaScript" type="text/javascript">
if (confirm('确定删除这条记录吗?'))
{
document.forms[0].zdeltrue.click();
//模拟确定删除按钮单击操作
}
</script>
</asp:label>
</td>
</tr>
</table>
<table width="549" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="82"> </td>
<td width="387"> 按文档描述:
<asp:textbox BorderStyle="solid" BorderWidth="1" Columns="25" Font-Size="10" ID="zfindkey" runat="server" TextMode="SingleLine" />
<asp:button Font-Size="10" ID="zfind" runat="server" Text="搜索" onclick="zscfind" /> </td>
<td width="80"> </td>
</tr>
</table>
</form>
</body>
</html>
<script language="vb" runat="server">
sub page_load(s as object,e as eventargs)
showhidescript.visible=false
'showhidescript是一个层,该层中存放了客户端脚本,该脚本是一个对话框
'当页面初始装入时应该例该层不显示,
if not ispostback then
bindlist()
'为DataGrid控件绑定数据
end if
end sub
sub bindlist()
'绑定myfile表中的数据到DataGrid控件。
dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("office.mdb"))
conn.open()
dim uinfo()=session("lguinfo")
'得到会话变量中的数据,uinfo(0)保存了当前登陆用户的id,用来取得当前用户的所有收藏的文件
dim objada as new oledbdataadapter("select * from myfile where myid='" & uinfo(0) & "' order by id desc",conn)
dim ds as new dataset()
objada.fill(ds,"myfile")
dim dv as new dataview(ds.tables("myfile"))
dv.rowfilter=zfilter.value
mygrid.datasource=dv
mygrid.databind()
'正式绑定数据到DataGrid控件
conn.close()
end sub
sub zscpage(s as object,e as DataGridPageChangedEventArgs)
'为DataGrid控件提供翻页操作
s.currentpageindex=e.newpageindex
bindlist()
end sub
sub zscedit(s as object,e as DataGridCommandEventArgs)
'当用户单击编辑按钮时,使当前记录进入编辑状态
s.edititemindex=e.item.itemindex
bindlist()
end sub
sub zsccancel(s as object,e as DataGridCommandEventArgs)
'当用户单击取消按钮时,使DataGrid退出编辑状态
s.edititemindex=-1
bindlist()
end sub
sub zscupdate(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 myfile set mytitle=? where id=?"
dim lstextbox as object=ctype(e.item.controls(0).controls(1),textbox)
'得到文件描述对应的字段
objcmd.parameters.add("@mytitle",oledbtype.char).value=lstextbox.text
objcmd.parameters.add("@id",oledbtype.char).value=s.datakeys(e.item.itemindex)
objcmd.executenonquery()
conn.close
s.edititemindex=-1
'退出编辑模式
bindlist()
end sub
sub zscdel(s as object,e as DataGridCommandEventArgs)
'该过程是DataGrid控件ondelete事件对应的过程,用来保存当前记录的ID,并使客
'户端脚本对应的层显示
deltedid.value=s.datakeys(e.item.itemindex)
'保存当前记录的ID号
showhidescript.visible=true
'显示客户端脚本对应的层
end sub
sub zscdeltrue(s as object,e as eventargs)
'真正删除myfile表中的数据,该过程对应的按钮用户是看不到的,过程的触发由客户端
'脚本用代码触发
dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("office.mdb"))
conn.open()
'删除相关附件
dim objcmd as new oledbcommand("select sizeZ,myfilename from myfile where id=" & deltedid.value,conn)
dim objrd as oledbdatareader=objcmd.executereader()
if objrd.read() then
'如果找到相关记录
if objrd("sizeZ")<>"N/S"
'如果有附件
dim lsfile as string
lsfile=session("uppath") & objrd("myfilename")
if file.Exists(lsfile) then
file.delete(lsfile)
end if
end if
end if
objrd.close()
objcmd=new oledbcommand()
objcmd.connection=conn
objcmd.commandtext="delete from myfile where id=" & deltedid.value
objcmd.executenonquery()
conn.close()
bindlist()
showhidescript.visible=false
end sub
sub zscfind(s as object,e as eventargs)
'在DataGrid控件中查找相应的数据,该过程中保存用户设置的过滤条件。
if zfindkey.text="" then
zfilter.value=""
else
zfilter.value="mytitle like '%" & zfindkey.text & "%'"
end if
mygrid.currentpageindex=0
'因为过滤条件可能使mygrid控件中的数据为0,如果用户其它页面中执行查找时,如果
'查找到的数据为0,但pageindex并非为第一页时,就会出现错误
bindlist()
end sub
</script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -