分页组件

package com.tzsw.pub;

import java.sql.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import java.rmi.*;
import org.apache.poi.hssf.usermodel.*;
import java.util.Date;
import com.tzsw.db.DbDataSource;
import com.tzsw.pub.FetchItem;
/**
通用翻页组件(Oracle 版本)
设计人员:
设计时间:2002/4/30
----修改-----
修改时间:2002/5/30
修改内容:增加 QueryTitle 属性
          增加 Linktarget  属性

修改时间:2002/6/2
修改内容:增加CellSpacing/Cellpadding/TbBorder/linkparas属性

修改时间:2002/8/29 (界面修改)
修改内容:增加 linktargetiframe 属性,用于在iframe之间传递页面
         linktarget和linktargetiframe两个属性不能在同一列上设置。

修改时间:2002/9/19
修改内容:删除从数据库读取设置的选项,增加列表头排序功能
          增加空数据时不显示NULL的功能
修改时间:2003/2/25
修改内容:生成表格可设置表宽,可传递常数参数,对fetchitem和fetchpost等的数据转换

修改时间2003/12/05
修改内容:分页组件基础类
*/
public class pager
{
   String docroot="";
   String imgpath="";

   String excelpath="c://";
   String excelname="tempexcel";
   String hasexcel="NO";

   Connection conn;
   Statement st;
   ResultSet rst;

  //排序
  public static String sortOrder=" desc";
  //当前页
  private static int ppno=1;
  //页面参数
  private int TotalPage,CurrentPage,PageSize,reccount;
  //查询语句
  private String SQL="",CountSQL="",OrderBy="",HeadBGColor="",HeadFontColor="";
  //表格属性
  private String TbClass="",TbBGColor="",PageLink="",QueryTitle="",TBWidth="95%",Tbalign="center",Tbid="tableid";
  //新开窗口属性
  private String Winproperty="height=480,width=640,menubar=no,scrollbars=yes,status=no,titlebar=no,resizable=no";
  //表格属性
  private int CellPadding=2,CellSpacing=0,TbBorder=1;
  //标签,列,连接,列宽存储空间
  private Hashtable lable,cols,links,colwidths;
  //连接参数存储空间
  private Hashtable linkparas,linkconstparas;
  //连接存储空间
  private Hashtable linktarget,linktargetiframe;
  //转换函数存储空间
  private Hashtable resfunc;

/**
构造函数:
设置变量
初始化所有的Hashtable
*/

  public pager(int pSize,String SQL,String CountSQL)
  {

    if(imgpath.equals(""))imgpath="/emhr/images";
    this.TotalPage=0;
    this.CurrentPage=0;
    this.PageSize=pSize;
    this.SQL=SQL;
    this.CountSQL=CountSQL;

    this.lable=new Hashtable(30);
    this.cols=new Hashtable(30);
    this.links=new Hashtable(10);
    this.colwidths=new Hashtable(30);
    this.linktarget=new Hashtable(10);
    this.linktargetiframe=new Hashtable(10);
    this.linkparas=new Hashtable(30);
    this.linkconstparas=new Hashtable(10);
    this.resfunc=new Hashtable(5);

    try{
      conn=DbDataSource.getDataSource().getConnection();
    }catch(Exception e)
    {
       try{if(conn!=null)conn.close();}catch(Exception ex){}
       System.out.println("[com.zjtz.Pager:Pager Bean]Init Error Found:Cant't Get Database Connection.Nested Error is:"+e.toString());
    }
    try{
      st=conn.createStatement();
      rst=st.executeQuery(CountSQL);
      rst.next();
      this.reccount=rst.getInt(1);
      if(this.reccount==0){
        this.PageSize=0;
        this.TotalPage=0;
      }else{
        if(this.PageSize==0)
          {
          this.PageSize=this.reccount;
          this.TotalPage=1;
          }
        else
          this.TotalPage=(this.reccount%this.PageSize==0)?this.reccount/this.PageSize:this.reccount/this.PageSize+1;
      }
      this.CurrentPage=1;
      rst.close();
      st.close();
      conn.close();
    }catch(Exception e)
    {
     try{if(rst!=null)rst.close();
     if(st!=null)st.close();
     if(conn!=null)conn.close();}catch(Exception ex){}
     System.out.println("[com.zjtz.Pager:Pager Bean]GetData Error Found:Please Check Your SqlCount Prop.Nested Error Is:"+e.toString());
    }
  }
  /**
   * 设置应用根
   */
  public void setDocRoot(String DocRoot)
  {
    this.docroot="/"+DocRoot;
  }
/**
 * 设置图片路径
 */
  public void setImgpath(String Imgpath)
  {
    this.imgpath=this.docroot+"/"+Imgpath;
  }
  /**
   * 设置排序
   */
  public void setOrderBy(String OrderBy)
  {
   this.OrderBy=OrderBy;

  }
/**
   * 设置excel路径
   */
  public void setExcelPath(String sexcelpath)
  {
    this.excelpath=sexcelpath;
  }

/**
   * 设置excel名称
   */
  public void setExcelName(String sexcelname)
  {
    this.excelname=sexcelname;
  }
/**
   * 设置是否生成excel
   */
  public void setHasExcel(String shasexcel)
  {
    this.hasexcel=shasexcel;
  }

  public void setHeadFontColor(String HeadFontColor)
  {
   this.HeadFontColor=HeadFontColor;

  }

