站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题JSP实现树型组织架构(4)--插入页面orgInsert.jsp

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

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

<textarea readonly style="border:none;font-family:Courier New;line-height:150%;width:760px;overflow-y:visible">//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+"
");
String tempF=null;
PreparedStatement ps=conn.prepareStatement(queryF);
ResultSet rs=ps.executeQuery();
while(rs.next())
{ tempF=rs.getString("total");}
//out.println(tempF+"
");
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(sameMaxsameMax=sameMaxTemp;
//out.println(sameMax+"//"+"
");

}

//如果值小于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+"
");
int result =ps.executeUpdate();
if(result>0)
{

%>

<head>

新增部門