Exemplo n.º 1
0
  @Override
  public void onDataLoad(DataLoadEvent se) {
    WebSession ses = getGlobalContext().getWebSession();
    String cmd = (String) ses.getAttribute("cmd");
    String pk_message = (String) ses.getAttribute("pk_message");
    LfwWidget widget = getGlobalContext().getPageMeta().getWidget("main");
    Dataset ds = widget.getViewModels().getDataset("msgds");

    /** 初始化数据集 */
    ds.setCurrentKey(Dataset.MASTER_KEY);
    Row row = ds.getEmptyRow();
    ds.addRow(row);
    ds.setSelectedIndex(ds.getRowIndex(row));
    ds.setEnabled(true);

    /** 撰写 */
    if (cmd.equals("compose")) {
      return;
    }
    PtMessageVO vo = null;
    try {
      vo = PortalServiceUtil.getMessageQryService().getMessageByPK(pk_message);
    } catch (PortalServiceException e) {
      LfwLogger.error(e.getMessage(), e);
    }

    if (vo == null || vo.getPk_message() == null) return;

    /** 转发 */
    if (cmd.equals("fwd")) {
      row.setString(ds.nameToIndex("title"), "转发:" + vo.getTitle());
      row.setString(ds.nameToIndex("content"), vo.doGetContent());
    }
    /** 回复 */
    if (cmd.equals("reply")) {
      if (!MCConstant.PERSON_MESSAGE.equals(vo.getSystemcode()))
        throw new LfwRuntimeException("无法回复非私人信息!");
      row.setString(ds.nameToIndex("title"), "回复:" + vo.getTitle());
      row.setString(ds.nameToIndex("pk_user"), vo.getPk_sender());
      row.setString(ds.nameToIndex("username"), vo.getSendername());
    }
  }
Exemplo n.º 2
0
  /**
   * 根据状态转换成相应地记录应答格式,注意,因为如果是删除记录不会返回ajax应答,所以 此处不处理删除状态。
   *
   * @param xmlSb
   * @param pm
   * @param rows
   * @param state
   */
  protected void processRecord(StringBuffer xmlSb, RowData data) {

    StringBuffer rowCountsb = null;
    int size = data.getRowCount();
    for (int i = 0; i < size; i++) {
      Row row = data.getRow(i);
      int fieldCount = row.size();
      rowCountsb = new StringBuffer();

      boolean isEmptyRow = (row instanceof EmptyRow);
      String recordSign = "<" + EventContextConstant.record + "";
      String recordESign = "</" + EventContextConstant.record + ">";
      if (isEmptyRow) {
        recordSign = "<" + EventContextConstant.erecord;
        recordESign = "</" + EventContextConstant.erecord + ">";
      }
      xmlSb.append(recordSign + " id=\"" + row.getRowId() + "\" ");
      if (!isNull(row.getParentId())) xmlSb.append(" parentid=\"" + row.getParentId() + ">");
      else xmlSb.append(">");

      if (!isEmptyRow) {
        String[] startend = getStartEndByState(row.getState());
        xmlSb.append(startend[0]);

        Object value = null;
        for (int j = 0; j < fieldCount; j++) {
          value = row.getValue(j);
          if (value != null) {
            // 处理日期时间类型 dingrf
            if (row.getContent()[j] instanceof UFDate) {
              value = ((UFDate) row.getContent()[j]).getMillis();
            } else if (row.getContent()[j] instanceof UFDateTime) {
              value = ((UFDateTime) row.getContent()[j]).getMillis();
            } else if (row.getContent()[j] instanceof UFLiteralDate) {
              value = ((UFLiteralDate) row.getContent()[j]).getMillis();
            }
            rowCountsb.append(JsURLEncoder.encode(value.toString(), "UTF-8"));
          } else rowCountsb.append(EventContextConstant.NULL);
          if (j < fieldCount - 1) rowCountsb.append(",");
        }
        xmlSb.append(rowCountsb);
        xmlSb.append(startend[1]);

        // dingrf记录本行中发生修改的列索引
        String changedSign = "<" + EventContextConstant.changed + ">";
        String changedESign = "</" + EventContextConstant.changed + ">";
        xmlSb.append(changedSign);
        for (int k = 0; k < row.getChangedIndices().size(); k++) {
          xmlSb.append(row.getChangedIndices().get(k));
          if (k < row.getChangedIndices().size() - 1) xmlSb.append(",");
        }
        xmlSb.append(changedESign);
      }
      xmlSb.append(recordESign + "\n");
    }

    try {
      Method m = RowData.class.getDeclaredMethod("getDeleteRows", new Class[] {});
      m.setAccessible(true);
      Row[] delRows = (Row[]) m.invoke(data, new Object[] {});
      if (delRows != null && delRows.length > 0) {
        for (int i = 0; i < delRows.length; i++) {
          xmlSb.append(
              "<" + EventContextConstant.drecord + " id=\"" + delRows[i].getRowId() + "\"/>");
        }
      }
    } catch (Exception e) {
      LfwLogger.error(e);
    }
  }
Exemplo n.º 3
0
  private void processFormular(Dataset ds) {
    RowData rd = ds.getCurrentRowData();
    if (rd == null) return;
    int rcount = rd.getRowCount();
    List<String> executedFpList = new ArrayList<String>();
    int fieldCount = ds.getFieldSet().getFieldCount();
    for (int i = 0; i < fieldCount; i++) {
      try {
        Field field = ds.getFieldSet().getField(i);
        List<String> fieldFormulars = new ArrayList<String>();
        String formular = field.getEditFormular();
        if (formular != null) fieldFormulars.add(formular);

        formular = field.getLoadFormular();
        if (formular != null) fieldFormulars.add(formular);

        Iterator<String> fit = fieldFormulars.iterator();
        while (fit.hasNext()) {
          formular = fit.next();
          String exp = null;
          if (formular != null) exp = JsURLDecoder.decode(formular, "UTF-8");
          // 如果没有加载公式,继续下一个字段
          if (exp == null) continue;

          if (executedFpList.contains(exp)) continue;
          executedFpList.add(exp);
          String[] expArr = exp.split(";");

          fp.setExpressArray(expArr);
          VarryVO[] varryVOs = fp.getVarryArray();
          if (varryVOs == null || varryVOs.length == 0) continue;
          String[] formularNames = new String[varryVOs.length];

          Map<String, Integer> indexMap = getIndexMap(ds);
          for (int j = 0; j < varryVOs.length; j++) {
            String[] keys = varryVOs[j].getVarry();
            if (keys != null) {
              for (String key : keys) {
                List<Object> valueList = new ArrayList<Object>();
                for (int k = 0; k < rcount; k++) {
                  Row r = rd.getRow(k);
                  //
                  Object value = r.getValue(indexMap.get(key));
                  Field f = ds.getFieldSet().getField(key);
                  if (f != null && value != null) {
                    //										//如果是Double类型,进行一下转换
                    if (StringDataTypeConst.UFDOUBLE.equals(f.getDataType())
                        || StringDataTypeConst.DOUBLE.equals(f.getDataType())
                        || StringDataTypeConst.Decimal.equals(f.getDataType())) {
                      if (!(value instanceof UFDouble)) value = new UFDouble(value.toString());
                    } else if (StringDataTypeConst.INTEGER.equals(f.getDataType())) {
                      if (!(value instanceof Integer)) value = new Integer((String) value);
                    }
                  }
                  valueList.add(value);
                }
                fp.addVariable(key, valueList);
              }
              formularNames[j] = varryVOs[j].getFormulaName();
            }
          }

          Object[][] result = fp.getValueOArray();
          if (result != null) {
            for (int l = 0; l < formularNames.length; l++) {
              int index = ds.nameToIndex(formularNames[l]);
              if (index == -1) {
                LfwLogger.error(
                    "can not find column:" + formularNames[l] + ", ds id:" + ds.getId());
                continue;
              }
              for (int k = 0; k < rcount; k++) {
                Row r = rd.getRow(k);
                r.setValue(index, result[l][k]);
              }
            }
          }
        }
      } catch (Throwable e) {
        Logger.error(e.getMessage(), e);
      }
    }
  }