<!--#include file="conn.asp"-->
<!--#include file="inc/cook2.asp"-->
<!--#include file="inc/dimflag.asp"-->
<!--#include file="inc/page.asp"-->
<%
tid = int(Request("tid"))
word=trim(request("word"))

typeid=request("typeid")
id=request.QueryString("id")

call setKucun(typeid)

canshu1="tid="&tid&"&typeid="&typeid&"&cid="&cid&""
canshu3="word="&word&"&sortpath="&sortpath&"&pt="&pt&"&tuij="&tuij&"&"&canshu1&""
canshu2="page="&page&"&"&canshu3&""


post=request("post")
if post="edit" then
		set rs=server.CreateObject("adodb.recordset")
		sql="select * from com_PCR where id="&id
		rs.open sql,conn,1,3
		rs("proid")=typeid
		rs("colorid")=request("colorid")
		rs("sizeid")=request("sizeid")
		if request("kucun")<>"" then
		rs("kucun")=request("kucun")
		else
		rs("kucun")=0
		end if
		rs.update
		rs.close
		set rs=nothing
		


response.Write "<script>location='?"&canshu2&"'</script>"
end if


if post="add" then
		set rs=server.CreateObject("adodb.recordset")
		sql="select * from com_PCR"
		rs.open sql,conn,1,3
		rs.addnew
		rs("proid")=typeid
		rs("colorid")=request("colorid")
		rs("sizeid")=request("sizeid")
		if request("kucun")<>"" then
		rs("kucun")=request("kucun")
		else
		rs("kucun")=0
		end if
		rs.update
		rs.close
		set rs=nothing


	
response.Write "<script>location='?"&canshu2&"'</script>"
end if

select case action
case "del" 
 id=replace(request("id")," ","")
 id=split(id,",")
 for i=0 to UBound(id)
 conn.execute("delete from com_PCR where id="&id(i))
 next
 
 response.Write "<script>location='?"&canshu1&"'</script>"
case "order" 
 pi=REQUEST("pi")
 pi=REPLACE(pi,", ",",")
 SQL5="SELECT * from com_PCR where id IN ("&pi&")"
 SET RS5=SERVER.CREATEOBJECT("ADODB.RECORDSET")
 rs5.open sql5,conn,1,3
 while not rs5.eof 
 RS5("pid")=REQUEST("pid"&RS5("id"))
 RS5.UPDATE
 RS5.MOVENEXT
 wend
 response.Write "<script>location='?"&canshu2&"'</script>"
 response.end
case "inputedit"
 attrKey = split(Trim(Request("id")), "$")(0) 
 index = split(Trim(Request("id")), "$")(1) 
 set rs=server.CreateObject("adodb.recordset")
 sql="select kucun from com_PCR where id="&index
 rs.open sql,conn,1,3
 rs("kucun")=Trim(Request("value"))
 rs.update
 rs.close
 set rs=nothing
 Response.Write(Trim(Request("value"))) 
 Response.end()  
end select
%>
<!--#include file="top.asp"-->
<div id="container">
<%if post="" then%>
<div class="top_but">
 <li class="left">&nbsp;</li>
 <li><a href="?post=addnew&typeid=<%=typeid%>&cid=<%=cid%>" onClick="parent.frmleft.bb('2_2')"><img src="images/but_1.gif" alt="添加" ></a></li>
 <li><img src="images/but_2.gif" alt="排序" onclick="form1.action='?action=order&<%=canshu2%>';form1.submit();"></li>
 <li><img src="images/but_3.gif" alt="删除" onclick="form1.action='?action=del&<%=canshu2%>';ConfirmDel();"></li>
 <li><img src="images/but_8.gif" alt="刷新" onClick="window.location.reload(true);"></li>
</div>


<%
if word<>"" then
sql= "select * from com_PCR where proid="&typeid&" and kucun like'%"&word&"%'  order by pid asc,id desc"
else
sql= "select * from com_PCR where proid="&typeid&" order by pid asc,id desc"
end if
set rs=server.createobject("adodb.recordset")                     
rs.open sql,conn,1,1                     
if rs.eof and rs.bof then                     
response.write conn_eof
else 
page1("20")
i=1	
set colorid=rs("colorid")
set proid=rs("proid")
set sizeid=rs("sizeid")
set kucun=rs("kucun")
set id=rs("id")
set pid=rs("pid")
%>
<div class="tablesearch"><%
set rs1=server.CreateObject("adodb.recordset")
rs1.open "select * from com_books where id="&proid&"",conn,1,1
response.write(rs1("titlecn"))
rs1.close
set rs1=nothing
%></div>

