NC65项目表头编辑项目类型后,会隐藏自定义项字段,需要哪个项目类型显示哪些自定义字段的处理方法
代码逻辑:
package nc.ui.pmpub.project.handler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import nc.bs.framework.common.NCLocator;
import nc.bs.uif2.BusinessExceptionAdapter;
import nc.impl.pub.util.db.StringUtil;
import nc.itf.org.IOrgConst;
import nc.itf.pmpub.pub.IProjectTypeQueryService;
import nc.ui.pm.uap.handler.DefaultHeadAfterEditHandler;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pub.bill.BillItem;
import nc.ui.pub.bill.BillItemPropertyChangeEvent;
import nc.ui.pub.bill.IBillItem;
import nc.ui.pubapp.uif2app.event.card.CardHeadTailAfterEditEvent;
import nc.vo.logging.Debug;
import nc.vo.pmpub.common.utils.BillCardPanelUtil;
import nc.vo.pmpub.common.utils.ListUtil;
import nc.vo.pmpub.common.utils.PsnAndDeptUtil;
import nc.vo.pmpub.project.IProjectConst;
import nc.vo.pmpub.project.ProjectHeadVO;
import nc.vo.pmpub.projecttype.ProjectTypeBodyVO;
import nc.vo.pmpub.uap.currency.CurrencyUtils;
import nc.vo.pub.BusinessException;
import org.apache.commons.lang.StringUtils;
/**
* 项目表头编辑后
*
*/
public class HeadTailAfterEditEventHandler extends DefaultHeadAfterEditHandler {
BillCardPanel billCardPanel;
private Map<String, Boolean> defNullInfo = new HashMap<String, Boolean>();
@Override
public void handleAppEvent(CardHeadTailAfterEditEvent e) {
billCardPanel = e.getBillCardPanel();
if (ProjectHeadVO.PK_PROJECTCLASS.equals(e.getKey())) {
this.afterProjectType(e);
}
if (ProjectHeadVO.PK_DUTY_ORG_V.equals(e.getKey())) {
billCardPanel.getHeadItem(ProjectHeadVO.PK_DUTY_DEPT).setValue(null);
billCardPanel.getHeadItem(ProjectHeadVO.PK_DUTY_DEPT_V).setValue(null);
billCardPanel.getHeadItem(ProjectHeadVO.PK_DUTIER).setValue(null);
// 得到项目组织
String pk_duty_org = BillCardPanelUtil.getHeadStringValue(billCardPanel, ProjectHeadVO.PK_DUTY_ORG);
if (StringUtil.isNotEmpty(pk_duty_org)) {
String pk_currtype = CurrencyUtils.getLocalCurrencyPK4Project(pk_duty_org);
BillCardPanelUtil.setHeadValue(billCardPanel, ProjectHeadVO.PK_CURRTYPE, pk_currtype);
}
}
if (ProjectHeadVO.PK_DUTIER.equals(e.getKey())) {
String pk_org = BillCardPanelUtil.getHeadStringValue(this.getBillCardPanel(), ProjectHeadVO.PK_ORG);
String pk_group = BillCardPanelUtil.getHeadStringValue(this.getBillCardPanel(), ProjectHeadVO.PK_GROUP);
String pk_duty_dept = BillCardPanelUtil.getHeadStringValue(this.getBillCardPanel(), ProjectHeadVO.PK_DUTY_DEPT);
if (StringUtil.isEmpty(pk_duty_dept)) {
if (pk_org.equals(pk_group) || IOrgConst.GLOBEORG.equals(pk_org)) {
// 人员主键
String pk_person = BillCardPanelUtil.getHeadStringValue(this.getBillCardPanel(), ProjectHeadVO.PK_DUTIER);
if (StringUtil.isNotEmpty(pk_person)) {
PsnAndDeptUtil.setPk_deptByPk_person_Group(this.getBillCardPanel(), ProjectHeadVO.PK_DUTY_ORG, ProjectHeadVO.PK_DUTIER, ProjectHeadVO.PK_DUTY_DEPT);
}
} else {
PsnAndDeptUtil.setPk_deptByPk_person_Group(this.getBillCardPanel(), ProjectHeadVO.PK_ORG, ProjectHeadVO.PK_DUTIER, ProjectHeadVO.PK_DUTY_DEPT);
}
}
}
}
/**
* 项目类型改变以后
*
* @param e <br>
* 说明:先隐藏用户自定义项,再显示类型中勾选的自定义项</br>
*/
private void afterProjectType(CardHeadTailAfterEditEvent e) {
if (e.getValue() != null) {
String pk = (String) e.getValue();
List<String> strKeyList = new ArrayList<String>();
for (int i = 1; i <= IProjectConst.PROJECTDEF_NUM; i++) {
// 清空值
BillItem item = this.getBillCardPanel().getHeadItem(IProjectConst.PROJECT_PRESTR + i);
if (item == null) {
continue;
}
item.setValue(null);
// 再隐藏
strKeyList.add(IProjectConst.PROJECT_PRESTR + i);
}
this.getBillCardPanel().hideHeadItem(strKeyList.toArray(new String[0]));
this.setDefBillItems(pk);
}
}
/** 通过项目类型过滤项目自定义项 */
private void setDefBillItems(String pk_projectclass) {
ProjectTypeBodyVO[] bodyvos = null;
if (StringUtils.isNotEmpty(pk_projectclass)) {
bodyvos = this.queryProjectType(pk_projectclass);//查询哪些自定义字段可以显示,查询不到数据,则没有可显示的字段。
}
// 更新用户自定义项显示
// 清除显示
this.hideUserDefItems();
// 更新显示
for (int i = 0; i < bodyvos.length; i++) {
String[] strKeys = new String[1];
if (bodyvos[i].getPreindex() != 0) {
strKeys[0] = IProjectConst.PROJECT_PRESTR + bodyvos[i].getPreindex();
this.getBillCardPanel().showHeadItem(strKeys);
BillItem item = this.getBillCardPanel().getHeadItem(strKeys[0]);
// 必填
item.setNull(defNullInfo.get(item.getKey()) == null ? false : defNullInfo.get(item.getKey()));
if (item.getDataType() == IBillItem.UFREF) {
// 非末级节点不可选
item.getRefTypeSet().setNotLeafSelected(false);
if (item.getBillItemPropertyChangeListener() != null) {
BillItemPropertyChangeEvent ent = new BillItemPropertyChangeEvent(this, BillItemPropertyChangeEvent.NOT_LEAF_SELECTED);
item.getBillItemPropertyChangeListener().propertyChange(ent);
}
}
}
this.getBillCardPanel().showHeadItem(strKeys);
}
}
/**
* 隐藏用户自定义项
*/
protected void hideUserDefItems() {
String[] strKey = new String[IProjectConst.PROJECTDEF_NUM];
for (int i = 1; i <= IProjectConst.PROJECTDEF_NUM; i++) {
// 清空值 (修改后要清空值)
BillItem item = this.getBillCardPanel().getHeadItem(IProjectConst.PROJECT_PRESTR + i);
if (null != item) {
if (defNullInfo.get(item.getKey()) == null) {
defNullInfo.put(item.getKey(), item.isNull());
}
item.setNull(false);
}
// 再隐藏
strKey[i - 1] = IProjectConst.PROJECT_PRESTR + i;
}
if (strKey.length > 0) {
List<String> list = new ArrayList<String>();
for (String key : strKey) {
if (this.getBillCardPanel().getHeadItem(key) != null) {
list.add(key);
}
}
if (!ListUtil.isEmpty(list)) {
this.getBillCardPanel().hideHeadItem(ListUtil.toArray(list));
}
}
}
/**
* 查询项目类型表体
*
* @param pk_projecttype
* @return
*/
private ProjectTypeBodyVO[] queryProjectType(String pk_projecttype) {
ProjectTypeBodyVO[] bodyVOS = null;
try {
bodyVOS = NCLocator.getInstance().lookup(IProjectTypeQueryService.class).queryProjectTypeBodyVOsByHeadPK(pk_projecttype);
} catch (BusinessException e) {
Debug.error(e.getMessage());
throw new BusinessExceptionAdapter(e);
}
return bodyVOS;
}
public BillCardPanel getBillCardPanel() {
return billCardPanel;
}
}
package nc.impl.pmpub.projecttype;
import java.util.Collection;
import nc.itf.pmpub.pub.IProjectTypeQueryService;
import nc.md.persist.framework.IMDPersistenceQueryService;
import nc.md.persist.framework.MDPersistenceService;
import nc.vo.pmpub.projecttype.ProjectTypeBodyVO;
import nc.vo.pub.BusinessException;
/**
* 项目类型查询接口后台实现
* 即查询哪些自定义字段可以显示,查询不到数据,则没有可显示的字段。
* @author
*
*/
public class ProjectTypeQueryServiceImpl implements IProjectTypeQueryService{
@Override
public ProjectTypeBodyVO[] queryProjectTypeBodyVOsByHeadPK(String pk) throws BusinessException {
String whereConStr = null;
whereConStr = ProjectTypeBodyVO.PK_PROJECTCLASS + "= '" + pk + "'";
IMDPersistenceQueryService service = MDPersistenceService.lookupPersistenceQueryService();
Collection<ProjectTypeBodyVO> col = service.queryBillOfVOByCond(ProjectTypeBodyVO.class, whereConStr, false);
return col.toArray(new ProjectTypeBodyVO[0]);
}
}
处理方式:
1、首先在用户自定义属性设置节点的项目自定义属性设置需要显示的字段,如下图:
2、在项目类型节点,选择对应的项目类型,修改,然后勾选需要显示的项目自定义属性,保存即可。如下图,不勾选和勾选后的效果对比。
不勾选:
勾选后: