JSP实现树型组织架构(3)--管理页面orgManage.jsp

//orgManage.jsp 管理页面,在前一个页面修改一下,加上可以插入和删除的功能

<%@ page contentType="text/html;charset=Big5"%>
<%@ include file="orgConnInclude.jsp"%>

<%
request.setCharacterEncoding("big5");
PreparedStatement ps=null;
ResultSet rs=null;

String  queryCount=" select count(*) "+
                   " from ngb_org "+
                   " where total like ? ORDER BY TOTAL  ";
             
String queryName=" select * "+
                 " from ngb_org "+
                 " where total like ? ORDER BY TOTAL ";
%>

<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=Big5">
    <title>管理組織架構</title>
    <style type="text/css">
<!--
.style1 {color: #FFFFFF}
.style2 {color: #0066FF}
-->
    </style>
  </head>
  <body>
    <form action="orgInsert.jsp">
      <fieldset>
        <legend align="Right">
          <span class="style2">新增組織架構</span>
        </legend>
        <p align="left" class="style2">所 &nbsp;屬 &nbsp;&nbsp;部 &nbsp;門
  <select name="fDep">
  <optgroup label="總經理室">
  <option value="總經理室">總經理室
    <optgroup label="製造處">
  <option value="製造處">製造處
  <option value="製造一部">製造一部
  <option value="製造二部">製造二部
  <option value="製造三部">製造三部
  </optgroup>
  <optgroup label="管理處">
  <option value="管理處">管理處
  <option value="管理部">管理部
  </optgroup>
  <optgroup label="行銷處">
  <option value="行銷處">行銷處
    <optgroup label="財務部">
  <option value="財務部">財務部
    <optgroup label="研發處">
  <option value="研究發">研發處
    <optgroup label="品保部">
  <option value="品保部">品保部
    <optgroup label="稽核室">
  <option value="稽核室">稽核室
  </optgroup>
  
  </select>
  </p>
        <p align="left" class="style2">新增部門名稱
        <input type="text" name="dep"/>
       <input type="submit" id="Submit" value="確認">
        </p>
      </fieldset>
    </form>
  <font color="#0099FF" size=4></font>
  <center>
 
 
 <font color="#0099FF" size=4><center>*****有限公司組織架構圖</center></font>

  <table width="100%"  border="1" cellspacing="1" cellpadding="1">
    <tr>
      <!--th width="7%" rowspan="2" bgcolor="#0099FF" scope="col">&nbsp;&nbsp;&nbsp;</th-->
      <th width="29%" bgcolor="#0099FF" scope="col"><span class="style1">總經理</span></th>
      <th width="19%" bgcolor="#0099FF" scope="col"><span class="style1">總經理直屬</span></th>
      <th width="19%" bgcolor="#0099FF" scope="col"><span class="style1">處級所屬</span></th>
      <th width="19%" bgcolor="#0099FF" scope="col"><span class="style1">部級所屬</span></th>
      <th width="19%" bgcolor="#0099FF" scope="col"><span class="style1">刪除部門</span></th>
    </tr>
    <%
    try{
     int i=1;
     ps=conn.prepareStatement(queryCount);
     ps.setString(1, "A10%");
     rs=ps.executeQuery();
     int result=1;
     while(rs.next())
     { result++;}
     //out.println(result);
    
     for( i=1; i<=result; i++){
     ps=conn.prepareStatement(queryName) ;
     String queryNameCondition="A"+(9+i)+"%";
     //out.println(queryNameCondition);
     ps.setString(1, queryNameCondition);
     ResultSet rs1=ps.executeQuery();
     String qa=null;
     String qaTemp=null;
     String qaTemp1=null;
    
     while( rs1.next()){
      qa=rs1.getString("total");
     qaTemp=qa.substring(3,5);
     qaTemp1=qa.substring(3,6);
   
     %>
    
    <tr bgcolor="#F0F8FF">
      <td width="29%" height="18"><%=rs1.getString("name")%></td>
      <td width="19%" height="18">&nbsp;</td>
      <td width="19%" height="18">&nbsp;</td>
      <td width="19%" height="18">&nbsp;</td>
      <td width="19%" height="18"><a href="orgDelete.jsp?name=<%=rs1.getString("name")%>">刪除部門</a></td>
   
    </tr>
    <%
  
     queryNameCondition=qaTemp1+"%";
     //out.println(queryNameCondition);
     ps.setString(1, queryNameCondition);
     ResultSet rs2=ps.executeQuery();
     int result1=1;
     while(rs2.next())
     { result1++;}
     //out.println(result1);
     for(  i=1; i<=result1; i++){
     ps=conn.prepareStatement(queryName) ;
     ps.setString(1, queryNameCondition);
     ResultSet rs3=ps.executeQuery();
     String qb=null;
     String qbTemp=null;
     String qbTemp1=null;
     while( rs3.next()){
    
     qb=rs3.getString("total");
     qbTemp=qb.substring(3,5);
     qbTemp1=qb.substring(3,6);
      %>
    <tr bgcolor="#F0F8FF">
      <td width="29%" height="18">&nbsp;</td>
      <td width="19%" height="18"><%=rs3.getString("name")%></td>
      <td width="19%" height="18">&nbsp;</td>
      <td width="19%" height="18">&nbsp;</td>
      <td width="19%" height="18"><a href="orgDelete.jsp?name=<%=rs3.getString("name")%>">刪除部門</a></td>
    </tr>
     <%
     ps=conn.prepareStatement(queryCount);
    
      queryNameCondition=qbTemp1+"%";
   
     
    
     //out.println(queryNameCondition);
     ps.setString(1, queryNameCondition);
     ResultSet rs4=ps.executeQuery();
     int result2=1;
     while(rs4.next())
     { result2++;}
     //out.println(result);
     for(  i=1; i<=result2; i++){
     ps=conn.prepareStatement(queryName) ;
     ps.setString(1, queryNameCondition);
     ResultSet rs5=ps.executeQuery();
     String qc=null;
     String qcTemp=null;
     String qcTemp1=null;
     while( rs5.next()){
     qc=rs5.getString("total");
     qcTemp=qc.substring(3,5);
     qcTemp1=qc.substring(3,6);
     %>
       
    <tr bgcolor="#F0F8FF">
      <td width="29%" height="18">&nbsp;</td>
      <td width="19%" height="18">&nbsp;</td>
      <td width="19%" height="18"><%=rs5.getString("name")%></td>
      <td width="19%" height="18">&nbsp;</td>
      <td width="19%" height="18"><a href="orgDelete.jsp?name=<%=rs5.getString("name")%>">刪除部門</a></td>
    </tr>
    <%
    
    /*  ps=conn.prepareStatement(queryC2);   
    ResultSet qd2=ps.executeQuery();
    int cd2=0;
    while(qd2.next())
    {cd2++;}
    out.println(cd2);
    ps=conn.prepareStatement(queryCount);
     if(cd2>0)
     { queryNameCondition="D"+(i+19)+"%";}
     else
     { queryNameCondition="D"+(i+9)+"%";}*/
     ps=conn.prepareStatement(queryCount);
   
       queryNameCondition=qcTemp1+"%";
 
          //out.println(queryNameCondition);
     ps.setString(1, queryNameCondition);
     ResultSet rs6=ps.executeQuery();
     int result3=1;
     while(rs6.next())
     { result3++;}
     //out.println(result3);
     for(  i=1; i<=result3; i++){
     ps=conn.prepareStatement(queryName) ;
     ps.setString(1, queryNameCondition);
     ResultSet rs7=ps.executeQuery();
     while( rs7.next()){
    %>
    <tr bgcolor="#F0F8FF">
      <td width="29%" height="18">&nbsp;</td>
      <td width="19%" height="18">&nbsp;</td>
      <td width="19%" height="18">&nbsp;</td>
      <td width="19%" height="18"><%=rs7.getString("name")%></td>
      <td width="19%" height="18"><a href="orgDelete.jsp?name=<%=rs7.getString("name")%>">刪除部門</a></td>
    </tr>
     <%
     ps=conn.prepareStatement(queryCount);
     queryNameCondition="E"+(i+9)+"%";
     //out.println(queryNameCondition);
     ps.setString(1, queryNameCondition);
     ResultSet rs8=ps.executeQuery();
     int result4=1;
     while(rs8.next())
     { result4++;}
     //out.println(result3);
     for(  i=1; i<=result4; i++){
     ps=conn.prepareStatement(queryName) ;
     ps.setString(1, queryNameCondition);
     ResultSet rs9=ps.executeQuery();
     while(rs9.next()){
     rs9.getString("name");    %>
    <%}}%>
    <%}}%>
   <% }}%>
   <% }}%>
      <%}}%>
       
  </table>
  </body>
  <%}
  catch(SQLException se1)
  {se1.printStackTrace();}
  finally{conn.close();}%>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package com.svse.struts.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.svse.struts.entity.PartBean; import com.svse.struts.util.DBConnection; public class PartDao { private Connection conn = null; private PreparedStatement pre = null; private ResultSet rs = null; private DBConnection b = new DBConnection(); /** ******************查询所有部门************************* */ public List getx() { conn = b.getConnection(); List array = new ArrayList(); try { String sql = "select sjid,zjid,zjmc from t_part"; pre = conn.prepareStatement(sql); rs = pre.executeQuery(); while (rs.next()) { int sjid = rs.getInt("sjid"); int zjid = rs.getInt("zjid"); String zjmc = rs.getString("zjmc"); PartBean vo = new PartBean(); vo.setSjid(sjid); vo.setZjid(zjid); vo.setZjmc(zjmc); array.add(vo); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (pre != null) { pre.close(); } if (conn != null) { conn.close(); } } catch (SQLException e1) { e1.printStackTrace(); } } return array; } /** ********************增加部门********************** */ public void addpart(PartBean vo) { conn = b.getConnection(); try { int count = 0; String sql = "select max(zjid) as t from t_part"; String sql1 = "insert into t_part(sjid,zjid,zjmc,zjjs) values(?,?,?,?)"; pre = conn.prepareStatement(sql); rs = pre.executeQuery(); while (rs.next()) { count = rs.getInt("t"); } count = count + 1; pre = conn.prepareStatement(sql1); pre.setInt(1, vo.getSjid()); pre.setInt(2, count); pre.setString(3, vo.getZjmc()); pre.setString(4, vo.getZjjs()); pre.executeUpdate(); pre.close(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (pre != null) { pre.close(); } if (conn != null) { conn.close(); } } catch (SQLException e1) { e1.printStackTrace(); } } } /********************查询单个部门***********************/ public PartBean getdep(int zjid) { PartBean bean=new PartBean(); conn = b.getConnection(); try { String sql="select sjid,zjid,zjmc,zjjs from t_part where zjid=?"; pre=conn.prepareStatement(sql); pre.setInt(1,zjid); rs=pre.executeQuery(); while(rs.next()) { bean.setSjid(rs.getInt("sjid")); bean.setZjid(rs.getInt("zjid")); bean.setZjmc(rs.getString("zjmc")); String tx=null; tx=rs.getString("zjjs"); if(tx==null) { String tt="暂无"; bean.setZjjs(tt); } else { bean.setZjjs(tx); } } } catch(SQLException e) { e.printStackTrace(); } finally { try { if(pre!=null) { pre.close(); } if(conn!=null) { conn.close(); } } catch(SQLException e1) { e1.printStackTrace(); } } return bean; } /**************************修改部门***********************/ public void up(PartBean bean) { conn = b.getConnection(); try { String sql="update t_part set zjmc=?,zjjs=?,sjid=? where zjid=?"; pre=conn.prepareStatement(sql); pre.setString(1,bean.getZjmc()); pre.setString(2,bean.getZjjs()); pre.setInt(3,bean.getSjid()); pre.setInt(4,bean.getZjid()); pre.executeUpdate(); } catch(SQLException e) { e.printStackTrace(); } finally { try { if(pre!=null) { pre.close(); } if(conn!=null) { conn.close(); } } catch(SQLException e1) { e1.printStackTrace(); } } } /********************删除部门**********************/ public int del(int sjid,int zjid) { int s=0; conn = b.getConnection(); String sql="delete from t_part where sjid=? and zjid=?"; try { int count=0;//统计了结点 String sqlCount="select count(*) as t from t_part where sjid=?"; pre=conn.prepareStatement(sqlCount); pre.setInt(1,zjid); rs=pre.executeQuery(); while(rs.next()) { count=rs.getInt("t"); } if(count>0) { s=0;//下面有了结点,不能删除! } else { pre=conn.prepareStatement(sql); pre.setInt(1,sjid); pre.setInt(2,zjid); pre.executeUpdate(); s=1; } } catch(SQLException e) { e.printStackTrace(); } finally { try { if(pre!=null) { pre.close(); } if(conn!=null) { conn.close(); } } catch(SQLException e1) { e1.printStackTrace(); } } return s; } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值