<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.system.SzOut" %>
<%@ page import="net.sz600.database.SzDataReader" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.tool.*" %>
<%
  String strSkin_SESSION = "../../images/skin2_blue2";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../../share/js/commonTool.js"></script>
</head>
<%
	//查询时间段
	String sSearchBegin = SzConvert.strWriteData(request.getParameter("txtSearchBegin"));
	String sSearchEnd = SzConvert.strWriteData(request.getParameter("txtSearchEnd"));
	String sSearch = SzConvert.strWriteData(request.getParameter("txtSearch"));

	//如果开始时间和结束时间都为空，就默认为当前月
	Date curDate = null;
	Date searchEndDate = null;
	if(sSearchBegin.equals("")&&sSearchEnd.equals("")){
		//curDate = SzDateHelp.getFirstDateMonth();
		//searchEndDate = SzDateHelp.getLastDateMonth();
		//sSearchBegin = SzDateHelp.dateToYMD(SzDateHelp.getFirstDateMonth());
		//sSearchEnd = SzDateHelp.dateToYMD(SzDateHelp.getLastDateMonth());
	}else if(!sSearchEnd.equals("")){
		searchEndDate = SzDateHelp.stringToDate(sSearchEnd);
	}
	String searchEnd = searchEndDate!=null?SzDateHelp.dateToYMD(SzDateHelp.dayAfter(searchEndDate,1)):"";

	StringBuffer sqlSB = new StringBuffer();
	sqlSB.append("SELECT distinct b1.MAC,b1.DOG,b1.IP,b2.MinSJ,b2.MaxSJ,b2.TIMES FROM SZXT_OA b1,");
	sqlSB.append("(");
	sqlSB.append("SELECT MAC,MAX(SJ) MaxSJ,MIN(SJ) MinSJ,COUNT(ID) TIMES FROM SZXT_OA GROUP BY MAC ");
	sqlSB.append(") b2");
	sqlSB.append(" WHERE b1.MAC=b2.MAC AND b1.SJ=b2.MaxSJ");
	if (!sSearchBegin.equals("")){
		sqlSB.append(" AND b2.MaxSJ>'"+sSearchBegin+"'");
	}
	if (!searchEnd.equals("")){
		sqlSB.append(" AND b2.MaxSJ<='"+searchEnd+"'");
	}
	if (!sSearch.equals("")){
		sqlSB.append(" AND (");
		sqlSB.append(" b1.MAC like '%");
              sqlSB.append(sSearch);
              sqlSB.append("%'");
		sqlSB.append(" or b1.DOG like '%");
              sqlSB.append(sSearch);
              sqlSB.append("%'");
		sqlSB.append(" or b1.IP like '%");
              sqlSB.append(sSearch);
              sqlSB.append("%'");
              sqlSB.append(" )");
	}
  
       sqlSB.append(" ORDER BY b2.MaxSJ DESC");

	//out.println(sqlSB.toString());
	ArrayList list = new ArrayList();
	Object value[] = null;
	int valueLength = 6;
	try {
		SzDataReader dataReader = new SzDataReader();
		ResultSet rs = dataReader.readInfo(sqlSB.toString());
		while (rs != null && rs.next()) {
			value = new Object[valueLength];
			for (int i =0;i<valueLength;i++){
				value[i] = rs.getObject(i+1);
			}
			list.add(value);
		}
		// 关闭所有的连接
		dataReader.closeAll();
	} catch (java.sql.SQLException e) {
		SzOut.printlnError(e.getMessage());
	}
%>
<body>
<!-----上面的工具栏------>
<table width="100%">
  <form name="formBar" method="post">
  
  <tr>
    <td>
      网卡或IP、加密狗查询<input type="text" name="txtSearch" class="txtClassSearch" value="<%=sSearch%>">

      开始<input type="text" name="txtSearchBegin" class="txtClassSearch" value="<%=sSearchBegin%>">
      <%=SzPageHelp.calendar2Select("../../","formBar.txtSearchBegin")%>
      结束<input type="text" name="txtSearchEnd" class="txtClassSearch" value="<%=sSearchEnd%>">
      <%=SzPageHelp.calendar2Select("../../","formBar.txtSearchEnd")%>
      <%=SzPageHelp.button("查询", "javascript:FormSubmit(formBar,'index.jsp');")%>
    </td>
  </tr>
  </form>
</table>
<!-----信息列表----->
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formList" method="post">
  <tr class="trClassTitle">
    <td>网卡</td>
    <td>加密狗</td>
    <td>IP</td>
    <td>第一次访问时间</td>
    <td>最后一次访问时间</td>
    <td>总访问次数</td>
  </tr>
<%
	int listSize = list.size();
	int i=0;
	for (i=0;i<listSize;i++){
		value = (Object[])list.get(i);
		if (value != null){
			out.println("<tr>");
			for(int j=0;j<valueLength;j++){
				out.println("<td>"+ (value[j]!=null? value[j]:"") +"&nbsp;</td>");
			}
			out.println("</tr>");
		}
	}
	out.println(SzPageHelp.outIndexTableTr(i, 16, 6));
%>

  </form>
</table>
</body>
</html>
<%
    ////如果要使用日历控件，必须输出这个calendarFrame
    out.println(SzPageHelp.calendar2Frame("../../"));
%>