<form name="form1" id="form1" method="post" action="?<%=canshu2%>">
<div class="tableAll titlebgcolor">
<ul>
 <li style="width:30px"><input name="chkall" type="checkbox" id="chkall" value="select" onClick="CheckAll(this.form);" ></li>

 <li style="width:50px;">操作</li>
  <li style="width:100px;">颜色</li>
   <li style="width:100px;">尺寸</li>
    <li style="width:120px;">库存</li>
	
 <li style="width:50px;">排序</li>
 </ul>
</div>
<%
kucunall=0
while not rs.eof and i<=rs.pagesize
%>
<div class="tableAll trbgcolor">
 <li style="width:30px;"><input type="checkbox" name="ID"  value="<%=id%>"></li>

 <li style="width:50px;"><a href="?post=modify&id=<%=id%>&<%=canshu2%>">编辑</a></li>

  <li style="width:100px;">
<%
set rs1=server.CreateObject("adodb.recordset")
rs1.open "select * from com_color where id="&colorid&"",conn,1,1
response.write(rs1("ClassNamecn"))
rs1.close
set rs1=nothing
%>
</li>
  <li style="width:100px;">
<%
set rs1=server.CreateObject("adodb.recordset")
rs1.open "select * from com_size where id="&sizeid&"",conn,1,1
response.write(rs1("ClassNamecn"))
rs1.close
set rs1=nothing
%>
  </li>
  <li style="width:120px;"><span id="name$<%=id%>" class="edit"><%=kucun%></span></li>

 <li style="width:50px;"><input name="pid<%=id%>" type="text" id="pid<%=id%>" value="<%=pid%>" size="3"> 
<input name="pi" type="hidden" id="pi" value="<%=id%>"></li>
</div>
<%
kucunall=kucun+kucunall
i=i+1
rs.movenext
wend
%>
</form>
<div class="tableAll trbgcolor">
 <li style="width:30px;">&nbsp;</li>
 <li style="width:50px;">&nbsp;</li>
  <li style="width:80px;">&nbsp;</li>  <li style="width:80px;">&nbsp;</li>
  <li style="width:120px;">总库存：<%=kucunall%></li>
 <li style="width:50px;">&nbsp;</li>
</div>


<div id="divStayTop" class="bottom titlebgcolor">
<%call page2(5,""&canshu3&"&")%> 
</div>
<!--小图放大div-->
<div id="a1" style="position:absolute; z-index:10;"></div>
<%
end if
rs.close
set rs=nothing
%>
</div>
<%end if%>

<%if post="modify" then%>
<div class="top_but">
 <li class="left">&nbsp;</li>
 <li><a href="book_PCR.asp?typeid=<%=typeid%>&cid=<%=cid%>"><img src="images/but_11.gif" alt="管理"></a></li>
 <li><img src="images/but_8.gif" alt="刷新" onClick="window.location.reload(true);"></li>

</div>
<div class="tableAll titlebgcolor">
  <li style="width:30px;">&nbsp;</li>
 <li style="width:700px;">修改内容</li>
</div>
<%
set rs=server.CreateObject("adodb.recordset")
sql="select * from com_PCR where id="&id
rs.open sql,conn,1,1
%>
<form name="myform" method="post" action="?post=edit&id=<%=rs("id")%>&word=<%=word%>&pt=<%=pt%>&tuij=<%=tuij%>&sortpath=<%=sortpath%>&page=<%=page%>&tid=<%=tid%>&typeid=<%=typeid%>&cid=<%=cid%>" >


<div class="tableAll trbgcolor">
  <li style="width:30px;">&nbsp;</li>
 <li style="width:100px;">选择颜色</li>
 <li>
<%
  set rs1=server.CreateObject("adodb.recordset")
  rs1.open "select * from com_color order by pid asc, id desc",conn,1,1
  %>
   <select name="colorid" size="1" >
    <%
    do while not rs1.eof
	%>
    <option value="<%=rs1("ID")%>" <%if rs("colorid")=rs1("id") then%>selected<%end if%>><%=rs1("ClassNamecn")%>
    <%
	rs1.movenext
    loop
	rs1.close
	set rs1=nothing
	%>
    </select>
    </li>
</div>

<div class="tableAll trbgcolor">
  <li style="width:30px;">&nbsp;</li>
 <li style="width:100px;">选择尺寸</li>
 <li>
