本文主要是介绍EAS BOS 报表开发,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
EAS BOS 报表开发
只是做为新手BOS报表开发一个参考:
开发所需要新建的文件
- ContractReportFilterUI:报表弹出的条件选择框,在新建时需要继承系统UI类
com.kingdee.eas.framework.report.client.CommRptBaseConditionUI - ContractReportUI:用于报表展示,需要继承系统UI类 com.kingdee.eas.framework.report.client.CommRptBaseUI
- ContractReportFacade:用于调用系统查询的Facade,也需要继承系统类com.kingdee.eas.framework.report.app.CommRptBase 通用报表查询Facade,Facade可以没有添加方法。
- ContractReportBillViewUI: 用于报表联查,新建时直接继承CoreUI即可。
ContractReportFilterUI 方法说明及关键代码
新建UI发布之后,有3个方法是需要重写,getCustomCondition 、setCustomCondition 、onInit ,需要验证输入信息,再重写 verify方法即可
- getCustomCondition:用于获取报表界面的界面参数,也可以理解成过滤信息
- setCustomCondition: 用于将弹出UI的界面参数保存起来,和上面方法对应
- onInit: 系统初始化方法,你可以初始化控件,也可以初始化控件值
以下为完成代码:
/*** output package name*/package your package;import java.util.Map;import org.apache.log4j.Logger;import com.kingdee.bos.ui.face.CoreUIObject;import com.kingdee.eas.framework.report.util.RptConditionManager;import com.kingdee.eas.framework.report.util.RptParams;import com.kingdee.eas.util.SysUtil;import com.kingdee.eas.util.client.MsgBox;import com.kingdee.util.StringUtils;public class ContractReportFilterUI extends AbstractContractReportFilterUI {private static final Logger logger = CoreUIObject.getLogger(ContractReportFilterUI.class);public ContractReportFilterUI() throws Exception {super();initControl();}public void initControl() {ApF7InitUtils.initAdminF7(prmtAdmin, this, null, null);ApF7InitUtils.initCompanyF7(prmtFiCompany, this, null, null, false);txtStartDate.setValue(ApRptConstant.getFirstDay());txtEndDate.setValue(ApRptConstant.getLastDay());txtStatus.setSelectedItem(null);txtContractWay.setSelectedItem(null);}public RptParams getCustomCondition() {RptParams param = new RptParams();// 放置本界面的参数RptConditionManager rcm = new RptConditionManager();if (null != prmtFiCompany.getValue()) {rcm.setProperty("fiCompany", prmtFiCompany.getValue());} else {rcm.setProperty("fiCompany", null);}if (null != prmtAdmin.getValue()) {rcm.setProperty("admin", prmtAdmin.getValue());} else {rcm.setProperty("admin", null);}if (null != prmtType.getValue()) {rcm.setProperty("type", prmtType.getValue());} else {rcm.setProperty("type", null);}if (!StringUtils.isEmpty(txtNumber.getText())) {rcm.setProperty("number", txtNumber.getText());} else {rcm.setProperty("number", null);}if (!StringUtils.isEmpty(txtName.getText())) {rcm.setProperty("name", txtName.getText());} else {rcm.setProperty("name", null);}if (null != txtStartDate.getValue()) {rcm.setProperty("startDate", txtStartDate.getValue());} else {rcm.setProperty("startDate", null);}if (null != txtEndDate.getValue()) {rcm.setProperty("endDate", txtEndDate.getValue());} else {rcm.setProperty("endDate", null);}if (null != txtContractWay.getSelectedItem()) {rcm.setProperty("contractWay", txtContractWay.getSelectedItem());} else {rcm.setProperty("contractWay", null);}if (null != txtStatus.getSelectedItem()) {rcm.setProperty("status", txtStatus.getSelectedItem());} else {rcm.setProperty("status", null);}Map map = rcm.toMap();param.putAll(map);return param;}public void onInit(RptParams initParams) throws Exception {initControl();}public void setCustomCondition(RptParams params) {if (null != params.getObject("fiCompany")) {prmtFiCompany.setValue(params.getObject("fiCompany"));} else {prmtFiCompany.setValue(null);}if (null != params.getObject("admin")) {prmtAdmin.setValue(params.getObject("prmtAdmin"));} else {prmtAdmin.setValue(null);}if (null != params.getObject("type")) {prmtType.setValue(params.getObject("type"));} else {prmtType.setValue(null);}if (null != params.getObject("number")) {txtNumber.setText(params.getObject("number") + "");} else {txtNumber.setText(null);}if (null != params.getObject("name")) {txtName.setText(params.getObject("name") + "");} else {txtName.setText(null);}if (null != params.getObject("startDate")) {txtStartDate.setValue(params.getObject("startDate"));} else {txtStartDate.setValue(null);}if (null != params.getObject("endDate")) {txtEndDate.setValue(params.getObject("endDate"));} else {txtEndDate.setValue(null);}if (null != params.getObject("contractWay")) {txtContractWay.setSelectedItem(params.getObject("contractWay"));} else {txtContractWay.setSelectedItem(null);}if (null != params.getObject("status")) {txtStatus.setSelectedItem(params.getObject("status"));} else {txtStatus.setSelectedItem(null);}}public boolean verify() {if (null == prmtFiCompany.getValue()) {MsgBox.showError("请选择组织.");SysUtil.abort();}return super.verify();}}
ContractReportUI 方法说明及关键代码
新建完UI发布之后,同样的也是需要重写父类方法,其中包括:getParamsForInit,getQueryDialogUserPanel,getRemoteInstance,getTableForPrintSetting,query,下面分别简单说明下各方法的用途
- getParamsForInit:从弹出UI获取界面参数
- getQueryDialogUserPanel:指定弹出UI类
- getRemoteInstance:远程调用查询的接口
- getTableForPrintSetting:获取表格打印设置
- query:查询对话框点击确定后执行
另外我自己还添加一个功能,报表联查,方法名为:actionBillView_actionPerformed,完整示例请参考代码:
public class ContractReportUI extends AbstractContractReportUI
{private static final Logger logger = CoreUIObject.getLogger(ContractReportUI.class);public ContractReportUI() throws Exception{super();this.setUITitle("合同一览表");btnBillView.setEnabled(true);}protected void tblMain_tableClicked(com.kingdee.bos.ctrl.kdf.table.event.KDTMouseEvent e) throws Exception{if (e.getClickCount()==2) {actionBillView_actionPerformed(null);}}public void actionBillView_actionPerformed(ActionEvent e) throws Exception{int row = KDTableUtil.getSelectedRow(tblMain);if (row==-1) {MsgBox.showInfo("请选择行..");SysUtil.abort();}String orgId=null;if (null!=params.getObject("fiCompany")) {CompanyOrgUnitInfo object = (CompanyOrgUnitInfo)params.getObject("fiCompany");orgId=object.getId().toString();}String id = APRuleUtil.getString(tblMain.getCell(row, "ID").getValue());UIContext uiContext = new UIContext(this);uiContext.put("ID", id);uiContext.put("orgId", orgId);IUIWindow uiWindow = UIFactory.createUIFactory(UIFactoryName.EDITWIN).create(ContractReportBillViewUI.class.getName(), uiContext, null, OprtState.VIEW);uiWindow.show();}protected RptParams getParamsForInit() {return params;}protected CommRptBaseConditionUI getQueryDialogUserPanel() throws Exception {return new ContractReportFilterUI();}protected ICommRptBase getRemoteInstance() throws BOSException {return ContractReportFacadeFactory.getRemoteInstance();}protected KDTable getTableForPrintSetting() {return this.tblMain;}/*** 查询对话框点击确定后执行* @param params 查询条件*/protected void query() {//查询条件设置到界面initParamToUI(params);tblMain.checkParsed();tblMain.setEditable(false);try {//设置光标处于等待状态setCursorOfWair();//查询数据,在Facade查询方法里返回值是RptParams,需要把查询集保存到RptParams里,再通过界面取出即可RptParams rps = ((ICommRptBase)getRemoteInstance()).query(params);if(rps!=null){IRowSet conReport = ((IRowSet)rps.getObject(ApRptConstant.RPT_PARAMETERS)) ;if(conReport!=null){fillTable(conReport);tblMain.getSelectManager().setSelectMode(KDTSelectManager.ROW_SELECT);}}} catch (Exception e) {e.printStackTrace();this.handUIException(e);} finally {this.setCursorOfDefault();}}private int fillTable(IRowSet rs) throws SQLException {tblMain.removeRows();while (rs.next()) {IRow row = tblMain.addRow();row.getCell("number").setValue(rs.getString("FNUMBER"));row.getCell("name").setValue(rs.getString("CFNAME"));row.getCell("ContractType").setValue(rs.getString("CONTRACTTYPE"));row.getCell("status").setValue(StatusEnum.getEnum(rs.getString("CFSTATUS")).getAlias());row.getCell("inOutType").setValue(rs.getString("INOUTTYPE"));row.getCell("contractWay").setValue(ContractTypeEnum.getEnum(rs.getString("CFCONTRACTWAY")).getAlias());row.getCell("customer").setValue(rs.getString("CUSTOMER"));row.getCell("supplier").setValue(rs.getString("SUPPLIER"));row.getCell("bizDate").setValue(rs.getString("FBIZDATE"));row.getCell("startDate").setValue(rs.getString("CFSTARTDATE"));row.getCell("endDate").setValue(rs.getString("CFENDDATE"));row.getCell("days").setValue(rs.getString("CFDAYS"));row.getCell("amount").setValue(rs.getBigDecimal("CFAMOUNT"));row.getCell("totalAmount").setValue(rs.getBigDecimal("CFTOTALAMOUNT"));row.getCell("unAmount").setValue(rs.getBigDecimal("CFUNAMOUNT"));row.getCell("person").setValue(rs.getString("CFPERSON"));row.getCell("department").setValue(rs.getString("DEPARTMENT"));row.getCell("createDate").setValue(rs.getString("FCREATETIME"));row.getCell("ID").setValue(rs.getString("ID"));}String [] cols=new String[]{"amount","totalAmount","unAmount"};ApRptConstant.formatTableNumber(tblMain, cols);ApRptConstant.appendFootRow(tblMain, cols);cols=new String[]{"bizDate","startDate","endDate","createDate"};ApRptConstant.formatTableDate(tblMain, cols);return tblMain.getRowCount();}public void initParamToUI(RptParams params) {if (null!=params.getObject("fiCompany")) {CompanyOrgUnitInfo object = (CompanyOrgUnitInfo)params.getObject("fiCompany");txtFiCompany.setText(object.getNumber()+"-"+object.getName());}else {txtFiCompany.setText("");}}
Facade关键代码
因为Facade已经继承了父类,所以这里不需要再新建方法,重写父类方法即可,整个Facade只需要写一个方法就好了。protected RptParams _query(Context ctx, RptParams params) 在方法中,需要先获取界面参数再拼SQL即可,参考代码如下:
@Overrideprotected RptParams _query(Context ctx, RptParams params)throws BOSException, EASBizException {if (null == params) {throw new EASBizException(new NumericExceptionSubItem("0003","请先设置过滤条件.."));}String fiCompanyId=null;if (null!=params.getObject("fiCompany")) {CompanyOrgUnitInfo object = (CompanyOrgUnitInfo)params.getObject("fiCompany");fiCompanyId=object.getId().toString();}String departmentId=null;if (null!=params.getObject("admin")) {AdminOrgUnitInfo object = (AdminOrgUnitInfo)params.getObject("prmtAdmin");departmentId=object.getId().toString();}String contractTypeId=null;if (null!=params.getObject("type")) {ContractTypeInfo object = (ContractTypeInfo)params.getObject("type");contractTypeId=object.getId().toString();}String number=null;if (null!=params.getObject("number")) {number=APRuleUtil.getString(params.getObject("number"));}String name=null;if (null!=params.getObject("name")) {name=APRuleUtil.getString(params.getObject("name"));}Date startDate=null;if (null!=params.getObject("startDate")) {startDate = APRuleUtil.getDateValue(params.getObject("startDate"));}Date endDate=null;if (null!=params.getObject("endDate")) {endDate = APRuleUtil.getDateValue(params.getObject("endDate"));}String contractWayId=null;if (null!=params.getObject("contractWay")) {ContractTypeEnum object = (ContractTypeEnum)params.getObject("contractWay");contractWayId = object.getValue();}String status=null;if (null!=params.getObject("status")) {StatusEnum object = (StatusEnum)params.getObject("status");status=object.getValue();}StringBuffer sql = new StringBuffer();SqlParams sp = new SqlParams();sql.append("SELECT A.FNUMBER,A.CFNAME,B.FNAME_L2 CONTRACTTYPE,A.CFSTATUS,C.FNAME_L2 INOUTTYPE,A.CFCONTRACTWAY ,D.FNAME_L2 CUSTOMER,E.FNAME_L2 SUPPLIER,A.FBIZDATE,\r\n");sql.append("A.CFSTARTDATE,A.CFENDDATE,A.CFDAYS,A.CFAMOUNT,A.CFTOTALAMOUNT,A.CFUNAMOUNT,A.CFPERSON,F.FNAME_L2 DEPARTMENT,A.FCREATETIME,A.FID ID FROM CT_AP_APPRAISE A \r\n");sql.append("LEFT JOIN CT_BD_ContractType b on a.CFContractTypeID=b.FID \r\n");sql.append("LEFT JOIN CT_BD_InOutType C ON C.FID=A.CFInOutTypeID \r\n");sql.append("LEFT JOIN T_BD_Customer D ON D.FID=A.CFCustomerID \r\n");sql.append("LEFT JOIN T_BD_Supplier E ON E.FID=A.CFSupplierID \r\n");sql.append("LEFT JOIN T_ORG_Admin F ON F.FID=A.CFDepartmentID \r\n");sql.append("WHERE 1=1 \r\n");if (null!=fiCompanyId) {sql.append("and a.CFFICompanyID=? \r\n");sp.addString(fiCompanyId);}if(null!=departmentId){sql.append("and a.CFDepartmentID=? \r\n");sp.addString(departmentId);}if(null!=contractTypeId){sql.append("and a.CFContractTypeID=? \r\n");sp.addString(contractTypeId);}if(null!=number){sql.append("and a.FNumber like '%"+number+"%' \r\n");//sp.addString(number);}if(null!=name){sql.append("and a.CFName like '%"+name+"%' \r\n");//sp.addString(name);}if(null!=startDate){sql.append("and a.FBizDate>=? \r\n");java.sql.Date date=new java.sql.Date(startDate.getTime());sp.addDate(date);}if(null!=endDate){sql.append("and a.FBizDate<=? \r\n");java.sql.Date date=new java.sql.Date(endDate.getTime());sp.addDate(date);}if(null!=contractWayId){sql.append("and a.CFContractWay=? \r\n");sp.addString(contractWayId);}if(null!=status){sql.append("and a.CFStatus=? \r\n");sp.addString(status);}sql.append("ORDER BY a.FNumber");IRowSet set = DbUtil.executeQuery(ctx, sql.toString(), sp.getParams());//这里返回值是RptParams,需要把查询集保存到RptParams里,再通过界面取出即可params.setObject(ApRptConstant.RPT_PARAMETERS, set);return params;}
另外在联查中,是通过调用之前已经新建好的单据的EditUI直接显示即可,也可以参考完整显示代码,
public class ContractReportBillViewUI extends AbstractContractReportBillViewUI{private static final Logger logger = CoreUIObject.getLogger(ContractReportBillViewUI.class);private AppraiseEditUI currentBaseUI=null;//基础资料private DepositRegisterListUI currentDepositUI=null;//保证金private ContractChangeListUI currentContractChangeUI=null;//合同变更private ReceiveBillListUI currentReceiveBillUI=null;//合同收款单private PaymentBillListUI currentPaymentBillUI=null;//合同付款单public ContractReportBillViewUI() throws Exception{super();Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setPreferredSize(screenSize);}public void onLoad() throws Exception {super.onLoad();kDTabbedPane1.remove(changeUI);//补充协议String ID = APRuleUtil.getString(getUIContext().get("ID"));String orgId = APRuleUtil.getString(getUIContext().get("orgId"));if (this.baseUI.getComponentCount() == 0) {currentBaseUI = ((AppraiseEditUI) UIFactoryHelper.initUIObject(AppraiseEditUI.class.getName(),getUIContext(), null, getOprtState()));currentBaseUI.repaint();baseUI.add(currentBaseUI);}if (DepositUI.getComponentCount()==0) {Map context = getUIContext();context.clear();context.put("appraise.id", ID);//context.put("orgId", orgId);//currentDepositUI = ((DepositRegisterListUI) UIFactoryHelper.initUIObject(DepositRegisterListUI.class.getName(),context, null, getOprtState()));currentDepositUI.repaint();DepositUI.add(currentDepositUI);}if (ContractChangeUI.getComponentCount()==0) {Map context = getUIContext();context.clear();context.put("appraise.id", ID);context.put("orgId", orgId);currentContractChangeUI = ((ContractChangeListUI) UIFactoryHelper.initUIObject(ContractChangeListUI.class.getName(),context, null, getOprtState()));currentContractChangeUI.repaint();ContractChangeUI.add(currentContractChangeUI);}if (ReceiveBillUI.getComponentCount()==0) {Map context = getUIContext();context.clear();context.put("appraise.id", ID);context.put("orgId", orgId);currentReceiveBillUI = ((ReceiveBillListUI) UIFactoryHelper.initUIObject(ReceiveBillListUI.class.getName(),context, null, getOprtState()));currentReceiveBillUI.repaint();ReceiveBillUI.add(currentReceiveBillUI);}if (PaymentBillUI.getComponentCount()==0) {Map context = getUIContext();context.clear();context.put("appraise.id", ID);context.put("orgId", orgId);currentPaymentBillUI = ((PaymentBillListUI) UIFactoryHelper.initUIObject(PaymentBillListUI.class.getName(),context, null, getOprtState()));currentPaymentBillUI.repaint();PaymentBillUI.add(currentPaymentBillUI);}}}
THE END
这篇关于EAS BOS 报表开发的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!