/** * 递归读取分销商树 * * 第四步: 采用div生成树形结构 * @param conn * @param id * @param level 控制层次 */ private void readClientTree(Connection conn, int id, int level) throws SQLException { String sql = "select * from t_client where pid=?"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); rs = pstmt.executeQuery(); while (rs.next()) { sbTreeHTML.append("<div>"); sbTreeHTML.append(" "); for (int i=0; i<level; i++) { sbTreeHTML.append("<img src="../images/white.gif">"); sbTreeHTML.append(" "); } //if ("N".equals(rs.getString("is_leaf"))) { if (Constants.NO.equals(rs.getString("is_leaf"))) { sbTreeHTML.append("<img alt="展开" style="cursor:hand;" onClick="display('" + rs.getInt("id") + "');" id="img" + rs.getInt("id") + "" src="../images/plus.gif">"); sbTreeHTML.append(" "); sbTreeHTML.append("<img id="im" + rs.getInt("id") + "" src="../images/closedfold.gif">"); sbTreeHTML.append(" "); sbTreeHTML.append("<a href="client_node_crud.jsp?id=" + rs.getInt("id") + "" target="clientDispAreaFrame">" + rs.getString("name") + "</a>"); sbTreeHTML.append(" "); sbTreeHTML.append("<div style="display:none;" id="div" + rs.getInt("id") + "">"); sbTreeHTML.append(" "); readClientTree(conn, rs.getInt("id"), level + 1); sbTreeHTML.append("</div>"); sbTreeHTML.append(" "); }else { sbTreeHTML.append("<img src="../images/minus.gif">"); sbTreeHTML.append(" "); sbTreeHTML.append("<img src="../images/openfold.gif">"); sbTreeHTML.append(" "); //if ("Y1".equals(rs.getString("is_client"))) { if (Constants.YES.equals(rs.getString("is_client"))) { sbTreeHTML.append("<a href="client_crud.jsp?id=" + rs.getInt("id") + "" target="clientDispAreaFrame">" + rs.getString("name") + "</a>"); }else { sbTreeHTML.append("<a href="client_node_crud.jsp?id=" + rs.getInt("id") + "" target="clientDispAreaFrame">" + rs.getString("name") + "</a>"); } sbTreeHTML.append(" "); } sbTreeHTML.append("</div>"); sbTreeHTML.append(" "); } }finally { DbUtil.close(rs); DbUtil.close(pstmt); } }