<%@ 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" %>
<%!
    public  static  String getDays(ConnectionFactory cf,Connection conn,String h_id){
        Vector list = cf.doQuery(conn,"select id,day from zb_holiday where h_id=? order by id asc",null,new Object[]{h_id});
        String day_list="";
        if(list!=null && list.size()>0){
            for(int i=0;i<list.size();i++){
                Hashtable ht = (Hashtable)list.get(i);
                String day = (String)ht.get("day");
                day_list=day_list+day+"</br>";
            }
        }
        return day_list;
    }
%>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    String login_id = (String) session.getAttribute("session_login_id");
    if ("".equals(login_id)) {
        System.out.println("当前没有用户信息");
    }
    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"));
    if ("".equals(page_size)) page_size = "10";
    StringBuffer sql = new StringBuffer();
    List list = new ArrayList();
    sql.append("select h_id,name,h_day from zb_holiday group by name,h_id order by h_day asc ");
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        v_list = cf.doPageQueryWithCount(conn, sql.toString(), page_number, page_size, null, list.toArray());
        if (v_list == null) {
            out.println("查询用户出错");
            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"));
%>
<div >
    <a class="btn btn-primary " onclick="addUser();">
        新建</a>
</div>
<table class="table table-border table-bordered table-hover table-bg table-sort">
    <thead>
    <tr class="text-c">
        <th width="30">序号</th>
        <th width="100">假日名称</th>
        <th width="120">日期</th>
        <th width="140">操作</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 h_id = pub.trimNull((String) ht.get("h_id"));
                String name = pub.trimNull((String) ht.get("name"));
                String getDay=getDays(cf,conn,h_id);
                String day = pub.trimNull((String) ht.get("h_day"));
                String edit_url="./editUser-t.jsp?action=update&id="+h_id;
    %>
    <tr <%if(i%2==0){%>id="tr_doub"<%}else{%>id="tr_single"<%}%> class="text-c">
        <td><%=i%>
        </td>
        <td><%=name%>
        </td>
        <td><%=day%>
        </td>
        <td>
            <a  onclick="viewDeptOrUserInfo('假日信息','<%=edit_url%>','1000','500');" style="padding:4px 0px;font-size:12px;">
                编辑</a>
            <a onclick="deleteUser('<%=h_id%>');" style="padding:4px 0px;font-size:12px;">
                删除</a>
        </td>
    </tr>
    <%
            }
        }
    %>
    </tbody>
</table>
<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">
    function deleteUser(id){
      layer.confirm('确认要删除吗？', function (index) {
			$.ajax({
				type: "POST",
				url: "./action.jsp?id="+id+"&action=delete",
				success: function (msg) {
					if (msg.indexOf("success") >= 0) {
						layer.msg('操作成功!', {icon: 1, time: 1000},
							function () {
								searchModel();
							});
					} else {
						layer.msg('操作失败', {
							icon: 5,
							time: 2000 //2秒关闭（如果不配置，默认是3秒）
						}, function () {
							// console.log("********************8")
						});
					}
				}
			});
		})
    }
</script>
<%
    } catch (Exception e) {
        out.println("查询用户信息异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>