<%
  set rs1=server.CreateObject("adodb.recordset")
  rs1.open "select * from com_size order by pid asc, id desc",conn,1,1
  %>
   <select name="sizeid" size="1" >
    <%
    do while not rs1.eof
	%>
    <option value="<%=rs1("ID")%>" <%if rs("sizeid")=rs1("id") then%>selected<%end if%>><%=rs1("ClassNamecn")%>
    <%
	rs1.movenext
    loop
	rs1.close
	set rs1=nothing
	%>
    </select>
    </li>
</div>

<div class="tableAll trbgcolor">
<li style="width:30px;">&nbsp;</li>
<li style="width:100px">库存</li>
<li><input name="kucun" type="text" id="kucun" value="<%=rs("kucun")%>"></li>
</div>

<div class="tableAll trbgcolor">
  <li style="width:30px;">&nbsp;</li>
 <li><input class="button" type="submit" name="Submit" value="确认修改" > </li>
</div>
<%
rs.close
set rs=nothing
%>
</form>
<%end if%>

<%if post="addnew" then%>
<div class="top_but">
 <li class="left">&nbsp;</li>
 <li><a href="book_PCR.asp?typeid=<%=typeid%>&cid=<%=cid%>"><img src="images/but_11.gif" alt="管理"></a></li>
 <li><img src="images/but_8.gif" alt="刷新" onClick="window.location.reload(true);"></li>
</div>
<div class="tableAll titlebgcolor">
  <li style="width:30px;">&nbsp;</li>
 <li style="width:700px;">修改内容</li>
</div>

<form name="myform" method="post" action="?post=add&word=<%=word%>&pt=<%=pt%>&tuij=<%=tuij%>&sortpath=<%=sortpath%>&page=<%=page%>&tid=<%=tid%>&typeid=<%=typeid%>&cid=<%=cid%>" >
<div class="tableAll trbgcolor">
  <li style="width:30px;">&nbsp;</li>
 <li style="width:100px;">选择颜色</li>
 <li>
<%
  set rs1=server.CreateObject("adodb.recordset")
  rs1.open "select * from com_color order by pid asc, id desc",conn,1,1
  %>
   <select name="colorid" size="1" >
    <%
    do while not rs1.eof
	%>
    <option value="<%=rs1("ID")%>" ><%=rs1("ClassNamecn")%>
    <%
	rs1.movenext
    loop
	rs1.close
	set rs1=nothing
	%>
    </select>
    </li>
</div>

<div class="tableAll trbgcolor">
  <li style="width:30px;">&nbsp;</li>
 <li style="width:100px;">选择尺寸</li>
 <li>
<%
  set rs1=server.CreateObject("adodb.recordset")
  rs1.open "select * from com_size order by pid asc, id desc",conn,1,1
  %>
   <select name="sizeid" size="1" >
    <%
    do while not rs1.eof
	%>
    <option value="<%=rs1("ID")%>" ><%=rs1("ClassNamecn")%>
    <%
	rs1.movenext
    loop
	rs1.close
	set rs1=nothing
	%>
    </select>
    </li>
</div>

<div class="tableAll trbgcolor">
<li style="width:30px;">&nbsp;</li>
<li style="width:100px">库存</li>
<li><input name="kucun" type="text" id="kucun" value=0></li>
</div>

<div class="tableAll trbgcolor">
  <li style="width:30px;">&nbsp;</li>
 <li><input class="button" type="submit" name="Submit" value="确认添加" > </li>
</div>

</form>
<%end if%>
 <!--script language="JavaScript" type="text/JavaScript" src="js/jquery.latest.js"></script-->
<!--#include file="footer.asp"-->


<%
function setKucun(typeid)
		sql= "select * from com_PCR where proid="&typeid&" order by pid asc,id desc"
		set rs=server.createobject("adodb.recordset")                     
		rs.open sql,conn,1,1                     
		if rs.eof and rs.bof then                     
		kucun_all=0
		else 
			set kucun=rs("kucun")
			while not rs.eof
			kucun_all=kucun_all+kucun
			rs.movenext
			wend
		end if
		rs.close
		set rs=nothing
		
		
		set rs=server.CreateObject("adodb.recordset")
		sql="select * from com_books where id="&typeid
		rs.open sql,conn,1,3
		rs("kucun")=kucun_all
		rs.update
		rs.close
		set rs=nothing
end function
%>