EAS-BOS表头-分录多表开发高级教程
准备工作:新建包,子系统简码(必录)
http://s2/middle/4d6be6f349fbfa6478b21&690
1、实体层
新建实体:“父实体对象”选择框架的一个基类(必须)
单据头Student:
http://s15/middle/4d6be6f349fbfaa88d40e&690
选择基类:
http://s11/middle/4d6be6f349fbfacee4dba&690
系统方法“全部不选”
http://s3/middle/4d6be6f349fbfaf07d9b2&690
重新选择基类
http://s6/middle/4d6be6f349fbfb01d8765&690
将系统自动生成的id删除,因为基类已经存在id的字段, 增加自有属性
http://s12/middle/4d6be6f349fbfb18bd80b&690
定义逻辑键
http://s2/middle/4d6be6f349fbfb42b3f71&690
分录Course:
http://s8/middle/4d6be6f349fbfb61041b7&690
选择父实体对象
http://s12/middle/4d6be6f349fbfb9768c0b&690
将系统自动生成的id删除,因为基类已经存在id的字段, 增加只有属性
http://s12/middle/4d6be6f30765ff91d6eab&690
2、建立一对多关联关系(单据头-分录)
1、建立关联关系,类型选择“聚合”,client选择表头实体,supplier选择分录实体
http://s14/middle/4d6be6f349fbfc19b1eed&690
2、单据头实体Student建立关联属性,关系选择建好的关联关系
http://s13/middle/4d6be6f349fbfc3e95e8c&690
关联名称会在分录EditUI中使用到
http://s13/middle/4d6be6f349fbfc55212cc&690
3、分录实体Course建立“关联属性”,关系选择建好的关联关系
http://s11/middle/4d6be6f349fbfd196c50a&690
关系名称会在建数据库时使用
http://s10/middle/4d6be6f349fbfd3af87f9&690
3、实体导出表
表头
http://s9/middle/4d6be6f349fc065c0e0f8&690
分录
http://s12/middle/4d6be6f349fc067f1707b&690
3、导出数据表创建SQL语句
http://s13/middle/4d6be6f349fc06b1596cc&690
4、在数据库执行SQL(运行时执行)
5、查询层
http://s14/middle/4d6be6f349fc06f750bed&690
选择实体
http://s11/middle/4d6be6f349fc0720c5baa&690
Course的连接属性选择“父对象所有行”
http://s12/middle/4d6be6f32e3d848e4bdbb&690
导入查询字段(需要显示的),逻辑建包括:表头id和分录id
http://s7/middle/4d6be6f349fc085430d46&690
2、定义字段扩展属性,过滤条件
http://s6/middle/4d6be6f349fc08680d345&690
3、查询:参数定义用不上
6、用户界面层
1、新建查询列表用户界面
http://s1/middle/4d6be6f3076600f13c9f0&690
选择父UI对象(必须)
http://s5/middle/4d6be6f349fc08c9517c4&690
选择BO对象
http://s6/middle/4d6be6f349fc08dcfcf45&690
选择需要的字段
http://s8/middle/4d6be6f349fc09a44c597&690
选择layout属性
http://s13/middle/4d6be6f349fc09b2d26cc&690
2、新建编辑界面
http://s6/middle/4d6be6f349fc09d618285&690
选择父UI对象(必须)
http://s4/middle/4d6be6f349fc09daab353&690
http://s15/middle/4d6be6f349fc0a12505ee&690
选择BO对象
http://s5/middle/4d6be6f30766010832a74&690
选择需要显示的字段
http://s10/middle/4d6be6f349fc0a5fbf669&690
7、发布元数据
http://s13/middle/4d6be6f349fc0a82b7e5c&690
打开“包资源管理器”视图,刷新
8、修改列表界面
StudentListUI.java增加两方法:
ListUI继承com.kingdee.eas.framework.client.BillListUI,(必须)实现的方法:
http://s8/middle/4d6be6f349fc0ad8ba0d7&690
@Override
protected String getEditUIName()
{
MsgBox.showWarning("2.返回编辑界面名称全路径,新增、查看数据时使用getEditUIName");
return StudentEditUI.class.getName();
}
@Override
protected ICoreBase getBizInterface() throws Exception
{
MsgBox.showWarning("3.通过Factory返回业务接口,查看数据时使用getBizInterface");
return StudentFactory.getRemoteInstance();
}
9、修改编辑界面
StudentEditUI.java增加四方法:
EditUI继承com.kingdee.eas.framework.client.BillEditUI,(必须)实现的方法:
http://s3/middle/4d6be6f349fc0af3d73d2&690
@Override
protected KDTable getDetailTable()
{
MsgBox.show("11.返回分录列表getDetailTable");
return kdtEntrys;
}
protected IObjectValue createNewData()
{
MsgBox.show("21.创建新的数据对象,赋初始值createNewData");
StudentInfo info = new StudentInfo();
info.setState(ItemStateEnum.x);
info.setCreator((com.kingdee.eas.base.permission.UserInfo)
(com.kingdee.eas.common.client.SysContext.getSysContext().getCurrentUser()));
return info;
}
protected ICoreBase getBizInterface() throws Exception
{
MsgBox.show("22.通过Factory返回业务接口getBizInterface");
return StudentFactory.getRemoteInstance();
}
@Override
protected IObjectValue createNewDetailData(KDTable
arg0)
{
MsgBox.show("31.创建新的分录行createNewDetailData");
return new CourseInfo();
}
10、增加实体方法,ListUI增加按钮,实现按钮调用实体方法
1、在Student实体创建方法myDoSomething
http://s3/middle/4d6be6f349fc0b318e312&690
定义方法参数
http://s11/middle/4d6be6f349fc0b3cc3cfa&690
发布实体
2、在StudentListUI新增Action,新增工具条,并指派工具条对应的Action
打开StudentListUI.ui,打开“大纲”视图
http://s8/middle/4d6be6f30766012484547&690
展开“Actions”、按“右键”新建Action(Action类名首字符大写ActionMyDoSomething,Action实例名首字符小写actionMyDoSomething)
http://s13/middle/4d6be6f349fc0b82aa32c&690
展开“ToolBarPanel”,新建“KDWorkButton”
http://s13/middle/4d6be6f349fc0ba17339c&690
修改按钮name、text属性,绑定action为新建的action实例
发布ListUI
打开StudentControllerBean的java源码,实现“_myDoSomething”方法供StudentListUI调用
可以通过工具选择需要实现重载的方法
http://s13/middle/4d6be6f349fc0be18083c&690
http://s16/middle/4d6be6f349fc0c098e29f&690
protected void _myDoSomething(Context ctx, IObjectPK id)
throws BOSException
{
try
{
// 取得值对象
StudentInfo info = (StudentInfo) this.getValue(ctx, id);
// 业务判断
if (info.getState().equals(ItemStateEnum.y))
{
// 修改属性值
info.setState(ItemStateEnum.z);
// 提交更新到数据库
this.update(ctx, id, info);
}
} catch (EASBizException e)
{
e.printStackTrace();
}
}
打开StudentListUI的java源码,实现按钮事件调用实体函数
http://s12/middle/4d6be6f307660149f264b&690
http://s2/middle/4d6be6f349fc0d7aa12b1&690
@Override
public void actionMyDoSomething_actionPerformed(ActionEvent
e) throws Exception
{
// 取得选中行主键
ObjectUuidPK pk = new ObjectUuidPK(this.getSelectedKeyValue());
// 取得远程业务接口,调用方法
StudentFactory.getRemoteInstance().myDoSomething(pk);
// 刷新列表
refresh(null);
// 弹出提示框
MsgBox.showWarning("关闭actionMyDoSomething_actionPerformed");
SysUtil.abort();
}
其他常用方法:
在onLoad函数中将按钮设置为可用
@Override
public void onLoad() throws Exception
super.onLoad();
MsgBox.showWarning("打开界面时设置初始化状态onLoad");
btnMyDoSomething.setEnabled(true);
}
@Override
public String[] getMergeColumnKeys()
{
MsgBox.showWarning("1.设置合并重复的列getMergeColumnKeys");
return new String[]
{ "id", "xh", "mc" };
}
重新“启动测试“
11、通过定义“属性”给表头编辑框增加F7关联基础资料功能
queryInfo定义“查询”:com.kingdee.eas.custom.stu.app.StudentQuery
displayFormat定义“显示字段”:$mc$
editFormat定义“编辑字段”:$xh$
commitFormat定义“提交字段”:$xh$
http://s1/middle/4d6be6f349fc0dee82760&690
12、通过定义“事件”给表头F7编辑框增加值改变事件
1、设置“事件”
http://s3/middle/4d6be6f307660168cea52&690
2、实现事件代码
http://s13/middle/4d6be6f349fc0e273d9dc&690
@Override
protected void prmtAuditor_stateChanged(ChangeEvent e)
throws Exception
{
//实现事件代码
MsgBox.showInfo(prmtAuditor.getText());
}
3、也可以手工在onLoad方法中注册监听事件,prmtAuditor为字段名称
this.prmtAuditor.addChangeListener(new javax.swing.event.ChangeListener()
{
public void stateChanged(javax.swing.event.ChangeEvent
e)
{
try
{
prmtAuditor_stateChanged(e);
} catch (Exception exc)
{
handUIException(exc);
} finally
{
}
}
});
13、F7选择值改变与ListUI列表界面查询联动(动态改变查询的过滤条件)
1、注册值改变事件监听
http://s8/middle/4d6be6f349fc0e686a807&690
@Override
public void onLoad() throws Exception
{
super.onLoad();
this.myxh.addChangeListener(new javax.swing.event.ChangeListener()
{
public void stateChanged(javax.swing.event.ChangeEvent
e)
{
try
{
myxh_stateChanged(e);
} catch (Exception exc)
{
handUIException(exc);
} finally
{
}
}
});
}
2、实现F7选择框值改变事件
http://s5/middle/4d6be6f349fc0e98824f4&690
protected void myxh_stateChanged(ChangeEvent e)
throws Exception
{
// 实现事件代码
MsgBox.showInfo(myxh.getText() + "-" + myxh.getData());
//获取F7选择的值转换为值对象
StudentInfo student = (StudentInfo) this.myxh.getData();
//取得ID(数据库字段)
String sql = "select fid from t_STU_Student
where fid ='" + student.getId().toString() + "'";
//创建过滤器
FilterInfo filter = new FilterInfo();
//增加过滤项及条件(实体属性)
filter.getFilterItems().add(new FilterItemInfo("id", sql, CompareType.INNER));
//创建实体视图
EntityViewInfo entryViewInfo = new EntityViewInfo();
//设置实体视图过滤条件
entryViewInfo.setFilter(filter);
//设置主查询为增加过滤条件的实体视图
this.mainQuery = entryViewInfo;
//刷新查询结果
ActionEvent event = new ActionEvent(this.btnRefresh, 0, "Refresh");
actionRefresh_actionPerformed(event);
}
3、设置列表界面缺省过滤条件
http://s3/middle/4d6be6f349fc0eced26e2&690
protected FilterInfo getDefaultFilterForQuery()
{
//设置列表界面查询缺省过滤条件(数据库字段)
String sql = "select fid from t_STU_Student
where fxh1 ='444'";
FilterInfo filter = new FilterInfo();
//增加过滤项及条件(实体属性)
filter.getFilterItems().add(new FilterItemInfo("id", sql, CompareType.INNER));
return filter;
}
14、表格分录编辑框通过F7关联基础资料,日期格式设置(必须通过编码实现)
http://s12/middle/4d6be6f349fc0f053ebdb&690
@Override
public void onLoad() throws Exception
{
super.onLoad();
//创建日期选择控件
KDDatePicker myDatePicker = new KDDatePicker();
myDatePicker.setName("myDatePicker");
myDatePicker.setVisible(true);
myDatePicker.setEditable(true);
//创建表格编辑控件,指定日期选择方式
KDTDefaultCellEditor myCellEditor = new KDTDefaultCellEditor(myDatePicker);
//将表格字段设置为编辑格式
this.kdtEntrys.getColumn("kssj").setEditor(myCellEditor);
//创建F7选择提示框
KDBizPromptBox prmtFytype = new KDBizPromptBox();
//设置查询
prmtFytype.setQueryInfo("com.kingdee.eas.custom.stu.app.StudentQuery");
prmtFytype.setVisible(true);
prmtFytype.setEditable(true);
//设置显示字段
prmtFytype.setDisplayFormat("$mc$");
//设置编辑字段
prmtFytype.setEditFormat("$xh$");
//设置提交(到数据库)字段
prmtFytype.setCommitFormat("$xh$");
KDTDefaultCellEditor CEFyType = new KDTDefaultCellEditor(prmtFytype);
//指定编辑字段为F7选择模式
this.kdtEntrys.getColumn("kcmc").setEditor(CEFyType);
//指定显示字段
ObjectValueRender kdtEntry__OVR = new ObjectValueRender();
kdtEntry__OVR.setFormat(new BizDataFormat("$mc$"));
this.kdtEntrys.getColumn("kcmc").setRenderer(kdtEntry__OVR);
}
15、对新增的字段(控件)与元数据作绑定
在BOS视图下,打开所要修改的*.ui文件后,如下图:
http://s9/middle/4d6be6f349fc0f4d034d8&690
选中“数据绑定”标签,点“添加”可对新增的字段与元数据实体进行绑定。
对于手动绑定字段的需要修改方法:
public void
loadFields()
{
super.loadFields();
// editData允许强类型访问
txtIsoCode.setText(editData.getIsoCode());
}
public void
storeFields()
{
super.storeFields();
editData.setIsoCode(txtIsoCode.getText());
}
对于手动选择字段有连接属性的需要修改方法:
public
SelectorItemCollection getSelectors() {
SelectorItemCollection sic = new
SelectorItemCollection();
sic.add(new SelectorItemInfo("*"));
sic.add(new
SelectorItemInfo("partUnionGroup.stockControlCompany.*"));
sic.add(new SelectorItemInfo("maintainCU.*"));
return sic;
}
16、对UI上的字段添加事件,并实现事件方法体
如下图,在*.ui视图中,选中想要添加事件的控制,执行以下步骤:
1、
在下面选择“属性”页签,点击“事件“按钮,在想要添加的事件对应的Mehod Name里双击。平台会自动生成方法名。
http://s7/middle/4d6be6f349fc0f89a4f46&690
2、
选中*.ui文件,右键选择发布,对刚刚增加事件的ui进行发布。
发布成功后,在java视图找到此ui对应的java类
http://s5/middle/4d6be6f349fc0faf55cc4&690
重写刚刚在第一步中生成的方法,方法名可以从第一步中获取。
http://s4/middle/4d6be6f349fc0fcc22f93&690
@Override
protected void txtSourceBillId_focusLost(FocusEvent e)
throws Exception
{
if (txtSourceBillId.getText().length() < 1)
MsgBox.showConfirm2("失去焦点了!");
else
MsgBox.showConfirm2(txtSourceBillId.getText());
}
17、去掉UI上的“新增、修改、删除”等按钮
http://s8/middle/4d6be6f349fc0ffd49c37&690
@Override
public void onLoad() throws Exception
{
super.onLoad();
btnAddLine.setVisible(false);
btnInsertLine.setVisible(false);
btnRemoveLine.setVisible(false);
}
18、分录表格增加保存提交时的数据校验
1、覆盖输入校验函数
@Override
protected void verifyInput(ActionEvent e) throws Exception
{
MsgBox.showInfo("43.保存提交时:验证当前数据对象中的数据是否正确verifyInput");
super.verifyInput(e);
kdtEntrys_validate();
}
2、添加自定义校验函数
public void kdtEntrys_validate() throws Exception
{
for (int rowIndex = 0, n = kdtEntrys.getRowCount(); rowIndex < n;
rowIndex++)
{
if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(kdtEntrys.getCell(rowIndex, "sl").getValue()) ||
(com.kingdee.bos.ui.face.UIRuleUtil.getBigDecimalValue(kdtEntrys.getCell(rowIndex, "sl").getValue()) <= 0))
{
com.kingdee.eas.util.client.MsgBox.showInfo(this, "数量不能为空,且不能为零!");
com.kingdee.eas.util.SysUtil.abort();
}
if (com.kingdee.bos.ui.face.UIRuleUtil.isNull(kdtEntrys.getCell(rowIndex, "dj").getValue()) ||
(com.kingdee.bos.ui.face.UIRuleUtil.getBigDecimalValue(kdtEntrys.getCell(rowIndex, "dj").getValue()) <= 0))
{
com.kingdee.eas.util.client.MsgBox.showInfo(this, "单价不能为空,且不能为零!");
com.kingdee.eas.util.SysUtil.abort();
}
}
}
19、分录表格数据项增加值改变事件
1、声明值改变监听事件
@Override
public void onLoad() throws Exception
{
super.onLoad();
// 分录表格增加值修改监听事件
kdtEntrys.addKDTEditListener(new KDTEditAdapter()
{
public void editStopped(KDTEditEvent e)
{
try
{
kdtEntrys_Changed(e.getRowIndex(), e.getColIndex());
} catch (Exception exc)
{
handUIException(exc);
}
}
});
}
2、实现值改变事件
public void kdtEntrys_Changed(int rowIndex, int colIndex) throws Exception
{
if ("kssj".equalsIgnoreCase(kdtEntrys.getColumn(colIndex).getKey()))
{
MsgBox.showInfo(com.kingdee.bos.ui.face.UIRuleUtil.getString(kdtEntrys.getCell(rowIndex, "kssj").getValue()));
}
if ("sl".equalsIgnoreCase(kdtEntrys.getColumn(colIndex).getKey()))
{
kdtEntrys.getCell(rowIndex, "hj").setValue(com.kingdee.bos.ui.face.UIRuleUtil.getBigDecimal(com.kingdee.bos.ui.face.UIRuleUtil.getBigDecimalValue(kdtEntrys.getCell(rowIndex, "sl").getValue()) *
com.kingdee.bos.ui.face.UIRuleUtil.getBigDecimalValue(kdtEntrys.getCell(rowIndex, "dj").getValue())));
}
if ("dj".equalsIgnoreCase(kdtEntrys.getColumn(colIndex).getKey()))
{
kdtEntrys.getCell(rowIndex, "hj").setValue(com.kingdee.bos.ui.face.UIRuleUtil.getBigDecimal(com.kingdee.bos.ui.face.UIRuleUtil.getBigDecimalValue(kdtEntrys.getCell(rowIndex, "sl").getValue()) *
com.kingdee.bos.ui.face.UIRuleUtil.getBigDecimalValue(kdtEntrys.getCell(rowIndex, "dj").getValue())));
}
}
20、自定义查询过滤条件、排序字段、检索字段、获取查询结果集
//取所有的合并范围
//定义实体视图
EntityViewInfo viewInfo = new EntityViewInfo();
//设置排序字段
viewInfo.getSorter().add(new SorterItemInfo("tree.number"));
//设置查询字段
viewInfo.getSelector().add(new SelectorItemInfo("tree.*"));
//设置过滤条件
FilterInfo filter = new FilterInfo();
filter.getFilterItems().add(new FilterItemInfo("tree.type", new Integer(8), CompareType.EQUALS)); // 合并范围
filter.getFilterItems().add(new FilterItemInfo("unit.isunion", new Integer(1), CompareType.EQUALS)); // 合并单元
filter.getFilterItems().add(new FilterItemInfo("tree.status", UnionVersionStatusEnum.START, CompareType.EQUALS));// 启用的
filter.setMaskString("#0 and #1 and #2");//条件关系默认为and
viewInfo.setFilter(filter);
//获取远程接口
IOrgStructure iStruct =
OrgStructureFactory.getRemoteInstance();
OrgStructureCollection structCol
//返回结果集
structCol =
iStruct.getOrgStructureCollection(viewInfo);
//合并范围组织架构实体关系
http://s8/middle/4d6be6f349fc102b81c17&690
//合并范围组织架构数据模型
http://s11/middle/4d6be6f349fc103a2b8ea&690
//根据合并范围取实体公司
OrgTreeInfo orgTreeInfo = ctx.getCurOrgBound();
EntityViewInfo view = new EntityViewInfo();
SelectorItemCollection selector =
view.getSelector();
selector.add(new SelectorItemInfo("unit.id"));
FilterInfo filter = new FilterInfo();
String treeid =
orgTreeInfo.getId().toString();//合并范围ID
filter.getFilterItems().add(new FilterItemInfo("tree.id", treeid, CompareType.EQUALS));//根据合并范围ID
filter.getFilterItems().add(new FilterItemInfo("unit.isunion", new Integer(0), CompareType.EQUALS)); // 0取实体公司ID,1取合并单元ID
view.setFilter(filter);
OrgStructureCollection orgs =
OrgStructureFactory.getRemoteInstance().getOrgStructureCollection(view);
List existOrgList = new ArrayList(orgs.size());
for (Iterator it = orgs.iterator();
it.hasNext();)
{
OrgStructureInfo structure = (OrgStructureInfo)
it.next();
existOrgList.add(structure.getUnit().getId().toString());
System.out.println("合并范围ID:"+ treeid +" | "+"合并单元之财务组织ID:"+structure.getUnit().getId().toString());
}
--合并范围
select * from t_org_tree where ftype=8 and
fid='dhg9rvxZSt2IoSJuHPN3dU8oJ/0=';
--ftreeid:合并范围ID,funitid:合并单元、财务组织ID
select funitid,ftreeid,fid from t_org_structure
where ftreeid = 'dhg9rvxZSt2IoSJuHPN3dU8oJ/0=';
--合并单元、财务组织
select * from t_org_baseunit where fisunion=0 and
fid in (select funitid from t_org_structure where ftreeid =
'dhg9rvxZSt2IoSJuHPN3dU8oJ/0=');
21、给KDSpinner(上下选框)控件设置上下选择范围
参数:初始值、最小值、最大值、步长
//设置会计年度选择范围
this.spCurYear.setModel(new
SpinnerNumberModel(2010, 2010, 2099, 1));
//设置会计期间选择范围
this. spCurPeriod.setModel(new SpinnerNumberModel(2010,
2010, 2099, 1));
22、实体方法事务属性
http://s16/middle/4d6be6f349fc1057bc10f&690
Required与数据库相关的增删改
Supports查询
RequiresNew更新