/**
* 得到过滤类型
* @param name 过滤选择名称(包括表名和字段名)
* @param isAdd 是否添加ClassID,BindField等信息
* @return
*/
public static String getFilterType(String name,boolean isAdd){
if(name!=null){
int index=name.indexOf("_");
if(index>=0){
String[] str=new String[2];
str[0]=name.substring(0,index);
str[1]=name.substring(index+1);
ResultSet rs=DBAccess.getInstance().OpenCommand(Common.Format(SQL,str));
try{
if(rs.next()){//时间
if(Common.in(TIME,rs.getString("FieldType"))){
return "1";
}else if(!isDBNull(rs.getString("ClassID"))){//固定代码
if(isAdd)
return "2_"+rs.getString("ClassID");
else
return "2";
}else if(!isDBNull(rs.getString("BindTable"))){//外键关联
if(isAdd)
return "3_"+rs.getString("BindTable")
+"_"+rs.getString("BindField")
+"_"+rs.getString("BindShowField");
else
return "3";
}else if(Common.in(NUM,rs.getString("FieldType"))){//数值
return "4";
}
}
}catch(Exception e){}
}
}
return "0";//普通字符串
}
/**
* 获取过滤字符串
* @param name 过滤类型名称
* @param value 第一个过滤值
* @param value1 第二个过滤值(主要针对时间)
* @return
*/
public static String getFilter(String name,String value,String value1){
String type=getFilterType(name,true);
int flag=0,pos=type.indexOf("_");
String[] other=type.split("_");
if(pos>=0){
flag=Integer.parseInt(type.substring(0,pos));
}else{
flag=Integer.parseInt(type);
}
return getFilter(flag,other,value,value1);
}
/**
* 获取过滤字符串
* @param type 过滤类型
* @param other 固定代码编号等
* @param value 第一个过滤值
* @param value1 第二个过滤值(主要针对时间)
* @return
*/
public static String getFilter(int type,String[] other,String value,String value1){
if(value==null) value="";
if(value1==null) value1="";
switch(type){
case 0:return DEFAULT.replaceAll("@value",value);//字符串
case 1:return ("从:"+DATE.replaceAll("@name","FromDate").replaceAll("@value",value)
+" 到:"+DATE.replaceAll("@name","ToDate").replaceAll("@value",value1));//时间
case 2:if(other.length==2)
return Html.getInstance().GetList("Exec P_GetBaseCode '"
+other[1]+"'",true,true,"FilterValue","100%",value);//固定代码
case 3:if(other.length==4)
return Html.getInstance().GetList("select distinct "+other[2]+","+other[3]
+" from "+other[1],true,true,"FilterValue","100%",value);//外键关联
case 4:return DEFAULT.replaceAll("@value",value);//数值
}
return "";
}
/**
* 得到过滤字符串
* @param name 过滤名称
* @return
*/
public static String getFilter(String name){
return getFilter(name,"","");
}
/**
* 检查是否为空
* @param obj 要检查的对象
* @return
*/
public static boolean isNull(Object obj){
if(obj==null || obj.toString().equals(""))
return true;
else
return false;
}
/**
* 判断是否为空,包括空字段
* @param obj 要判断的对象
* @return
*/
public static boolean isDBNull(Object obj){
if(isNull(obj) || obj.toString().trim().toLowerCase().equals("null"))
return true;
else
return false;
}
//*****************************************************************************************//
原理:根据选择不同的过滤条件,获取条件中的表名和字段名,利用Ajax根据表名和字段名在数据字典中获取它的类型:
(1)如果是日期型:返回日期范围选择
(2)如果是固定代码:返回一个下拉列表,并初始化固定代码
(3)如果是外键关联:则读出所有的外键所对应的名称
(4)否则返回一个文本输入框
这样选择不同的过滤条件(或者说过滤字段),产生不同的过滤效果,而且是异步的,下面显示的数据列表不用刷新,在这个项目中获得了较好的用户体验。
以下是截图: