<%--
  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 boolean isChecked(ConnectionFactory cf,Connection conn,String zc_id,String ly_id){
        Vector list = cf.doQuery(conn,"select zc_id from zc_ly where zc_id=? and ly_id=?",null,new Object[]{zc_id,ly_id});
        if(list!=null&&list.size()>0){
            return true;
        }else{
            return false;
        }
    }
	public String getLyZcId(ConnectionFactory cf,Connection conn,String ly_id){
		String zc_ids="";
        Vector list = cf.doQuery(conn,"select zc_id from zc_ly where ly_id=?",null,new Object[]{ly_id});
        if(list!=null&&list.size()>0){
            for (int i = 0; i < list.size(); i++) {
				Hashtable ht = (Hashtable) list.get(i);
				String zc_id = pub.trimNull((String) ht.get("zc_id"));
				zc_ids="'"+zc_id+"',"+zc_ids;
			}
			return zc_ids.substring(0,zc_ids.length()-1);
        }else{
			return "";
		}
		
    }
%>
<%
    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 ly_id = pub.trimNull(request.getParameter("ly_id"));
    //System.out.println("list_zc_ajax.jsp===ly_id="+ly_id);
    String zc_name_s = pub.trimNull(request.getParameter("zc_name"));
    String zc_gj_type_s = pub.trimNull(request.getParameter("zc_gj_type"));
    String zc_fl_s = pub.trimNull(request.getParameter("zc_fl"));
    String jz_type_s = pub.trimNull(request.getParameter("jz_type"));
    String sb_type_s = pub.trimNull(request.getParameter("sb_type"));
    String b_time = pub.trimNull(request.getParameter("b_time"));
    String e_time = pub.trimNull(request.getParameter("e_time"));
    //if ("".equals(page_size))
    page_size = "100000";
    List list_s = new ArrayList();
    try {
		conn = com.censoft.db.DBUtil.getConnection();
		String ly_zc_id=getLyZcId(cf,conn,ly_id);
        StringBuffer sb = new StringBuffer();
        sb.append("select * from zc_register ");
		if(!"".equals(ly_zc_id)){
			sb.append("where (zc_status='0' or zc_id in ("+ly_zc_id+"))");
			//list_s.add(ly_zc_id);
		}else {
			sb.append("where zc_status='0' ");
		}
        if(!"".equals(zc_name_s)){
            sb.append(" and zc_name like ?");
            list_s.add("%"+zc_name_s+"%");
        }if(!"".equals(zc_gj_type_s)){
            sb.append(" and zc_gj_type = ?");
            list_s.add(zc_gj_type_s);
        }if(!"".equals(zc_fl_s)){
            sb.append(" and zc_fl = ?");
            list_s.add(zc_fl_s);
        }if(!"".equals(jz_type_s)){
            sb.append(" and jz_type = ?");
            list_s.add(jz_type_s);
        }if(!"".equals(sb_type_s)){
            sb.append(" and sb_type = ?");
            list_s.add(sb_type_s);
        }
        sb.append(" order by add_time desc");
        
        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"));
%>
<form action="" method="post" id="form1" name="form1">
    <input type="hidden" name="ly_id" id="ly_id" value="<%=ly_id%>">
    <input type="hidden" name="action" id="action" value="update">
    <div class="cl mb-10  bk-gray " style="height: 50px;">
        <div class="col-sm-3 pd-10" style="width:100%;text-align: left;">
            <input class="btn btn-primary radius btn-green" type="button" onclick="javascript:saveForm();" value="&nbsp;&nbsp;领用&nbsp;&nbsp;">
        </div>
    </div>
<div class="table-list" style="height:300px;">
    <table class="table  table-hover table-bg">
        <thead>
        <tr class="text-c">
            <th width="30px">
                <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>
            <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_id = pub.trimNull((String) ht.get("zc_id"));
                    boolean b=isChecked(cf,conn,zc_id,ly_id);
                    String sb_type = pub.trimNull((String) ht.get("sb_type"));
                    String zc_name = pub.trimNull((String) ht.get("zc_name"));
                    String zc_gj_type = pub.trimNull((String) ht.get("zc_gj_type"));
                    String zc_fl = pub.trimNull((String) ht.get("zc_fl"));
                    String jz_type = pub.trimNull((String) ht.get("jz_type"));
                    String gg_type = pub.trimNull((String) ht.get("gg_type"));
                    String jiazhi = pub.trimNull((String) ht.get("jiazhi"));
                    String cw_date = pub.trimNull((String) ht.get("cw_date"));
        %>
        <tr <%if(i%2==0){%>id="tr_doub"<%}else{%>id="tr_single"<%}%> class="text-c">
            <td >
                <input type="checkbox" class="info" id="zc_ids" name="zc_ids" <%if(b){%>checked="checked"<%}%>
                       name="zc_id" value="<%=zc_id%>" />
            </td>
            <td><%=zc_name%>
            </td>
            <td><%=zc_fl%>
            </td>
            <td><%=zc_gj_type%>
            </td>
            <td><%=jz_type%>
            </td>
            <td><%=jiazhi%>
            </td>
            <td><%=sb_type%>
            </td>
            <td><%=cw_date%>
            </td>
            <td><%=gg_type%>
            </td>
        </tr>
        <%
                }
            }
        %>
        </tbody>
    </table>
</div>
</form>
<script type="text/javascript">
    var checkAll = function (checkbox) {
        $(".info").prop("checked", checkbox.checked);
    }

</script>
<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>
<%
    } catch (Exception e) {
        out.println("查询异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>