  public void setTbClass(String TbClass)
  {
   this.TbClass=TbClass;

  }
  public void setTbBGColor(String TbBGColor)
  {
   this.TbBGColor=TbBGColor;

  }
  public void setAlign(String tbalign)
  {
   this.Tbalign=tbalign;
  }

  public void setTableid(String tbid)
  {
   this.Tbid=tbid;
  }


  /**
   * 设置表格宽度
   */
  public void setTBWidth(String sTBWidth)
  {
   this.TBWidth=sTBWidth;
  }

  public void setWinproperty(String sWinproperty)
  {
   this.Winproperty=sWinproperty;
  }

 

  /**
   * 设置连接信息
   */
  public void setPageLink(String PageLink)
  {
   this.PageLink=PageLink;

  }
/**
 * 设置表格头信息
 */
  public void setQueryTitle(String QueryTitle)
  {
   this.QueryTitle=QueryTitle;

  }

  public void setCellPadding(int CellPadding)
  {
   this.CellPadding=CellPadding;

  }

  public void setCellSpacing(int CellSpacing)
  {
   this.CellSpacing=CellSpacing;

  }

  public void setTbBorder(int TbBorder)
  {
   this.TbBorder=TbBorder;

  }
/**
 * 设置列标签信息
 */
  public void setlable(String item,String Content)
  {
   this.lable.put(item,Content);

  }
/**
 * 设置列信息
 */
  public void setcols(String item,String Content)
  {
   this.cols.put(item,Content);

  }
/**
 * 设置连接信息
 */
  public void setlinks(String item,String Content)
  {
   this.links.put(item,Content);

  }
/**
 * 设置列宽
 */
  public void setcolwidths(String item,String Content)
  {
   this.colwidths.put(item,Content);

  }
/**
 * 设置连接参数
 */
  public void setlinkparas(String item,String Content)
  {
   this.linkparas.put(item,Content);

  }
/**
 * 设置连接常参
 */
  public void setlinkconstparas(String item,String Content)
  {
   this.linkconstparas.put(item,Content);

  }
/**
 * 设置连接对象
 */
  public void setlinktarget(String item,String Content)
  {
   this.linktarget.put(item,Content);

  }
/**
 * 设置连接对象
 */
  public void setlinktargetiframe(String item,String Content)
  {
   this.linktargetiframe.put(item,Content);

  }
/**
 * 设置连接函数
 */
  public void setresfunc(String item,String Content)
  {
   this.resfunc.put(item,Content);
  }
/**
 * 取当前页表格信息
 */
  public String getPage(int pnum)
  {

   if(pnum==this.ppno)
   {

      if(this.sortOrder==" desc")
       {
         this.sortOrder=" asc";
         this.imgpath=this.imgpath+"/up.gif";
       }
      else
       {
        this.sortOrder=" desc";
        this.imgpath=this.imgpath+"/down.gif";
       }

   }
   else
   {
      if(this.sortOrder==" desc")
       {

         this.imgpath=this.imgpath+"/down.gif";
       }
      else
       {

        this.imgpath=this.imgpath+"/up.gif";
       }

   }

   this.ppno=pnum;
   StringBuffer result=new StringBuffer(1000);
   try{
     conn=DbDataSource.getDataSource().getConnection();
     st=conn.createStatement();
     String www="select * from (select tb.*,rownum as numrow from ("+this.SQL+" order by "+this.OrderBy+" "+this.sortOrder+") tb) where numrow>"+(pnum-1)*this.PageSize+" and numrow <="+pnum*this.PageSize;
     System.out.println("-----------www-------------");
     System.out.println("---------www----"+www);
     System.out.println("-----------www-------------");

     rst=st.executeQuery("select * from (select tb.*,rownum as numrow from ("+this.SQL+" order by "+this.OrderBy+" "+this.sortOrder+") tb) where numrow>"+(pnum-1)*this.PageSize+" and numrow <="+pnum*this.PageSize);
     result.append("<table bordercolorlight=#000000 bordercolordark=#FFFFFF align="+Tbalign+" id="+this.Tbid+" class="+this.TbClass+" bgcolor="+this.TbBGColor+" cellspacing="+this.CellSpacing+" cellpadding="+this.CellPadding+" border="+this.TbBorder+" width='"+this.TBWidth+"'>");
     if(!this.QueryTitle.equals("")){
      result.append("<tr><td colspan="+this.lable.size()+"><b>"+this.QueryTitle+"</b></td></tr>");
     }
     result.append("<tr bgcolor="+this.HeadBGColor+">");
     int m=this.lable.size();
     for(int i=1;i<=m;i++){
        if(i==(new Integer(this.OrderBy)).intValue()){
          result.append("<td bgcolor=#CCCCCC width="+this.colwidths.get(""+i+"")+"><font color="+this.HeadFontColor+"><a href="+this.PageLink+pnum+"&pagesize="+((this.PageSize==this.reccount)?0:this.PageSize)+"&orderby="+i+"><img border=0 src="+this.imgpath+">&nbsp;<b>"+this.lable.get(""+i+"").toString()+"</b></a></font></td>");
        }else{
         result.append("<td bgcolor=#CCCCCC width="+this.colwidths.get(""+i+"")+"><font color="+this.HeadFontColor+"><a href="+this.PageLink+pnum+"&pagesize="+((this.PageSize==this.reccount)?0:this.PageSize)+"&orderby="+i+"><b>"+this.lable.get(""+i+"").toString()+"</b></a></font></td>");
        }
      }
      result.append("</tr>");
      int n=this.cols.size();
      while(rst.next())
      {
        result.append("<tr>");
        for(int j=1;j<=n;j++)
        {
          if(j>m)break;
          String tempstr="";
          String tempstr2=((rst.getString(this.cols.get(""+j+"").toString())==null||rst.getString(this.cols.get(""+j+"").toString()).equals("null"))?"":new String(rst.getString(this.cols.get(""+j+"").toString())));
          if(this.resfunc.containsKey(""+j+"$fetchitem")){
            tempstr=FetchItem.fetchSelectOne(this.resfunc.get(""+j+"$fetchitem").toString(),tempstr2);
          }else{
            tempstr=((rst.getString(this.cols.get(""+j+"").toString())==null||rst.getString(this.cols.get(""+j+"").toString()).equals("null"))?"&nbsp;":new String(rst.getString(this.cols.get(""+j+"").toString())));
          }

          if(this.links.size()==0){
            result.append("<td>"+((tempstr.trim().equals(""))?"&nbsp;":tempstr)+"</td>");
          }else{
            if(this.links.containsKey(""+j+"")){
              String templink="";
              String tempresult="";

              if(this.links.get(""+j+"").toString().indexOf("?")!=-1){
                templink=this.links.get(""+j+"").toString().substring(0,this.links.get(""+j+"").toString().indexOf("?")+1);
              }else{
                templink=this.links.get(""+j+"")+"?";
              }

              Enumeration em=this.linkconstparas.keys();
              while(em.hasMoreElements()){
                String tempkey=em.nextElement().toString();
                if(tempkey.indexOf(j+"$")!=-1){
                  String tempname=tempkey.substring(tempkey.indexOf("$")+1);
                  templink=templink+tempname+"="+this.linkconstparas.get(tempkey).toString()+"&";
                }
              }

              em=this.linkparas.keys();
              while(em.hasMoreElements()){
                String tempkey=em.nextElement().toString();
                if(tempkey.indexOf(j+"$")!=-1){
                  String tempname=tempkey.substring(tempkey.indexOf("$")+1);
                  templink=templink+tempname+"="+rst.getString(this.linkparas.get(tempkey).toString())+"&";
                }
              }

              if(this.linktargetiframe.containsKey(""+j+"")){
                tempresult="<td><a href=javascript:void(0) οnclick=javascript:"+this.linktargetiframe.get(""+j+"").toString()+".src='"+templink+"'>"+tempstr+"</a></td>";
              }else{
                if(this.linktarget.containsKey(""+j+"")){
                  tempresult="<td><a href=javascript:void(0) οnclick=javascript:window.open('"+templink+"','detail','"+Winproperty+"')>"+tempstr+"</a></td>";
                }else{
                  tempresult="<td><a href="+templink+">"+tempstr+"</a></td>";
                }
              }
              result.append(tempresult);
            }else{
              result.append("<td>"+((tempstr.trim().equals(""))?"&nbsp;":tempstr)+"</td>");
            }
          }
        }
         result.append("</tr>");
      }
      result.append("</table>");
      rst.close();

      if(this.hasexcel.equals("YES")){
        rst=st.executeQuery(this.SQL+" order by "+this.OrderBy+" "+this.sortOrder);
        File excelfile= new File(this.excelpath+this.excelname+".xls");
        FileOutputStream fileoutputstream = new FileOutputStream(excelfile);
        HSSFWorkbook xls=new HSSFWorkbook();
        HSSFSheet sheet=xls.createSheet();
        xls.setSheetName(0,"list");
        HSSFRow row=sheet.createRow((short)0);
        HSSFCell cell;
        for(int i=1;i<=m;i++){
          cell=row.createCell((short)i);
          cell.setEncoding((short)1);
          cell.setCellType(1);
          cell.setCellValue(this.lable.get(""+i+"").toString()) ;
        }
        short rownum=1;
        String tempstr2="";
        while(rst.next()){
          row=sheet.createRow(rownum);
          for(short cellnum=1;cellnum<=n;cellnum++){
            cell=row.createCell(cellnum);
            cell.setEncoding((short)1);
            cell.setCellType(1);
            tempstr2=((rst.getString(this.cols.get(""+cellnum+"").toString())==null||rst.getString(this.cols.get(""+cellnum+"").toString()).equals("null"))?"":new String(rst.getString(this.cols.get(""+cellnum+"").toString())));
            if(this.resfunc.containsKey(""+cellnum+"$fetchitem"))tempstr2=FetchItem.fetchSelectOne(this.resfunc.get(""+cellnum+"$fetchitem").toString(),tempstr2);
            cell.setCellValue(tempstr2);
          }
          rownum++;
        }
        xls.write(fileoutputstream);
        fileoutputstream.close();
        rst.close();
      }
      st.close();
      conn.close();
     this.CurrentPage=pnum;
    }catch(Exception e)
    {
       try{if(rst!=null)rst.close();
       if(st!=null)st.close();
       if(conn!=null)conn.close();}catch(Exception ex){}
       e.printStackTrace();
       System.out.println("[com.zjtz.Pager:Pager Bean]GetData2 Error Found:"+e.toString());

    }
       return result.toString();
   }
/**
 * 取分页信息
 */
  public String getFooter(int pnum)
  {
    StringBuffer resutlbuffer=new StringBuffer();
    if(this.TotalPage!=0)
    {
      if(pnum==1){
        resutlbuffer.append("<p align=center>第一页 上一页 ");
      }else{
        resutlbuffer.append("<p align=center><a href="+this.PageLink+"1&pagesize="+((this.PageSize==this.reccount)?0:this.PageSize)+"&orderby="+this.OrderBy+">第一页</a> <a href="+this.PageLink+(pnum-1)+"&pagesize="+((this.PageSize==this.reccount)?0:this.PageSize)+"&orderby="+this.OrderBy+">上一页</a> ");
      }
      resutlbuffer.append(" 总共有"+this.TotalPage+"页,共"+this.reccount+"条记录,当前第<select name=/"sohappy/" οnchange=/"javascript:window.location.href='"+this.PageLink+"'+this.value+'&pagesize="+((this.PageSize==this.reccount)?0:this.PageSize)+"&orderby="+this.OrderBy+"'/">");
      for(int k=1;k<=this.TotalPage;k++){
        if(pnum==k){
          resutlbuffer.append("<option value=/""+k+"/" selected>"+k+"</option>");
        }else{
          resutlbuffer.append("<option value="+k+">"+k+"</option>");
        }
      }
      resutlbuffer.append("</select>页 ");
      if(pnum==this.TotalPage){
         resutlbuffer.append("下一页 最后一页");
      }else{
         resutlbuffer.append("<a href="+this.PageLink+(pnum+1)+"&pagesize="+((this.PageSize==this.reccount)?0:this.PageSize)+"&orderby="+this.OrderBy+">下一页</a> <a href="+this.PageLink+this.TotalPage+"&pagesize="+((this.PageSize==this.reccount)?0:this.PageSize)+"&orderby="+this.OrderBy+">最后一页</a>");
       }
    }else{
      resutlbuffer.append("<p align=center>对不起,没有找到你要求的记录,请重新运行查询!");
    }
    return resutlbuffer.toString();
  }
/**
 * 取显示条数设置信息
 */
  public String getSizeInput()
  {
    StringBuffer resutlbuffer=new StringBuffer();
    resutlbuffer.append("<br><form name=pager method=get action=" + PageLink + "1&orderby=" + OrderBy +">");
    resutlbuffer.append("每页显示<input size=5 maxlength=5 name=pagesize value="+((this.PageSize==this.reccount)?0:this.PageSize)+">条记录");
    int qpos=PageLink.indexOf("?");
    String qs=PageLink.substring(qpos+1);
    HashMap qpair=new HashMap();
    qpos=0;
    int ppos=0;
    while(qpos!=-1){
       String bs;
       qpos=qs.indexOf("&",ppos);
       if(qpos==-1)break;
       bs=qs.substring(ppos,qpos);
       qpair.put(bs.substring(0,bs.indexOf("=")),bs.substring(bs.indexOf("=")+1));
       ppos=qpos+1;
    }
    qpair.put("pnum","1");
    qpair.put("orderby",OrderBy);
    Iterator s=qpair.keySet().iterator();
    while(s.hasNext()){
       String key=s.next().toString();
       resutlbuffer.append("<input type=hidden name="+key+" value="+qpair.get(key)+">");
    }
    resutlbuffer.append("<input type=submit value=GO>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=button value=生成excel οnclick=window.location.href='"+PageLink+"1&orderby="+OrderBy+"&saveasexcel='></form>");
    //resutlbuffer.append("<input type=submit value=GO></form>");
    return resutlbuffer.toString();
  }
/**
 * 取页面总数
 */
  public int getTotalPage()
  {
    return this.TotalPage;
  }
/**
 * 取记录总数
 */
  public int getTotalNum()
  {
    return this.reccount;
  }
/**
 * 是否还有下一页
 */
   public boolean hasMorePage()
   {
     System.out.println("TotalPage="+this.TotalPage);
     System.out.println("CurrentPage"+this.CurrentPage);
     if(this.CurrentPage<this.TotalPage)
     {
         return true;
     }
     else
     {
         return false;
     }
   }
}



package com.tzsw.pub;

import java.util.*;
import com.tzsw.data.*;
import com.tzsw.db.*;
import com.tzsw.db.query.*;
import com.tzsw.input.*;

/**
 * 主要用于取参数表cnst,country,nation,trade,post,department,ufsyscd,region的值
 */
public class FetchItem
{
 
  private static int CNST_TYPE_COUNTS=0;
  private final static int OTHER_COUNTS=9; 
  private final static String QUE_CNST_STATEMENT="select csttp,cstcd,cstnm from cnst order by csttp,cstcd_&ST_csttp,ST_cstcd,ST_cstnm_&";
  private final static String QUE_COUNTRY_STATEMENT="select cntcd,cntname from country order by cntcd_&ST_cntcd,ST_cntname_&";
  private final static String QUE_NATION_STATEMENT="select ntncd,ntnname from nation order by ntncd_&ST_ntncd,ST_ntnname_&";
  private final static String QUE_TRADE_STATEMENT="select trdcd,trdname from trade order by trdcd_&ST_trdcd,ST_trdname_&";
  private final static String QUE_POST_STATEMENT="select pstcd,pstabc||pstname pstname from post order by pstname_&ST_pstcd,ST_pstname_&";
  private final static String QUE_DEPARTMENT_STATEMENT="select de_deptid,de_deptname from department where substr(de_deptid,0,6)='330105' order by de_deptid_&ST_de_deptid,ST_de_deptname_&";
  private final static String QUE_UFSYSCD_STATEMENT="select usccd,uscnm from ufsyscd_&ST_usccd,ST_uscnm_&";
  private final static String QUE_REGION_STATEMENT="select rgncd,rgnname from region_&ST_rgncd,ST_rgnname_&"; 
  private final static String QUE_USERINFO_STATEMENT="select us_userid,us_username from userinfo where substr(us_deptid,0,6)='330105'_&ST_us_userid,ST_us_username_&";
  private final static String QUE_DEPARTMENTSQUEEN_STATEMENT="select de_id,de_deptname from department where substr(de_deptid,0,6)='330105' order by de_id_&ST_de_id,ST_de_deptname_&";
 
