NC6 列表界面 和卡片界面 取值工具类

列表界面 取值工具类

package nc.ui.pubapp.util;

import nc.ui.pub.bill.BillItem;
import nc.ui.pub.bill.BillListPanel;
import nc.ui.pub.bill.BillModel;
import nc.ui.pub.bill.IBillItem;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.data.ValueUtils;

/**
 * 列表取值工具类
 */
public class ListPanelValueUtils {

  private BillModel billModel;

  private BillListPanel listPanel;

  public ListPanelValueUtils(BillListPanel billListPanel) {
    this.listPanel = billListPanel;
  }

  public String getBodyStringValueAt(int row, String strKey) {
    Object value = this.getBodyValueAt(row, strKey);
    return ValueUtils.getString(value);
  }

  public UFBoolean getBodyUFBooleanValueAt(int row, String strKey) {
    Object value = this.getBodyValueAt(row, strKey);
    return ValueUtils.getUFBoolean(value);

  }

  /**
   * 
   * 方法功能描述:返回UFDouble类型值。
   * <p>
   * <b>参数说明</b>
   * 
   * @param row
   * @param strKey
   * @return
   *         <p>
   * @author fengjb
   * @time 2010-6-22 下午07:05:21
   */
  public UFDouble getBodyUFDoubleValueAt(int row, String strKey) {
    Object value = this.getBodyValueAt(row, strKey);
    return ValueUtils.getUFDouble(value);
  }

  /**
   * 修正获取表体参照类型值时只能获得显示值,而不能获得真实PK值的Bug
   * 
   * @param row
   * @param strKey
   * @return
   * @return Object
   */
  public Object getBodyValueAt(int row, String strKey) {
    this.billModel = this.listPanel.getBodyBillModel();
    return this.getValueAt(row, strKey);
  }

  public String getHeadStringValueAt(int row, String strKey) {
    Object value = this.getHeadValueAt(row, strKey);
    return ValueUtils.getString(value);

  }

  public UFBoolean getHeadUFBooleanValueAt(int row, String strKey) {
    Object value = this.getHeadValueAt(row, strKey);
    return ValueUtils.getUFBoolean(value);
  }

  public UFDouble getHeadUFDoubleValueAt(int row, String strKey) {
    Object value = this.getHeadValueAt(row, strKey);
    return ValueUtils.getUFDouble(value);
  }

  /**
   * 修正获取表头参照类型值时只能获得显示值,而不能获得真实PK值的Bug
   * 
   * @param row
   * @param strKey
   * @return
   * @return Object
   */
  public Object getHeadValueAt(int row, String strKey) {
    this.billModel = this.listPanel.getHeadBillModel();
    return this.getValueAt(row, strKey);
  }

  /**
   * 
   * 方法功能描述:不带tableCode的setValue方法。
   * <p>
   * <b>参数说明</b>
   * 
   * @param aValue
   * @param row
   * @param strKey
   *          <p>
   * @author fengjb
   * @time 2010-6-22 下午07:25:51
   */
  public void setBodyValueAt(Object aValue, int row, String strKey) {
    this.billModel = this.listPanel.getBodyBillModel();
    this.setValueAt(aValue, row, strKey);
  }

  /**
   * 修正设置表体参照类型值时只能获得显示值,而不能获得真实PK值的Bug
   * 
   * @param aValue
   * @param row
   * @param strKey
   * @param tableCode
   * @return void
   */
  public void setBodyValueAt(Object aValue, int row, String strKey,
      String tableCode) {
    this.billModel = this.listPanel.getBodyBillModel(tableCode);
    this.setValueAt(aValue, row, strKey);
  }

  /**
   * 修正设置表头参照类型值时只能获得显示值,而不能获得真实PK值的Bug
   * 
   * @param aValue
   * @param row
   * @param strKey
   * @return void
   */
  public void setHeadValueAt(Object aValue, int row, String strKey) {
    this.billModel = this.listPanel.getHeadBillModel();
    this.setValueAt(aValue, row, strKey);
  }

