之前寫了一篇 EAS BOS F7 過濾 動態 級聯 詳細使用 現在再介紹一下分錄 F7的動態使用;
1、新建一張業務單據,存在兩個F7控件,基本庫位屬於倉庫,只有選擇了倉庫才,能確定庫位。發布業務單元,如下:
2、打開JAVA視圖,找到EDITUI JAVA文件,新增方法
a)首先為倉庫添加過濾,prmtwarehouse為倉庫F7,並添加監聽事件。分錄與表頭還是有區別的,但代碼大同小異;
區別在於分錄的F7並不像表頭一樣是個單獨的控件,而是屬於表格的一列。所以先拿到設置一個F7然后,將F7綁定到指定列就可以了。
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初始化。這是一個表格列級的初始化。
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過濾
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)的方法;
/** * 分錄必輸項檢查 */ @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並不會在打開單據時觸發。這樣會影響我們的級聯,所以要想辦法讓它執行,如下:
在loadFields()方法中,執行一下單元格級F7。loadFields()在執行將數據加載到界面UI控件。load是用來加載界面信息,只執行一次。在執行保存時,不會再次觸發。所以使用loadFields();
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); }
3、完成后,刷新啟動服務,即可實現F7動態級聯,並實現動態改必輸校驗。
PS:以上功能有個難點未實現,就是分錄單元格設置必輸項。如果是表頭設置 .setRequired(true) 就可以了,但如果是分錄,並沒有這個方法,研究多時,不得法;
本實例,只是為單元格添加了一個底色。如有同行知道如何設置,請評論,感激不盡。