  private static final LinkedHashMap allMap=new LinkedHashMap();
  private static FetchItem _instance=new FetchItem();
 
  private FetchItem()
  {
    System.out.print("Cnst and parameter is loading............");
    String[] cnst_type=getCnstTypes();
    int j=cnst_type.length;
    Vector vc=null;

    addcnst(querycnst(QUE_CNST_STATEMENT));
    for(int n=CNST_TYPE_COUNTS;n<j;n++)
    {
      if(n==CNST_TYPE_COUNTS){
        vc=queryother(QUE_COUNTRY_STATEMENT);
        addother(vc,cnst_type[n],"cntcd","cntname");
      }else if(n==CNST_TYPE_COUNTS+1){
        vc=queryother(QUE_NATION_STATEMENT);
        addother(vc,cnst_type[n],"ntncd","ntnname");
      }else if(n==CNST_TYPE_COUNTS+2){
        vc=queryother(QUE_TRADE_STATEMENT);
        addother(vc,cnst_type[n],"trdcd","trdname");
      }else if(n==CNST_TYPE_COUNTS+3){
        vc=queryother(QUE_POST_STATEMENT);
        addother(vc,cnst_type[n],"pstcd","pstname");
      }else if(n==CNST_TYPE_COUNTS+4){
        vc=queryother(QUE_DEPARTMENT_STATEMENT);
        addother(vc,cnst_type[n],"de_deptid","de_deptname");
      }else if(n==CNST_TYPE_COUNTS+5){
        vc=queryother(QUE_UFSYSCD_STATEMENT);
        addother(vc,cnst_type[n],"usccd","uscnm");
      }else if(n==CNST_TYPE_COUNTS+6){
        vc=queryother(QUE_REGION_STATEMENT);
        addother(vc,cnst_type[n],"rgncd","rgnname");
      }else if(n==CNST_TYPE_COUNTS+7){
        vc=queryother(QUE_USERINFO_STATEMENT);
        addother(vc,cnst_type[n],"us_userid","us_username");
      }else if(n==CNST_TYPE_COUNTS+8){
        vc=queryother(QUE_DEPARTMENTSQUEEN_STATEMENT);
        addother(vc,cnst_type[n],"de_id","de_deptname");
      }
    }
    System.out.println("ok!");
  }


/*
 * 取得该类的一个对象
 */
  public static FetchItem getInstance()
  { 
    return _instance; 
  }
/**
 * 根据传入的type类型,返回一个下拉列表的值(包括cnst,country,trade,nation,post,ufsyscd,region,userinfo,department的12位通用取法)
 */ 
  public static String fetchSelectItem(String type)
 {
      String returnstr="";     
      String key="";
      LinkedHashMap temp=(LinkedHashMap)_instance.allMap.get(type.toUpperCase());
      if(temp==null)return "";
      Iterator it=temp.keySet().iterator();
      while(it.hasNext())
      {
        key=(String)it.next();
        returnstr=returnstr+"<option value="+"/""+key+"/""+">"+temp.get(key);
      }
      return returnstr;
 }
/**
 * 根据传入的type类型和一个值,返回一个该值为选定的默认值的下拉列表的值(包括cnst,country,trade,nation,post,ufsyscd,region,userinfo,department的12位通用取法)
 */    
 public static String fetchSelectItem(String type,String value)
 {
      String returnstr="";
      String tempstr="";
      String key="";
      LinkedHashMap temp=(LinkedHashMap)_instance.allMap.get(type.toUpperCase());
      if(temp==null) return "";
      Iterator it=temp.keySet().iterator();
     
      while(it.hasNext())
      {
        key=(String)it.next();
        if(key.equals(value))
            {
              tempstr=" selected";           
            }
            else
            {
              tempstr="";          
            }
            returnstr=returnstr+"<option value="+"/""+key+"/""+tempstr+">"+temp.get(key);
      }
      return returnstr;
 }
/**
 * 取省市区县的下拉列表(带缓冲)
 * @param type region表示省,street表示市,recom表示区县
 */
 
