標題 | NC65開發相關代碼 |
---|---|
版本 | 1.0.1 |
做者 | walton |
說明 | 收集NC在平常開發中經常使用的代碼寫法,示例展現 |
1.1 經過BaseDAO查詢結果集並轉換java
//經過BaseDAO進行查詢,並將查詢結果轉換爲列表 SqlBuilder sql = new SqlBuilder(); sql.append(" select "); sql.append(" account.code,accasoa.name,accasoa.name2,accasoa.name3,accasoa.name4,accasoa.name5,accasoa.name6,account.balanorient,accasoa.pk_accasoa,accasoa.endflag"); 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>)this.getBaseDAO().executeQuery(sql.toString(), param, new BeanListProcessor(DiffAccasoaVO.class)); return result;
1.2 經過VOQuery查詢單表對象sql
//查詢條件以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.query(sql.toString(), (String)null);
1.3 經過EfficientBillQuery查詢聚合對象數據庫
SqlBuilder headCond = new SqlBuilder(); headCond.append(" from drugic_priceadjust_h where "); String pkGroup = (String) bgwc.getKeyMap().get("pk_group"); headCond.append("pk_group", pkGroup); headCond.append(" and "); String pkOrg = (String) bgwc.getKeyMap().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.query(headCond.toString());
1.4 經過IUAPQueryBS查詢結果集app
IUAPQueryBS iquery = (IUAPQueryBS)NCLocator.getInstance().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) iquery.executeQuery(sql, new ArrayListProcessor());
1.5 經過IOnhandQry查詢現存量信息ide
OnhandQryCond onhandQryCond = new OnhandQryCond();//構造查詢條件 if(cond.getByBatch()){//能夠根據條件來選擇要查詢的現存量維度字段 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("='") .append(cond.getInvWh()).append("' AND ");// 倉庫 sbSelFields.append(OnhandDimVO.ALIASNAME + ".").append(ICPubMetaNameConst.PK_ORG).append("='") .append(cond.getPk_org()).append("' ");// 庫存組織 if (!cond.getZeroOnhand()) {//添加現存量是否須要大於0的查詢條件 sbSelFields.append(" AND (").append(OnhandNumVO.TABLENAME).append(".nonhandnum <> 0 or ") .append(OnhandNumVO.TABLENAME).append(".nonhandastnum <> 0 ) "); } onhandQryCond.setWhere(sbSelFields.toString()); onhandQryCond.setBinnerWhere(true); try { OnhandVO[] onhandVOs = NCLocator.getInstance().lookup(IOnhandQry.class).queryOnhand(onhandQryCond); if (ValueCheckUtil.isNullORZeroLength(onhandVOs)) { return null; } return onhandVOs;//返回查詢到的現存量信息 } catch (BusinessException e) { ExceptionUtils.wrappException(e); }
1.6 客戶端Client端查詢(不建議使用)ui
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.class,whereSql.toString());
2.1 經過VOUpdate更新單表對象this
//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 = NCLocator.getInstance().lookup(IOnhandUpdate.class); update.modifyOnhandNum(onhandVOs);
3.1 根據model獲取當前選中的表頭表體數據code
AggPriceAdjustHeadVO aggVO = (AggPriceAdjustHeadVO)this.model.getSelectedData(); PriceAdjustHeadVO parentVO = aggVO.getParentVO(); CircularlyAccessibleValueObject[] childVOs = aggVO.getChildrenVO();
3.2 根據model獲取當前選中數據的審批狀態
if(null != getModel().getSelectedData()){ NCObject obj = NCObject.newInstance(getModel().getSelectedData()); if (obj != null) { Integer status = nc.bs.pubapp.pf.util.ApproveFlowUtil.getBillStatus(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 = panel.getBodyPanel().getBillTableAction(0); if (action instanceof AbstractBodyTableExtendAction) { AbstractBodyTableExtendAction addAction = (AbstractBodyTableExtendAction)action; ActionEvent ae = null; ae = new ActionEvent(panel.getBodyPanel().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 ListPaneScaleProcessor(AppContext.getInstance().getPkGroup(),this.getBillListPanel()); 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 CardPaneScaleProcessor(AppContext.getInstance().getPkGroup(),this.getBillCardPanel()); 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_org(headVO.getPk_org()); bodyVO.setPk_accountbook(headVO.getPk_accountingbook()); bodyVO.setPk_voucher(headVO.getPk_voucher()); bodyVO.setPk_detail(headVO.getPk_detail()); bodyVO.setPk_accasoa(headVO.getPk_accasoa()); int row = getCardPanel().getBillModel().getRowCount()-1; this.getCardPanel().getBillModel().setBodyRowVO(bodyVO, row); this.getCardPanel().getBillModel().loadLoadRelationItemValue();
3.9 禁止列表表頭排序
//重寫列表界面的初始化方法,移除監聽 nc.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 screen=Toolkit.getDefaultToolkit.getScreenSize();
4.1 界面彈窗(成功、失敗、警告等)
//彈框提示,能夠選擇多種,根據本身的需求選擇(提示界面標誌flag:{是:4,否:8,取消:2}) nc.ui.pub.beans.MessageDialog.showWarningDlg(null, "選擇提示", "請選擇單據後再點擊執行");
4.2 界面底部提示信息
//在界面底部提示信息 ShowStatusBarMsgUtil.showStatusBarMsg("執行成功!", getModel().getContext()); //在界面底部彈出異常信息,中斷當前操做(會出現失效狀況,可配合上面提示信息使用,終止操做) nc.vo.pubapp.pattern.exception.ExceptionUtils.wrappBusinessException("表體數據爲空時,不能保存。");
4.3 自定義檔案編碼和名稱的惟一性校驗
//能夠在[基礎數據管控模式]節點,配置規則,若是沒法新增規則,可在數據庫中插入數據 select * from bd_uniquerule ; select * from bd_uniquerule_item; 能夠在[基礎數據管控模式]節點中新增一條規則點擊保存後,而後在此方法中進行斷點調試,獲取須要插入的VO信息 nc.impl.bd.config.uniquerule.BDUniqueruleManageServiceImpl.insert(BDUniqueruleVO)
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.1 根據BillCardPanel獲取界面參照類型字段並設置是否可多選
BillItem item = e.getBillCardPanel().getBodyItem(e.getKey()); if (item == null) return; JComponent componen = item.getComponent(); if (componen instanceof UIRefPane){ UIRefPane refPane = (UIRefPane) componen; refPane.setMultiSelectedEnabled(true); }
6.2 獲取參照的值
UIRefPane measdocRef = (UIRefPane) getBillCardPanel().getHeadItem(MaterialVO.PK_MEASDOC).getComponent(); measdocRef.getRefPK(); //主鍵 measdocRef.getRefName(); //名稱 measdocRef.getRefCode(); //編碼
6.3 設置參照過濾條件
//能夠添加在編輯前事件中 UIRefPane refPane=(UIRefPane)billForm.getBillCardPanel().getHeadItem("def2").getComponent(); AbstractRefModel refModel=(AbstractRefModel) refPane.getRefModel(); String wherePart=" and def5='1001H2100000004MJ7SV' ";//Sql以and開頭 refModel.addWherePart(wherePart, false);//第二個參數爲是否刷新該數據 refPane.setMultiCorpRef(false);//設置不能跨組織
6.4 參照選擇後顯示主鍵或編碼,不顯示名稱
- 進入單據模板初始化節點,選擇對應節點的模板並點擊修改 - 進入節點模板,點擊要顯示名稱的參照字段,在左側界面選擇高級屬性 - 選中‘類型設置’行,雙擊值的位置會有一個參照按鈕,點擊參照會彈出一個界面 - 在界面中勾選‘焦點離開後顯示名稱’
7.1 查找多語信息
在NCHOME中找到langlib文件夾,內部有多語jar; 根據所屬模塊,在功能註冊節點中找到對應的編碼(如庫存管理爲ic); 根據模塊編碼找到對應的多語jar; 根據代碼中的resdir信息,找到jar中對應的文件夾;