  /**
   * 获取正确的itemkey,对于参照型的itemkey,需要增加一个后缀来操作正确值
   * 
   * @param itemKey
   * @return 正确的itemkey
   */
  private String getCorrectItemKey(String itemKey) {
    if (IBillItem.UFREF == this.getItemType(itemKey)) {
      return itemKey + IBillItem.ID_SUFFIX;
    }
    return itemKey;
  }

  /**
   * 获得字段类型
   * 
   * @param itemKey
   * @return 字段类型
   */
  private int getItemType(String itemKey) {
    BillItem billItem = this.billModel.getItemByKey(itemKey);
    return null == billItem ? IBillItem.UNSET : billItem.getDataType();
  }

  private Object getValueAt(int row, String strKey) {
    if (this.listPanel.getBillListData().isMeataDataTemplate()) {
      int colIndex = this.billModel.getBodyColByKey(strKey);
      if (colIndex < 0) {
        return null;
      }
      Object value = this.billModel.getValueAt(row, colIndex);
      BillItem item = this.billModel.getItemByKey(strKey);
      Object trueValue = item.converType(value);
      return trueValue;
    }
    return this.billModel.getValueAt(row, this.getCorrectItemKey(strKey));
  }

  private void setValueAt(Object aValue, int row, String strKey) {
    this.billModel.setValueAt(aValue, row, this.getCorrectItemKey(strKey));
    if (IBillItem.UFREF == this.getItemType(strKey)) {
      this.billModel.loadLoadRelationItemValue(row, strKey);
    }
  }
}

卡片界面 取值工具类

package nc.ui.pubapp.util;

import nc.md.model.MetaDataException;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pub.bill.BillData;
import nc.ui.pub.bill.BillItem;
import nc.ui.pub.bill.BillModel;
import nc.ui.pub.bill.IBillItem;
import nc.ui.pubapp.uif2app.view.util.BillRowNoUtils;
import nc.vo.pub.SuperVO;
import nc.vo.pub.bill.BillTabVO;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.data.ValueUtils;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.model.entity.bill.IBill;
import nc.vo.pubapp.pattern.pub.PubAppTool;
import nc.vo.pubapp.util.MetaUtils;

import org.apache.commons.lang.StringUtils;
/**
* 卡片界面取值工具类
*/
public class CardPanelValueUtils {
  private BillCardPanel card;

  public CardPanelValueUtils(BillCardPanel cardPanel) {
    this.card = cardPanel;
  }

  /**
   * 新增一行并自动加上行号
   * 
   * @param sRowNOKey
   *          行号字段
   * @author 皮之兵
   * @time 2010-2-2 下午04:13:55
   */
  public void addBodyLine(String sRowNOKey) {
    this.card.addLine();
    BillRowNoUtils.addLineRowNo(this.card, sRowNOKey);
  }

  /**
   * 方法功能描述:清空当前页签所有表体行指定字段的值。
   * 
   * @param itemKeys
   * @since 6.0
   * @author tianft
   * @time 2010-9-16 下午06:26:09
   */
  public void clearAllRowValueByItemKeys(String[] itemKeys) {
    this.clearAllRowValueByItemKeys(itemKeys, null);
  }

  /**
   * 清空所有表体行指定字段的值。
   * 
   * @param itemKeys
   *          需要被清空的表体字段数组。
   * @param tableCode
   *          页签,为null时默认当前页签
   * @author 孙伟
   * @time 2010-1-21 下午08:24:49
   */
  public void clearAllRowValueByItemKeys(String[] itemKeys, String tableCode) {
    int rowCount = this.card.getRowCount();
    for (int i = 0; i < rowCount; i++) {
      this.clearRowValueByItemKeys(i, itemKeys, tableCode);
    }
  }

  /**
   * 清空表头、表体指定字段的值。
   * 
   * @param itemKeys
   *          需要被清空的表头、表体字段数组。
   * @author 孙伟
   * @time 2010-1-21 下午08:48:01
   */
  public void clearHeadValueByItemKeys(String[] itemKeys) {
    for (String itemKey : itemKeys) {
      this.setHeadTailValue(itemKey, null);
    }
  }

  /**
   * 清空指定表体行指定字段的值。
   * 
   * @param iRow
   *          行
   * @param itemKeys
   *          需要被清空的表体字段数组。
   * @param tableCode
   *          页签,为null时默认当前页签
   * @author 孙伟
   * @time 2010-1-21 下午08:36:52
   */
  public void clearRowValueByItemKeys(int iRow, String[] itemKeys,
      String tableCode) {
    for (String itemKey : itemKeys) {
      this.setBodyValue(null, iRow, itemKey, tableCode);
    }
  }

  /**
   * 删除所有表体行
   * 
   * @author 皮之兵
   * @time 2010-2-2 下午04:13:55
   */
  public void delBodyLine() {
    int count = this.card.getRowCount();
    int[] rows = new int[count];
    for (int i = 0; i < count; i++) {
      rows[i] = i;
    }
    this.card.getBodyPanel().delLine(rows);
  }

  /**
   * 方法功能描述: 删除指定行索引的行
   * 
   * @param rowindexs
   * @since 6.0
   * @author 皮之兵
   * @time 下午04:50:09
   */
  public void delBodyLine(Integer[] rowindexs) {
    if (rowindexs == null || rowindexs.length == 0) {
      return;
    }
    int[] rows = new int[rowindexs.length];
    for (int i = 0; i < rowindexs.length; i++) {
      rows[i] = rowindexs[i].intValue();
    }
    this.card.getBodyPanel().delLine(rows);
  }

  public String filtSuffix(String porigItemkey) {
    String origItemkey = porigItemkey;
    if (origItemkey != null && origItemkey.indexOf(IBillItem.ID_SUFFIX) >= 0) {
      origItemkey =
          origItemkey.substring(0,
              origItemkey.length() - IBillItem.ID_SUFFIX.length());
    }
    return origItemkey;
  }

  /**
   * 从BillCardPanel中得到单据VO。
   * 
   * @return <p>
   * @author 孙伟
   * @time 2010-1-21 下午08:05:34
   */
  @SuppressWarnings("unchecked")
  public <B extends IBill> B getBillValueVO(Class<B> c) {
    // 此警告等孙伟回来确认后再改
    // for checkstyle start
    c.getClass();
    // for checkstyle end
    return (B) this.card.getBillData().getBillObjectByMetaData();
  }

  /**
   * 获取表体BillItem
   * 
   * @param sItemKey
   *          表体字段
   * @return BillItem
   * @author 皮之兵
   * @time 2010-2-2 下午01:24:20
   */
  public BillItem getBodyItem(String sItemKey) {
    BillItem btTemp = this.card.getBodyItem(sItemKey);
    return btTemp;
  }

  /**
   * 获得表体行字段字符串类型的值。
   * 
   * @param iRow
   *          行
   * @param sItemKey
   *          表体字段
   * @return String 字符串类型返回值。
   * @author 孙伟
   * @time 2010-1-21 下午01:24:59
   */
  public String getBodyStringValue(int iRow, String sItemKey) {
    Object value = this.getBodyValue(iRow, sItemKey, null);
    return ValueUtils.getString(value);
  }

  /**
   * 方法功能描述:返回表体行UFBoolean类型的值。
   * 
   * @param iRow
   * @param sItemKey
   * @time 2010-4-19 下午03:33:32
   */
  public UFBoolean getBodyUFBooleanValue(int iRow, String sItemKey) {
    Object objValue = this.getBodyValue(iRow, sItemKey);
    return ValueUtils.getUFBoolean(objValue);
  }

  /**
   * 方法功能描述:返回表体行UFDouble类型的值。
   * 
   * @param iRow
   * @param sItemKey
   * @time 2010-4-19 下午03:26:34
   */
  public UFDouble getBodyUFDoubleValue(int iRow, String sItemKey) {
    Object objValue = this.getBodyValue(iRow, sItemKey);
    return ValueUtils.getUFDouble(objValue);
  }

  /**
   * 获得表体行字段值。
   * 
   * @param iRow
   *          行
   * @param sItemKey
   *          表体字段
   * @return Object 调用者可根据需要,调用ValueUtils工具类将返回值转化为所需类型。
   * @author 孙伟
   * @time 2010-1-21 下午01:24:59
   */
  public Object getBodyValue(int iRow, String sItemKey) {
    return this.getBodyValue(iRow, sItemKey, null);
  }

  /**
   * 获得表体行字段值。
   * 
   * @param iRow
   *          行
   * @param sItemKey
   *          表体字段
   * @param tableCode
   *          页签,为null时默认当前页签
   * @return Object 调用者可根据需要,调用ValueUtils工具类将返回值转化为所需类型。
   * @author 孙伟
   * @time 2010-1-21 下午01:24:59
   */
  public Object getBodyValue(int rowIndex, String strKey, String tableCode1) {
    String tableCode = tableCode1;
    if (tableCode == null) {
      tableCode = this.card.getCurrentBodyTableCode();
    }
    Object ret = null;
    if (this.card.getBillData().isMeataDataTemplate()) {
      int colIndex = this.card.getBodyColByKey(tableCode, strKey);
      if (colIndex >= 0) {
        Object value =
            this.card.getBillModel(tableCode).getValueAt(rowIndex, colIndex);
        BillItem item = this.card.getBodyItem(tableCode, strKey);
        ret = item.converType(value);
      }
    }
    else {
      ret =
          this.card.getBillModel(tableCode).getValueAt(rowIndex,
              this.getCorrectItemKey(strKey));
    }
    return ret;
    /*
        Object oTemp = null;
        BillItem bt = null;
        if (tableCode != null) {
          bt = this.card.getBodyItem(tableCode, this.filtSuffix(sItemKey));
        }
        else {
          bt = this.card.getBodyItem(this.filtSuffix(sItemKey));
        }
        if (null == bt) {
          return null;
        }
        // IMetaDataProperty meta = bt.getMetaDataProperty();
        // int type = -1;
        // if (meta != null) {
        // type = meta.getAttribute().getDataType().getTypeType();
        // }
        // if (type == IType.REF || type == IType.ENTITY || type ==
        // IType.CUSTOMENTITY
        // || type == IType.ENUM) {
        int dataType = bt.getDataType();
        if (IBillItem.UFREF == dataType || IBillItem.COMBO == dataType) {
          if (tableCode == null) {
            oTemp =
                this.card.getBillModel().getValueAt(iRow,
                    sItemKey + IBillItem.ID_SUFFIX);
          }
          else {
            oTemp =
                this.card.getBillModel(tableCode).getValueAt(iRow,
                    sItemKey + IBillItem.ID_SUFFIX);
          }
        }
        else {
          if (tableCode == null) {
            oTemp = this.card.getBillModel().getValueAt(iRow, sItemKey);
          }
          else {
            oTemp = this.card.getBillModel(tableCode).getValueAt(iRow, sItemKey);
          }
        }
        oTemp = bt.converType(oTemp);
        return oTemp;
        */
  }

  /**
   * 
   * @author 苏建文
   * @param <T>
   * @param row
   * @param clazz
   * @return
   */
  @SuppressWarnings("unchecked")
  public <T extends SuperVO> T getBodyValueVO(int row, Class<T> clazz) {
    return (T) this.card.getBillModel().getBodyValueRowVO(row, clazz.getName());
  }

  /**
   * 从BillCardPanel中得到变化的单据VO。
   * 
   * @author 孙伟
   * @time 2010-1-21 下午08:11:26
   */
  @SuppressWarnings("unchecked")
  public <B extends IBill> B getChangeBillValueVO(Class<B> c) {
    // for checkstyle start
    c.getClass();
    // for checkstyle end
    return (B) this.card.getBillData().getChangeBillObjectByMetaData();
  }

  /**
   * 获取第一个子实体属性对应的BillItem
   * <p>
   * <b>注意:调用此方法的模板必须是元数据模板,同时对应的元数据VO必须是IBill</b>
   * 
   * @param itemkey
   * @return 如果有则返回都应的BillItem,否则返回null
   */
  public BillItem getFirstChildBodyItem(String itemkey) {
    String firstChildTableCode = this.getFirstChildTableCode();
    if (StringUtils.isEmpty(firstChildTableCode)) {
      return null;
    }
    return this.card.getBodyItem(firstChildTableCode, itemkey);
  }

  /**
   * 获取表头表尾BillItem
   * 
   * @param sItemKey
   *          表头或表尾字段
   * @return BillItem
   * @author 皮之兵
   * @time 2010-2-2 下午01:24:20
   */
  public BillItem getHeadTailItem(String sItemKey) {
    BillItem btTemp = this.card.getHeadTailItem(sItemKey);
    return btTemp;
  }

  /**
   * 获得表头、表尾字段字符串类型的值。
   * 
   * @param sItemKey
   *          表头或表尾字段
   * @return String 字符串类型返回值。
   * @author 孙伟
   * @time 2010-1-21 下午01:24:20
   */
  public String getHeadTailStringValue(String sItemKey) {
    BillItem btTemp = this.card.getHeadTailItem(sItemKey);
    if (btTemp == null) {
      return null;
    }
    return ValueUtils.getString(btTemp.getValueObject());
  }

  /**
   * 方法功能描述:返回卡片模板表头表尾UFBoolen类型值。
   * 
   * @param sItemKey
   * @author 冯加滨
   * @time 2010-4-27 上午11:38:41
   */
  public UFBoolean getHeadTailUFBooleanValue(String sItemKey) {
    BillItem headitem = this.card.getHeadTailItem(sItemKey);
    if (null == headitem) {
      return null;
    }
    return ValueUtils.getUFBoolean(headitem.getValueObject());
  }

  /**
   * 获得表头、表尾字段UFDate类型的值。
   * 
   * @param sItemKey
   *          表头或表尾字段
   * @return UFDate UFDate类型返回值。
   * @author 孙伟
   * @time 2010-1-21 下午01:24:20
   */
  public UFDate getHeadTailUFDateValue(String sItemKey) {
    BillItem btTemp = this.card.getHeadTailItem(sItemKey);
    if (btTemp == null) {
      return null;
    }
    return ValueUtils.getUFDate(btTemp.getValueObject());
  }

  /**
   * 方法功能描述:返回表头UFDouble类型的值。
   * 
   * @param iRow
   * @param sItemKey
   * @author liuzwc
   * @time 2010-4-19 下午03:26:34
   */
  public UFDouble getHeadTailUFDoubleValue(String sItemKey) {
    BillItem headitem = this.card.getHeadTailItem(sItemKey);
    if (null == headitem) {
      return null;
    }
    return ValueUtils.getUFDouble(headitem.getValueObject());
  }

  /**
   * 获得表头、表尾字段值。
   * 
   * @param sItemKey
   *          表头或表尾字段
   * @return Object 调用者可根据需要,调用ValueUtils工具类将返回值转化为所需类型。
   * @author 孙伟
   * @time 2010-1-21 下午01:24:20
   */
  public Object getHeadTailValue(String sItemKey) {
    BillItem btTemp = this.card.getHeadTailItem(sItemKey);
    if (btTemp == null) {
      return null;
    }
    return btTemp.getValueObject();
  }

  /**
   * 获取表体行数
   * 
   * @return
   */
  public int getRowCount() {
    return this.card.getRowCount();
  }

  /**
   * 表体字段是否为空。
   * 
   * @param iRow
   *          行
   * @param sItemKey
   *          字段
   * @param tableCode
   *          页签,为null时默认当前页签
   * @author 孙伟
   * @time 2010-1-25 下午04:13:55
   */
  public boolean isBodyItemNull(int iRow, String sItemKey, String tableCode) {
    Object value = this.getBodyValue(iRow, sItemKey, tableCode);
    if (value == null) {
      return true;
    }
    return PubAppTool.isNull(value.toString());
  }