  public static String fetchRegionSelectItem(String type)
 {
    return fetchRegionAddDepartmentSelectItem(type,"REGION");
  }
/**
 * 取区街道社区的下拉列表(带缓冲的12位取12位)
 * @param type region表示区,street表示街道,recom表示社区
 */
  public static String fetchDepartmentSelectItem(String type)
 {
    return fetchRegionAddDepartmentSelectItem(type,"DEPARTMENT");
  } 
/**
 * 取区街道社区的下拉列表,获取所有的区,街道或者社区(产生4位列表,不带缓冲)
 * @param type region表示区,street表示街道,recom表示社区
*/
  public static String fetchDepartmentSequenceSelectItem(String type)
  {
      return FetchItemJd.judgejd("DepartmentSequence",type.toUpperCase());
  }
/**
 * 取带默认值的区,街道或社区的下拉列表,获取所有的区,街道或者社区(产生4位列表,不带缓冲)
 * @param type region表示区,street表示街道,recom表示社区
*/
  public static String fetchDepartmentSequenceSelectDefaultItem(String type,String value)
  {
      return FetchItemJd.judgejddefault("DepartmentSequence",type.toUpperCase(),value);
  } 
/**
 * 取区街道社区的下拉列表,根据街道值产生社区列表,或者根据区产生街道列表(12位或者4位产生4位列表,不带缓冲)
 * @param type region表示区,street表示街道,recom表示社区
 * @param value 区或者街道的值,如果type为street,则value为该街道的12(4)位编码,返回该街道下的所有社区
 */
  public static String fetchDepartmentSequenceSelectItem(String type,String value)
  {
      return FetchItemJd.judgejd("DepartmentSequence",type.toUpperCase(),value);
  }
/**
 * 取带默认值的区街道社区的下拉列表,根据街道值产生社区列表,或者根据区产生街道列表(12位或者4位产生4位列表,不带缓冲)
 * @param type region表示区,street表示街道,recom表示社区
 * @param value 区或者街道的值,如果type为street,则value为该街道的12(4)位编码,返回该街道下的所有社区,默认为defaultvalue值选中
 * @param defaultvalue 缺省值
 */
  public static String fetchDepartmentSequenceSelectDefaultItem(String type,String value,String defaultvalue)
  {
      return FetchItemJd.judgejddefault("DepartmentSequence",type.toUpperCase(),value,defaultvalue);
  }
/**
 * 取区街道社区的单个值(产生4位对应中文值,不带缓冲)
 * @param value 区街道或者是社区的值
 */
  public static String fetchDepartmentSequenceSelectOne(String value)
  {
      return FetchItemJd.judgejdone("DepartmentSequence",value);
  }
/**
 * 取区街道社区的单个值(产生4位对应部门id,不带缓冲)
 * @param value 区街道或者是社区的值
 */
  public static String fetchDepartmentSequenceSelectDeptid(String value)
  {
      return FetchItemJd.judgejdone("DepartmentSequenceId",value);
  }
 
