<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/11
  Time: 12:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.*" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%@ page import="org.omg.CosCollection.IteratorInBetween" %>
<%!
    Pub pub = new Pub();
    public String getShengYu(ConnectionFactory cf,Connection conn,String zc_name,String gg_type,String pinpai,String jiage){
		String sums="0";
		StringBuffer sb = new StringBuffer();
		sb.append("select sum(counts) as sums from ( ");
		sb.append("select reg_id,max(counts) as counts from zc_register where ");
		sb.append("zc_name=? and gg_type=? and pinpai=? and jiazhi=? and zc_status='0' group by reg_id)");
        Vector list = cf.doQuery(conn,sb.toString(),null,new Object[]{zc_name,gg_type,pinpai,jiage});
        if(list==null){
            System.out.println("查询出错"+cf.getMsg());
        }
		if(list.size()==1){
			Hashtable ht = (Hashtable)list.get(0);
			sums=pub.trimNull((String) ht.get("sums"));
		}
        return sums;
    }
	 public String getCounts(ConnectionFactory cf,Connection conn,String zc_name,String gg_type,String pinpai,String jiage){
		String sums="0";
		StringBuffer sb = new StringBuffer();
		sb.append("select sum(counts) as sums from ( ");
		sb.append("select reg_id,max(counts) as counts from zc_register where ");
		sb.append("zc_name=? and gg_type=? and pinpai=? and jiazhi=? group by reg_id)");
        Vector list = cf.doQuery(conn,sb.toString(),null,new Object[]{zc_name,gg_type,pinpai,jiage});
        if(list==null){
            System.out.println("查询出错"+cf.getMsg());
        }
		if(list.size()==1){
			Hashtable ht = (Hashtable)list.get(0);
			sums=pub.trimNull((String) ht.get("sums"));
		}
        return sums;
    }
%>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    String page_number = pub.trimNull(request.getParameter("page_number"));
    if ("".equals(page_number)) page_number = "1";
    String page_size = pub.trimNull(request.getParameter("page_size"));
    String zc_name_s = pub.trimNull(request.getParameter("zc_name"));
    String pinpai_s = pub.trimNull(request.getParameter("pinpai"));
    if ("".equals(page_size)) page_size = "10";
    List list_s = new ArrayList();
    try {
        StringBuffer sb = new StringBuffer();
        sb.append("select zc_name,gg_type,pinpai,jiazhi from zc_register where 1=1 ");
        if(!"".equals(zc_name_s)){
            sb.append(" and zc_name like ?");
            list_s.add("%"+zc_name_s+"%");
        }if(!"".equals(pinpai_s)){
            sb.append(" and pinpai like ?");
            list_s.add("%"+pinpai_s+"%");
        }
        sb.append(" group by zc_name,gg_type,pinpai,jiazhi order by add_time desc");
        conn = com.censoft.db.DBUtil.getConnection();
        v_list = cf.doPageQueryWithCount(conn, sb.toString(), page_number, page_size, null, list_s.toArray());
        if (v_list == null) {
            out.println("查询出错" + cf.getMsg());
            return;
        }

    Hashtable ht_row = (Hashtable) v_list.get(0);
    String rowCnt = pub.trimNull((String) ht_row.get("ROWCOUNT"));
    String pageCnt = pub.trimNull((String) ht_row.get("PAGECOUNT"));
    String telSegmentUrl="./list_add-t.jsp";
%>
<div>
    <a class="btn btn-primary radius" onclick="operList();" >
        导出
    </a>
</div>
<form  method="post" id="form1" name="form1" action="export_query.jsp" >
<div class="table-list">
    <table class="table  table-hover table-bg">
        <thead>
        <tr class="text-c">
            <th width="30">
                <input id="checkboxAll" type="checkbox" onclick="checkAll(this);"></input>
            </th>
            <th width="50px">资产名称</th>
            <th width="50px">品牌</th>
            <th width="50px">规格型号</th>
            <th width="50px">价值</th>
            <th width="50px">库存数量</th>
            <th width="50px">剩余</th>
        </tr>
        </thead>
        <tbody>
        <%
            if (v_list != null && v_list.size() > 0) {
                    for (int i = 1; i < v_list.size(); i++) {
                        Hashtable ht = (Hashtable) v_list.get(i);
                        String reg_id = pub.trimNull((String) ht.get("reg_id"));
                        String zc_name = pub.trimNull((String) ht.get("zc_name"));
                        String gg_type = pub.trimNull((String) ht.get("gg_type"));
                        String pinpai = pub.trimNull((String) ht.get("pinpai"));
                        //String counts = pub.trimNull((String) ht.get("counts"));
                        String jiage = pub.trimNull((String) ht.get("jiazhi"));
                        int total=0;
						String counts=getCounts(cf,conn,zc_name,gg_type,pinpai,jiage);
                        String shengyu=getShengYu(cf,conn,zc_name,gg_type,pinpai,jiage);
                        if(!"".equals(counts)&&!"".equals(jiage)){
                            //total=Integer.parseInt(counts)*Integer.parseInt(jiage);
                        }
                        %>
                        <tr <%if(i%2==0){%>id="tr_doub"<%}else{%>id="tr_single"<%}%> class="text-c">
                            <td >
                                <input type="checkbox" class="info" id="reg_ids"
                                       name="reg_ids" value="<%=reg_id%>" />
                            </td>
                            <td><%=zc_name%>
                            </td>
                            <td><%=pinpai%>
                            </td>
                            <td><%=gg_type%>
                            </td>
                            <td><%=jiage%>
                            </td>
                            <td><%=counts%>
                            </td>
                            <td><%=shengyu%>
                            </td>
                        </tr>
                        <%
                    }
            }
        %>
        </tbody>
    </table>
</div>
</form>
<jsp:include page="/common/page_ajax.jsp" >
    <jsp:param name="page_number" value="<%=page_number%>" />
    <jsp:param name="rowCnt" value="<%=rowCnt%>" />
    <jsp:param name="page_size" value="<%=page_size%>" />
</jsp:include>
<script type="text/javascript">
    var checkAll = function (checkbox) {
        $(".info").prop("checked", checkbox.checked);
    }
</script>
<%
    } catch (Exception e) {
        out.println("查询异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>