<!--#include file="../include/Conn.jsp"-->
<!--#include file="Admin_IsLogin.jsp" -->
<%
dim i
dim rs,rst
dim mTypeName,mGrade,mSql,mFlag,mBgColor
'initialization 
mFlag=true'add

if request("action")="edit" then mFlag=false

'Insert Records
if request("action")="add" then
  mTypeName=Trim(server.htmlencode(request("txtTypeName")))
  if Trim(Request.QueryString("grade"))="" then mGrade=1 else mGrade=Cint(Request.QueryString("grade"))
  mSql="insert into Photo_Category(F_Value,F_Grade)values('"&mTypeName&"',"&mGrade&")"
  conn.execute(mSql)
  response.redirect "Admin_AlbumCategory.jsp?action=IsInsert&pageno="&Request("pageno")
end if

'Modify Records
if request("action")="editsave" then
  mTypeName=Trim(server.htmlencode(request.form("txtTypeName2")))
  mSql="update Photo_Category set F_Value='" & mTypeName &"' where F_ID="&request.querystring("ModifyID")
  conn.execute(mSql)
  response.redirect "Admin_AlbumCategory.jsp?action=IsModify&pageno="&Request.Querystring("pageno")
  flag=false
end if

'Delect Records
if request("action")="delete" then
  '删除一级栏目
  mSql = "Delete From Photo_Category WHERE F_ID=" & Request.QueryString("DeleteID")
  conn.Execute(mSql)
  Response.write "<script>location.replace('Admin_AlbumCategory.jsp?action=IsDelete&pageno="&Request.Querystring("pageno")&"')</script>"
end if

'Sort Grade Up
If Request.QueryString("action")="up" then
   mSql="update Photo_Category set F_Grade=F_Grade-1 where F_Grade="&request.querystring("grade")
   conn.execute(mSql)
   mSql="update Photo_Category set F_Grade=F_Grade+1 where F_Grade="&cint(request.querystring("grade"))-1&" and F_ID<>"&Request.QueryString("SortID")
   conn.execute(mSql)
   mBgColor=Request.QueryString("SortID")
   Response.Redirect "Admin_AlbumCategory.jsp?pageno="&Request("pageno")&"&BgColor="&mBgColor
 End if

'Sort Grade Down
If Request.QueryString("action")="down" then
   mSql="update Photo_Category set F_Grade=F_Grade+1 where F_Grade="&request.querystring("grade")
   conn.execute(mSql)
   mSql="update Photo_Category set F_Grade=F_Grade-1 where F_Grade="&cint(request.querystring("grade"))+1&" and F_ID<>"&Request.QueryString("SortID")
   conn.execute(mSql)
   mBgColor=Request.QueryString("SortID")
   Response.Redirect "Admin_AlbumCategory.jsp?pageno="&Request("pageno")&"&BgColor="&mBgColor
 End if
%>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="Images/Style.css" rel="stylesheet" type="text/css">
<SCRIPT language="JavaScript">
function jDelete(url)
{
  if((confirm(" 警告:请确定是否删除,删除后不能恢复! "))==true) 
	self.location=url+'&action=delete';
}
</SCRIPT>
<script language="javascript">
function CheckData(){
  if (document.form1.txtTypeName.value=="")
   {
    alert("该文本框不能为空，请输入！");
	document.form1.txtTypeName.focus();
	return false;
   }
}

function CheckData2(){
  if (document.form2.txtTypeName2.value=="")
   {
    alert("该文本框不能为空，请输入！");
	document.form2.txtTypeName2.focus();
	return false;
   }
}
</script>
</head>
<body text="#000000" >

     <%
      admin_flag=",4|6|0,"
      if instr(session("flag"),admin_flag)=0 or isnull(session("flag"))=true then
         Response.write "<p align=center><br><br><br><br><b><font size=2 color=red>对不起，您没有管理本页面的权限!</font></B></P>"
		 Response.end
	  end if
      %>
