JSP实现树型组织架构(4)--插入页面orgInsert.jsp

发表于:2007-07-04来源:作者:点击数: 标签:
//orgInsert.jsp插入页面 %@ include file=connectionDB.jsp% % request.setCharacterEncoding(big5); String fDep=request.getParameter(fDep); String dep=request.getParameter(dep); //out.println(fDep); //out.println(dep); boolean autoCommit=conn.g
//orgInsert.jsp插入页面


<%@ include file="connectionDB.jsp"%>
<%
request.setCharacterEncoding("big5");
String fDep=request.getParameter("fDep");
String dep=request.getParameter("dep");
//out.println(fDep);
//out.println(dep);
boolean autoCommit=conn.getAutoCommit();
try{
conn.setAutoCommit(false);
String queryF=" select total " +
" from ngb_org "+
" where name=''"+fDep+"'' ORDER BY TOTAL ";
//out.println(queryF+"<br>");
String tempF=null;
PreparedStatement ps=conn.prepareStatement(queryF);
ResultSet rs=ps.executeQuery();
while(rs.next())
{ tempF=rs.getString("total");}
//out.println(tempF+"<br>");
char tempFa=tempF.charAt(0);
char tempFb=tempF.charAt(1);
char tempFc=tempF.charAt(2);
char tempFd=tempF.charAt(3);
char tempFe=tempF.charAt(4);
char tempFf=tempF.charAt(5);
int tempFg=Integer.parseInt(tempF.substring(4,6));
String tempC=null;
String tempCC=null;
if(tempFd==''A'')
{tempC="%B%"; tempCC="B";}
else if(tempFd==''B'')
{tempC="%C%"; tempCC="C";}
else if (tempFd==''C'')
{tempC="%D%"; tempCC="D";}
else if (tempFd==''D'')
{tempC="%E%"; tempCC="E";}


String queryColumn=" select count(*) "+
" from ngb_org "+
" where total like ''"+tempC+"'' ";

String queryDefference=" select total "+
" from ngb_org "+
" where total like ? ";

int totalNumber=0;

//統計同層的部門最大值
ps=conn.prepareStatement(queryColumn);
ResultSet rs1=ps.executeQuery();

while(rs1.next())
{totalNumber+=rs1.getInt(1);}

String tempFDD=Character.toString(tempFd);
String totalNewTemp=tempFDD+tempFg+tempCC+(totalNumber+1);
String totalNew=null;
int sameMax=1;
String totalSame=tempFDD+"%"+tempCC+"%";


//查詢本層是否有相同的total值
ps=conn.prepareStatement(queryDefference);
ps.setString(1, totalSame);
ResultSet rsd=ps.executeQuery();
//boolean same=false;
while(rsd.next())
{

//找出同层最大的值
String same1=rsd.getString("total");
String same1Temp1=same1.substring(4,6);
int sameMaxTemp=Integer.parseInt(same1Temp1);
//out.println(sameMaxTemp+" & ");
if(sameMax<sameMaxTemp)
sameMax=sameMaxTemp;
//out.println(sameMax+"//"+"<br>");

}

//如果值小于10,把它赋值为10
if(sameMax<10)
{sameMax+=8;}

totalNew=tempFDD+tempFg+tempCC+(sameMax+1);
//out.println(totalNew);

String insertDep= " insert into ngb_org(id, p_layer, p_id, c_layer, c_id, total, name, sn, create_by, create_date, update_by,update_date) "+
" values(ngb_org_seq.nextval, ''"+tempFd+"'', "+tempFg+", ''"+tempCC+"'',"+(sameMax+1)+" , ''"+totalNew+"'', ''"+dep+"'', NULL, NULL, NULL, NULL, NULL) ";
ps=conn.prepareStatement(insertDep);
//out.println(insertDep+"<br>");
int result =ps.executeUpdate();
if(result>0)
{


%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Big5">
<title>新增部門</title>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
.style2 {color: #000066}
-->
</style>
</head>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<table width="38%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="17" bgcolor="#0099FF" scope="col"><div align="center" class="style1">信息添加成功</div></td>
</tr>

<tr>
<td height="160" colspan="2" bgcolor="#E6F0FF" scope="row"><div align="center" class="style2">部門: <%=dep%> 添加成功!</div> <br> <div align="center" class="style2"><a href="orgManage.jsp">繼續添加</a> &nbsp; &nbsp;&nbsp;<a href="orgView.jsp">返回組織架構</a></div></td>
</tr>
</table>


</body>
<%

}
conn.commit();

}
catch (SQLException se1)
{se1.printStackTrace();
conn.rollback();
}
finally{
conn.setAutoCommit(autoCommit);
conn.close();
}
%>


</html>



原文转自:http://www.ltesting.net