iDempiere 的工具栏中的查询功能主要分为简单搜索和高级搜索。现版本的简单搜索对文本的查询使用的后模糊查询,高级搜索中的Like是未对文本添加%处理的,需要用户自己在查询值添加%。这两种方式不能满足客户需求,现需要把简单搜索改成全模糊搜索、高级搜索添加前置%、后置%、前后都加%,使查询更加灵活,增加客户的可选择性,提升客户体验感。
1、简单搜索 文本查询更为全部模糊查询
修改FindWindow中的cmd_saveSimple方法,在指定位置添加红框内容
// Be more permissive for String columns
if (isSearchLike(field))
{
StringBuilder valueStr = new StringBuilder(value.toString().toUpperCase());
if (!valueStr.toString().endsWith("%"))
valueStr.append("%");
//jiangcheng 前面添加%
if (!valueStr.toString().startsWith("%"))
valueStr.insert(0, "%");
//
ColumnSQL = new StringBuilder("UPPER(").append(ColumnSQL).append(")");
value = valueStr.toString();
}
2、高级搜索 文本查询添加前置%、后置%、前后都加%
2.1在MQuery添加对应的相关变量
/**Before Like */
public static final String BEFORE_LIKE = " BEFORE LIKE ";
public static final String MSG_BEFORE_LIKE = "OPERATOR_BEFORE_LIKE";
/**After Like */
public static final String AFTER_LIKE = " AFTER LIKE ";
public static final String MSG_AFTER_LIKE = "OPERATOR_AFTER_LIKE";
/**Full Like */
public static final String FULL_LIKE = " FULL LIKE ";
public static final String MSG_FULL_LIKE = "OPERATOR_FULL_LIKE";
2.2 将2.1创建的变量加入到OPERATORS、OPERATORS_STRINGS
/** All the Operators */
public static final ValueNamePair[] OPERATORS = new ValueNamePair[] {
new ValueNamePair (EQUAL, MSG_EQUAL), // 0 - EQUAL_INDEX
new ValueNamePair (NOT_EQUAL, MSG_NOT_EQUAL), // 1 - NOT_EQUAL_INDEX
new ValueNamePair (LIKE, MSG_LIKE),
//jiangchen 添加 前% 后% 全%
new ValueNamePair (BEFORE_LIKE, MSG_BEFORE_LIKE),
new ValueNamePair (AFTER_LIKE, MSG_AFTER_LIKE),
new ValueNamePair (FULL_LIKE, MSG_FULL_LIKE),
new ValueNamePair (NOT_LIKE, MSG_NOT_LIKE),
new ValueNamePair (GREATER, MSG_GREATER),
new ValueNamePair (GREATER_EQUAL, MSG_GREATER_EQUAL),
new ValueNamePair (LESS, MSG_LESS),
new ValueNamePair (LESS_EQUAL, MSG_LESS_EQUAL),
new ValueNamePair (BETWEEN, MSG_BETWEEN), // 8 - BETWEEN_INDEX jiangchen 11
new ValueNamePair (NULL, MSG_NULL),
new ValueNamePair (NOT_NULL, MSG_NOT_NULL)
};
/** Operators for Strings */
public static final ValueNamePair[] OPERATORS_STRINGS = new ValueNamePair[] {
new ValueNamePair (EQUAL, MSG_EQUAL),
new ValueNamePair (NOT_EQUAL, MSG_NOT_EQUAL),
new ValueNamePair (LIKE, MSG_LIKE),
//jiangchen 添加 前% 后% 全%
new ValueNamePair (BEFORE_LIKE, MSG_BEFORE_LIKE),
new ValueNamePair (AFTER_LIKE, MSG_AFTER_LIKE),
new ValueNamePair (FULL_LIKE, MSG_FULL_LIKE),
new ValueNamePair (NOT_LIKE, MSG_NOT_LIKE),
new ValueNamePair (GREATER, MSG_GREATER),
new ValueNamePair (GREATER_EQUAL, MSG_GREATER_EQUAL),
new ValueNamePair (LESS, MSG_LESS),
new ValueNamePair (LESS_EQUAL, MSG_LESS_EQUAL),
new ValueNamePair (BETWEEN, MSG_BETWEEN),
new ValueNamePair (NULL, MSG_NULL),
new ValueNamePair (NOT_NULL, MSG_NOT_NULL)
};
注:因为我这里是在BETWEEN前面添加的数据,所以需要对BETWEEN_INDEX修改,否则会导致查询值2只读,当然,如果大家把数据放在BETWEEN后面的可以不需要管
2.3 修饰查询数据
根据运算符修改解析数据,修改FindWindow的cmd_saveAdvanced方法,在指定位置添加红框代码
parsedValue = getLikeString(parsedValue, Operator);
/**
* 获取Like 的字符串
*
* @param value
* @param operator
* @return
*/
private Object getLikeString(Object value, String operator) {
// TODO Auto-generated method stub
String str = value.toString();
if (operator.equals(MQuery.AFTER_LIKE) && !str.endsWith("%"))
return value + "%";
else if (operator.equals(MQuery.BEFORE_LIKE) && !str.startsWith("%"))
return "%" + value;
else if (operator.equals(MQuery.FULL_LIKE)) {
if (!str.endsWith("%"))
value = value + "%";
if (!str.startsWith("%"))
value = "%" + value;
return value;
} else
return value;
}// getLikeString
根据运算符获取指定运行符,修改FindWindow的cmd_saveAdvanced方法,在指定位置换成红框代码
m_query.addRestriction (ColumnSQL, getLikeOperator(Operator), parsedValue,
infoName, infoDisplay, and, not, openBrackets);
/**
* 获取Like 操作符
* @param operator
* @return
*/
private String getLikeOperator(String operator) {
// TODO Auto-generated method stub
if(operator.equals(MQuery.AFTER_LIKE)
||operator.equals(MQuery.BEFORE_LIKE)
||operator.equals(MQuery.FULL_LIKE)) {
return MQuery.LIKE;
}
return operator;
}//getLikeOperator
3 效果展示
注:需要在消息中进行翻译