 <%@ page contentType="text/html; charset=GBK"%>
 <%@page import="com.keyshop.shop.content.model.*, java.util.*,com.keyshop.shop.content.manager.*"
%>
<%@ taglib uri="/bean" prefix="bean" %>
<%@ taglib uri="/html" prefix="html" %>
<%@ taglib uri="/logic" prefix="logic" %>
<%@ taglib uri="/keyshop" prefix="keyshop" %>

<%
	String inqid = request.getParameter("inquId");
	
	boolean addSuccess = false;
	boolean addFail = false;
	String actionType = request.getParameter("actionType");
	
	System.out.println("inqid = " + inqid);
	if("add".equals(actionType)) {
		String send = (String)session.getAttribute("send"+ inqid);
		if(send == null) {
			String inqResultid = request.getParameter("inqResultId");
				System.out.println("inqResultid=" + inqResultid);
			ContentManager.addInquisitionCount(inqid, inqResultid);	
			addSuccess = true;
			session.setAttribute("send" + inqid, "true");
		} else {
			addFail = true;
		}
	}
	

	System.out.println("inquId=" + inqid);
	Inquisition inq = ContentManager.getInquisitionObject(inqid);
	
	String inqName = "";
	int totalNumber = 0;
	if(inq != null) {
		inqName = inq.getName();
		
		Set childs = inq.getChildList();
		if(childs != null && childs.size() > 0) {
			Iterator cits = childs.iterator();
			
			while(cits.hasNext()) {
				InquisitionResult result = (InquisitionResult)cits.next();
				totalNumber = totalNumber + result.getCount();
			}
		}
	}
%>
<html>
<head>
<title><%=inqName%>投票结果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="<%=request.getContextPath()%>/pub/list.css" rel="stylesheet" type="text/css">
</head>
<body leftmargin="0" topmargin="0" class="commend">
<br>
	<table width="700" border="0" cellpadding="0" cellspacing="0">
		<tr><td align="center">
				<table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
          <tr>
            <td>
            	 <%
							  	if(addSuccess) {
							  %>
							  <tr> 
							    <td  height="13" colspan="3" align="center">
							    	投票成功。
							    </td>
							  </tr>
							  <%
							  	} else if(addFail) {
							  %>
							  <tr> 
							    <td height="13" colspan="3" align="center">
							    	您已经投过票了，谢谢您的支持。
							    </td>
							  </tr>
							  <%
							  	}
							  %>
            </td>
          </tr>
        </table>
				<table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
          <tr>
            <td><p align="center" class="vote_title"><%=inq.getDescription()%></p>
              <p><span class="f14">共有<font color=#fc0a0b><%=totalNumber%></font>人参加</span></p></td>
          </tr>
        </table>
  		<table width=100% border=0 cellpadding=3 cellspacing=1 align=center>
				<tr bgcolor="BAC939" align=center>
					<td class=f14 width=20>&nbsp;</td>
					<td class=f14 width=180 height=20>选项</td>
					<td class=f14 width=150>比例</td>
					<td class=f14 width=50>票数</td>
				</tr>
				<%
				  	if(inq != null) {
				  	Set childs = inq.getChildList();
				  	int index = 1;
				  	if(childs != null && childs.size() > 0) {
				  		Iterator cits = childs.iterator();
				  		
				  		while(cits.hasNext()) {
				  			InquisitionResult result = (InquisitionResult)cits.next();
				%>
				<tr  bgcolor="EBFFB4" align=center>
					<td class=f14 width=20><%=index%></td>
					<td class=f14 width=230 height=20 align=left>
						<font  class="gwIndex_txt"><%=result.getName()%></font>
					</td>
					<td class=f14  bgcolor="EBFFB4"width=100 align=left> 
						<table border=0>
							<tr  bgcolor="EBFFB4" >
								<td align=left width=40>
									<font color=#0262cd>
										<%
											double bfb = 0;
											if(totalNumber > 0) {
												bfb = (result.getCount() * 100  / totalNumber);
										%>
											<%=bfb%>
										<%
											}
										%>%
									</font>
								</td>
								<td align=left width="60%">
									<table border=0 bgcolor=#black width="<%=bfb%>">
											<tr>
												<td>
												</td>
										</tr>
										</table>
								</td>
							</tr>
					</table>
				</td>
				<td class=f14 width=80 align=left><font color=#0262cd><%=result.getCount()%></font></td>
			</tr>
			 <%
  					}
		  		}
		  	}
		  %>
		</table>
</td></tr>
</table>
</body>
</html>
