Beispiel #1
0
  public static void dg1DataBind(DataGridAction dga) {
    String searchUserName = dga.getParam("searchUserName");

    QueryBuilder qb = new QueryBuilder("select * from ZSOrder where IsValid = 'Y' and status='10'");
    QueryBuilder totalQB =
        new QueryBuilder("select * from ZSOrder where IsValid = 'Y' and status='10'");
    if (StringUtil.isNotEmpty(searchUserName)) {
      qb.append(" and UserName like ? ", "%" + searchUserName + "%");
      totalQB.append(" and UserName like ? ", "%" + searchUserName + "%");
    }
    dga.setTotal(totalQB);

    qb.append(" order by id desc");
    DataTable dt = qb.executePagedDataTable(dga.getPageSize(), dga.getPageIndex());
    dt.decodeColumn("IsValid", HtmlUtil.codeToMapx("Order.IsValid"));
    dt.decodeColumn("HasInvoice", HtmlUtil.codeToMapx("Order.HasInvoice"));
    dt.decodeColumn("Status", HtmlUtil.codeToMapx("Order.Status"));
    DataTable dc =
        new QueryBuilder("select Name,Code from zddistrict Order by Code").executeDataTable();
    Mapx map = dc.toMapx("Code", "Name");
    dt.decodeColumn("Province", map);
    dt.decodeColumn("City", map);
    dt.decodeColumn("District", map);
    dga.bindData(dt);
  }
Beispiel #2
0
  public static void bindRoleList(DataGridAction dga) {
    String searchRoleName = dga.getParam("SearchRoleName");
    QueryBuilder qb = new QueryBuilder("select * from ZDRole");
    qb.append(" where BranchInnerCode like ?", User.getBranchInnerCode() + "%");
    if (StringUtil.isNotEmpty(searchRoleName)) {
      qb.append(" and (RoleCode like ?", "%" + searchRoleName.trim() + "%");

      qb.append(" or RoleName like ?)", "%" + searchRoleName.trim() + "%");
    }
    qb.append(" order by AddTime desc");
    dga.bindData(qb);
  }
Beispiel #3
0
  public static void bindUserList(DataGridAction dga) {
    String searchUserName = dga.getParam("SearchUserName");
    QueryBuilder qb = new QueryBuilder("select * from ZDUser");
    qb.append(" where BranchInnerCode like ?", User.getBranchInnerCode() + "%");
    qb.append(" and UserName <> ?", User.getUserName());
    if (StringUtil.isNotEmpty(searchUserName)) {
      qb.append(" and (UserName like ?", "%" + searchUserName.trim() + "%");

      qb.append(" or realname like ?)", "%" + searchUserName.trim() + "%");
    }
    qb.append(" order by AddTime desc");
    dga.setTotal(qb);
    DataTable dt = qb.executePagedDataTable(dga.getPageSize(), dga.getPageIndex());
    dt.decodeColumn("Status", UserList.STATUS_MAP);
    dga.bindData(dt);
  }
Beispiel #4
0
  public void dealSiteIDTable(String tableName, DataTable dt) throws Exception {
    this.task.setCurrentInfo("正在向表" + tableName + "插入站点数据");
    if (tableName.equalsIgnoreCase("ZCSite")) {
      dealZCSite(dt.getDataRow(0));
    } else {
      SchemaSet set =
          (SchemaSet) Class.forName("com.zving.schema." + tableName + "Set").newInstance();
      if (!tableName.equalsIgnoreCase("ZDMember")) {
        for (int i = 0; i < dt.getRowCount(); ++i) {
          Schema schema =
              (Schema) Class.forName("com.zving.schema." + tableName + "Schema").newInstance();
          DataRow dr = dt.getDataRow(i);
          setSiteIDTableMaxNo(tableName, dr, true);
          schema.setValue(dt.getDataRow(i));
          set.add(schema);
        }

        this.da.insert(set);
      } else {
        Schema schema =
            (Schema) Class.forName("com.zving.schema." + tableName + "Schema").newInstance();
        SchemaColumn[] scs = SchemaUtil.getColumns(schema);
        QueryBuilder qb = new QueryBuilder("select count(1) from " + tableName + " where 1=1 ");
        for (int i = 0; i < scs.length; ++i) {
          if (scs[i].isPrimaryKey()) {
            qb.append(" and " + scs[i].getColumnName() + "=?");
          }
        }
        for (int i = 0; i < dt.getRowCount(); ++i) {
          schema = (Schema) Class.forName("com.zving.schema." + tableName + "Schema").newInstance();
          DataRow dr = dt.getDataRow(i);

          qb.getParams().clear();
          for (int j = 0; j < scs.length; ++j) {
            if (scs[j].isPrimaryKey()) {
              qb.add(dr.get(scs[j].getColumnName()));
            }
          }
          int count = qb.executeInt();
          if (count > 0) setSiteIDTableMaxNo(tableName, dr, false);
          else {
            setSiteIDTableMaxNo(tableName, dr, true);
          }
          schema.setValue(dt.getDataRow(i));
          set.add(schema);
        }

        this.da.deleteAndInsert(set);
      }
    }
  }
