⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin_goods.asp

📁 [FIF]ASP互动视频VIP教程 书包
💻 ASP
字号:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<% Option Explicit %>
<!-- 后台公告管理 -->
<!-- #include file="../config/db.asp" -->
<!-- #include file="../config/function.inc.asp" -->
<%
dim sql,rst,myErrors,page,pagelistnum,nowclass,fs,sqlfy
on error resume next
set fs=Server.CreateObject("scripting.FileSystemObject")
set rst=server.CreateObject("adodb.recordset")
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>FIF VIP ASP教程后台管理--商品分类管理</title>
<style type="text/css">
<!--
body,td,th {
	font-size: 12px;
}
-->
</style></head>
<body>
<%
'处理参数
pagelistnum=15'设置每页显示15件商品
if request.QueryString("page")="" then
  page=1
else
  page=request.QueryString("page")
end if
if session("admin_gcid")="" then session("admin_gcid")="0"
if request.QueryString("c")<>"" then session("admin_gcid")=request.QueryString("c")
if request.QueryString("act")="add" or request.QueryString("act")="update" then
%>
  <!-- #include file="../config/formdata.inc.asp" -->
<%
end if
select case request.QueryString("act")
  case "add":'添加
    if formdata.item("f_name")<>"" and formdata.item("f_price")<>"" and IsNumeric(formdata.item("f_price")) then
	  sql="tbl_goods"
	  rst.open "tbl_goods",conn,1,3
	  rst.addnew
	  rst("gds_gcid")=formdata.item("f_gcid")
	  rst("gds_name")=formdata.item("f_name")
	  rst("gds_price")=formdata.item("f_price")
	  rst("gds_jj")=formdata.item("f_jj")
	  rst("gds_info")=formdata.item("f_info")
	  rst("gds_img")=formdata.item("f_img")
	  rst.update
	  rst.close
	  set myErrors=conn.errors
	  if myErrors.count=0 then
		msgboxU "添加成功!"
	  else
		msgboxU "添加失败!原因:"&myErrors.item(0).description
		'如果上传了图片则删除
		if formdata.item("f_img")<>"" then fs.deletefile server.MapPath("../upfile") & "\" & formdata.item("f_img")
	  end if
	else
	  msgboxU "没有输入商品名或是商品价格,或价格不为数字"
	  if formdata.item("f_img")<>"" then fs.deletefile server.MapPath("../upfile") & "\" & formdata.item("f_img")
	end if
  case "update":'更新
    if request.QueryString("id")="" or formdata.item("f_name")="" or formdata.item("f_price")="" or not IsNumeric(formdata.item("f_price")) then
	  msgboxU "错误的参数,或没有输入商品名或是商品价格,或价格不为数字"
	else
	  sql="select * from tbl_goods where gds_id=" & request.QueryString("id")
	  rst.open sql,conn,1,3
	  rst("gds_name")=formdata.item("f_name")
	  rst("gds_price")=formdata.item("f_price")
	  rst("gds_jj")=formdata.item("f_jj")
	  rst("gds_info")=formdata.item("f_info")
	  '判断图片是否需要更新
	  if formdata.item("f_img")<>"" then
	    '如果原有图片则删除
	    if rst("gds_img")<>"" then fs.deletefile server.MapPath("../upfile") & "\" & rst("gds_img")
		rst("gds_img")=formdata.item("f_img")
	  end if
	  rst.update
	  rst.close
	  set myErrors=conn.errors
	  if myErrors.count=0 then
		msgboxU "修改成功!"
	  else
		msgboxU "修改失败!原因:"&myErrors.item(0).description
	  end if
	end if
  case "del":'删除
    if request.QueryString("id")="" then
	  msgboxU "错误的参数"
	else
	  sql="select count(*) as num from tbl_buy where buy_gdsid=" & request.QueryString("id")
	  rst.open sql,conn,1,1
	  if rst("num")>0 then
	    msgboxU "此商品已经有人订购,您不能删除此商品"
	  else
	    sql="delete from tbl_goods where gds_id=" & request.querystring("id")
		conn.execute sql
		  set myErrors=conn.errors
		  if myErrors.count=0 then
			msgboxU "删除成功!"
		  else
			msgboxU "删除失败!原因:"&myErrors.item(0).description
		  end if
	  end if
	  rst.close
	end if
end select
%>
<p>商品分类:
  <select name="select" onChange="javascript:location='admin_goods.asp?c='+this.value;">
    <option value="0" selected>所有商品</option>
    <%
sql="select * from tbl_goodsclass"
rst.open sql,conn,1,1
do while not rst.eof 
%>
    <option value="<%=rst("gc_id")%>" <% if cint(session("admin_gcid"))=rst("gc_id") then 
	     response.Write(" selected") 
	     nowclass=rst("gc_name")'记录下当前分类名以便在新增商品时显示
	   end if
	   %>><%=rst("gc_name")%></option>
    <%
  rst.movenext
loop
rst.close
%>
  </select>
</p>
<table width="641" border="1" cellpadding="0" cellspacing="0">
  <tr align="center">
    <td width="62">ID</td>
    <td width="210">商品名</td>
    <td width="69">价格</td>
    <td width="188">分类</td>
    <td width="100">操作</td>
  </tr>
  <%
sql="select top " & (page*pagelistnum) & " * from tbl_goodsclass,tbl_goods where gds_gcid=gc_id"
sqlfy="select count(*) as num from tbl_goodsclass,tbl_goods where gds_gcid=gc_id"'翻页函数所需SQL语句
if cint(session("admin_gcid"))<>0 then'只显示选中的商品类别
  sql=sql & " and gc_id=" & session("admin_gcid")
  sqlfy=sqlfy & " and gc_id=" & session("admin_gcid")
end if
sql=sql & " order by gds_id"
rst.open sql,conn,1,1
rst.PageSize=pagelistnum
rst.AbsolutePage=page
do while not rst.eof 
%>
  <tr>
    <td align="right"><%=rst("gds_id")%></td>
    <td><%=rst("gds_name")%></td>
    <td align="right"><%=rst("gds_price")%></td>
    <td align="center"><%=rst("gc_name")%></td>
    <td align="center"><a href="admin_goods.asp?act=modify&id=<%=rst("gds_id")%>">修改</a>&nbsp; <a href="admin_goods.asp?act=del&id=<%=rst("gds_id")%>" onClick="javascript:return confirm('您确定要删除此商品分类吗?');">删除</a> </td>
  </tr>
  <%
  rst.movenext
loop
rst.close
%>
  <tr>
    <td colspan="5" align="right"><%
	fy sqlfy,page,pagelistnum,"admin_goods.asp?t="
	%></td>
  </tr>
</table>
<br>
<br>
<%
'如果选择了某个分类才允许添加商品//如果是编辑也显示
if cint(session("admin_gcid"))<>0 or request.QueryString("act")="modify" then
%>
<form action="<%
	  if request.querystring("act")="modify" then
	    response.write "admin_goods.asp?act=update&id=" & request.querystring("id")
	  else
	    response.write "admin_goods.asp?act=add"
	  end if
%>" method="post" enctype="multipart/form-data" name="frm">
  <table width="600" height="69" border="0" cellpadding="5" cellspacing="0">
    <tr>
      <td height="33" align="center"><%
	  if request.querystring("act")="modify" then
	    response.write "修改商品"
		sql="select * from tbl_goodsclass,tbl_goods where gds_gcid=gc_id and gds_id=" & request.QueryString("id")
		rst.open sql,conn,1,1
	  else
	    response.write "新增商品"
	  end if
	  %></td>
    </tr>
    <tr>
      <td>商品分类名:<% 
	  if request.QueryString("act")="modify" then 
	    response.Write rst("gc_name")
	  else
	    response.Write nowclass
	  end if 
	  %> <input name="f_gcid" type="hidden" id="f_gcid" value="<%
	  if  request.QueryString("act")="modify" then
	    response.Write rst("gc_id")
	  else
	    response.Write session("admin_gcid")
	  end if
		%>"></td>
    </tr>
    <tr>
      <td>品名:
      <input name="f_name" type="text" id="f_name" value="<% if request.QueryString("act")="modify" then response.Write(rst("gds_name")) %>"></td>
    </tr>
    <tr>
      <td>价格:
      <input name="f_price" type="text" id="f_price" value="<% if request.QueryString("act")="modify" then response.Write(rst("gds_price")) %>" size="20"></td>
    </tr>
    <tr>
      <td>简介:
      <input name="f_jj" type="text" id="f_jj" value="<% if request.QueryString("act")="modify" then response.Write(rst("gds_jj")) %>" size="50"></td>
    </tr>
    <tr>
      <td>说明:
        <textarea name="f_info" cols="40" rows="5" id="f_info"><% if request.QueryString("act")="modify" then response.Write(rst("gds_info")) %> </textarea></td>
    </tr>
    <tr>
      <td>图片:
      <input name="f_img" type="file" id="f_img">
      <% if request.QueryString("act")="modify" then
	    if rst("gds_img")<>"" then %><img src="<%=server.mappath("../upfile") & "\" & rst("gds_img")%>">
		<% 
		  end if
		end if %>
      新增时如果没有可以不上传,修改时若不修改图片可不上传</td>
    </tr>
    <tr>
      <td><input type="submit" name="Submit" value="<% 
	  if request.QueryString("act")="modify" then 
	    response.Write "修改商品"
		rst.close
	  else
	    response.Write "新增商品"
	  end if
	  %>"></td>
    </tr>
  </table>
</form>
<%
end if'新增或修改商品END
%>
<%
set rst=nothing
conn.close
set conn=nothing
%>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -