<%
if request.cookies("buyok")("admin")="" then response.write "<meta http-equiv='refresh' content='0;URL=../admin.asp'>"
%>
<!--#include file="../include/nowshop.asp"-->
<!--#include file="../md5.asp"-->

<script language=javascript src=../include/mouse.js></script>
  <%
sub checkmanage(str)
Set mrs = conn.Execute("select * from manage where username='"&request.cookies("buyok")("admin")&"'")
if not (mrs.bof and mrs.eof) then
manage=mrs("manage")
if instr(manage,str)<=0 then
response.write "<script language='javascript'>"
response.write "alert('警告：您没有此项操作的权限！');"
response.write "location.href='quit.asp';"
response.write "</script>"
response.end
else
session("buyok_admin_login")=0
end if
else 
response.write "<script language='javascript'>"
response.write "alert('没有登陆，不能执行此操作！');"
response.write "location.href='quit.asp';"
response.write "</script>"
response.end
end if
set mrs=nothing
end sub
%>
<%call checkmanage("04")%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="../images/css.css" type=text/css rel=stylesheet>
<LINK href="../list/newhead.css" type=text/css rel=stylesheet>
<script language=javascript>
<!--
function CheckAll(form){
for (var i=0;i<form.elements.length;i++){
var e = form.elements[i];
if (e.name != 'chkall') e.checked = form.chkall.checked; 
}
}
-->
</script>
</head>
<BODY bgcolor="#D9EAFC">

<%
action = request("action")
if action="" then call order_index()
if action="list" then call Order()
if action="删除" then call orderdel()


sub order_index()
%>
<table height="5"><tr><td></td></tr></table>
<TABLE cellSpacing=0 cellPadding=0 width=95% border=0 style="BORDER-RIGHT: #b1bfee 1px solid; BORDER-TOP: #b1bfee 1px solid; BORDER-LEFT: #b1bfee 1px solid; BORDER-BOTTOM: #b1bfee 1px solid" 
>
            <TBODY>
              <TR> 
                
      <TD bgColor=#f4f5fd height=30><font color="#000000">　<B><font color="#FF0000">&nbsp;定单管理</font></B></font></TD>
              </TR>
            </TBODY>
          </TABLE>
		  <table height="5"><tr><td></td></tr></table>

<table width="95%"  border="0" cellpadding="0" cellspacing="1" bgcolor="#b1bfee">
<form action=order1.asp method=post name=orderlist>
<%
ordersql=request.cookies("buyok")("ordersql")
if request("show")="yes" then
  response.cookies("buyok")("ordersql")=""
end if
pages = 20
set rs = server.createobject("adodb.recordset")
sql = "select a.ID,a.OrderNum,a.del,a.OrderSum,a.PayType,a.RecName,a.UserID,a.OrderTime,b.Status,b.StatusDefine from bOrderList a,type b where a.del=false and a.Status=b.Status "
if request("show")<>"yes" then sql=sql+ordersql 
sql= sql+" order by OrderTime desc"
rs.open sql,conn,1,3
if rs.eof and rs.bof then
response.write "<tr bgcolor=#FFFFFF><td colspan=7 align=center height=50>暂时没有订单</td></tr>"
response.end 
rs.close
set rs=nothing
end if
totalrs=rs.RecordCount
rs.pageSize = pages
allPages = rs.pageCount
page = Request("page")
If not isNumeric(page) then page=1
if isEmpty(page) or int(page) <= 1 then
page = 1
elseif int(page) > allPages then
page = allPages 
end if
rs.AbsolutePage = page
%>
<tr bgcolor="#f4f5fd">
<td width=5% align=center>选</td>
<td width='15%' align=center>订单号</td>
<td width='15%' align=center>金额</td>
<td width='12%' align=center>会员ID</td>
<td width='12%' align=center>收货人姓名</td>
<td width='23%' align=center>下单时间</td>
<td width='18%' align=center>订单状态</td>
</tr>
<%
Do While Not rs.eof and pages>0
response.write "<tr bgcolor=#FFFFFF><td><input type='checkbox' value='"&rs("ID")&"' name=id></td>"
response.write "<td align=center><a alt='查看/编辑订单' href=""order1.asp?action=list&ID="&rs("OrderNum")&""">"&rs("OrderNum")&"</a></td><td align=center>"&formatnum(csng(rs("OrderSum")),2)&"&nbsp;</td><td align=center>"
response.write "<a alt='查看会员资料' href='user1.asp?action=useredit&id="&rs("userid")&"'>"&rs("userid")&"</a></td><td align=center>"&rs("RecName")&"</td><td align=center>"&rs("OrderTime")&"</td><td align=center>"

if rs("Status")="0" then
response.write "<font color=red>"&rs("StatusDefine")&"</font>"
elseif rs("Status")="99" then 
response.write "<font color=blue>"&rs("StatusDefine")&"</font>"
elseif rs("Status")="88" then 
response.write "<font color=blue>"&rs("StatusDefine")&"</font>"
else
response.write "<font color=darkgray>"&rs("StatusDefine")&"</font>"
end if
response.write "</td></tr>"

pages = pages - 1
rs.movenext
if rs.eof then exit do
loop
%>	
<tr bgcolor="#FFFFFF"><td colspan=7>
<input type='checkbox' name=chkall onclick='CheckAll(this.form)'>
<input type="submit" name="action" value="删除" onclick="{if(confirm('提示：您确实删除所选定的订单吗？')){this.document.orderlist.submit();return true;}return false;}"> 	
</td></tr>
</form>
</table>
<%
rs.close
set rs=nothing
'if allpages<=1 then exit sub
response.write "<br>总订单数<font color=red>"&totalrs&"</font> &nbsp; 每页<font color=red>"& msg_per_page &"</font>&nbsp; "
if page = 1 then
response.write "<font color=darkgray>首页 前页</font>"
else
response.write "<a href=order1.asp?keywords="&keywords&"&page=1>首页</a> <a href=order1.asp?keywords="&keywords&"&page="&page-1&">前页</a>"
end if
if page = allpages then
response.write "<font color=darkgray> 下页 末页</font>"
else
response.write " <a href=order1.asp?keywords="&keywords&"&page="&page+1&">下页</a> <a href=order1.asp?keywords="&keywords&"&page="&allpages&">末页</a>"
end if
response.write " &nbsp;&nbsp;&nbsp;第"&page&"页 共"&allpages&"页"

end sub


sub Order()
OrderNum=request("ID")
if request.form("edit")="ok" then
	set rs=Server.Createobject("ADODB.RecordSet")
	sql="select * from bOrderList where OrderNum='"&OrderNum&"'"
	rs.Open sql,conn,1,3
'	if trim(request("RecName"))    <>"" then rs("RecName")      = trim(request("RecName"))
'	if trim(request("RecPhone"))   <>"" then rs("RecPhone")     = trim(request("RecPhone"))
'	if trim(request("CompPhone"))  <>"" then rs("CompPhone")    = trim(request("CompPhone"))
	rs("LastModifytime")                                        = now()
'	if trim(request("Recmail"))    <>"" then rs("Recmail")      = trim(request("Recmail"))
'	if trim(request("RecAddress")) <>"" then rs("RecAddress")   = trim(request("RecAddress"))
'	if trim(request("Province"))    <>"" then rs("Province")      = trim(request("Province"))
'	if trim(request("city"))    <>"" then rs("city")      = trim(request("city"))
'	if trim(request("Zipcode"))    <>"" then rs("Zipcode")      = trim(request("Zipcode"))
'	if trim(request("Notes"))      <>"" then rs("Notes")        = trim(request("Notes"))
	if trim(request("Memo"))       <>"" then rs("Memo")         = trim(request("Memo"))
	if trim(request("Status"))     <>"" then rs("Status")       = trim(request("Status"))

	if request("Status")="99" then
	conn.execute("update buser set totalsum= totalsum+"&rs("ordersum")&" where userid='"&request("userid")&"'")
	end if

	rs.update
	rs.close
	set rs=nothing

	response.write "<script language='javascript'>"
	response.write "alert('操作成功，您已经修改一个订单。');"
	response.write "location.href='order1.asp?action=list&id="&request("ID")&"';"
	response.write "</script>"
	response.end
end if

set rs=conn.execute("select A.ordertime,b.ordersum,A.Userid,A.OrderNum,A.PEI,A.FEI,A.ProdId,A.BuyPrice,A.ProdUnit,B.thiskou,B.Memo,B.Status,B.Recname,B.Recname2,B.RecPhone,B.RecPhone2,B.Recmail,B.Recmail2,B.RecAddress,B.RecAddress2,B.Zipcode,B.Zipcode2,B.Province,B.Province2,B.city,B.city2,B.Fetch_Mode,B.Paytype,B.Notes,B.Compphone,B.gettime,C.ProdName from bOrder A,bOrderList B,bproduc C where A.OrderNum='"&OrderNum&"' and A.OrderNum = B.OrderNum and A.ProdId=C.Prodid")

if rs.eof and rs.bof  then
	response.write "<script language='javascript'>"
	response.write "alert('出错了，没有此订单。');"
	response.write "location.href='javascript:history.go(-1)';"
	response.write "</script>"
	response.end
end if
%>
		  <table height="5"><tr><td></td></tr></table>


<table height="5"><tr><td></td></tr></table>
<TABLE cellSpacing=0 cellPadding=0 width=95% border=0 style="BORDER-RIGHT: #b1bfee 1px solid; BORDER-TOP: #b1bfee 1px solid; BORDER-LEFT: #b1bfee 1px solid; BORDER-BOTTOM: #b1bfee 1px solid" 
>
            <TBODY>
              <TR> 
                
      <TD bgColor=#f4f5fd height=30><font color="#000000">　<B><font color="#FF0000">&nbsp;查看/编辑订单资料</font></B></font></TD>
              </TR>
            </TBODY>
          </TABLE>
		  <table height="5"><tr><td></td></tr></table>

<table width="95%"  border="0" cellpadding="0" cellspacing="1" bgcolor="#b1bfee">
  <form action=order1.asp?action=list method=post name=orderedit>
    <INPUT TYPE="hidden" name=edit value=ok>
    <INPUT TYPE="hidden" name=Id value=<%=rs("OrderNum")%>>
    <tr bgcolor="#FFFFFF"> 
      <td width=20% align='right'>提交时间：</td>
      <td><input type="text" name="" value="<%=rs("Ordertime")%>" style="overflow:auto;width=80%" readonly></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>订 单 号：</td>
      <td><input type="text" name="" value="<%=rs("OrderNum")%>" style="overflow:auto;width=80%" readonly></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>订单金额：</td>
      <td><input type="text" name="ordersum" value="<%=formatnumber(rs("Ordersum"),2)%>" style="overflow:auto;width=80%" readonly></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>会员ID：</td>
      <td><input type="text" name="userid" value="<%=rs("userid")%>" style="overflow:auto;width=80%" readonly></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>配送方式：</td>
      <td><input alt=顾客选择的配送方式 type="text" name="post" value="<%=rs("pei")%>" readonly style="overflow:auto;width=80%"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>定货人姓名：</td>
      <td><input type="text" name="Recname" value="<%=rs("Recname")%>" readonly style="overflow:auto;width=80%" maxlength="30"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>联系电话：</td>
      <td><input type="text" name="RecPhone" value="<%=rs("RecPhone")%>" readonly style="overflow:auto;width=80%" maxlength="30"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>移动电话：</td>
      <td><input type="text" name="CompPhone" value="<%=rs("CompPhone")%>" readonly style="overflow:auto;width=80%" maxlength="30"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>电子邮箱：</td>
      <td><input type="text" name="Recmail" value="<%=rs("Recmail")%>" readonly style="overflow:auto;width=80%" maxlength="30"> 
        &nbsp; <a href='sendmail.asp?<%=rs("Recmail")%>'><img alt='发邮件' border=0 src='../images/small/e-mail.gif'></a></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>邮政编码：</td>
      <td><input type="text" name="Zipcode" value="<%=rs("Zipcode")%>" readonly style="overflow:auto;width=80%" maxlength="10"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>省份：</td>
      <td><input type="text" name="Province" value="<%=rs("Province")%>" readonly style="overflow:auto;width=80%" maxlength="10"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>城市：</td>
      <td><input type="text" name="city" value="<%=rs("city")%>" readonly style="overflow:auto;width=80%" maxlength="10"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>收货地址：</td>
      <td><input type="text" name="RecAddress" value="<%=rs("RecAddress")%>" readonly style="overflow:auto;width=80%" maxlength="30"></td>
    </tr>
	<% if rs("Fetch_Mode")=1 then %>
    <tr bgcolor="#FFFFFF">
      <td align='right'><font color="#FF0000">定货人送给：</font></td>
      <td><input type="text" name="Recname2" value="<%=rs("Recname2")%>" readonly style="overflow:auto;width=80%" maxlength="30"></td>
    </tr>
	    <tr bgcolor="#FFFFFF">
      <td align='right'><font color="#FF0000">省份：</font></td>
      <td><input type="text" name="Province2" value="<%=rs("Province2")%>" readonly style="overflow:auto;width=80%" maxlength="10"></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td align='right'><font color="#FF0000">城市：</font></td>
      <td><input type="text" name="city2" value="<%=rs("city2")%>" readonly style="overflow:auto;width=80%" maxlength="10"></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td align='right'><font color="#FF0000">地址：</font></td>
      <td><input type="text" name="RecAddress2" value="<%=rs("RecAddress2")%>" readonly style="overflow:auto;width=80%" maxlength="30"></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td align='right'><font color="#FF0000">邮政编码：</font></td>
      <td><input type="text" name="Zipcode2" value="<%=rs("Zipcode2")%>" readonly style="overflow:auto;width=80%" maxlength="10"></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td align='right'><font color="#FF0000">电话：</font></td>
      <td><input type="text" name="RecPhone2" value="<%=rs("RecPhone2")%>" readonly style="overflow:auto;width=80%" maxlength="30"></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td align='right'><font color="#FF0000">电子邮箱：</font></td>
      <td><input type="text" name="Recmail2" value="<%=rs("Recmail2")%>" readonly style="overflow:auto;width=80%" maxlength="30"></td>
    </tr>

	<% end if %>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>送货时间：</td>
      <td><input alt=顾客指定的送货时间 type="text" name="gettime" value="<%=rs("gettime")%>"  readonly style="overflow:auto;width=80%" maxlength="30"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>顾客说明：</td>
      <td><textarea alt=顾客对此订单的其它要求或说明 rows='5' name='Notes' readonly style="overflow:auto;width=80%"><%=rs("Notes")%></textarea></td>
    </tr><tr bgcolor="#FFFFFF"></tr>
    <tr bgcolor="#FFFFFF"> 
      <td align='right'>订单处理：</td>
      <td><textarea alt="填写对订单处理的说明" rows='5' name='memo' style="overflow:auto;width=80% ; background-color: #FFFFCC;"><%=rs("Memo")%></textarea></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height=30 align='right'>订单状态：</td>
      <td> <%
fei=rs("fei")
if rs("Status")="11" or  rs("Status")="12" or  rs("Status")="99" then
set rs2 = conn.Execute("select * from type where Status='"&rs("Status")&"'")
	response.write "<b>"&rs2("StatusDefine")&"<B>"
else
set rs2 = conn.execute("select * from type Order by Status asc")
	response.write	"<select name='Status'>"
	Do While Not rs2.eof	
	if rs2("Status") = rs("Status") then 
	response.write "<option value='"&rs2("Status")&"' selected>"&rs2("StatusDefine")&"</option>"
	else
	response.write "<option value='"&rs2("Status")&"'>"&rs2("StatusDefine")&"</option>"
	end if
	rs2.movenext
	if rs2.eof then	exit do
	loop
	response.write "</select>"
set rs2=nothing
end if
%> </td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td align=right>购物清单：</td>
      <td> 
	  
<table width="100%"  border="0" cellpadding="0" cellspacing="1" bgcolor="#b1bfee">
          <tr bgcolor="#f4f5fd"> 
            <td width=15%>商品编号</td>
            <td width="40%">商品名称</td>
            <td width="15%">购买数量</td>
            <td width="15%">结算单价</td>
            <td width="15%" align=center>金额</td>
          </tr>
          <%
	Total = 0
	do while not rs.eof 
	Sum = rs("ProdUnit")* csng(rs("BuyPrice")) * csng(rs("thiskou"))/10
	Sum = FormatNumber(Sum,2) 
	Total = Sum + Total
	
	response.write "<tr bgcolor=#FFFFFF><td>"&rs("ProdId")&"</td><td><a alt='查看此商品的前台页面' href=../gotourl.asp?list.asp?ProdId="&rs("ProdId")&" target='blank_'>"&rs("ProdName")&"</a></td>"
	response.write "<td>"&rs("ProdUnit")&"</td>"
	response.write "<td>"&FormatNumber(csng(rs("BuyPrice")) * csng(rs("thiskou"))/10,2)&"</td>"
	response.write "<td>"&Sum&"</td></tr>"

	rs.movenext
	loop

%>
          <TR bgcolor=#FFFFFF> 
            <TD colspan='5'> 商品总价：<%=FormatNumber(Total,2)%><br>
              配送费用：<%=formatnum(fei,2)%><br>
              总计费用：<font color=red><b><%=FormatNumber((Total+fei),2)%></font></b> 元 </td>
          </TR>
        </table></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td colspan=2> <input type='submit' name='action' value='修改订单'> &nbsp; &nbsp; 
      </td>
    </tr>
  </form>
</table>
		  <table height="5"><tr><td></td></tr></table>

<%
set rs=nothing
end sub







sub orderdel()
delid=request("id")
if Delid="" or isnull(Delid) then
response.write "<script language='javascript'>"
response.write "alert('操作失败，您什么也没有选择。');"
response.write "location.href='javascript:history.go(-1)';"
response.write "</script>"
response.end
end if

Set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from bOrderList where id in ("&Delid&")"
rs.open sql,conn,1,3
if rs.eof and rs.bof then
response.write "<script language='javascript'>"
response.write "alert('出错了，该订单不存在或者已经被删除。');"		
response.write "</script>"			
response.end 
else
Do while not rs.eof
rs("del")=true
rs.update
rs.movenext
loop
rs.close
set rs=nothing
response.write "<script language='javascript'>"
response.write "alert('操作成功，所选订单已被放入订单回收站，您可前往回收站彻底清除或恢复。');"
response.write "location.href='order1.asp';"			
response.write "</script>"
end if
end sub
%>
