以前寫了一篇 EAS BOS F7 過濾 動態 級聯 詳細使用 如今再介紹一下分錄 F7的動態使用;html
一、新建一張業務單據,存在兩個F7控件,基本庫位屬於倉庫,只有選擇了倉庫才,能肯定庫位。發佈業務單元,以下:java
二、打開JAVA視圖,找到EDITUI JAVA文件,新增方法app
a)首先爲倉庫添加過濾,prmtwarehouse爲倉庫F7,並添加監聽事件。分錄與表頭仍是有區別的,但代碼大同小異;ide
區別在於分錄的F7並不像表頭同樣是個單獨的控件,而是屬於表格的一列。因此先拿到設置一個F7而後,將F7綁定到指定列就能夠了。post
private void initF7() { final KDBizPromptBox kdtEntrys_warehouse_PromptBox = new KDBizPromptBox(); kdtEntrys_warehouse_PromptBox .setQueryInfo("com.kingdee.eas.basedata.scm.im.inv.app.F7AllWarehouseQuery"); kdtEntrys_warehouse_PromptBox.setVisible(true); kdtEntrys_warehouse_PromptBox.setEditable(true); kdtEntrys_warehouse_PromptBox.setDisplayFormat("$number$"); kdtEntrys_warehouse_PromptBox.setEditFormat("$number$"); kdtEntrys_warehouse_PromptBox.setCommitFormat("$number$"); EntityViewInfo entityView = new EntityViewInfo(); FilterInfo filter = new FilterInfo(); filter.getFilterItems().add( new FilterItemInfo("storageOrg.id", "FQgAAAAABmLM567U", CompareType.EQUALS)); entityView.setFilter(filter); kdtEntrys_warehouse_PromptBox.setEntityViewInfo(entityView); KDTDefaultCellEditor kdtEntrys_warehouse_CellEditor = new KDTDefaultCellEditor( kdtEntrys_warehouse_PromptBox); this.kdtEntrys.getColumn("warehouse").setEditor( kdtEntrys_warehouse_CellEditor); ObjectValueRender kdtEntrys_warehouse_OVR = new ObjectValueRender(); kdtEntrys_warehouse_OVR.setFormat(new BizDataFormat("$name$")); this.kdtEntrys.getColumn("warehouse").setRenderer( kdtEntrys_warehouse_OVR); kdtEntrys.addKDTEditListener(new KDTEditAdapter() { public void editStopped(KDTEditEvent e) { try { kdtEntrys_Changed(e.getRowIndex(), e.getColIndex()); } catch (Exception exc) { handUIException(exc); } } }); }
b)爲庫位添加過濾,prmtlocationhouse爲庫位F7;當前添加的F7過濾,與倉庫並沒有太大相關,只是在新打開單據時作的F7初始化。這是一個表格列級的初始化。ui
private void locationhouseF7(String warehouseid) { final KDBizPromptBox kdtEntrys_locationhouse_PromptBox = new KDBizPromptBox(); kdtEntrys_locationhouse_PromptBox .setQueryInfo("com.kingdee.eas.basedata.scm.im.inv.app.F7LocationQuery"); kdtEntrys_locationhouse_PromptBox.setVisible(true); kdtEntrys_locationhouse_PromptBox.setEditable(true); kdtEntrys_locationhouse_PromptBox.setDisplayFormat("$number$"); kdtEntrys_locationhouse_PromptBox.setEditFormat("$number$"); kdtEntrys_locationhouse_PromptBox.setCommitFormat("$number$"); EntityViewInfo entityView = new EntityViewInfo(); FilterInfo filter = new FilterInfo(); filter.getFilterItems().add( new FilterItemInfo("WAREHOUSE.id", warehouseid, CompareType.EQUALS)); entityView.setFilter(filter); kdtEntrys_locationhouse_PromptBox.setEntityViewInfo(entityView); KDTDefaultCellEditor kdtEntrys_locationhouse_CellEditor = new KDTDefaultCellEditor( kdtEntrys_locationhouse_PromptBox); this.kdtEntrys.getColumn("locationhouse").setEditor( kdtEntrys_locationhouse_CellEditor); ObjectValueRender kdtEntrys_locationhouse_OVR = new ObjectValueRender(); kdtEntrys_locationhouse_OVR.setFormat(new BizDataFormat("$name$")); this.kdtEntrys.getColumn("locationhouse").setRenderer( kdtEntrys_locationhouse_OVR); }
c)新增倉庫F7更新事件方法,併爲庫位添加單元格級F7過濾this
private void locationhouseCellF7(int rowIndex, Object object) { String warehouseid = null; if (object != null) { warehouseid = ((WarehouseInfo) object).getId().toString(); } final KDBizPromptBox kdtEntrys_locationhouse_PromptBox = new KDBizPromptBox(); kdtEntrys_locationhouse_PromptBox .setQueryInfo("com.kingdee.eas.basedata.scm.im.inv.app.F7LocationQuery"); kdtEntrys_locationhouse_PromptBox.setVisible(true); kdtEntrys_locationhouse_PromptBox.setEditable(true); kdtEntrys_locationhouse_PromptBox.setDisplayFormat("$number$"); kdtEntrys_locationhouse_PromptBox.setEditFormat("$number$"); kdtEntrys_locationhouse_PromptBox.setCommitFormat("$number$"); EntityViewInfo entityView = new EntityViewInfo(); FilterInfo filter = new FilterInfo(); filter.getFilterItems().add( new FilterItemInfo("WAREHOUSE.id", warehouseid, CompareType.EQUALS)); entityView.setFilter(filter); kdtEntrys_locationhouse_PromptBox.setEntityViewInfo(entityView); try { LocationCollection local = LocationFactory.getRemoteInstance() .getLocationCollection(entityView); if (local.size() > 0) { // kdtEntrys_locationhouse_PromptBox.setRequired(true); this.kdtEntrys.getCell(rowIndex, "locationhouse").setValue( local.get(0)); this.kdtEntrys.getCell(rowIndex, "locationhouse") .getFormattedStyleAttributes().setBackground( new Color(252, 251, 223)); } else { // kdtEntrys_locationhouse_PromptBox.setRequired(false); this.kdtEntrys.getCell(rowIndex, "locationhouse") .getFormattedStyleAttributes().setBackground( new Color(252, 255, 255)); } } catch (BOSException e1) { e1.printStackTrace(); } KDTDefaultCellEditor kdtEntrys_locationhouse_CellEditor = new KDTDefaultCellEditor( kdtEntrys_locationhouse_PromptBox); this.kdtEntrys.getCell(rowIndex, "locationhouse").setEditor( kdtEntrys_locationhouse_CellEditor); } //更新事件 public void kdtEntrys_Changed(int rowIndex, int colIndex) throws Exception { if ("warehouse" .equalsIgnoreCase(kdtEntrys.getColumn(colIndex).getKey())) { locationhouseCellF7(rowIndex, this.kdtEntrys.getCell(rowIndex, colIndex).getValue()); } }
d)重寫beforeStoreFields(ActionEvent e)方法進行必輸項驗證 ,一樣也可使用重寫verifyInput(ActionEvent e)的方法;url
/** * 分錄必輸項檢查 */ @Override protected void beforeStoreFields(ActionEvent arg0) throws Exception { for (int i = 0, n = kdtEntrys.getRowCount(); i < n; i++) { if (kdtEntrys.getCell(i, "locationhouse").getStyleAttributes() .getBackground().equals(new Color(252, 251, 223)) && com.kingdee.bos.ui.face.UIRuleUtil.isNull(kdtEntrys .getCell(i, "locationhouse").getValue())) { throw new com.kingdee.eas.common.EASBizException( com.kingdee.eas.common.EASBizException.CHECKBLANK, new Object[] { "庫位" }); } } super.beforeStoreFields(arg0); }
e)分錄單元格級的F7並不會在打開單據時觸發。這樣會影響咱們的級聯,因此要想辦法讓它執行,以下:orm
在loadFields()方法中,執行一下單元格級F7。loadFields()在執行將數據加載到界面UI控件。load是用來加載界面信息,只執行一次。在執行保存時,不會再次觸發。因此使用loadFields();htm
public void loadFields() { super.loadFields(); for (int i = 0, n = kdtEntrys.getRowCount(); i < n; i++) { locationhouseCellF7(i, this.kdtEntrys.getCell(i, "warehouse") .getValue()); } }
f)在構造方法中調用咱們寫的方法
public F7EntryFilterEditUI() throws Exception { super(); initF7(); locationhouseF7(null); }
三、完成後,刷新啓動服務,便可實現F7動態級聯,並實現動態改必輸校驗。
PS:以上功能有個難點未實現,就是分錄單元格設置必輸項。若是是表頭設置 .setRequired(true) 就能夠了,但若是是分錄,並無這個方法,研究多時,不得法;
本實例,只是爲單元格添加了一個底色。若有同行知道如何設置,請評論,感激涕零。