NC65在⽇常开发中常⽤的代码写法
标题NC65开发相关代码
版本1.0.1
作者walton
说明收集NC在⽇常开发中常⽤的代码写法,⽰例展⽰
1.查询
1.1 通过BaseDAO查询结果集并转换
//通过BaseDAO进⾏查询,并将查询结果转换为列表
SqlBuilder sql = new SqlBuilder();
sql.append(" select ");
sql.append(" de,accasoa.name,accasoa.name2,accasoa.name3,accasoa.name4,accasoa.na
me5,accasoa.name6,account.balanorient,accasoa.pk_dflag"); sql.append(" from BD_ACCASOA accasoa");
sql.append(" inner join BD_ACCOUNT account on accasoa.PK_ACCOUNT = account.PK_ACCOUNT ");
if(subjType != null && subjType.equals(1)){// 查询往来类科⽬
sql.append(" and account.TRAFFICSIGNS = 'Y' ");
}
sql.append(" inner join BD_ACCCHART accchart on accasoa.PK_ACCCHART = accchart.PK_ACCCHART ");
sql.append(" inner join BD_ACCTYPE acctype on account.PK_ACCTYPE = acctype.PK_ACCTYPE ");
if(subjType != null && subjType.equals(2)){ // 查询损益类科⽬
sql.append(" and acctype.TYPE = 1 ");
}
sql.append(" inner join ORG_ACCOUNTINGBOOK book on accchart.PK_ACCCHART = book.PK_CURRACCCHART and book.PK_ACCOUNTINGBOOK =?");
SQLParameter param = new SQLParameter();
param.addParam(pk_accountbook);
// BeanListProcessor 的参数VO不需要元数据,保证Sql查询出的列名与字段名⼀致即可(处理器可在同包下查看)
List<DiffAccasoaVO> result = (List<DiffAccasoaVO>)BaseDAO().String(), param, new BeanListProcessor(DiffAccasoaVO.class));
return result;
1.2 通过VOQuery查询单表对象
//查询条件以and开头,(String)null参数是order的语句,可为空
SqlBuilder sql = new SqlBuilder();
sql.append(" and ");
sql.append(ICPubMetaNameConst.PK_ORG, pk_org);
sql.append(" and ");
sql.append(ICPubMetaNameConst.CMATERIALVID,cmaterialvids);
VOQuery<OnhandDimVO> query = new VOQuery<OnhandDimVO>(OnhandDimVO.class);
query.String(), (String)null);
1.3 通过EfficientBillQuery查询聚合对象
SqlBuilder headCond = new SqlBuilder();
headCond.append(" from drugic_priceadjust_h where ");
String pkGroup = (String) KeyMap().get("pk_group");
headCond.append("pk_group", pkGroup);
headCond.append(" and ");
String pkOrg = (String) KeyMap().get("pk_org");
headCond.append("pk_org", pkOrg);
headCond.append(" and ");
headCond.append("approvestatus", BillStatusEnum.APPROVED.valueIndex());
headCond.append(" and ");
headCond.append("dr", 0);
EfficientBillQuery<AggPriceAdjustHeadVO> query = new EfficientBillQuery<AggPriceAdjustHeadVO>(AggPriceAdjustHeadVO.class);
AggPriceAdjustHeadVO[] vos = (AggPriceAdjustHeadVO[]) query.String());
1.4 通过IUAPQueryBS查询结果集
IUAPQueryBS iquery = (Instance().lookup(IUAPQueryBS.class);
ArrayList list = null;
String sql =" select pk_dept from bd_psnjob where ismainjob ='Y' and pk_psndoc ='"+pk_psndoc+"' and dr = 0 ";
list = (ArrayList) uteQuery(sql, new ArrayListProcessor());
1.5 通过IOnhandQry查询现存量信息
OnhandQryCond onhandQryCond = new OnhandQryCond();//构造查询条件
ByBatch()){//可以根据条件来选择要查询的现存量维度字段
onhandQryCond.addAllSelectFields();
}else{
onhandQryCond.addSelectFields(new String[]{"pk_group", "pk_org",
"cwarehouseid", "cmaterialvid", "cmaterialoid", "castunitid",
"clocationid", "vchangerate",
"cvmivenderid", "ctplcustomerid", "cstateid", "cvendorid",
"cprojectid", "casscustid", "cproductorid", "cffileid", "vfree1",
"vfree2", "vfree3", "vfree4", "vfree5", "vfree6", "vfree7",
"vfree8", "vfree9", "vfree10"});
}
onhandQryCond.setISSum(true);//设置现存量是否求和
StringBuilder sbSelFields = new StringBuilder();
sbSelFields.append(OnhandDimVO.ALIASNAME + ".").append(ICPubMetaNameConst.CWAREHOUSEID).append("='")
.InvWh()).append("' AND ");// 仓库
sbSelFields.append(OnhandDimVO.ALIASNAME + ".").append(ICPubMetaNameConst.PK_ORG).append("='")
.Pk_org()).append("' ");// 库存组织
if (!ZeroOnhand()) {//添加现存量是否需要⼤于0的查询条件
sbSelFields.append(" AND (").append(OnhandNumVO.TABLENAME).append(".nonhandnum <> 0 or ")
.append(OnhandNumVO.TABLENAME).append(".nonhandastnum <> 0 ) ");
}
onhandQryCond.String());
onhandQryCond.setBinnerWhere(true);
try {
OnhandVO[] onhandVOs = Instance().lookup(IOnhandQry.class).queryOnhand(onhand
QryCond);
if (ValueCheckUtil.isNullORZeroLength(onhandVOs)) {
return null;
}
return onhandVOs;//返回查询到的现存量信息
} catch (BusinessException e) {
ExceptionUtils.wrappException(e);
}
1.6 客户端Client端查询(不建议使⽤)
SqlBuilder whereSql = new SqlBuilder();
whereSql.append(MaintensDrugVO.PK_STOCK,this.m_sWhID);
whereSql.append(" and ");
whereSql.append(MaintensDrugVO.PRODUCTNAME, CollectionUtils.setToArray(set));
MaintensDrugVO[] MaintensDrugVOs = (MaintensDrugVO[])HYPubBO_Client.queryByCondition(MaintensDrugVO.String());
2.更新
2.1 通过VOUpdate更新单表对象
//VO中的status必须设置为更新态,可以更新指定字段
VOUpdate<OnhandNumVO> updateOnhand = new VOUpdate<OnhandNumVO>();
onhandNum.setStatus(VOStatus.UPDATED);
updateOnhand.update(onhandNumVOs, new String[]{"nnum1"});
2.1 通过BillUpdate更新单据(聚合对象)
BillUpdate<AggPriceAdjustHeadVO> billUpd = new BillUpdate<>();
billUpd.update(new AggPriceAdjustHeadVO[]{aggVO},new AggPriceAdjustHeadVO[]{originBill});
2.1 通过IOnhandUpdate更新现存量
IOnhandUpdate update = Instance().lookup(IOnhandUpdate.class);
3.界⾯操作
3.1 根据model获取当前选中的表头表体数据
AggPriceAdjustHeadVO aggVO = (SelectedData();
PriceAdjustHeadVO parentVO = ParentVO();
CircularlyAccessibleValueObject[] childVOs = ChildrenVO();
3.2 根据model获取当前选中数据的审批状态
if(null != getModel().getSelectedData()){
NCObject obj = wInstance(getModel().getSelectedData());
if (obj != null) {
Integer status = nc.bs.pubapp.pf.BillStatus(obj);
}
}
3.3 根据条件控制按钮是否可操作性
//按钮的Action中,继承NCAction并重写isActionEnable⽅法是控制按钮是否可操作的⽅法,默认返回true(可以操作)
@Override
protected boolean isActionEnable() {return true}
//----------------------------------------------------------------------
//点击新增,⾃动增⾏(在新增事件--addhandler实现implements IAppEventHandler<AddEvent>)
public void handleAppEvent(AddEvent e) {
BillCardPanel panel = e.getBillForm().getBillCardPanel();
Action action = BodyPanel().getBillTableAction(0);
if (action instanceof AbstractBodyTableExtendAction) {
AbstractBodyTableExtendAction addAction = (AbstractBodyTableExtendAction)action;
ActionEvent ae = null;
ae = new BodyPanel().getTable(), 1234, "AutoLine");
addAction.actionPerformed(ae);
}
}
3.4 根据BillCardPanel动态设置表头表体字段是否为必输项(固定则在单据模板中配置)
getBillCardPanel().getHeadItem(DrugBDInfoVO.PRICE_SALE).setNull(true);
getBillCardPanel().getBodyItem("code").setNull(true);
3.5 根据BillCardPanel获取当前页签及其billModel
String tableCode = getBillCardPanel().getCurrentBodyTableCode();
BillModel billModel = getBillCardPanel().getBillModel(tableCode);
3.6 根据BillCardPanel获取界⾯的聚合对象,返回AggregatedValueObject
需要传⼊三个VO的名字,返回值类型可强制转换
AggregatedValueObject bill = e.getBillCardPanel().getBillValueVO(aggClassName, headClassName, bodyClassName);
3.7 根据BillListPanel或者BillCardPanel处理界⾯精度
//列表界⾯(在界⾯InitUI中加⼊)
ListPaneScaleProcessor scaleProcessor = new Instance().getPkGroup(),BillListPanel());
String[] pricekeys = new String[]{"localdebitamount","localcreditamount","debitamount","creditamount"};
PosEnum pos = PosEnum.head;
scaleProcessor.setPriceCtlInfo(pricekeys, pos, (String)null, "pk_currtype", pos, (String)null);
scaleProcessor.process();
//卡⽚界⾯(在界⾯InitUI中加⼊)
CardPaneScaleProcessor scaleProcessor = new Instance().getPkGroup(),BillCardPanel()); String[] pricekeys = new String[]{"amount"};
PosEnum pos = PosEnum.body;
scaleProcessor.setPriceCtlInfo(pricekeys, pos, (String)null, "currtype", pos, (String)null);
scaleProcessor.process();
3.8 根据BillCardPanel设置表体数据及加载参照显⽰信息(不加载则显⽰主键)
DiffAdjustVO headVO = ((AggDiffAdjustVO)agg).getParentVO();
DiffAdjustBodyVO bodyVO = new DiffAdjustBodyVO();
bodyVO.setPk_Pk_org());
bodyVO.setPk_Pk_accountingbook());
bodyVO.setPk_Pk_voucher());
bodyVO.setPk_Pk_detail());
bodyVO.setPk_Pk_accasoa());
int row = getCardPanel().getBillModel().getRowCount()-1;
3.9 禁⽌列表表头排序
//重写列表界⾯的初始化⽅法,移除监听
panenc.ui.pubapp.uif2app.view.ShowUpableBillListView
public void initUI() {
super.initUI();
getBillListPanel().getHeadTable().removeSortListener();
}
3.10 根据BillCardPanel控制某个单元格是否可编辑
getBillCardPanel().getBillModel().setCellEditable(int row,String key,Boolean editable);
3.11 获取当前屏幕尺⼨
Dimension ScreenSize();
4.窗⼝提⽰
4.1 界⾯弹窗(成功、失败、警告等)
//弹框提⽰,可以选择多种,根据⾃⼰的需求选择(提⽰界⾯标志flag:{是:4,否:8,取消:2})
nc.ui.pub.beans.MessageDialog.showWarningDlg(null, "选择提⽰", "请选择单据后再点击执⾏");
4.2 界⾯底部提⽰信息
//在界⾯底部提⽰信息
ShowStatusBarMsgUtil.showStatusBarMsg("执⾏成功!", getModel().getContext());
//在界⾯底部弹出异常信息,中断当前操作(会出现失效情况,可配合上⾯提⽰信息使⽤,终⽌操作)
nc.vo.ption.ExceptionUtils.wrappBusinessException("表体数据为空时,不能保存。");
4.3 ⾃定义档案编码和名称的唯⼀性校验
//可以在[基础数据管控模式]节点,配置规则,如果⽆法新增规则,可在数据库中插⼊数据
select * from bd_uniquerule ;
select * from bd_uniquerule_item;
可以在[基础数据管控模式]节点中新增⼀条规则点击保存后,然后在此⽅法中进⾏断点调试,获取需要插⼊的VO信息
nc.fig.uniquerule.BDUniqueruleManageServiceImpl.insert(BDUniqueruleVO)
5.单据模板公式
5.1 单据模板根据公式获取值
//公式可以直接获取返回值并赋值给下⼀条语句
pk_onhandim->getcolvalue(IC_ONHANDDIM ,PK_ONHANDDIM ,CMATERIALVID ,code_pd.pk_source );
num1->getcolvalue(IC_ONHANDNUM ,NNUM1 ,PK_ONHANDDIM ,pk_onhandim );//(表名,查询字段,
条件字段,条件值)
price->getcolvalue(drugic_priceadjust_b ,price_before ,pk_priceadjust_b ,pk_priceadjust_b );
iif(price>0 ,price ,num1 );
6.参照
6.1 根据BillCardPanel获取界⾯参照类型字段并设置是否可多选
BillItem item = e.getBillCardPanel().Key());
if (item == null)
return;
JComponent componen = Component();
if (componen instanceof UIRefPane){
UIRefPane refPane = (UIRefPane) componen;
refPane.setMultiSelectedEnabled(true);
}
6.2 获取参照的值
UIRefPane measdocRef = (UIRefPane) getBillCardPanel().getHeadItem(MaterialVO.PK_MEASDOC).getComponent(); RefPK(); //主键
6.3 设置参照过滤条件
//可以添加在编辑前事件中
UIRefPane refPane=(BillCardPanel().getHeadItem("def2").getComponent(); AbstractRefModel refModel=(AbstractRefModel) RefModel();
String wherePart=" and def5='1001H2100000004MJ7SV' ";//Sql以and开头
refModel.addWherePart(wherePart, false);//第⼆个参数为是否刷新该数据
refPane.setMultiCorpRef(false);//设置不能跨组织
6.4 参照选择后显⽰主键或编码,不显⽰名称
- 进⼊单据模板初始化节点,选择对应节点的模板并点击修改
- 进⼊节点模板,点击要显⽰名称的参照字段,在左侧界⾯选择⾼级属性
- 选中‘类型设置’⾏,双击值的位置会有⼀个参照按钮,点击参照会弹出⼀个界⾯
- 在界⾯中勾选‘焦点离开后显⽰名称’
7.其他
7.1 查多语信息
在NCHOME中到langlib⽂件夹,内部有多语jar;
根据所属模块,在功能注册节点中到对应的编码(如库存管理为ic);
根据模块编码到对应的多语jar;
根据代码中的resdir信息,到jar中对应的⽂件夹;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论