<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="checklogin.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>产品管理</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
ul{margin:0px; padding:0px;}
li{margin:2px; padding:0px;}
-->
</style>
<script language="javascript">
function check(obj){
	if(obj.Title.value==""){
		alert("产品名称不能为空!");
		obj.Title.focus();
		obj.Title.select();
		return false;
	}
	return true;
}
function goto(frm)
{
	var gourl ="?";
	gourl += "page=" + (frm.page.value);
     var hid=parseInt(frm.hid.value);
	 if(parseInt(frm.page.value)>hid||frm.page.value<=0){
	 alert("错误！请确定你输入的数字在1-"+hid+"之间");
	 return false;
	 }
	window.location.href(gourl);
}
function ConfirmDel()
{
   if(confirm("确认删除？，并且不能恢复！确定要删除此信息吗？"))
     return true;
   else
     return false;
	 
}
</script>
</head>

<body>
<!--#include file="top.asp"-->
<%
dim act
act=trim(request.QueryString("act"))
if isempty(act) or act="" then
	call News_List
elseif(act="add") then
	call News_Add
elseif(act="addok") then
	call News_AddOk
elseif(act="mod") then
	call News_Mod
elseif(act="modok") then
	call News_ModOk
elseif(act="del") then
	call News_Del
end if
%>
<%
Sub News_Add
%>
<FORM method="POST" name="form1" action="?act=addok" style="margin:0 0 0 0;" onSubmit="return check(this)">
  <TABLE width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#ffffff" class="border">
<TR bgcolor="#FF9900">
  <TD height="24" colspan="2" bgcolor="#FF9900" class="th_title"><span class="style3">添加产品</span></TD>
  </TR>
<TR bgcolor="#F5F5F5">
  <TD width="13%" height="24"><div align="right">产品名称：</div></TD>
  <TD width="87%"><input name="Title" type="text" id="Title" size="50">
    (*)</TD>
</TR>
<tr>
      <td height="24" align="right" bgcolor="#F5F5F5" class="pad_5">产品图片：</td>
      <td bgcolor="#F5F5F5" class="pformleft"><input name="Photo" type="text" id="Photo" size="50">
      <input type="button" name="Button" value="上传->" onClick="javascript:document.form1.Photo.value=window.showModalDialog('upimg.htm','','dialogHeight:130px;dialogWidth:410px;help:no;status:no;scroll:no')"></td>
    </tr>
<TR bgcolor="#F5F5F5">
  <TD height="24" align="right">产品型号：</TD>
  <TD><input name="Types" type="text" id="Types" size="50" /></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD height="24" align="right">产品价格：</TD>
  <TD><input name="Price" type="text" id="Price" size="50" /></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD height="24" align="right">产地： </TD>
  <TD><input name="Address" type="text" id="Address" size="50" /></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD height="24" align="right">产品规格：</TD>
  <TD><input name="Guige" type="text" id="Guige" size="50" /></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD width="13%"><div align="right">详细说明：</div></TD>
  <TD width="87%">
    <INPUT type="hidden" name="content1" value="">
    <IFRAME ID="eWebEditor1" src="webedit/editor.html" frameborder="0" scrolling="no" width="98%" height="350"></IFRAME>
    </TD>
</TR>
<TR bgcolor="#F5F5F5">
	<TD align=right>&nbsp;	  </TD>
    <TD height="32" align=right><div align="left"> 
        <input type=submit name=b1 value="提 交">&nbsp;&nbsp;
        <input type=reset name=b2 value="重 填">       
    </div></TD>
</TR>
</TABLE>
</FORM>
<%
end Sub
Sub News_Del
	dim id
	id=Clng(request.QueryString("id"))
	conn.execute("delete from t_member_products where id="&id)
	response.Redirect(request.ServerVariables("HTTP_REFERER"))
end Sub

Sub News_AddOk
	dim title,Types,Price,Address,Area,Sexs,Guige,Salary,Content,Photo
	Photo=request.Form("Photo")
	title=replace(request.Form("Title"),"'","")
	Types=request.Form("Types")
	Price=request.Form("Price")
	Address=request.Form("Address")
	Area=request.Form("Area")
	Sexs=request.Form("Sexs")
	Guige=request.Form("Guige")
	Salary=request.Form("Salary")
	Content=request.Form("content1")
	set rs=server.createobject("adodb.recordset")
	rs.open "select top 1 * from t_member_products where 1=0",conn,3,3
	rs.addnew
	rs("Photo")=Photo
	rs("MemberId")=checkusername
	rs("Title")=title
	rs("Types")=Types
	rs("Price")=Price
	rs("Address")=Address
	rs("Guige")=Guige
	rs("Content")=content
	rs("PubDate")=now()	
	rs.update	
	response.Write("<p align=""center"">发布产品成功~!<br>")
	response.Write("<br><a href=""?"">返回</a></p>")
	rs.close
	set rs=nothing
end Sub
Sub News_ModOk
	dim id,title,Types,Price,Address,Area,Sexs,Guige,Salary,Content,Photo
	id=Clng(request.QueryString("id"))
	title=replace(request.Form("Title"),"'","")
	Photo=request.Form("Photo")
	Types=request.Form("Types")
	Price=request.Form("Price")
	Address=request.Form("Address")
	Area=request.Form("Area")
	Sexs=request.Form("Sexs")
	Guige=request.Form("Guige")
	Salary=request.Form("Salary")
	Content=request.Form("content1")
	set rs=server.createobject("adodb.recordset")
	rs.open "select top 1 * from t_member_products where MemberId='"&checkusername&"' and id="&id,conn,3,3
	if not rs.eof then		
		rs("Photo")=Photo
		rs("Title")=title
		rs("Types")=Types
		rs("Price")=Price
		rs("Address")=Address
		rs("Guige")=Guige
		rs("Content")=content
		rs("PubDate")=now()	
		rs.update	
		response.Write("<p align=""center"">修改产品成功~!")
		response.Write("<br><a href=""?"">返回</a></p>")
	end if
	rs.close
	set rs=nothing
end Sub
Sub News_Mod
	dim id,rs
	id=Clng(request.QueryString("id"))
	set rs=conn.execute("select * from t_member_products where id="&id)
	if not rs.eof then
%>
<FORM method="POST" name="form1" action="?act=modok&id=<%=id%>" style="margin:0 0 0 0;" onSubmit="return check(this)">
  <TABLE width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#ffffff" class="border">
<TR bgcolor="#FF9900">
  <TD height="24" colspan="2" class="th_title"><span class="style3">修改产品</span></TD>
  </TR>
<TR bgcolor="#F5F5F5">
  <TD width="13%" height="24"><div align="right">产品名称：</div></TD>
  <TD width="87%"><input name="Title" type="text" id="Title" value="<%=rs("Title")%>" size="50"></TD>
</TR>
<tr>
      <td height="24" align="right" bgcolor="#F5F5F5" class="pad_5">产品图片：</td>
      <td bgcolor="#F5F5F5" class="pformleft"><input name="Photo" type="text" id="Photo" size="50" value="<%=rs("Photo")%>">
      <input type="button" name="Button" value="上传->" onClick="javascript:document.form1.Photo.value=window.showModalDialog('upimg.htm','','dialogHeight:130px;dialogWidth:410px;help:no;status:no;scroll:no')"></td>
    </tr>
<TR bgcolor="#F5F5F5">
  <TD height="24" align="right">产品型号：</TD>
  <TD><input name="Types" type="text" id="Types" value="<%=rs("Types")%>" size="50" /></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD height="24" align="right">产品价格：</TD>
  <TD><input name="Price" type="text" id="Price" value="<%=rs("Price")%>" size="50" /></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD height="24" align="right">产地： </TD>
  <TD><input name="Address" type="text" id="Address" value="<%=rs("Address")%>" size="50" /></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD height="24" align="right">产品规格：</TD>
  <TD><input name="Guige" type="text" id="Guige" value="<%=rs("Guige")%>" size="50" /></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD width="13%"><div align="right">详细说明：</div></TD>
  <TD width="87%">
    <textarea name="content1" style="display:none; "><%=rs("Content")%></textarea>
    <IFRAME ID="eWebEditor1" src="webedit/editor.html" frameborder="0" scrolling="no" width="98%" height="350"></IFRAME>
    </TD>
</TR>
<TR bgcolor="#F5F5F5">
	<TD align=right>&nbsp;	  </TD>
    <TD height="32" align=right><div align="left"> 
        <input type=submit name=b1 value="提 交">&nbsp;&nbsp;
        <input type=reset name=b2 value="重 填">       
    </div></TD>
</TR>
</TABLE>
</FORM>
<%
	end if
	rs.close
	set rs=nothing
end Sub
Sub News_List
	dim BeginTime,i,currentpage,allrec,totalpage,n,p
	BeginTime=Timer
	const recpage=20
	if not isempty(request("page")) and request("page")<>"" then 
		currentpage=Clng(request("page"))
	else
		currentpage=1
	end if
%>
<div style="line-height:30px; text-align:left; padding:0p 0px 0px 10px; font-weight:bold; width:98%; margin:0px auto;"><a href="?act=add">添加产品--&gt;</a></div>
<table width="98%"  border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#ffffff" class="border">
  <tr bgcolor="#FF9900">
    <td height="22" colspan="11" bgcolor="#FF9900" class="th_title">产品管理</td>
  </tr>
  <tr bgcolor="#EEEEEE">
    <td width="3%" height="22"><div align="center">id</div></td>
    <td width="30%"><div align="center">标题</div></td>
    <td width="12%" align="center">产品图片</td>
    <td width="10%" align="center">产品型号</td>
    <td width="10%" align="center">产地</td>
    <td width="8%" align="center">产品价格</td>
    <td width="12%"><div align="center">日期</div></td>    
    <td width="8%"><div align="center">修改</div></td>
    <td width="7%"><div align="center">删除</div></td>
  </tr>
  <%
  		set rs=server.createobject("adodb.recordset")
  		rs.open "select count(*) AS co from t_member_products where MemberId='"&checkusername&"'",conn,3,1
		allrec=rs(0)
		totalpage=int((allrec+recpage-1)/recpage)
		rs.close
		set rs=nothing
		set rs=server.createobject("adodb.recordset")
		sql="select top "&recpage&" id,Title,Photo,Price,Address,Types,PubDate from t_member_products where id<=(select min(id) from (select top "&(recpage*(currentpage-1)+1)&" id from t_member_products where MemberId='"&checkusername&"' order by id desc) as t) and MemberId='"&checkusername&"' order by id desc "
		rs.open sql,conn,3,1		
		do while not rs.eof		
	%>
  <tr>
    <td height="20" bgcolor="#FFFFFF"><div align="center"><%=rs(0)%></div></td>    
    <td height="24" align="left" bgcolor="#FFFFFF"><div align="left">&nbsp;<a href="/show.asp?id=<%=checkusername%>&act=product_show&vars=<%=rs(0)%>" target="_blank"><%=rs(1)%></a></div></td>
    <td align="center" bgcolor="#FFFFFF"><a href="/show.asp?id=<%=checkusername%>&act=product_show&vars=<%=rs(0)%>" target="_blank"><img src="<%=rs(2)%>" width="118" height="104" border="0" /></a></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs(5)%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs(4)%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs(3)%></td>
    <td bgcolor="#FFFFFF"><div align="center"><%=rs(6)%></div></td>    
    <td bgcolor="#FFFFFF"><div align="center"><a href="?act=mod&id=<%=rs(0)%>">修改</a></div></td>
    <td bgcolor="#FFFFFF"><div align="center"><a href="?act=del&id=<%=rs(0)%>" onClick="return ConfirmDel()">删除</a></div></td>
  </tr>
  <%
			rs.movenext
	  loop
	  rs.close
	  set rs=nothing
  %>
  <tr>
    <td height="22" colspan="11" bgcolor="#FFFFFF">
	<div align="center">
	<form name="form1" method="post" action="" style="margin:0 0 0 0">
	<%
	n=currentpage+1
	p=currentpage-1
	if p>0then
		response.write("["&"<a href='?page="&cstr(p)&"'>上一页</a>]&nbsp;&nbsp;&nbsp;")
	else response.write("上一页&nbsp;&nbsp;&nbsp;")
	end if 
	if (n-1)*recpage>=allrec then 
		response.write("下一页" )
	else
		response.Write("["&"<a href='?page="&cstr(n)&"'>下一页</a>]")
	end if
	response.write("&nbsp;共"&allrec&"条&nbsp;")
	response.Write("&nbsp;共"&totalpage&"页&nbsp;")
	response.Write("&nbsp;第"&currentpage&"页&nbsp;")
	%>
          <input type="hidden" name="hid" value="<%=totalpage%>">
&nbsp;&nbsp;跳至
          <input name="page" type="text" size="5" onChange="goto(this.form)" style="border:1px solid #000000;height:18px ">
          页
          <input type="button" name="Button22" value="Go->" style="font-size:12px ;border:1px solid #000000;height:18px ">
        </form></div></td>
  </tr>
</table>
<%end Sub%>
</body>
</html>
<%
call connclose()
%>