Beispiel #5
0
 public static void historyDataBind(DataGridAction dga) {
   QueryBuilder qb =
       new QueryBuilder(
           "select ZCMessage.*,case readFlag when 1 then '已读' else '未读' end as ReadFlagStr,case readFlag when 1 then '' else 'red' end as color from ZCMessage where fromuser=?",
           User.getUserName());
   qb.append(dga.getSortString());
   DataTable dt = qb.executePagedDataTable(dga.getPageSize(), dga.getPageIndex());
   dt.insertColumn("ReadFlagIcon");
   for (int i = 0; i < dt.getRowCount(); ++i) {
     String flag = dt.getString(i, "ReadFlag");
     if (!"1".equals(flag)) dt.set(i, "ReadFlagIcon", "<img src='../Icons/icon037a7.gif'>");
     else {
       dt.set(i, "ReadFlagIcon", "<img src='../Icons/icon037a17.gif'>");
     }
   }
   dga.setTotal(qb);
   dga.bindData(dt);
 }
  public static void processSubmit(HttpServletRequest request, HttpServletResponse response) {
    ZCCustomTableSchema table = new ZCCustomTableSchema();
    table.setID(request.getParameter("_TableID"));
    if (!table.fill()) {
      LogUtil.warn("没有ID为" + table.getCode() + "的表!");
      return;
    }
    if ((!"Y".equals(table.getAllowModify())) && (!User.isManager())) {
      LogUtil.warn("ID为" + table.getID() + "的表不允许前台修改!");
      return;
    }

    DataAccess da = null;
    String code = table.getCode();
    if (table.getType().equals("Link")) {
      da = new DataAccess(OuterDatabase.getConnection(table.getDatabaseID()));
      code = table.getOldCode();
    } else {
      da = new DataAccess();
    }
    try {
      da.setAutoCommit(false);
      ZCCustomTableColumnSet set =
          new ZCCustomTableColumnSchema().query(new QueryBuilder("where TableID=?", table.getID()));
      StringBuffer insertSB = new StringBuffer("insert into " + code + "(");
      QueryBuilder deleteQB = new QueryBuilder("delete from  " + code + " where 1=1 ");
      for (int j = 0; j < set.size(); ++j) {
        if (j != 0) {
          insertSB.append(",");
        }
        insertSB.append(set.get(j).getCode());
      }
      insertSB.append(") values (");
      for (int j = 0; j < set.size(); ++j) {
        if (j != 0) {
          insertSB.append(",");
        }
        insertSB.append("?");
        if ("Y".equals(set.get(j).getIsPrimaryKey())) {
          String v = request.getParameter("_Form_" + set.get(j).getCode() + "_Old");
          deleteQB.append(" and " + set.get(j).getCode() + "=?", v);
        }
      }
      insertSB.append(")");
      QueryBuilder qb = new QueryBuilder(insertSB.toString());
      StringBuffer messageSB = new StringBuffer();
      for (int j = 0; j < set.size(); ++j) {
        ZCCustomTableColumnSchema column = set.get(j);
        String v = request.getParameter("_Form_" + set.get(j).getCode());
        if (StringUtil.isEmpty(v)) {
          v = null;
          if ("Y".equals(set.get(j).getIsAutoID())) {
            v = String.valueOf(OrderUtil.getDefaultOrder());
          }
        }
        if (((("Y".equals(column.getIsMandatory())) || ("Y".equals(column.getIsPrimaryKey()))))
            && (StringUtil.isEmpty(v))) {
          messageSB.append(column.getName() + "不能为空!\\n");
        }

        int dataType = Integer.parseInt(column.getDataType());
        if (v != null) {
          if ((column.getMaxLength() != 0) && (v.length() < column.getMaxLength()))
            messageSB.append(column.getName() + "数据过长,最大允许" + column.getMaxLength() + "个字符!\\n");
          try {
            if (dataType == 0) {
              v = DateUtil.toDateTimeString(DateUtil.parseDateTime(v));
              if (v == null) {
                throw new SQLException("日期时间错误");
              }
            }
            if ((dataType == 8) || (dataType == 9)) {
              v = String.valueOf(new Double(Double.parseDouble(v)).intValue());
            }
            if (dataType == 7) {
              v = String.valueOf(new Double(Double.parseDouble(v)).longValue());
            }
            if (dataType == 5) {
              v = String.valueOf(new Double(Double.parseDouble(v)).floatValue());
            }
            if ((dataType == 4) || (dataType == 6) || (dataType == 3))
              v = String.valueOf(Double.parseDouble(v));
          } catch (Exception e) {
            messageSB.append(column.getName() + "数据不正确!\\n");
          }
        }
        qb.add(v);
      }
      if (messageSB.length() != 0) {
        insertSB = new StringBuffer();
        insertSB.append("<script>");
        insertSB.append("alert(\"" + messageSB + "\");");
        insertSB.append("history.go(-1);");
        insertSB.append("</script>");
        response.getWriter().print(insertSB);
      } else {
        da.executeNoQuery(deleteQB);
        da.executeNoQuery(qb);
        da.commit();
        insertSB = new StringBuffer();
        insertSB.append("<script>");
        insertSB.append("alert(\"提交成功!\");");
        insertSB.append("window.location=\"" + request.getHeader("referer") + "\";");
        insertSB.append("</script>");
        response.getWriter().print(insertSB);
      }
    } catch (Exception e) {
      e.printStackTrace();
      try {
        da.rollback();
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
      StringBuffer sb = new StringBuffer();
      sb.append("<script>");
      sb.append("alert(\"提交失败!\");");
      sb.append("history.go(-1);");
      sb.append("</script>");
      try {
        response.getWriter().print(sb);
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    } finally {
      try {
        da.setAutoCommit(true);
        da.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }