예제 #1
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);
      }
    }
  }
예제 #2
0
  public static Mapx initDetailDialog(Mapx params) {
    String id = params.getString("ID");
    String Type = params.getString("Type");
    if (StringUtil.isEmpty(id)) {
      return null;
    }
    DataTable dt = new QueryBuilder("select * from ZCMessage where ID=?", id).executeDataTable();
    if ((dt != null) && (dt.getRowCount() > 0)) {
      params.putAll(dt.getDataRow(0).toMapx());
      if ("history".equals(Type)) {
        params.put("UserType", "收");
        params.put("FromUser", "");
      } else {
        params.put("UserType", "发");
        params.put("ToUser", "");

        int readFlag = Integer.parseInt(dt.getDataRow(0).getString("ReadFlag"));
        if (readFlag == 0) {
          new QueryBuilder("update ZCMessage set ReadFlag = 1 where ID=?", id).executeNoQuery();
          QueryBuilder qb =
              new QueryBuilder(
                  "select count(1) from ZCMessage where ReadFlag=0 and ToUser=?",
                  User.getUserName());
          CacheManager.set("Message", "Count", User.getUserName(), qb.executeInt());
        }
      }
    }
    return params;
  }
예제 #3
0
 public static Mapx initReplyDialog(Mapx params) {
   String id = params.getString("ID");
   if (StringUtil.isEmpty(id)) {
     return null;
   }
   DataTable dt = new QueryBuilder("select * from ZCMessage where ID=?", id).executeDataTable();
   if ((dt != null) && (dt.getRowCount() > 0)) {
     return dt.getDataRow(0).toMapx();
   }
   return null;
 }
예제 #4
0
 public static void dg1PrintDataBind(DataGridAction dga) {
   String sql1 = "select * from ZSOrderItem where OrderID = ? order by GoodsID";
   DataTable dt = new QueryBuilder(sql1, dga.getParam("OrderID")).executeDataTable();
   Mapx factoryMap =
       new QueryBuilder(
               "select id,Factory from zsgoods where exists(select * from zsorderitem where orderID = ? and GoodsID = zsgoods.ID)",
               dga.getParam("OrderID"))
           .executeDataTable()
           .toMapx(0, 1);
   dt.insertColumn("Factory");
   for (int i = 0; (dt != null) && (i < dt.getRowCount()); ++i) {
     dt.set(i, "Factory", factoryMap.getString(dt.getString(i, "GoodsID")));
   }
   dga.bindData(dt);
 }
예제 #5
0
 public void dealRelaTable(SiteTableRela.TableRela tr, DataTable dt) throws Exception {
   System.out.println("正在向表" + tr.TableCode + "插入站点数据");
   if (!tr.isExportData) {
     return;
   }
   SchemaSet set =
       (SchemaSet) Class.forName("com.zving.schema." + tr.TableCode + "Set").newInstance();
   for (int i = 0; i < dt.getRowCount(); ++i) {
     Schema schema =
         (Schema) Class.forName("com.zving.schema." + tr.TableCode + "Schema").newInstance();
     DataRow dr = dt.getDataRow(i);
     setRelaTableMaxNo(tr, dr, true);
     schema.setValue(dt.getDataRow(i));
     set.add(schema);
   }
   this.da.insert(set);
 }
예제 #6
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);
 }
예제 #7
0
 public void dataBindAllColumns(DataListAction dla) {
   ZCCustomTableSchema table = new ZCCustomTableSchema();
   table.setSiteID($V("SiteID"));
   table.setCode($V("TableCode"));
   ZCCustomTableSet set = table.query();
   if ((set == null) || (set.size() < 1)) {
     LogUtil.warn("ID为" + table.getSiteID() + "的站点下没有代码为" + table.getCode() + "的表!");
     return;
   }
   table = set.get(0);
   if (!"Y".equals(table.getAllowView())) {
     LogUtil.warn("ID为" + table.getSiteID() + "的站点下代码为" + table.getCode() + "的表不允许前台查看!");
     return;
   }
   DataTable dt = CustomTableUtil.getData(set.get(0), null, dla.getPageSize(), dla.getPageIndex());
   ZCCustomTableColumnSet cset =
       new ZCCustomTableColumnSchema().query(new QueryBuilder("where TableID=?", table.getID()));
   HtmlTR tr = new HtmlTR();
   ArrayList list = new ArrayList();
   for (int i = 0; i < cset.size(); ++i) {
     HtmlTD td = new HtmlTD();
     td.setInnerHTML(cset.get(i).getName());
     tr.addTD(td);
   }
   list.add(tr);
   for (int i = 0; i < dt.getRowCount(); ++i) {
     tr = new HtmlTR();
     for (int j = 0; j < dt.getColCount(); ++j) {
       HtmlTD td = new HtmlTD();
       td.setInnerHTML(dt.getString(i, j));
       tr.addTD(td);
     }
     list.add(tr);
   }
   dt = new DataTable();
   dt.insertColumn("RowHTML");
   for (int i = 0; i < list.size(); ++i) {
     tr = (HtmlTR) list.get(i);
     dt.insertRow(new Object[] {tr.getOuterHtml()});
   }
   dla.setTotal(CustomTableUtil.getTotal(table, "where 1=1"));
   dla.bindData(dt);
 }
예제 #8
0
  public void add() {
    String toUser = $V("ToUser");
    if (!StringUtil.checkID(toUser)) {
      this.Response.setLogInfo(0, "传入参数错误!");
      return;
    }
    String[] userList = toUser.split(",");

    String toRole = $V("ToRole");
    if (!StringUtil.checkID(toRole)) {
      this.Response.setLogInfo(0, "传入参数错误!");
      return;
    }
    String[] roleList = toRole.split(",");

    if (roleList.length > 0) {
      String roleStr = "";
      for (int j = 0; j < roleList.length; ++j) {
        if (StringUtil.isNotEmpty(roleList[j])) {
          if (j == 0) roleStr = roleStr + "'" + roleList[j] + "'";
          else {
            roleStr = roleStr + ",'" + roleList[j] + "'";
          }
        }
      }
      if (StringUtil.isNotEmpty(roleStr)) {
        DataTable dt =
            new QueryBuilder("select UserName from zduserRole where rolecode in (" + roleStr + ")")
                .executeDataTable();
        for (int k = 0; k < dt.getRowCount(); ++k) {
          String userName = dt.getString(k, "UserName");
          if ((!User.getUserName().equals(userName))
              && (!ArrayUtils.contains(userList, userName))) {
            userList = (String[]) ArrayUtils.add(userList, userName);
          }
        }
      }
    }

    if (MessageCache.addMessage($V("Subject"), $V("Content"), userList, User.getUserName()))
      this.Response.setLogInfo(1, "新建成功!");
    else this.Response.setLogInfo(0, "新建失败!");
  }
예제 #9
0
 private void dealCustomTable(DataTable dt, QueryBuilder qb) throws Exception {
   try {
     qb.clearBatches();
     qb.getParams().clear();
     for (int i = 0; i < dt.getRowCount(); ++i) {
       for (int j = 0; j < dt.getColCount() - 1; ++j) {
         String v = dt.getString(i, j);
         if (StringUtil.isEmpty(v)) {
           v = null;
         }
         qb.add(v);
       }
       qb.addBatch();
     }
     this.da.executeNoQuery(qb);
   } catch (Throwable t) {
     t.printStackTrace();
   }
 }
예제 #10
0
 public void dealOneEntry(byte[] bs, Object obj) throws Exception {
   if ((bs == null) || (obj == null)) {
     return;
   }
   if (obj instanceof String) {
     String name = obj.toString();
     if (name.startsWith("File:")) {
       dealFile(name, bs);
     } else if (name.startsWith("CustomTable:")) {
       name = name.substring("CustomTable:".length());
       this.task.setCurrentInfo("正在导入自定义表:" + name);
       DataTable dt = (DataTable) FileUtil.unserialize(bs);
       try {
         if (!this.customTableMap.containsKey(name)) {
           QueryBuilder qb =
               new QueryBuilder(
                   "select * from ZCCustomTableColumn where exists (select ID from ZCCustomTable where SiteID=? and Code=? and Type='Custom' and ZCCustomTableColumn.TableID=ID)",
                   this.newSiteID,
                   name);
           DataTable cdt = this.da.executeDataTable(qb);
           SchemaColumn[] scs = new SchemaColumn[cdt.getRowCount()];
           for (int j = 0; j < scs.length; ++j) {
             DataRow cdr = cdt.getDataRow(j);
             int type = Integer.parseInt(cdr.getString("DataType"));
             SchemaColumn sc =
                 new SchemaColumn(
                     cdr.getString("Code"),
                     type,
                     j,
                     cdr.getInt("Length"),
                     0,
                     "Y".equals(cdr.getString("isMandatory")),
                     "Y".equals(cdr.getString("isPrimaryKey")));
             scs[j] = sc;
           }
           TableCreator tc = new TableCreator(this.da.getConnection().getDBConfig().DBType);
           tc.createTable(scs, name, true);
           tc.executeAndClear(this.da.getConnection());
           this.customTableMap.put(name, "");
           StringBuffer sb = new StringBuffer("insert into " + name + "(");
           for (int j = 0; j < cdt.getRowCount(); ++j) {
             if (j != 0) {
               sb.append(",");
             }
             sb.append(cdt.get(j, "Code"));
           }
           sb.append(") values (");
           for (int j = 0; j < cdt.getRowCount(); ++j) {
             if (j != 0) {
               sb.append(",");
             }
             sb.append("?");
           }
           sb.append(")");
           this.insertQB = new QueryBuilder(sb.toString());
           this.insertQB.setBatchMode(true);
         }
         dealCustomTable(dt, this.insertQB);
       } catch (Exception e) {
         LogUtil.warn("未成功导入表" + name);
         e.printStackTrace();
       }
     } else {
       dealSiteIDTable(name, (DataTable) FileUtil.unserialize(bs));
     }
   } else {
     dealRelaTable((SiteTableRela.TableRela) obj, (DataTable) FileUtil.unserialize(bs));
   }
 }