📄 queryconditionconfig.java
字号:
/*
* Created on 2004-4-1
*
*/
package com.esimple.service.query.config;
import java.util.*;
import com.esimple.framework.util.*;
import com.esimple.service.dict.DictManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author steven
*
*/
public class QueryConditionConfig extends Config{
public static final int DAY_MILLISECONDS = 24*60*60*1000;
private String type;
private String dict;
private String defaultValue;
private DictManager dictManager;
protected Log logger = LogFactory.getLog(this.getClass());
public void setDictManager(DictManager dictManager){
this.dictManager = dictManager;
}
public DictManager getDictManager(){
return this.dictManager;
}
public String toHtml(){
StringBuffer buffer = new StringBuffer(label);
buffer.append(":");
if( type.equalsIgnoreCase("dict") ){
rendeDictHtml(buffer);
}else if(type.equalsIgnoreCase("select")){
rendeSelectHtml(buffer);
}else{
rendeTextHtml(buffer);
}
return buffer.toString();
}
private void rendeDictHtml(StringBuffer buffer) {
buffer.append("<select name=\"");
buffer.append( this.id );
buffer.append( "\">\n" );
Iterator it = dictManager.getDictContent(dict).keySet().iterator();
while ( it.hasNext() ) {
buffer.append( "<option value='" );
String key = (String)it.next();
buffer.append( key );
buffer.append( "'>" );
buffer.append( dictManager.getDictContent(dict,key));
buffer.append( "</option>\n" );
}
buffer.append( "</select>\n" );
}
private void rendeTextHtml(StringBuffer buffer) {
buffer.append("<input type='text' size='10' notNull name='");
buffer.append(id);
buffer.append("' valueType='");
buffer.append(type);
buffer.append("' label='");
buffer.append(label);
buffer.append("'");
if( defaultValue != null ){
buffer.append(" value='");
buffer.append( getDefaultValue() );
buffer.append("'");;
}
buffer.append(">");
if( type.equalsIgnoreCase("date")){
buffer.append("<input type=\"button\" class=\"button\" " );
buffer.append("onclick=javascript:show_calendar(\"queryFrm.elements['");
buffer.append( id );
buffer.append("']\"," );
buffer.append("null,null,'YYYYMMDD') value=\"日历\" width=\"24\" " );
buffer.append("height=\"22\" border=\"0\" title=\"日历\">" );
}
}
private void rendeSelectHtml(StringBuffer buffer) {
String[] value=StringUtils.split(defaultValue,",",true,true);
String[] label=StringUtils.split(dict,",",true,true);
buffer.append("<select name=\"");
buffer.append( this.id );
buffer.append( "\">\n" );
for (int i=0;i<value.length;i++){
buffer.append( "<option value='" );
buffer.append( value[i] );
buffer.append( "'>" );
buffer.append( label[i] );
buffer.append( "</option>\n" );
}
buffer.append( "</select>\n" );
}
public void setType(String type){
this.type = type;
}
public String getType(){
return this.type;
}
public void setDict(String dict){
this.dict = dict;
}
public String getDict(){
return this.dict;
}
public void setDefaultValue(String defaultValue){
this.defaultValue = defaultValue;
}
public String getDefaultValue(){
if(defaultValue==null) return null;
logger.debug("defaultValue:" + defaultValue);
defaultValue = replaceDateVar(defaultValue);
return defaultValue;
}
private String replaceDateVar(String defaultValue ){
java.util.Date date= new java.util.Date();
long td = date.getTime();
if(defaultValue.equals("$MONTHFIRST")){
return TimeHelper.nowDate("yyyyMM")+"01";
}
if(defaultValue.equals("$YEARFIRST")){
return TimeHelper.nowDate("yyyy")+"0101";
}
if(defaultValue.equals("$TOMORROW")){
td = date.getTime() + DAY_MILLISECONDS;
return TimeHelper.toString(new java.util.Date(td));
}
if(defaultValue.equals("$TODAY")){
return TimeHelper.nowDate("yyyyMMdd");
}
if(defaultValue.equals("$YESTODAY")){
td = date.getTime()- DAY_MILLISECONDS;
return TimeHelper.toString( new java.util.Date(td) );
}
if(defaultValue.equals("$DATEBEFORE_5")){
td = date.getTime()- DAY_MILLISECONDS*5;
return TimeHelper.toString( new java.util.Date(td) );
}
if(defaultValue.equals("$DATEBEFORE_10")){
td = date.getTime()- DAY_MILLISECONDS*10;
return TimeHelper.toString( new java.util.Date(td) );
}
if(defaultValue.equals("$DATEBEFORE_30")){
td = date.getTime()- DAY_MILLISECONDS*30;
return TimeHelper.toString( new java.util.Date(td) );
}
return defaultValue;
}
public static void main(String[] args ){
java.util.Date date= new java.util.Date();
long td = date.getTime();
System.out.println( TimeHelper.toString(date,"yyyyMM") );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -