NC65参照多选
nc65的参照多选主要有两个问题,两种情况。
两个问题分别是如何显示、如何保存。
两种情况分别是表体参照多选还是表头参照多选。
情况一:表头参照多选
首先在单据编辑前事件里为相应字段开启参照多选
if ("ywbq".equals(key)){
BillItem item = cpanel.getBodyItem(key);
UIRefPane ref = (UIRefPane) item.getComponent();
ref.setMultiSelectedEnabled(true);//设置可以多选
ref.setNotLeafSelectedEnabled(false);//不允许选择非末级
}
然后在BillFrom显示类中处理显示问题
AggregatedValueObject billVO = (AggregatedValueObject)getModel().getSelectedData();
if(null!=billVO){
String pks = PuPubVO.getString_NullAsValue( billVO.getParentVO().getAttributeValue("def11"));
if(null!=pks&&pks.contains(",")){
String[] pkstr = pks.split(",");
UIRefPane buildrefPene =(UIRefPane) getBillCardPanel().getHeadItem("def11").getComponent();
buildrefPene.setPKs(pkstr);
DefaultConstEnum buildrefEnum = new DefaultConstEnum(pkstr, buildrefPene.getRefShowName());
getBillCardPanel().getBillModel().setValueAt(buildrefEnum, 0, "def11");
}
}
最后在保存动作里面处理保存问题
String transi_type = PuPubVO.getString_NullAsValue(quipvo.getParentVO()
.getTransi_type());
if (null != transi_type) {
UIRefPane panel = (UIRefPane) getBillCardPanel().getHeadItem(
"def11").getComponent();
String[] splitVos = (String[]) panel.getRefPKs();
if (splitVos != null && splitVos.length > 0) {
String houseTemp = "";
String strTemp1 = "";
for (int i = 0; i < splitVos.length; i++) {
if (!strTemp1.equals((String) splitVos[i]))
houseTemp = houseTemp + (String) splitVos[i] + ",";
strTemp1 = (String) splitVos[i];
}
houseTemp = houseTemp.substring(0, houseTemp.length() - 1);
quipvo.getParentVO().setDef11(houseTemp);
}
}
情况二:表体参照多选
同样在单据编辑前事件里为相应字段开启参照多选,不同的地方是得增加一个假列设置相应参照,用于展示,真列设置字符格式,用于存值。比如:
假列是[物料A,物料B],真列是[主键1,主键2]。
为什么要这样呢?因为表体的情况,如果只用一个字段来处理的话,会遇到一些无法解决的奇葩问题,至于什么问题这里就不描述了。
设置了参照多选后,要在编辑后作相应处理,也就是一个存值,一个展示:
// 业务标签多选
if ("ywbq".equals(key)) {
UIRefPane ref = (UIRefPane) cpanel.getBodyItem(key).getComponent();
String[] pks = ref.getRefPKs();
StringBuffer sbf = new StringBuffer();
// 处理PK
if (pks == null || pks.length <= 0) {
sbf.append(",");
} else {
for (int i = 0; i < pks.length; i++) {
sbf.append(pks[i]+",");
}
}
ref.setPKs(pks);
DefaultConstEnum refEnum = new DefaultConstEnum(sbf.toString().substring(0, sbf.toString().length()-1), ref.getRefShowName());
cpanel.setBodyValueAt(refEnum, e.getRow(), "ywbq","id_turnaroundbodyvo");
cpanel.setBodyValueAt(sbf.toString().substring(0, sbf.toString().length()-1), e.getRow(), "def17","id_turnaroundbodyvo");
}
这样,在编辑后就能就能实现多选和多展示了,但是如果是查询没有触发编辑后事件呢,那就要在显示类里面做文章了:
/**
* 展示参照多选
*/
private void showdef17() {
BillManageModel model = (BillManageModel) getModel();
boolean flag = getModel().getUiState() == UIState.EDIT || getModel().getUiState() == UIState.ADD;
if (flag) {
return;
}
AggregatedValueObject billVO = (AggregatedValueObject) model
.getSelectedData();
if (null != billVO) {
int length = billVO.getChildrenVO().length;
for (int i = 0; i < length; i++) {
String pks = PuPubVO.getString_NullAsValue(billVO
.getChildrenVO()[i].getAttributeValue("def17"));
if (null != pks && pks.contains(",")) {
String[] pkstr = pks.split(",");
UIRefPane buildrefPene = (UIRefPane) getBillCardPanel()
.getBodyItem("ywbq").getComponent();
buildrefPene.setPKs(pkstr);
DefaultConstEnum buildrefEnum = new DefaultConstEnum(pkstr,
buildrefPene.getRefShowName());
getBillCardPanel().getBillModel().setValueAt(buildrefEnum,
i, "ywbq");
}else{
UIRefPane buildrefPene = (UIRefPane) getBillCardPanel()
.getBodyItem("ywbq").getComponent();
buildrefPene.setPKs(new String[]{pks});
DefaultConstEnum buildrefEnum = new DefaultConstEnum(new String[]{pks},
buildrefPene.getRefShowName());
getBillCardPanel().getBillModel().setValueAt(buildrefEnum,
i, "ywbq");
}
}
}
}
完成后,字段存在真列里,展示则用假列,就可以完美实现需求了。