<br>
<table class=tableBorder width="95%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#ebeef6">
      <tr> 
          
    <th height=21 colspan="7" sytle="line-height:150%">相册类别</th>
    </tr>
  <tr style="cursor:hand" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#EBEEF6'"> 
    <td width="6%" height="11" align="center" class=forumHeaderBackgroundAlternate><b>ID</b></td>
    <td width="6%" height="11" align="center" class=forumHeaderBackgroundAlternate><b>新序</b></td>
    <td width="18%" align="center" class=forumHeaderBackgroundAlternate><b>类别名称</b></td>
    <td width="8%" align="center" class=forumHeaderBackgroundAlternate><b>排序</b></td>
    <td width="11%" height="11" align="center" class=forumHeaderBackgroundAlternate><b>管理</b></td>
  </tr>
  <%  
	Set rs=Server.createobject("Adodb.RecordSet")
    pageno=request.querystring("pageno")
    pmcount=16  
    mSql="select * from Photo_Category order by F_Grade"
	rs.open mSql,conn,1,1
	if rs.eof then
	   'response.write "<br><p  align='center'><font color=red><B> 对不起，数据已清空！</B></font></p>"
    else
    rs.pagesize=pmcount
    mpage=rs.pagecount
    if pageno="" then pageno=1
    if  cint(pageno)<1 or cint(pageno)>mpage then  pageno=1
    rs.absolutepage=pageno

 Dim rc,re
 rc=rs.pagesize
 re=1
 i=0
 do while not rs.eof and rc>0
 i=i+1
 mBgColor=Request.Querystring("BgColor")
 if Trim(rs("F_ID"))=Trim(mBgColor) then mColor= "D6DFFF" else mColor= "ffffff"
%>
  <tr bgcolor="<%=mColor%>"  > 
    <td class=forumRow width="6%" height="20" align="center" ><%=rs("F_ID")%></td>
    <td class=forumRow width="6%" height="20" align="center" ><%=i+(Pageno-1)*pmcount%> </td>
    <td class=forumRow width="18%" align="center" > <%=rs("F_Value")%> </td>
    <td class=forumRow width="8%" align="center" > <%
	 if i+(Pageno-1)*pmcount=1 then 
	    Response.write "拉上"
	  else
		Response.write "<a href='Admin_AlbumCategory.jsp?pageno="&Request("pageno")&"&action=up&SortID="&rs("F_ID")&"&grade="&i+(Pageno-1)*pmcount&"'>拉上</a>"
      end if
	  Response.write "&nbsp;|&nbsp;"

	  if i+(Pageno-1)*pmcount=rs.recordcount then 
	    response.write "拉下"
	  else
		response.write "<a href='Admin_AlbumCategory.jsp?pageno="&Request("pageno")&"&action=down&SortID="&rs("F_ID")&"&grade="&i+(Pageno-1)*pmcount&"'>拉下</a>"
      end if
	%> </td>
    <td  class=forumRow width="11%" height="20" align="center" > <a href='Admin_AlbumCategory.jsp?pageno=<%=mPage%>'><font color="#666666">添加</font></a> 
      | <a href='Admin_AlbumCategory.jsp?action=edit&TypeName=<%=rs("F_Value")%>&ModifyID=<%=rs("F_ID")%>&BgColor=<%=rs("F_ID")%>&pageno=<%=cstr(pageno)%>'><font color="#666666">修改</font></a> 
      | <a href="javascript:jDelete('Admin_AlbumCategory.jsp?DeleteID=<%=rs("F_ID")%>&pageno=<%=cstr(pageno)%>')"><font color="#666666">删除</font></a> 
    </td>
  </tr>
    <%
 rs.movenext
 re=re+1
 rc=rc-1
 loop
 end if
%>
  <tr bgcolor="<%=mColor%>"  > 
    <td  class=forumRowHighlight height="20" colspan="3" >共 <font color=red><strong> 
      <% = rs.recordcount%>
      </strong></font> 条记录 当前第 <font color=red><strong> 
      <% = Trim(pageno)%>
      </strong></font>页/共 <font color=red><strong> 
      <% = Trim(mpage)%>
      </strong></font>页 </td>
    <td class=forumRowHighlight height="20" colspan="2" align="right" > <%