  private static String fetchRegionAddDepartmentSelectItem(String type,String type1)
  {
    if(type==null) return "";

    String returnstr=""; 
    type=type.toUpperCase();
    String key="";
    LinkedHashMap temp=(LinkedHashMap)_instance.allMap.get(type1);
    if(temp==null)return "";
    Iterator it=temp.keySet().iterator();

    if(type.equals("REGION")){
      while(it.hasNext()){
        key=(String)it.next();
        if(trimZeroLength(key)==4){
          returnstr=returnstr+"<option value="+"/""+key+"/""+">"+temp.get(key);
        }
      }
    }else if(type.equals("STREET")){
      while(it.hasNext()){
        key=(String)it.next();
        if(trimZeroLength(key)==2){
          returnstr=returnstr+"<option value="+"/""+key+"/""+">"+temp.get(key);
        }
      }
    }else if(type.equals("RECOM")){
      while(it.hasNext()){
        key=(String)it.next();
        if(trimZero(key).length()==key.length()){
          returnstr=returnstr+"<option value="+"/""+key+"/""+">"+temp.get(key);
        }
      }
    }
    it=null;
    temp=null;
    return returnstr;  
  }

 
/**
 * 取省市区县的下拉列表
 * 根据传入的type类型和一个值,返回一个该值为选定的默认值的下拉列表的值
 * @param type region表示省,street表示市,recom表示区县
 * @param value 省市区县的某一个值
 */
  public static String fetchRegionSelectItem(String type,String value)
 {
    return fetchRegionAddDepartmentSelectItem(type,"REGION",value);
  }
/**
 * 取区街道社区的下拉列表(带缓冲的12位取12位)
 * 根据传入的type类型和一个值,返回一个该值为选定的默认值的下拉列表的值
 * @param type region表示区,street表示街道,recom表示社区
 * @param value 区街道社区的某一个值
 */
  public static String fetchDepartmentSelectItem(String type,String value)
 {
    return fetchRegionAddDepartmentSelectItem(type,"DEPARTMENT",value);
  } 
  private static String fetchRegionAddDepartmentSelectItem(String type,String type1,String value)
  {
      String returnstr="";
      String tempstr="";
      String key="";
      type=type.toUpperCase();
      LinkedHashMap temp=(LinkedHashMap)_instance.allMap.get(type1);
      if(temp==null)return "";
      Iterator it=temp.keySet().iterator();
      if(type.equals("REGION")){
        while(it.hasNext()){
          key=(String)it.next();
          if(trimZeroLength(key)==4){
            if(key.equals(value)){
              tempstr=" selected";           
            }else{
              tempstr="";          
            }
            returnstr=returnstr+"<option value="+"/""+key+"/""+tempstr+">"+temp.get(key);
          }
        }
      }else if(type.equals("STREET")){
        while(it.hasNext()){
          key=(String)it.next();
          if(trimZeroLength(key)==2){
            if(key.equals(value)){
              tempstr=" selected";           
            }else{
              tempstr="";          
            }
            returnstr=returnstr+"<option value="+"/""+key+"/""+tempstr+">"+temp.get(key);
          }
        }
      }else if(type.equals("RECOM")){
        while(it.hasNext()){
          key=(String)it.next();
          if(trimZero(key).length()==key.length()){
            if(key.equals(value)){
              tempstr=" selected";           
            }else{
              tempstr="";          
            }
            returnstr=returnstr+"<option value="+"/""+key+"/""+tempstr+">"+temp.get(key);
          }
        }
      }
      it=null;
      temp=null;
      return returnstr;
 }
/**
 * 根据区产生所属街道的下拉列表(带缓冲的12位取12位)
 * @param value 所属区的值
 */
  public static String fetchStreetRegionSelectItem(String value)
  {
    if(value==null) return "";
    String tempvalue=trimZero(value);
    String returnstr=""; 
    String key="";
    LinkedHashMap temp=(LinkedHashMap)_instance.allMap.get("DEPARTMENT");
    if(temp==null)return "";
    Iterator it=temp.keySet().iterator();
    while(it.hasNext()){
      key=(String)it.next();
      if(key.startsWith(tempvalue)&&trimZeroLength(key)==2)returnstr=returnstr+"<option value="+"/""+key+"/""+">"+temp.get(key);
    }
    it=null;
    temp=null;
    return returnstr;  
  }
/**
 * 根据街道产生所属社区的下拉列表(带缓冲的12位取12位)
 * @param value 所属街道的值
 */
  public static String fetchRecomStreetSelectItem(String value)
  {
    if(value==null) return "";
    String tempvalue=trimZero(value);
    String returnstr=""; 
    String key="";
    LinkedHashMap temp=(LinkedHashMap)_instance.allMap.get("DEPARTMENT");
    if(temp==null)return "";
    Iterator it=temp.keySet().iterator();
    while(it.hasNext()){
      key=(String)it.next();
      if(key.startsWith(tempvalue)&&trimZero(key).length()==value.length())returnstr=returnstr+"<option value="+"/""+key+"/""+">"+temp.get(key);
    }
    it=null;
    temp=null;
    return returnstr;  
  }


/*
 * 根据传入的type类型和部门以及模块信息,返回一个带有缺省值的下拉列表的值
 */     
/*  public static String fetchInitSelectItem(String type,String departmentid,String module)
  {
      String retstr="";
      retstr=FetchItemJd.judgejd(type,departmentid,module);
      return fetchSelectItem(type,retstr);
  }*/
 
/**
 * 根据部门编号获取该部门以及下属部门的列表(不带缓冲的12位取12位,或者4位取4位)
 */
  public static String fetchIncludeDepartment(String departmentid)
  {
    String returnstr="";     
      String key="";
      LinkedHashMap temp=FetchItemRJD.IncludeDepartment(departmentid.toUpperCase());
      if(temp==null)return "";
      Iterator it=temp.keySet().iterator();
      while(it.hasNext())
      {
        key=(String)it.next();
        returnstr=returnstr+"<option value="+"/""+key+"/""+">"+temp.get(key);
      }
      return returnstr;
  }
/**
 * 根据部门编号获取该部门以及下属部门的列表(不带缓冲的12位取12位,或者4位取4位,带默认值)
 */
  public static String fetchIncludeDepartment(String departmentid,String value)
  {
      String returnstr="";
      String tempstr="";
      String key="";
      if(departmentid.length()==12&&(!departmentid.endsWith("00"))){
        departmentid=departmentid.substring(0,10)+"00";
      }
      LinkedHashMap temp=FetchItemRJD.IncludeDepartment(departmentid.toUpperCase());
      if(temp==null)return "";
      Iterator it=temp.keySet().iterator();
      while(it.hasNext())
      {
        key=(String)it.next();
        if(key.equals(value))
            {
              tempstr=" selected";           
            }
            else
            {
              tempstr="";          
            }
            returnstr=returnstr+"<option value="+"/""+key+"/""+tempstr+">"+temp.get(key);
      }
      return returnstr;
  }
/**
 * 根据部门编号获取该部门以及下属部门的列表(不带缓冲的12位取4位)
 */
  public static String fetchIncludeDepartmentSqueen(String departmentid)
  {
    String returnstr="";     
      String key="";
      LinkedHashMap temp=FetchItemRJD.IncludeDepartmentSqueen(departmentid.toUpperCase());
      if(temp==null)return "";
      Iterator it=temp.keySet().iterator();
      while(it.hasNext())
      {
        key=(String)it.next();
        returnstr=returnstr+"<option value="+"/""+key+"/""+">"+temp.get(key);
      }
      return returnstr;
  }
/**
 * 根据部门编号获取该部门以及下属部门的列表(不带缓冲的12位取4位,带默认值)
 */
  public static String fetchIncludeDepartmentSqueen(String departmentid,String value)
  {     
      String returnstr="";
      String tempstr="";
      String key="";
      LinkedHashMap temp=FetchItemRJD.IncludeDepartmentSqueen(departmentid.toUpperCase());
      if(temp==null)return "";
      Iterator it=temp.keySet().iterator();
      while(it.hasNext())
      {
        key=(String)it.next();
        if(key.equals(value))
            {
              tempstr=" selected";           
            }
            else
            {
              tempstr="";          
            }
            returnstr=returnstr+"<option value="+"/""+key+"/""+tempstr+">"+temp.get(key);
      }
      return returnstr;
  }

/**
 * 根据region编号获取该市县或者区的下属机构列表
 */
  public static String fetchIncludeRegionSqueen(String rgncd)
  {
      String returnstr="";     
      String key="";
      LinkedHashMap temp=FetchItemRJD.IncludeRegionSqueen(rgncd);
      if(temp==null)return "";
      Iterator it=temp.keySet().iterator();
      while(it.hasNext())
      {
        key=(String)it.next();
        returnstr=returnstr+"<option value="+"/""+key+"/""+">"+temp.get(key);
      }
      return returnstr;
  }

 

 

/**
 * 根据传入的type类型和一个值,返回该值在映射表中的文字描述(包括cnst,country,trade,nation,post,ufsyscd,region,userinfo,department的12位通用取法)
 * @param type 类型标识
 * @param value 该类型列表中的某个值
 * @return 该值在的中文描述字符串
 */
 public static String fetchSelectOne(String type,String value)
 {
      if((value==null)||(value=="")||(value.equals(""))||(value.equals("null")))
      {
       return "";
      }
      LinkedHashMap temp=(LinkedHashMap)_instance.allMap.get(type.toUpperCase());
      String returnstr=(String)temp.get(value);
   if(returnstr==null)returnstr=value;
      return returnstr;
 }  
///
  private static Vector queryother(String sql)
  {
    try{
      TzDynInput tzdyninput=new TzDynInput();
      tzdyninput.setSql(sql);
      DbQuery tzdynquery=new TzDbQuery();     
      Vector vc=tzdynquery.runm(tzdyninput);
      return vc;
    }catch (Exception se){         
      se.printStackTrace();
      return null;
    }
  }

