这是个工具类,里边封装了很多方法函数,但是我看不懂具体的作用有些,求高手能给加点详细的注释
[code]package lderp;
import java.sql.*;
import lderp.HttpServletBean;
import lderp.ext;
public class esql {
// a=esql.baseAdd(a,hsBean,"TYPE","");
public static String[] baseAdd(String[] str, HttpServletBean hsBean,
String Col, String type, boolean pri) throws Exception {
return baseAdd(str, Col, hsBean.getParameter(Col), type, pri);
}
public static String[] baseAdd(String[] str, HttpServletBean hsBean,
String Col, String type) throws Exception {
return baseAdd(str, Col, hsBean.getParameter(Col), type);
}
// b=esql.baseAdd(b,"新增","add","num");
/**
* str[0]=",新曾,修改" str[1]=",add,update" str[2]=",新曾=add,修改=update"
*/
public static String[] baseAdd(String[] str, String Col, String value,
String type, boolean pri) throws Exception {
str[0] = str[0] + "," + Col;
if (type.equals("date")) {
value = "to_date('" + value + "','yyyy-mm-dd')";
str[1] = str[1] + "," + value;
str[2] = str[2] + "," + Col + "=" + value;
} else if (type.equals("date16")) {
value = "to_date('" + value + "','yyyy-mm-dd HH24:MI')";
str[1] = str[1] + "," + value;
str[2] = str[2] + "," + Col + "=" + value;
} else if (type.equals("num")) {
str[1] = str[1] + "," + value;
str[2] = str[2] + "," + (pri ? "1" : "0");
} else {
str[1] = str[1] + ",'" + value + "'";
str[2] = str[2] + "," + Col + "='" + value + "'";
}
return str;
}
public static String[] baseAdd(String[] str, String Col, String value,
String type) throws Exception {
str[0] = str[0] + "," + Col;
if (type.equals("date")) {
value = "to_date('" + value + "','yyyy-mm-dd')";
str[1] = str[1] + "," + value;
str[2] = str[2] + "," + Col + "=" + value;
} else if (type.equals("date16")) {
value = "to_date('" + value + "','yyyy-mm-dd HH24:MI')";
str[1] = str[1] + "," + value;
str[2] = str[2] + "," + Col + "=" + value;
} else if (type.equals("num")) {
str[1] = str[1] + ",'" + value + "'";
str[2] = str[2] + "," + Col + "='" + value + "'";
} else {
str[1] = str[1] + ",'" + value + "'";
str[2] = str[2] + "," + Col + "='" + value + "'";
}
return str;
}
// esql.ModOk(hsBean,"",0,true);
public static void ModOk(HttpServletBean hsBean, String str, int tab,
boolean success) throws Exception {
hsBean.println("<SCRIPT LANGUAGE=javascript>");
if (str.length() > 0) {
hsBean.println("alert('" + str + "');");
}
if (tab >= 0 && success) {
hsBean
.println("if(window.dialogArguments){window.dialogArguments.ListReload("
+ tab + ");}");
}
hsBean.println("window.close();");
hsBean.println("</script>");
}
public static void ModOkFrame(HttpServletBean hsBean, String str, int tab,
boolean success) throws Exception {
hsBean.println("<SCRIPT LANGUAGE=javascript>");
if (str.length() > 0) {
hsBean.println("alert('" + str + "');");
}
if (tab >= 0 && success) {
hsBean
.println("if(parent.window.dialogArguments){parent.window.dialogArguments.ListReload("
+ tab + ");}");
}
if (success)
hsBean.println("parent.window.close();");
hsBean.println("</script>");
}
public static void ModOk2(HttpServletBean hsBean, String str, int tab,
boolean success) throws Exception {
hsBean.println("<SCRIPT LANGUAGE=javascript>");
if (str.length() > 0) {
hsBean.println("alert('" + str + "');");
}
if (tab >= 0 && success) {
hsBean
.println("if(window.dialogArguments){window.dialogArguments.ListReload("
+ tab + ");}");
}
hsBean.println("</script>");
}
public static int getCurPage(HttpServletBean hsBean) throws Exception {
int CurPage = 10;
if (!hsBean.getParameter("CurPage").equals("")) {
CurPage = Integer.parseInt(hsBean.getParameter("CurPage"));
}
return CurPage;
}
public static int getTotle(HttpServletBean hsBean, Statement stmt,
String sql_from, String str) throws Exception {
int totle = 0;
String sql = "select count(" + str + ") " + sql_from;
ResultSet rs = hsBean.executeQuery(sql, stmt);
if (rs.next()) {
totle = rs.getInt(1);
}
return totle;
}
public static int getTotle(HttpServletBean hsBean, Statement stmt,
String sql_from) throws Exception {
return getTotle(hsBean, stmt, sql_from, "1");
}
public static String pageSql(HttpServletBean hsBean, String select,
String sql_from, String Morderby, int PageSize, int CurPage)
throws Exception {
if (select.equals("")) {
select = "*";
}
String sort = hsBean.getParameter("sort");
String dir = hsBean.getParameter("dir");
String orderby = "";
if (!sort.equals("")) {
orderby = " order by " + sort + " " + dir;
} else {
orderby = " order by " + Morderby;
}
String sql = "SELECT ROWNUM as A,b.*";
sql += " FROM (SELECT " + select + " " + sql_from + orderby + ") b";
sql = "SELECT * FROM (" + sql + ") WHERE A>" + (CurPage - 1) * PageSize
+ " AND A<=" + CurPage * PageSize;
return sql;
}
public static String JsonItem(String name, ResultSet rs, String type)
throws Exception {
String str = (rs.getString(name) == null ? "" : rs.getString(name));
if (type.equals("date") && !str.equals("")) {
str = str.substring(0, 10);
} else if (type.equals("date16") && !str.equals("")) {
str = str.substring(0, 16);
} else if (type.equals("date19") && !str.equals("")) {
str = str.substring(0, 19);
}
return JsonItem(name, str);
}
public static String JsonItem(String name, String str) throws Exception {
str = (str == null ? "" : str);
str = MyTools.replaceAll(str, "'", "");
str = MyTools.replaceAll(str, "\r\n", "");
str = MyTools.replaceAll(str, "\n", "");
str = MyTools.replaceAll(str, "\\", "");
str = MyTools.replaceAll(str, "null", "");
return ",'" + name + "':'" + str.trim() + "'";
}
public static String condition(HttpServletBean hsBean, String condition,
String zhiduan, String type) throws Exception {
return condition(condition, zhiduan, hsBean.getParameter(zhiduan), type);
}
public static String condition(String condition, String zhiduan,
String value, String type) throws Exception {
if (value.equals("")) {
return condition;
}
if (type.equals("num")) {
condition += " AND " + zhiduan + "=" + value;
} else if (type.equals("date")) {
condition += " AND " + zhiduan + "to_date('" + value
+ "','yyyy-mm-dd')";
} else if (type.equals("date16")) {
condition += " AND " + zhiduan + "to_date('" + value
+ "','yyyy-mm-dd HH24:MI')";
} else if (type.equals("like")) {
condition += " AND " + zhiduan + " like '%" + value + "%'";
} else if (type.equals("flike")) {
condition += " AND '" + value + "' like '%'||" + zhiduan
+ "||'%' and length(" + zhiduan + ")>0";
} else {
condition += " AND " + zhiduan + "='" + value + "'";
}
return condition;
}
public static String mulcondition(String condition, String zhiduan,
String value, String type) throws Exception {
if (value.equals("")) {
return condition;
}
String str = "";
String[] a = MyTools.split_(value, ";");
for (int i = 0; i < a.length; i++) {
if (a[i] != null && a[i].length() > 0) {
str += " or " + zhiduan + " like '%" + a[i] + "%'";
}
}
if (str.length() > 3) {
condition += " AND (" + str.substring(3) + ")";
}
return condition;
}
public static String qjcondition(String condition, String zhiduan,
String value) throws Exception {
if (value.equals("")) {
return condition;
}
String[] a = MyTools.split_(value, "-");
if (a[0] != null && !a[0].equals("undefined") && a[0].length() > 0) {
condition += " AND " + zhiduan + ">" + a[0];
}
if (a.length > 1 && a[1] != null && a[1].length() > 0) {
condition += " AND " + zhiduan + "<=" + a[1];
}
return condition;
}
public static String qjcondition2(String condition, String zhiduan,
String value) throws Exception {
if (value.equals("")) {
return condition;
}
String[] a = MyTools.split_(value, "-");
if (a[0] != null && !a[0].equals("undefined") && a[0].length() > 0) {
condition += " AND " + zhiduan + ">=" + a[0];
}
if (a.length > 1 && a[1] != null && a[1].length() > 0) {
condition += " AND " + zhiduan + "<=" + a[1];
}
return condition;
}
public static String getSeq(HttpServletBean hsBean, Statement stmt,
String seq) throws Exception {
String sql = "select " + seq + ".nextval from dual";
ResultSet rs = hsBean.executeQuery(sql, stmt);
rs.next();
return rs.getString(1);
}
public static String getProfile(HttpServletBean hsBean, Statement stat,
String type) throws Exception {
String sql = "select * from OY_PROFILE where IFDELETED=0 and COMPANYID="
+ hsBean.getCompanyId()
+ " and TYPE='"
+ type
+ "' order by TABORDER";
ResultSet rs = hsBean.executeQuery(sql, stat);
String str = "";
while (rs.next()) {
str += ",'" + rs.getString("NAME") + "'";
}
if (str.length() > 0) {
str = "[" + str.substring(1) + "]";
}
return str;
}
|