  /**
   * 表头字段是否为空。
   * 
   * @param itemKey
   *          字段
   * @author 孙伟
   * @time 2010-1-25 下午04:13:36
   */
  public boolean isHeadItemNull(String itemKey) {
    Object value = this.getHeadTailValue(itemKey);
    if (value == null) {
      return true;
    }
    return PubAppTool.isNull(value.toString());
  }

  /**
   * 加载表头编辑关联项
   * 
   * @param sItemKey
   */
  public void loadEditHeadRelation(String sItemKey) {
    this.card.getBillData().loadEditHeadRelation(sItemKey);
  }

  /**
   * 方法功能描述:加载卡片元数据关联项。
   * 
   * @author pizb
   * @time 2010-8-5 上午11:27:02
   */
  public void loadLoadRelationItemValue() {
    this.card.getBillModel().loadLoadRelationItemValue();
  }

  public void resetBillData() {
    this.card.setBillData(this.card.getBillData());
  }

  /**
   * 重置卡片面板数据, 恢复面板数据到初始状态,不重置行号
   * 
   * @param rownoKey
   *          行号字段
   * @param tableCode
   *          页签,为null时默认当前页签
   * @author 皮之兵
   * @time 2010-2-2 下午02:08:11
   */
  public void resetCardPanel(String rownoKey, String tableCode) {
    // 重置表头数据
    BillItem[] headItems = this.card.getHeadItems();
    if (headItems != null) {
      for (BillItem item : headItems) {
        item.setValue(item.getDefaultValue());
      }
    }
    // 重置表体数据
    BillItem[] bodyItems = this.card.getBodyItems();
    if (bodyItems != null) {
      for (BillItem item : bodyItems) {
        if (item.getKey().equals(rownoKey)) {
          continue;
        }
        this.setBodyValue(item.getDefaultValue(), item.getKey(), tableCode);
      }
    }
    // 重置表尾数据
    BillItem[] tailItems = this.card.getTailItems();
    if (tailItems != null) {
      for (BillItem item : tailItems) {
        item.setValue(item.getDefaultValue());
      }
    }
  }

  /**
   * 方法功能描述:设置表体所有项不可编辑。
   * 
   * @author pizb
   * @time 2010-7-13 下午08:19:17
   */
  public void setBodyDisable() {
    this.setBillItemDisable(this.card.getBodyItems());
  }

  public void setBodyDisable(int row, String key) {
    this.card.getBillModel().setCellEditable(row, key, false);
  }

  public void setBodyDisable(int row, String[] keys) {
    for (String key : keys) {
      this.setBodyDisable(row, key);
    }
  }

  /**
   * 方法功能描述:设置表体项不可编辑。
   * 
   * @param bodyItemKeys
   * @author pizb
   * @time 2010-7-13 下午08:19:38
   */
  public void setBodyDisable(String[] bodyItemKeys) {
    if (bodyItemKeys == null || bodyItemKeys.length == 0) {
      return;
    }
    for (String itemKey : bodyItemKeys) {
      BillItem item = this.card.getBodyItem(itemKey);
      if (item != null) {
        item.setEdit(false);
      }
    }
  }

  public void setBodyEnable(int row, String key) {
    this.card.getBillModel().setCellEditable(row, key, true);
  }

  public void setBodyEnable(int row, String[] keys) {
    for (String key : keys) {
      this.setBodyEnable(row, key);
    }
  }

  /**
   * 方法功能描述:设置表体项可编辑。
   * 
   * @param bodyItemKeys
   * @author pizb
   * @time 2010-7-13 下午08:19:38
   */
  public void setBodyEnable(String[] bodyItemKeys) {
    if (bodyItemKeys == null || bodyItemKeys.length == 0) {
      return;
    }
    for (String itemKey : bodyItemKeys) {
      BillItem item = this.card.getBodyItem(itemKey);
      if (item != null) {
        item.setEdit(true);
      }
    }
  }

  /**
   * 为表体行字段赋值。
   * 
   * @param value
   *          新的值
   * @param iRow
   *          行
   * @param sItemKey
   *          表体字段
   *          <p>
   * @author 孙伟
   * @time 2010-1-21 下午05:07:11
   */
  public void setBodyValue(Object value, int iRow, String sItemKey) {
    this.setBodyValue(value, iRow, sItemKey, null);
  }

  /**
   * 为表体行字段赋值。
   * 
   * @param value
   *          新的值
   * @param iRow
   *          行
   * @param sItemKey
   *          表体字段
   * @param tableCode
   *          页签,为null时默认当前页签
   *          <p>
   * @author 孙伟
   * @time 2010-1-21 下午05:07:11
   */
  public void setBodyValue(Object value, int iRow, String sItemKey,
      String tableCode) {
    BillModel bm = null;
    if (tableCode == null) {
      bm = this.card.getBillModel();
    }
    else {
      bm = this.card.getBillModel(tableCode);
    }
    if (bm == null) {
      return;
    }

    BillItem bt = bm.getItemByKey(sItemKey);
    if (bt == null) {
      return;
    }

    int dataType = bt.getDataType();
    if (IBillItem.UFREF == dataType || IBillItem.COMBO == dataType) {
      bm.setValueAt(value, iRow, sItemKey + IBillItem.ID_SUFFIX);
      // bm.loadLoadRelationItemValue(iRow, sItemKey);
    }
    else {
      bm.setValueAt(value, iRow, sItemKey);
    }
  }

  /**
   * 为所有表体行指定字段赋值。
   * 
   * @param value
   *          新的值
   * @param sItemKey
   *          表体字段
   *          <p>
   * @author 皮之兵
   * @time 2010-2-2 下午02:03:11
   */
  public void setBodyValue(Object value, String sItemKey) {
    this.setBodyValue(value, sItemKey, null);
  }

  /**
   * 为所有表体行指定字段赋值。
   * 
   * @param value
   *          新的值
   * @param sItemKey
   *          表体字段
   * @param tableCode
   *          页签,为null时默认当前页签
   *          <p>
   * @author 皮之兵
   * @time 2010-2-2 下午02:03:11
   */
  public void setBodyValue(Object value, String sItemKey, String tableCode) {
    BillModel bm = null;
    if (tableCode == null) {
      bm = this.card.getBillModel();
    }
    else {
      bm = this.card.getBillModel(tableCode);
    }
    if (bm == null) {
      return;
    }

    BillItem bt = bm.getItemByKey(sItemKey);
    if (bt == null) {
      return;
    }

    int dataType = bt.getDataType();
    for (int iRow = 0; iRow < this.card.getRowCount(); iRow++) {
      if (IBillItem.UFREF == dataType || IBillItem.COMBO == dataType) {
        bm.setValueAt(value, iRow, sItemKey + IBillItem.ID_SUFFIX);
        // bm.loadLoadRelationItemValue(iRow, sItemKey);
      }
      else {
        bm.setValueAt(value, iRow, sItemKey);
      }
    }
  }

  /**
   * @author 苏建文
   * 
   * @param value
   * @param iRow
   * @param itemkey
   */
  public void setBodyValueForEdit(Object value, int iRow, String itemkey) {
    BillItem item = this.card.getBodyItem(itemkey);
    if (item == null) {
      return;
    }

    // IMetaDataProperty meta = item.getMetaDataProperty();
    // int type = -1;
    String key = itemkey;
    // if (meta != null) {
    // type = meta.getAttribute().getDataType().getTypeType();
    // }
    // if (type == IType.REF || type == IType.ENTITY || type ==
    // IType.CUSTOMENTITY) {
    int dataType = item.getDataType();
    if (IBillItem.UFREF == dataType || IBillItem.COMBO == dataType) {
      key = itemkey + IBillItem.ID_SUFFIX;
    }

    this.card.getBillModel().setValueAt(value, iRow, key);
    this.card.getBillModel().loadLoadRelationItemValue(iRow, key);
    this.card.getBillModel().loadEditRelationItemValue(iRow, itemkey);
  }

  /**
   * @author 苏建文
   * 
   * @param row
   * @param vo
   */
  public void setBodyValueVO(int row, SuperVO vo) {
    this.card.getBillModel().setBodyRowObjectByMetaData(vo, row);
  }

  /**
   * 设置卡片不可编辑。
   * 
   * @author 皮之兵
   * @time 2010-2-2 下午03:13:55
   */
  public void setCardDisabled() {
    this.card.setEnabled(false);
  }

  /**
   * 设置卡片可编辑。
   * 
   * @author 皮之兵
   * @time 2010-2-2 下午03:13:55
   */
  public void setCardEnabled() {
    this.card.setEnabled(true);
  }

  /**
   * 方法功能描述:设置表头表尾所有项不可编辑。
   * 
   * @author pizb
   * @time 2010-7-13 下午08:19:17
   */
  public void setHeadTailDisable() {
    this.setBillItemDisable(this.card.getHeadItems());
    this.setBillItemDisable(this.card.getTailItems());
  }

  /**
   * 方法功能描述:设置表头表尾项不可编辑。
   * 
   * @param headTailItemKeys
   *          <p>
   * @author pizb
   * @time 2010-7-13 下午08:19:17
   */
  public void setHeadTailDisable(String[] headTailItemKeys) {
    if (headTailItemKeys == null || headTailItemKeys.length == 0) {
      return;
    }
    for (String itemKey : headTailItemKeys) {
      BillItem item = this.card.getHeadTailItem(itemKey);

      if (item != null) {
        item.setEdit(false);
      }
    }
  }

  /**
   * 为表头字段赋值。
   * 
   * @param sItemKey
   *          表头字段
   * @param value
   *          要设置的值
   * @author 孙伟
   * @time 2010-1-21 下午05:03:38
   */
  public void setHeadTailValue(String sItemKey, Object value) {
    BillItem item = this.card.getHeadItem(sItemKey);
    if (item == null) {
      item = this.card.getTailItem(sItemKey);
    }

    if (item != null) {
      item.setValue(value);
    }
  }

  /**
   * @author 苏建文
   * 
   * @param sItemKey
   * @param value
   */
  public void setHeadTailValueForEdit(String sItemKey, Object value) {
    BillItem item = this.card.getHeadItem(sItemKey);
    if (item != null) {
      this.card.setHeadItem(sItemKey, value);
    }
    else {
      this.card.setTailItem(sItemKey, value);
    }
    this.card.getBillData().loadEditHeadRelation(sItemKey);
  }

  /**
   * 获取正确的itemkey,对于参照型的itemkey,需要增加一个后缀来操作正确值
   * 
   * @param itemKey
   * @return 正确的itemkey
   */
  private String getCorrectItemKey(String itemKey) {
    if (IBillItem.UFREF == this.getItemType(itemKey)) {
      return itemKey + IBillItem.ID_SUFFIX;
    }
    return itemKey;
  }

  private String getFirstChildTableCode() {
    BillData billData = this.card.getBillData();
    String beanName =
        billData.getBillTempletVO().getHeadVO().getMetadataclass();
    try {
      String firstChildBeanName = MetaUtils.getFirstChildBeanFullName(beanName);
      BillTabVO[] tabVOs = billData.getAllTabVos();
      for (BillTabVO tabVO : tabVOs) {
        if (StringUtils.equals(firstChildBeanName, tabVO.getMetadataclass())) {
          return tabVO.getTabcode();
        }
      }
    }
    catch (MetaDataException e) {
      ExceptionUtils.wrappException(e);
    }
    return null;
  }

  /**
   * 获得字段类型
   * 
   * @param itemKey
   * @return 字段类型
   */
  private int getItemType(String itemKey) {
    BillItem billItem = this.getBodyItem(itemKey);
    return null == billItem ? IBillItem.UNSET : billItem.getDataType();
  }

  /**
   * 方法功能描述:设置单据项不可编辑。
   * 
   * @param items
   * @author pizb
   * @time 2010-8-5 下午12:48:39
   */
  private void setBillItemDisable(BillItem[] items) {
    if (items == null || items.length == 0) {
      return;
    }
    for (BillItem item : items) {
      if (item != null) {
        item.setEdit(false);
      }
    }
  }

  public BillCardPanel getCardPanel() {
	    return this.card;
	  }

}

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值