//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> </p>
<p> </p>
<p> </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> <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>