给大家看一个反面的教材

Posted on 2005-11-30 09:48 hj12 阅读(198) 评论(0)  编辑  收藏 所属分类: 工作

<%
PreparedStatement pstmt = null;
//拼出查询表名称 版本信息
 String version=(String)session.getAttribute("version");//版本号
 String tabitem="indicatoritem"+"_"+version;
 String tabtree="indicatortree"+"_"+version;
 String tabatt="attributelist"+"_"+version;
 String tabval="indicatorvaluelist"+"_"+version;
//节点不需要预警,存在数据源,只显示列表
 PublicTools pt = new PublicTools();
 String selectNodeID=request.getParameter("selectNode");  //选中节点的id即指标指
 //System.out.println(selectNodeID);
 
 String xmbm = (String)session.getAttribute("xmbm");

 String hybm = (String)session.getAttribute("hybm");
 String stitle="";
 String scontent="";
 String table_name="";
 int selectrow=0;
 int ics=0;
 int jl=0;
 xmbm=xmbm==null?"":xmbm;
 hybm=hybm==null?"":hybm;
 String sSelectRow=request.getParameter("index");        //从sigledata.jsp页面返回时,被高亮显示的行号
 sSelectRow=sSelectRow==null?"":sSelectRow;
 if(!sSelectRow.equals(""))
 {
     selectrow= Integer.parseInt(sSelectRow);

 }
     //当前查看的指标

 selectNodeID=selectNodeID==null?"":selectNodeID;
 if(!(selectNodeID.equals("")))
 {
 session.setAttribute("ID",selectNodeID);
 }


 
//flag是1标志是selectdate.jsp发的请求
// String sflag=request.getParameter("flag");
// sflag=sflag==null?"":sflag;


//cs是标志查询那次记录
 String cs=request.getParameter("cs");
 cs=cs==null?"":cs;


//时间变为全局变量
// String sTime = request.getParameter("time");         //取从selectdate.jsp页面返回的值。用时间查询。
// sTime=sTime==null?"":sTime;
 String startTime = request.getParameter("starttime");         //取从selectdate.jsp页面返回的值。用时间查询。
 String endTime = request.getParameter("endtime"); 
  String type=request.getParameter("type");
 startTime=startTime==null?"":startTime;
 endTime=endTime==null?"":endTime;
  type=type==null?"":type;
 //startTime="2004-01";
 //endTime="2005-12";

 


 if(type.equals("D"))
 {
 session.setAttribute("bz","time");
 session.setAttribute("starttime",startTime);
 session.setAttribute("endtime",endTime);
 }else if(type.equals("T"))
 {
 session.setAttribute("bz","cs");
 session.setAttribute("cs",cs);
 }
 
 if(type.equals(""))
 {
  String bz=(String)session.getAttribute("bz");
  if(bz.equals("time"))
  {
 startTime=(String)session.getAttribute("starttime");
 endTime=(String)session.getAttribute("endtime");
 startTime=startTime==null?"":startTime;
 endTime=endTime==null?"":endTime; 
 
  }else if(bz.equals("cs"))
  {
  cs=(String)session.getAttribute("cs");
  cs=cs==null?"":cs;
  }
  }
 

 


 //目的是在选择
 if((selectNodeID.equals("")&&(!startTime.equals("")))|(selectNodeID.equals("")&&(!type.equals(""))))
 {
  selectNodeID=(String)session.getAttribute("ID");
  selectNodeID=selectNodeID==null?"":selectNodeID;
  xmbm=(String)session.getAttribute("xmbm");
  xmbm=xmbm==null?"":xmbm;
 }
                     //查询指标对应的表名字,注意射定行业值 
 String aSQL="select tablename A from "+tabitem+" where HYBM='"+hybm+"' and id='"+selectNodeID+"'";
 String aSqlCount="select count(*) A  from "+tabitem+" where HYBM='"+hybm+"' and id='"+selectNodeID+"'";
 int tableCount=queryatt.QueryCount(aSqlCount); 

