本文本主要描述了一系列在软件界面加载时(onload)执行的常用代码片段,包括执行SQL查询、界面关闭操作、设置UI组件属性(如按钮文本、标题、界面大小等)、处理分页显示、设置数据库连接及查询、以及分录(明细)行的各种操作(如过滤、编辑停止时的联动更新、添加按钮等)。此外,还涉及了编辑界面刷新数据、关闭窗口处理以及通过代码在表格上添加按钮等功能的实现。整体上,这些代码展示了在软件开发中,特别是在基于BOS(金蝶业务操作系统)的ERP系统中,用户界面层(UI)的初始化和交互逻辑的实现。
/*************************************** onload常用代码 ************************************************/
SQLExecutorFactory.getRemoteInstance("/*dialect*/ ".intern() + sql.toString()).executeSQL(); //只查询不执行,返回的是结果集。
DbUtil.execute(ctx, sql1); // 执行sql;
this.uiWindow.close(); // 关闭界面
actionExitCurrent_actionPerformed(e); // 关闭界面.(调用右上角X按钮事件)
Distinct sql查询时去重复 /*dialect*/ sql方言
fauditTime={ts'"+date+"'}" // BOS KSQL日期格式
pkDateTo.setDatePattern("yyyy-MM-dd 23:59:59");
this.setUITitle("投保单"); //设置界面标题(list、edit)
kdtEntrys_detailPanel.setTitle("费用明细"); // 设置分录标题
btnCreateICBill.setText("生成索赔单"); //设置按钮名字
if(getOprtState().equals("VIEW") && UIRuleUtil.isNotNull(getUIContext().get("this"))){
oEdit = (OutInsuranceManageEditUI)getUIContext().get("this");
}
this.setPreferredSize(new Dimension(1000,600)); //界面打开的大小
chkMenuItemSubmitAndAddNew.setSelected(false); //设置提交后是否清空界面
ctx.put("CHECK_DATAPERMISSION", false);//不检查权限
BOSObjectType bosType = BOSUuid.read(sourceId).getType();
kdtEntrys_detailPanel.getAddNewLineButton().setVisible(false); //设置分录按钮隐藏
MetaDataLoaderFactory.getRemoteMetaDataLoader().getEntity(info.getId().getType()).getTable(); //通过实体获取表名
String tableName = FMIsqlFacadeFactory.getLocalInstance(ctx).getTableNameByBosType(bosType); //通过BOSType获取表名
kdtable.getRow(i).setChange(true); //table空白行也保存
OrgSwitchFacadeFactory.getLocalInstance(ctx).orgSwitch(company.getId().toString()); //组织切换(app下代码处理)
this.kDTabbedPane1.setSelectedIndex(0); //指定显示第一个页签
this.prmtCompany.setEnabledMultiSelection(true); //设置F7多选
prmtsupplier.setQueryInfo("com.kingdee.eas.rj.customersrv.basedata.app.SupplierNewQuery"); 设置供应商格式
RjUtils.setSupplierNewF7(prmtsupplier);
UserInfo userInfo = SysContext.getSysContext().getCurrentUserInfo(); // 客户端获取当前登录人
UserInfo userInfo = ContextUtil.getCurrentUserInfo(ctx); //服务端获取当前登录人
pluginCtx.getKDComboBox("").setSelectedIndex(1); DEP枚举默认值的设置
this.kdtEntrys.removeKDTMouseListener(this.kdtEntrys.getSortMange());//屏蔽分录双击排序功能 所有列
tblMain.getColumn(i).setSortable(false); //屏蔽分录双击排序功能 单个
KDTableHelper.autoFitColumnWidth(tblMain, i); //列宽度自适应
txtNumber.requestFocusInWindow(); //获取鼠标焦点
//获取编码规则
ICodingRuleManager ICodingRuleManager = CodingRuleManagerFactory.getLocalInstance(ctx);
String[] DLNumber= ICodingRuleManager.getBatchNumber(new
DeviceLedgerInfo(),
ContextUtil.getCurrentOrgUnit(ctx).getId().toString(),
proInfo.getEntrys().size());
BosUtils.getTableName(ctx, billId) //根据id获取表名
String requestUrl = UIRuleUtil.getString(ParamManager.getParamValue(ctx,new ObjectUuidPK("00000000-0000-0000-0000-000000000000CCE7AED4"), "requestUrl"));//获取系统参数参数
系统化菜单表:t_bas_sysmenuitem
客户化菜单表:t_pm_mainmenuitem
扩展报表存储表:T_BAS_definereport
分录汇总显示
@Override protected void setTableToSumField() { super.setTableToSumField(kdtProduction, new String[] { "originaValue@#,###.00", "netValue@#,###.00", "tolMonthDepreciable@#,###.00", "monthDepreciable@#,###.00" }); }
合并这两个EntityViewInfo
EntityViewInfo view1 = new EntityViewInfo(); EntityViewInfo view2 = new EntityViewInfo(); view1.getFilter().mergeFilter(view2.getFilter(), "and");
//服务端获取当前登陆语言:
String nameFld = "FName_" + ctx.getLocale().getLanguage() + " ";
//服务端获取获取数据库链接:
Connection con = EJBFactory.getConnection(ctx);
Statement stmt = con.createStatement();
/*************************************** onload常用代码 ************************************************/
/*************************************** 分录中F7过滤 ************************************************/
final KDBizPromptBox kdtPaymentObject_supplier_PromptBox = new KDBizPromptBox(); kdtPaymentObject_supplier_PromptBox.setQueryInfo("com.kingdee.eas.rj.customersrv.basedata.app.SupplierNewQuery"); kdtPaymentObject_supplier_PromptBox.setVisible(true); kdtPaymentObject_supplier_PromptBox.setEditable(true); String suppIDS = ""; for(int i=0;i<kdtPaymentObject.getRowCount();i++){ IRow row = kdtPaymentObject.getRow(i); SupplierInfo suppInfo = (SupplierInfo) row.getCell("supplier").getValue(); if(UIRuleUtil.isNotNull(suppInfo)){ suppIDS += suppInfo.getId().toString()+","; } } if(UIRuleUtil.isNotNull(suppIDS)){ suppIDS = suppIDS.substring(0, suppIDS.length()-1); } EntityViewInfo ev = new EntityViewInfo(); FilterInfo filter = new FilterInfo(); filter.getFilterItems().add(new FilterItemInfo("id",suppIDS,CompareType.NOTINCLUDE)); ev.setFilter(filter); kdtPaymentObject_supplier_PromptBox.setEntityViewInfo(ev); kdtPaymentObject_supplier_PromptBox.setDisplayFormat("$number$"); kdtPaymentObject_supplier_PromptBox.setEditFormat("$number$"); kdtPaymentObject_supplier_PromptBox.setCommitFormat("$number$"); KDTDefaultCellEditor kdtPaymentObject_supplier_CellEditor = new KDTDefaultCellEditor(kdtPaymentObject_supplier_PromptBox); this.kdtPaymentObject.getColumn("supplier").setEditor(kdtPaymentObject_supplier_CellEditor); ObjectValueRender kdtPaymentObject_supplier_OVR = new ObjectValueRender(); kdtPaymentObject_supplier_OVR.setFormat(new BizDataFormat("$name$"));
/*************************************** 分录中一项变化带出另一项 ************************************************/
@Overrideprotected void kdtEntrys_editStopped(KDTEditEvent e) throws Exception {super.kdtEntrys_editStopped(e);int rowIndex = kdtEntrys.getSelectManager().getActiveRowIndex();if(e.getColIndex()==kdtEntrys.getColumnIndex("expenseItem")){ExpenseItemDataInfo itemInfo = (ExpenseItemDataInfo) kdtEntrys.getCell(rowIndex,"expenseItem").getValue();kdtEntrys.getCell(rowIndex,"expenseType").setValue(com.kingdee.bos.ui.face.UIRuleUtil.getString(com.kingdee.bos.ui.face.UIRuleUtil.getProperty((com.kingdee.bos.dao.IObjectValue)kdtEntrys.getCell(rowIndex,"expenseItem").getValue(),"treeid.name")));//ExpenseItemDataTreeInfo treeInfo = ExpenseItemDataTreeFactory.getRemoteInstance().getExpenseItemDataTreeInfo("where id='"+itemInfo.getTreeid().getId().toString()+"'");//kdtEntrys.getCell(rowIndex,"expenseType").setValue(treeInfo.getName());}}
/*************************************** 分按钮监听 ************************************************/
kdtPaymentObject_detailPanel.addRemoveListener(new IDetailPanelListener(){public void afterEvent(DetailPanelEvent paramDetailPanelEvent) throws Exception {claimantTotal();}public void beforeEvent(DetailPanelEvent paramDetailPanelEvent) throws Exception {} });
/*************************************** onload常用代码 ************************************************/
/** * 分录统计行 */@Overrideprotected void setTableToSumField() {super.setTableToSumField();setTableToSumField(kdtEntrys, new String[] {"insuranceAmount","**"});}
/*************************************** 编辑界面刷新数据 ************************************************/
public void refreshSelf() {if(STATUS_ADDNEW.equals(this.oprtState)){return;}try {ObjectUuidPK pk = new ObjectUuidPK(editData.getId());IObjectValue objValue = getValue(pk);setDataObject(objValue);loadFields();getUIContext().put(UIContext.ID, pk);getUIContext().put(UIContext.INIT_DATAOBJECT, objValue);} catch (Exception e) {handUIException(e);}}
/*************************************** 关闭窗口************************************************/
/** * 关闭窗口 */ @Override public boolean destroyWindow() { return super.destroyWindow(); }
分录上添加按钮
/** * 在KDTable添加button * @param table * @param button */ public static void addButtonToHMDEntry(KDTable table, KDWorkButton button) { if (table.getParent() == null || table.getParent().getParent() == null) return; // 隐藏按钮 Component c = table.getParent().getParent(); if (c instanceof DetailPanel) { JPanel panel = (JPanel) c; JPanel controlPanel = null; // 获取controlPanel Component[] components = panel.getComponents(); for (int i = 0; i < components.length; i++) { Component component = components[i]; if ("controlPanel".equals(component.getName())) { controlPanel = (KDPanel) component; } } // 添加btn if (controlPanel != null) { controlPanel.add(button, new com.kingdee.bos.ctrl.swing.KDLayout.Constraints(table.getWidth()-140, 5, button.getWidth(), 19, 9));// 9=1+8上右固定,左边缩放 } } }//调用方法public void onLoad() throws Exception { super.onLoad(); addButtonToHMDEntry(getDetailTable(), btnAudit);}
关闭eas页面时校验是否修改的提示
@Overridepublic boolean checkBeforeWindowClosing() { return true;}
获取EAS产品网络网络互斥锁
IMutexServiceControl mutexServiceControlDao = MutexServiceControlFactory.getLocalInstance(ctx); boolean request = mutexServiceControlDao.requestObjIDForUpdate(saleOrderId);//EAS产品互斥锁 if (!request) { throw new ZBException(ZBException.CUSTOM, new Object[] { "数据占用中不允许操作!" }); }
private void writeBackSaleBill(Context ctx, String saleBillId, Timestamp timestamp, VerifyCapitalEnum verifyCapitalEnum, String companyId) throws BOSException, EASBizException { Connection con = null; Statement stm = null; BOSUuid uuid = BOSUuid.read(saleBillId); BOSObjectType objectType = uuid.getType(); StringBuffer updSql = new StringBuffer(); try { con = this.getConnection(ctx); stm = con.createStatement(); EntityObjectInfo entity = MetaDataLoaderFactory.getMetaDataLoader(ctx).getEntity(objectType); String tableName = entity.getTable().getName(); updSql.append(" /*dialect*/ "); updSql.append(" UPDATE " + tableName + " SET "); updSql.append(" FCompanyOrgUnitID = '" + companyId + "', "); updSql.append(" FVerifyCapital = " + verifyCapitalEnum.getValue() + ", "); updSql.append(" FLastUpdateTime = SYSDATE "); updSql.append(" WHERE FID ='" + saleBillId + "' "); updSql.append(" AND FLastUpdateTime = TO_TIMESTAMP('" + timestamp + "', 'yyyy-mm-dd hh24:mi:ss.ff6')"); int result = stm.executeUpdate(updSql.toString()); if (result != 1) { throw new ZBException(ZBException.CUSTOM, new Object[] { "更新数据异常,数据已经发生修改!!" }); } } catch (SQLException exc) { logger.error(exc); exc.printStackTrace(); throw new ZBException(ZBException.CUSTOM, new Object[] { exc.getMessage() }); } finally { SQLUtils.cleanup(stm, con); } }
根据单据id找到单据的相关信息(实体,表,ui等)
BOSUuid id = BOSUuid.read(billId);BOSObjectType type = id.getType();IMetaDataLoader loader = MetaDataLoaderFactory.getRemoteMetaDataLoader();EntityObjectInfo vo = loader.getEntity(type);String editUi = vo.getExtendedProperty("editUI");
推荐阅读