  private static Vector querycnst(String sql)
  {
    try{
      TzDynInput tzdyninput=new TzDynInput();
      tzdyninput.setSql(sql); 
      DbQuery tzquery=new TzDbQuery();     
      Vector vc=tzquery.runm(tzdyninput);
      return vc;
    }catch (Exception se){         
      se.printStackTrace();
      return null;
    }
  }
 
  private static void addother(Vector vc,String name,String var1,String var2)
  {
    if(vc==null)return;
    int j=vc.size();   
    HashMap hm=null;
    LinkedHashMap thash=new LinkedHashMap();
    for(int i=0;i<j;i++)
    {
        hm=(HashMap)vc.get(i);
        thash.put(hm.get(var1),(hm.get(var2)==null)?"":hm.get(var2));       
        hm=null;
    }
    allMap.put(name,thash);
  }

  private static void addcnst(Vector vc)
  {
    if(vc==null)return;
    int j=vc.size(); 
    String name="";
    HashMap hm=null;
    LinkedHashMap newhash=null;
    LinkedHashMap oldthash=null;
    for(int i=0;i<j;i++)
    {
        hm=(HashMap)vc.get(i);
        if(hm!=null)
        {
          name=((String)hm.get("csttp")).trim();
          if(allMap.containsKey(name)){
            oldthash=(LinkedHashMap)allMap.get(name);
            oldthash.put(hm.get("cstcd"),(hm.get("cstnm")==null)?"":hm.get("cstnm"));     
            allMap.put(name,oldthash);
            oldthash=null;
          }else{
            newhash=new LinkedHashMap();
            newhash.put(hm.get("cstcd"),(hm.get("cstnm")==null)?"":hm.get("cstnm"));     
            allMap.put(name,newhash);
            newhash=null;
          }
        }
        hm=null;
    }
  }

