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