if pageno>1 then
   response.write "<a href='Admin_AlbumCategory.jsp'> <img alt='首页' src='Images/boqb02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='首页' src='Images/boqb02.gif' border=0 width='15' height='14'>"
end if

if pageno>1 then
   response.write "<a href='Admin_AlbumCategory.jsp?pageno="&pageno-1&"'><img alt='上一页' src='Images/bob02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='上一页' src='Images/bob02.gif' border=0 width='15' height='14'>"
end if

add=5'数字分页个数+1
if pageno-int(add/2)<=1 then m=1 else m=pageno-int(add/2)
if m+add>mpage then 
   n=mpage
   if mpage-add<=1 then m=1 else m=mpage-add
else
   n=m+add
end if

for pno=m to n
 if pno=cint(pageno) then
   response.write "&nbsp;<font color=red>"&pno&"</font>"
 else
   response.write "<b>&nbsp;<a href='Admin_AlbumCategory.jsp?pageno="&pno&"'>"&pno&"</a></b>"
 end if
next
response.write "&nbsp"

if int(pageno) < int(rs.pagecount) then
  response.write "<a href='Admin_AlbumCategory.jsp?pageno="&pageno+1&"'><img alt='下一页' src='Images/fbob02.gif' border=0 width='15' height='14'></a>"
else 
  response.write "<img alt='下一页' src='Images/fbob02.gif' border=0 width='15' height='14'>"
end if

if int(pageno) < int(rs.pagecount) then
   response.write "<a href='Admin_AlbumCategory.jsp?pageno="&mpage&"'><img alt='末页' src='Images/fboqb02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='末页' src='Images/fboqb02.gif' border=0 width='15' height='14'>"
end if
Response.write "&nbsp;&nbsp;"
%> </td>
  </tr>

</table> 
        <%if mFlag=true then'add%>


            <form name="form1" method="post" action="Admin_AlbumCategory.jsp?pageno=<%=mpage%>&action=add&grade=<%=rs.recordcount+1%>" onSubmit="return CheckData()">
<table class=tableBorder width="95%" height="32" border="0" align="center" cellpadding="2" cellspacing="1">
    <tr> 
          <th height=21 colspan="7" sytle="line-height:150%">新增记录</th>
    </tr>
          <tr> 
            <td class=forumRow width="12%" height="7">类别名称： <br> </td>
            <td class=forumRow width="88%">
			<input name="txtTypeName" type="text"  class="INPUT" value="" size="23" maxlength="20">
			</td>
          </tr>
          <tr> 
            
      <td height="32" colspan="2" class=forumRow> <input type="submit" name="Submit3" value="提交" class="button"> 
        <input type="reSet" name="Submit22" value="重置" class="button"> </td>
          </tr>
        </table>   
            
  <br>
</form>

        <%else%>

            <form name="form2" method="post" action="Admin_AlbumCategory.jsp?pageno=<%=request("pageno")%>&action=editsave&ModifyID=<%=request("ModifyID")%>" onSubmit="return CheckData2()">
  <table class=tableBorder width="95%" height="32" border="0" align="center" cellpadding="2" cellspacing="1">
    <tr> 
          <th height=21 colspan="7" sytle="line-height:150%">功能：修改记录</th>
    </tr>

    <tr> 
      <td class=forumRow width="12%" height="7">类别名称： <br> </td>
      <td class=forumRow><input name="txtTypeName2" type="text" class="INPUT" value="<%=request("TypeName")%>" size="23" maxlength="20"></td>
    </tr>
    <tr> 
      <td height="32" colspan="2" class=forumRow> <input type="submit" name="Submit32" value="提交" class="button"> 
        <input type="reSet" name="Submit222" value="重置" class="button"> </td>
    </tr>
  </table>
  <br>
</form>

        <%end if%>
</body>
</html>
<%
 rs.close
 set rs=nothing
 conn.close
 set conn=nothing
%>