  private static Vector querycnsttype()
  {
    try{
      TzDynInput tzdyninput=new TzDynInput();
      tzdyninput.setSql("select distinct csttp from cnst_&ST_csttp_&");
      DbQuery tzquery=new TzDbQuery();     
      Vector vc=tzquery.runm(tzdyninput);
      return vc;
    }catch (Exception se){         
      se.printStackTrace();
      return null;
    }
  }
 
  private static String[] getCnstTypes()
  {
    Vector vc=querycnsttype();
    if(vc==null)return null;   
    CNST_TYPE_COUNTS=vc.size();
    String[] cnst_type=new String[CNST_TYPE_COUNTS+OTHER_COUNTS];
    for(int i=0;i<CNST_TYPE_COUNTS;i++)
    cnst_type[i]=(String)((HashMap)vc.get(i)).get("csttp");
    cnst_type[CNST_TYPE_COUNTS]="COUNTRY";//国家
    cnst_type[CNST_TYPE_COUNTS+1]="NATION";//民族
    cnst_type[CNST_TYPE_COUNTS+2]="TRADE";//行业
    cnst_type[CNST_TYPE_COUNTS+3]="POST";//工种
    cnst_type[CNST_TYPE_COUNTS+4]="DEPARTMENT";//部门
    cnst_type[CNST_TYPE_COUNTS+5]="UFSYSCD";//主管部门
    cnst_type[CNST_TYPE_COUNTS+6]="REGION";//省市区县
    cnst_type[CNST_TYPE_COUNTS+7]="USERINFO";//用户
    cnst_type[CNST_TYPE_COUNTS+8]="DEPARTMENTSQUEEN";//部门
    return cnst_type;
  }
  private static String trimZero(String str)
  {
    if(str==null)return "";
    while(str.endsWith("0")){
      str=str.substring(0,str.length()-1); 
    }
    return str;
  }
  private static int trimZeroLength(String str)
  {
    int length=0;
    while(str.endsWith("0")){
      str=str.substring(0,str.length()-1); 
      length++;
    }
    return length;
  }
/**
 * 测试方法,返回当前缓存的所有内容
 */
  public static String getString(){
    return allMap.toString();
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值