<%@ page language="java" import="java.util.*,com.letousky.lottery.action.MemberCenter,com.letousky.exception.LotteryException,jxl.Workbook,jxl.write.Label,jxl.write.WritableSheet,jxl.write.WritableWorkbook,com.util.DateUtil,com.util.GameCodeToGameType;" pageEncoding="UTF-8"%>
<%
	String[] params=new String[7];
	params[0]=request.getParameter("userid");
	params[1]=request.getParameter("gameid");
	params[2]=request.getParameter("status"); 
	params[3]=request.getParameter("beginTime");
	params[4]=request.getParameter("endTime");
	params[5]=request.getParameter("pages"); //当前页数
	params[6]=request.getParameter("every"); //当前页显示的条数
	if(params[5]==null)params[5]="0";
	if(params[6]==null)params[6]="0";
	if(!"0".equals(params[6])){
	List list=new MemberCenter().buyLottery(params);
	String[] str=null;
	String d=",";
	Object[] obj=list.toArray();
	List items=(List)obj[0];
	String[] recod=(String[])obj[1];
	Object[] item=items.toArray();
	
	out.print("{\"recod\":\""+recod[0]+"\",\"countRgPrice\":\""+recod[1]+"\",\"countZjPrice\":\""+recod[2]+"\",\"items\":[");
	for(int i=0;i<item.length;i++){
		
		str=(String[])item[i];
		
		if(i==(item.length-1)){ d=""; }
		
		out.print("{\"gameid\":\""+str[0]+"\",\"bettingType\":\""+str[1]+"\",\"userName\":\""+str[2]+"\",\"bdPrice\":\""+str[3]+"\",\"rgPrice\":\""+str[4]+"\",\"zjPrice\":\""+str[5]+"\",\"status\":\""+str[6]+"\",\"starTime\":\""+str[7]+"\",\"trnNumber\":\""+str[8]+"\",\"progress\":\""+str[9]+"\",\"id\":\""+str[10]+"\"}"+d+"");
		
	}
	out.print("]}");
	}else{
		List list=new MemberCenter().buyLottery(params);
        Object[] obj=list.toArray();
    	List items=(List)obj[0];
    	Object[] item=items.toArray();
		params[5]="0";
		String[] str=null;
		//导出到excel文件中attachment/inline打开方式两种
	    String filename = new String("彩票交易记录".getBytes("GBK"),"iso8859-1"); 
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition",
                "inline; filename="+filename
                + DateUtil.toStringInYearMonthDayPattern(DateUtil
                        .getNowPreciseToDay()) + ".xls");
        ServletOutputStream os = response.getOutputStream();
        WritableWorkbook workbook = Workbook.createWorkbook(os);
        WritableSheet sheet = workbook.createSheet("日志", 0);

        Label label = null;
        label = new Label(0, 0, "彩种");
        sheet.addCell(label);
        label = new Label(1, 0, "投注时间");
        sheet.addCell(label);
        label = new Label(2, 0, "投注金额");
        sheet.addCell(label);
        label = new Label(3, 0, "当前状态");
        sheet.addCell(label);
        label = new Label(4, 0, "购买方式");
        sheet.addCell(label);
        label = new Label(5, 0, "购买信息");
        sheet.addCell(label);

    	
    	for(int i=0;i<item.length;i++){
    		str=(String[])item[i];
    		if("0".equals(str[11])){
    			str[11]="手机";
    		}
    		if("1".equals(str[11])){
    			str[11]="邮箱";
    		}
            if (str!=null) {
            	String userName = "";
                //**彩种**
				label = new Label(0, i + 1, GameCodeToGameType.getTypeByGameCode(str[0]));
	            sheet.addCell(label);             
                //**投注时间**
                label = new Label(1, i + 1, DateUtil.formaTime(str[7]));
                sheet.addCell(label);
                //**投注金额**
                label = new Label(2, i + 1, str[4]);
                sheet.addCell(label);
                //**当前状态**
                label = new Label(3, i + 1, str[6]);
                sheet.addCell(label);
                //**购买方式**
                label = new Label(4, i + 1, str[11]);
                sheet.addCell(label);
                //**购买信息**
                label = new Label(5, i + 1, str[12]);
                sheet.addCell(label);
            }
        }
        workbook.write();
        workbook.close();
        os.close();
	}
%>