//取 INDICATORCODE的值 和INDICATORNAME 的值

 ProjIndicatorItemControl pit = new ProjIndicatorItemControl();
 ProjIndicatorItemModel pim = (ProjIndicatorItemModel)pit.getModel(selectNodeID,version);
 String code = pim.getINDICATORCODE();
 String indicatorname = pim.getINDICATORNAME();


 if(!selectNodeID.equals(""))
 {
 if(tableCount>0)
 {
  table_name= queryatt.getStrSigle(aSQL);
 table_name=table_name==null?"":table_name;

 if(!table_name.equals("")){
  
   
  
  
 //取显示的字段名
 String sSql="select attributeid,attributename,attributevaluetype,attributedescription,coltype,collen,SHOWWIDE from "+tabatt+" where table_name='"+table_name.trim()+"' and showseq>0 order by showseq";

 queryatt.setSql(sSql);
 HashMap aMap= queryatt.getColumnData();
 String[] attributeid=(String[])aMap.get("ATTRIBUTEID");
 


//拼出查询指标SQL 
 //System.out.println(table_name);
 String executeSql="";
 
 if(!cs.equals(""))                  //首先判断时间
 {
 ics=Integer.parseInt(cs);

 executeSql="select * from "+ table_name +" where cspc="+ics+" and xmbm='"+xmbm+"'";

 }else {
 
 if(startTime.equals(""))
 {
 
 executeSql="select * from "+ table_name  +" where XMBM='"+xmbm+"'";


 }
 else
 {
 
  //判断传过来时间的长度
  if(startTime.trim().length()==4)
  {
  executeSql="select * from "+ table_name +" where to_char(fssj,'yyyy') between '"+startTime+"' and '"+endTime+"' and xmbm='"+xmbm+"'";
  }else if(startTime.trim().length()==7)
  {
  
  executeSql="select * from "+ table_name +" where to_char(fssj,'yyyy-mm') between '"+startTime+"' and '"+endTime+"' and xmbm='"+xmbm+"'";

  }
  

 }
 }
 //取有多少条显示的记录


 executeSql +=" order by fssj desc";

 //System.out.println(">>>>>>>>>>>>>>>>>"+executeSql);
 String executeCount=CenterUtil.replaceAll(executeSql,"*","count(*) A ",0);
 jl=queryatt.QueryCount(executeCount);


 
 String[] attributename=(String[])aMap.get("ATTRIBUTENAME");
 String[] collen=(String[])aMap.get("SHOWWIDE");
 String[] coltype=(String[])aMap.get("COLTYPE");
 

//拼表头


 stitle=""+
      "<tr class='tableButton'>";

  for(int i=0;i<collen.length;i++)
  {
  if(!("file".equals(coltype[i].trim())))                              //拼字段类型不为file的表头
  {
  stitle=stitle+"  <td  width='"+collen[i]+"px' height=22 >"+attributename[i]+"</td>";
  }
  }
  for(int i=0;i<coltype.length;i++)          ////拼字段类型为file的表头 
  {
     if("file".equals(coltype[i].trim()))
     {
    stitle+="<td align=middle width=10% height=22>"+attributename[i]+"</td>"; 
     }
  }
  
  stitle+="<td align=middle width=10% height=22>详细内容</td>";
    stitle=stitle+  " </tr>";
    
    queryatt.setSql(executeSql);
    HashMap dataMap=queryatt.getColumnData();
 
  String[] tablename=(String[])aMap.get("ATTRIBUTEID");
  
  String[] tabledata=null;
  if(tablename.length> 0)
  {
   
   tabledata=(String[])dataMap.get(tablename[0].toUpperCase());
   
  }
 scontent="";
 String[] INDICATORVALUE=null;

 for(int j=0; j< tabledata.length;j++)
 {
  scontent=scontent+" <TR  class='tableContent' onmouseover='this.style.cursor=\"default\"'   id='tr"+(j+1)+"' onclick=\"selectRow('tr"+(j+1)+"','"+(j+1)+"')\"   id='tr"+(j+1)+"'>";

  for(int k=0;k<tablename.length;k++)
  {
  tabledata=(String[])dataMap.get(tablename[k].toUpperCase());
  if(!("file".equals(coltype[k])))                      //拼字段类型不为file的行记录
  {
  if(coltype[k].equals("date"))
  {
  if(!tabledata[j].equals("")){
         scontent=scontent+"  <td height=22>"+tabledata[j].substring(0,10) +"</td> ";
         }
         }else{
         scontent=scontent+"  <td height=22>"+pt.limitLength(tabledata[j],15) +"</td> ";
         }
         }
         }
      for(int i=0;i<coltype.length;i++)                //拼字段类型为file的行记录
   {
     if("file".equals(coltype[i]))
     {
        scontent+="<td align=middle height=22>";
        scontent+="<input class='buttonFour' type='button' value='浏览' alt='点击下载'";
        scontent+="onclick=\"printData('tr"+(j+1)+"','"+(j+1)+"','"+tablename[i]+"')\"   >";
     scontent+="</td>"; 
     }
     }
      scontent+="<td align=middle height=22>";
        scontent+="<input class='buttonFour' type='button' value='查看'";
        scontent+="onclick=\"changeRow('tr"+(j+1)+"','"+(j+1)+"')\"  >";
     scontent+="</td>"; 
       scontent=scontent + "</tr>"; 
 
 }
 
 
 //取查询表的主键 
 String primarySql="select attributeid,attributename,attributevaluetype,attributedescription,coltype,collen,SHOWWIDE from "+tabatt+" where table_name='"+table_name.trim()+"' and PRIMARYkey='1' order by colsort";
 String primarySqlCount="select count(*) from "+tabatt+" where table_name='"+table_name.trim()+"' and PRIMARYkey='1' ";

 int count=queryatt.QueryCount(primarySqlCount);
 ArrayList saveArraylist=new ArrayList();
 if(count>0)
 {
 String priwhere="select * from  "+ table_name +" where ";
 queryatt.setSql(primarySql);
 
 HashMap priMap= queryatt.getColumnData();
 String[] priattributeid=(String[])priMap.get("ATTRIBUTEID");
 String[] pricoltype=(String[])priMap.get("COLTYPE");

 //savearraylist 1、存主键个数
 saveArraylist.add(new Integer(count));
 
 int[] pritype=new int[count];
 for(int i=0;i<count;i++)
 {
  if(pricoltype[i].equals("vc"))
  {
  pritype[i]=Types.VARCHAR;
  }else if(pricoltype[i].equals("int"))
  {
  pritype[i]=Types.INTEGER;
  }else if(pricoltype[i].equals("numeric"))
  {
  pritype[i]=Types.NUMERIC;
  }else if(pricoltype[i].equals("date"))
  {
  pritype[i]=Types.TIMESTAMP;
  }else if(pricoltype[i].equals("file"))
  {
  pritype[i]=Types.LONGVARBINARY;
  }
  //savearraylist 2、存数据类型
  saveArraylist.add(new Integer(pritype[i]));
  if(i>0)
  {
  priwhere +=" and ";
  }
  priwhere+=" "+priattributeid[i]+" = ? ";
  
  
  
 }
 //savearraylist 3、存条件
 //System.out.println(priwhere);
 saveArraylist.add(new String(priwhere));
 
 //savearraylist 4、存条件主键的对应的值
  Connection con= null;
   ResultSet rs=null;
   try{
 con=DBUtil.getConnection();
 pstmt=con.prepareStatement(executeSql);
 rs=pstmt.executeQuery();
 for(int i =1;rs.next();i++)
 {
 for(int j=0;j<priattributeid.length;j++)
 {
 saveArraylist.add(rs.getObject(priattributeid[j]));
 }
 }
 }catch(Exception e)
 {
 
 }
 finally{
try {
 rs.close();
 pstmt.close();
  } catch (Exception ex1) { }
 DBUtil.returnConnection(con);
 }
 }
  session.setAttribute("privalues",saveArraylist);
 
 
 }
 }
 }
%>

昨天花了一天的时间优化这个代码~哎!!苦呀~~


只有注册用户登录后才能发表评论。


网站导航: