<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" %>
<%@ page import="java.io.*" %> 
<%@ page import="java.util.*" %>

<%@ include file = "func/parameter.jsp" %>
<jsp:useBean id="statistics" scope="page" class="net.jspcn.db.DbConnect" />
<jsp:useBean id="gd" scope="page" class="net.jspcn.util.GetData" />
<jsp:useBean id="cg" scope="page" class="net.jspcn.util.ChartGraphics" />

<%
statistics.openConnection();
String type,sql,path;
path = message[8];
ResultSet rs;
int type_id;
int[] id = new int[20];
int[] insum = new int[20];
String[] name = new String[20];
int maxinsum=10;
int i=0;

if (Integer.parseInt((String) session.getValue("user_power"))<9999)
response.sendRedirect("login.jsp");

File dir = new java.io.File(path);
//dir.delete();
dir.mkdir();

sql="";

if(request.getParameter("type")==null)
	type = "t";
else
	type = request.getParameter("type");

if(request.getParameter("type_id")==null)
	type_id = 1;
else
	{
	type_id = Integer.parseInt(request.getParameter("type_id"));
	type = "b";
	}
	
if("t".equalsIgnoreCase(type))
	sql = "select a.type_id id,type_name name,count(*) inall from "+news_table+" a,"+type_table+" b where a.type_id=b.type_id group by a.type_id";

if("b".equalsIgnoreCase(type))
	sql = "select a.board_id id,board_name name,count(*) inall from "+news_table+" a,"+board_table+" b where a.type_id="+type_id+" and a.board_id=b.board_id group by a.board_id";

rs = statistics.executeQuery(sql);

while(rs.next())
{
id[i]=rs.getInt("id");
name[i]=rs.getString("name");
insum[i]=rs.getInt("inall");
if(insum[i]>maxinsum)
maxinsum = insum[i];
i++;
}

cg.setProportion((double)(450/maxinsum));

cg.setOutPath(path+"0.jpg");
cg.graphicsGeneration(maxinsum,10,"red");
%>

<%@ include file = "func/header.jsp" %>
<table width="90%"  border="1" cellspacing="0" cellpadding="0"  bordercolor="#00CC66"  borderColorDark="#FFFFFF" borderColorLight="#00CC66">
<tr>
<td width="15%">
名称
</td>
<td width="5%">
数量
</td>
<td width="80%">
图例
</td>
</tr>
<tr>
<td>
标准图例
</td>
<td>
<%=maxinsum%>
</td>
<td>
<img SRC="images/statistics/0.jpg" BORDER="0">
</td>
</tr>
<%
for(int j=0;j<i;j++)
{
cg.setOutPath(path+id[j]+".jpg");
cg.graphicsGeneration(insum[j],10,"green");
%>
<tr>
<td>
<% if ("t".equalsIgnoreCase(type)) { %>
<a href="statistics.jsp?type_id=<%=id[j]%>"><%=name[j]%></a>
<%} else 
out.println(name[j]);
%>
</td>
<td>
<%=insum[j]%>
</td>
<td>
<img SRC="images/statistics/<%=id[j]%>.jpg" BORDER="0">
</td>
</tr>
<%
}
%>
</table>

<br>
<div align="center">
<a href="statistics.jsp">返回</a>
</div>
<%@ include file = "func/footer.jsp" %>
