2.1 单据新增代码
如:新增一行付款单
//构造一条付款单信息(构造值对象)
PaymentBillInfo payInfo = new PaymentBillInfo();
payInfo.setNumber(“1001”);
//关联用户
UserInfo userInfo = new UserInfo();
userInfo.setId(BOSUuid.read("867d5df6-00f8-1000-e000-0009c0a81089sysu")); //通过BOSUuid建立实体对象
userInfo.setName(“John”);
userInfo.setNumber(“2000”);
BigDecimal ex = new BigDecimal("343434.445");//建立属性
BigDecimal ex2 = new BigDecimal(12345678901234567.8);//错误
payInfo.setExchangeRate(ex);
payInfo.setCreator(userInfo);
payInfo.setAuditDate(new Date(System.currentTimeMillis()));//时间属性
Timestamp createdate = new Timestamp(System.currentTimeMillis());
payInfo.setCreateDate(createdate);
payInfo.setBizState(BillBizState.create);//枚据属性
payInfo.setSave(true);//Boolean 属性
PaymentBillItemInfo itemInfo = new PaymentBillItemInfo();//建立分录
itemInfo.setLineNo(34);
itemInfo.setAmounts(ex2);
payInfo.getEntries().add(itemInfo);//添加分录
payInfo.getEntries().add(new ErrandTaskItemInfo());//添加分录
调用新增方法进行保存
IPaymentBill iPayBill = PaymentBillFactory.getRemoteInstance();//获取实体
IObjectPK pk = iPayBill.addnew(payInfo);//保存值对象,返回逻辑键,可以通过逻辑键获取值对象(如下)
2.2 单据修改代码
修改一条付款单信息
IPaymentBill iPayBill = PaymentBillFactory.getRemoteInstance();
String id="8b35b903-00f8-1000-e000-0008c0a81089errt";
ObjectUuidPK pk = new ObjectUuidPK(BOSUuid.read(id));//建立逻辑键
PaymentBillInfo payInfo = iPayBill.getValue(pk);//获取值对象;
System.out.println("this:"+ payInfo.getExchangeRate());//获取属性
payInfo.setExchangeRate(ex);//修改属性属性
iPayBill.update(pk, payInfo);//更新数据
2.3 单据删除代码
iPayBill.remove(pk);//通过逻辑键删除单据内容获取集合
2.4 获取集合
CurrencyInfo cur = new CurrencyInfo();
ICurrency c = CurrencyFactory.getRemoteInstance();//建立实体对象
EntityViewInfo evi = new EntityViewInfo();//建立视图信息
FilterInfo i = new FilterInfo();//建立过滤条件
i.getFilterItems().add(new FilterItemInfo("number", "ddff", CompareType.EQUELS));
i.getFilterItems().add(new FilterItemInfo("id", "ddff", CompareType.EQUELS));
i. setMaskString(" (#0 and #1)");
evi.setFilter(i);//添加过滤条件
evi.getSelector().add(new SelectorItemInfo("id"));//添加获取属性
evi.getSelector().add(new SelectorItemInfo("*"));
evi.getSelector().add(new SelectorItemInfo("company.id"));
evi.getSelector().add(new SelectorItemInfo("company.name"));
//三种获取集合方法
1. 获取所有数据:
CurrencyCollection co = c. getCurrencyCollection ();//获取集合
2. 获取满足上述条件的所有数据
CurrencyCollection co = c.getCurrencyCollection(evi);//获取集合
3. 获取满足oql所写的条件的所有数据
CurrencyCollection co = c. getCurrencyCollection (evi);//获取集合
2.5 获取值对象
CurrencyInfo cur = new CurrencyInfo();
ICurrency c = CurrencyFactory.getRemoteInstance();//建立实体对象
String id="8b35b903-00f8-1000-e000-0008c0a81089errt";
ObjectUuidPK pk = new ObjectUuidPK(BOSUuid.read(id));//建立逻辑键
c.getValue(pk); 或 : c.getCurrencyInfo(pk);
2.6 界面之间传递参数
1. 收集父界面要传递给子界面的参数集 HashMap map = new HashMap();
map.put("Owner", this); //必须。被启动UI的父UI对象
map.put("EASMode", new Integer(this.EASMode));
map.put("table", this.accountTablePrompBox.getData());
map.put("cu", currentCtrlUnit);
map.put("auxAccount", this.asstAccountPromptBox.getData());
IUIFactory uiFactory = null;
uiFactory = UIFactory.createUIFactory("com.kingdee.eas.base.uiframe.client.UIModelDialogFactory"); //以模态对话框方式启动
IUIWindow uiWindow = uiFactorycreate("com.kingdee.eas.basedata.master.auxacct.client.AccountSelectUI", /* 被启动对象的类名称 */
map);
uiWindow.show();
2. 在子界面获取传递下来的数据
private void loadContext()
{
int mode = ((Integer)this.getUIContext().get("EASMode")).intValue();
AccountTableInfo accountTableInfo = (AccountTableInfo) this.getUIContext().get("table");
CtrlUnitInfo cuInfo = (CtrlUnitInfo) this.getUIContext().get("cu");
AsstAccountInfo asstAccountInfo = (AsstAccountInfo) this.getUIContext().get("auxAccount");
AuxAccountEditUI ui = (AuxAccountEditUI) this.getUIContext().get("Owner");
}
2.7 给Query传过滤条件
EntityViewInfo evi = new EntityViewInfo();
FilterInfo filterInfo = new FilterInfo(); //建立过滤条件
filterInfo.getFilterItems().add(
new FilterItemInfo("typelink.id", info.getId(),
CompareType.EQUALS));
filterInfo.getFilterItems().add(
new FilterItemInfo("currencyCompany.id", companyID,
CompareType.EQUALS));
filterInfo.setMaskString("#0 and #1 ");
evi.setFilter(filterInfo);
if (mainQuery == null) {
mainQuery = new EntityViewInfo();
}
mainQuery.setFilter(filterInfo); //添加过滤条件
this.execQuery();
2.8 接口方法的访问方式
3. 客户端访问
CurrencyInfo cur = new CurrencyInfo();
ICurrency c = CurrencyFactory.getRemoteInstance();//建立实体对象
c. getCurrencyCollection();
4. 服务端访问
CurrencyInfo cur = new CurrencyInfo();
ICurrency c = CurrencyFactory. getLocalInstance (ctx);//建立实体对象
c. getCurrencyCollection();
2.9 控件的初始化
1.使用枚举给ComboBox控件赋值
public void setReceiveType()
{
this.kDComboBox2.removeAllItems();
List list = new List();
Iterator it = ReceiveType.iterator();
while (it.hasNext())
{
list.add(ReceiveType.getEnum(it.toString()).toString());
}
}
2.使用值对象集合给ComboBox控件赋值
// 获取结算方式列表
IAsstActTypeDefault iAsstActType = AsstActTypeDefaultFactory.getRemoteInstance();
AsstActTypeDefaultCollectioni asstActTypeColl = iAsstActType
.getAsstActTypeDefaultCollection(" where isAccountCussent = 1");
AsstActTypeDefaultInfo defaultVal = null;
int count = asstActTypeColl.size();
Object[] typeValue = new Object[count];
for (int i = 0; i < count; i++)
{
AsstActTypeDefaultInfo value = (AsstActTypeDefaultInfo) asstActTypeColl.get(i);
if (value.isIsDefaultAccountPayable())
{
defaultVal = value;
}
ObjectUuidPK pk = new ObjectUuidPK(BOSUuid.read(value.getAsstActType().getString("id")));
AsstActTypeInfo asstInfo = AsstActTypeFactory.getRemoteInstance().getAsstActTypeInfo(pk);
//cbi[i] = new ComBoxInfo(asstInfo, asstInfo.getName(), true);
String typeName = asstInfo.getName();
String typeId = asstInfo.getId().toString();
String typeQueryName = asstInfo.getDefaultQueryName();
String typeTableName = asstInfo.getRealtionDataObject();
int csType = 0; //asstActTypeInfo.getCsType().getValue();
asstActType = new AsstActTypeUtils(typeName, typeId, typeTableName, typeQueryName, csType);
typeValue[i] = (Object) asstActType;
}
///String strQueryName = "F7SupplierQuery";
this.kDComAccountCussentType.removeAllItems();
this.kDComAccountCussentType.addItems(typeValue);
this.kDComAccountCussentType.setSelectedIndex(0);
2.10 F7赋值
ObjectUuidPK pk = new ObjectUuidPK(id);
IObjectValue objVal = DynamicObjectFactory.getRemoteInstance().getValue(pk.getObjectTypei(), pk);
bizPrompt.setData(objVal);
private void setCompanyF7()
{
//公司的F7的设置
OrgType[] CompanyType = { OrgType.Company };
//首先定义需要显示那些树,这里只显示财务树
//为F7控件指定PromptBox
this.bizPromptCompany.setEditFormat("$number$");
this.bizPromptCompany.setDisplayFormat("$name$");
this.bizPromptCompany.setEditable(true);
this.bizPromptCompany.setCommitFormat("$number$");
OrgUnitTreePromptBox boxCompany = new OrgUnitTreePromptBox(this, CompanyType, null,
OrgSelect.OnlySelectCompanyEntity, false, false, false);
bizPromptCompany.setSelector(boxCompany);
bizPromptCompany.setData(currentCompany);
bizPromptCompany.setEnabled(false);
}
//设置币别
private void setCurrency() throws EASBizException, BOSException
{
ICurrency iCurrency = null;
CurrencyCollection con = null;
try
{
iCurrency = CurrencyFactory.getRemoteInstance();
con = iCurrency.getCurrencyCollection(true);
}
catch (Exception e)
{
// TODO 自动生成 catch 块
MsgBox.showError(this, EASResource.getString(resClassName, "currencyFail"));
SysUtil.abort();
}
if (con != null)
{
Object[] typeValue = new Object[con.size()];
int j = 0;
for (int i = 0; i < con.size(); i++)
{
CurrencyInfo currencyInfo = (CurrencyInfo) con.get(i);
String typeName = currencyInfo.getName();
String typeId = currencyInfo.getId().toString();
String typeQueryName = currencyInfo.getNumber();
asstActType = new AsstActTypeUtils(typeName, typeId, typeQueryName);
if (asstActType != null)
{
typeValue[i] = (Object) asstActType;
if(typeId.equalsIgnoreCase(((CurrencyInfo)currentCompany.getBaseCurrency()).getId().toString()
))
{
j = i;
}
}
}
this.bizPromptcurrency.removeAllItems();
this.bizPromptcurrency.addItems(typeValue);
//默认值为当前公司的本位币
this.bizPromptcurrency.setSelectedIndex(j);
}
else
{
MsgBox.showError(this, EASResource.getString(resClassName, "currencyFail"));
SysUtil.abort();
}
}
2.11 设置单据分录单元格格式
// 设置单据分录格式
getDetailTable().getColumn(TB_RELABILL).setWidth(100);
getDetailTable().getColumn(TB_ORGUNIT).setWidth(180);
getDetailTable().getColumn(TB_BIZMAN).setWidth(100);
getDetailTable().getColumn(TB_PAYAMOUNT).setEditor(number_CellEditor); getDetailTable().getColumn(TB_PAYAMOUNT).getStyleAttributes().setNumberFormat("%r-[=]{#.00}f"); getDetailTable().getColumn(TB_PAYAMOUNT).getStyleAttributes().setHorizontalAlign(HorizontalAlignment.RIGHT);
2.12 设置单元格可编辑
for (int i = 0; i < kdtEntrys.getRowCount(); i++)
{
kdtEntrys.getRow(i).getCell("orgUnit").getStyleAttributes().setLocked(false);
kdtEntrys.getRow(i).getCell("bizMan").getStyleAttributes().setLocked(false);
}
//如果折扣金额为null则初始化为0
if (kdtEntrys.getRow(i).getCell("discountAmount").getValue() == null)
{
kdtEntrys.getRow(i).getCell("discountAmount").setValue(new BigDecimal("0.0"));
}
//汇总分录行金额
BigDecimal amount = new BigDecimal("0");
for (int i = 0, n = kdtEntrys.getRowCount(); i < n; i++)
{
amount = amount.add(UIRuleUtil.getBigDecimal(UIRuleUtil.getBigDecimalValue
(kdtEntrys.getCell(i,TB_PAYAMOUNT).getValue())));
}
this.txtTotalAmounts.setText(null);
this.txtTotalAmounts.setEnable(false);
this.txtTotalAmounts.setText(amount);
//和零比较
if (amount.compareTo(new BigDecimal("0.00")) == 0)
2.13 删除行
public void actionDeleteLine_actionPerformed(ActionEvent e)throws Exception {
IRow row = getSelectedRow();
if (row != null) {
kDTable1.removeRow(row.getRowIndex());
}
}
2.14 F7专用选择界面的设置
public void setF7Selector() throws Exception
{
KDBizPromptBox bizPromptBox = new KDBizPromptBox();// 要绑定的F7控件
CoreUIObject ui = null;// 父界面对象
CompanyOrgUnitInfo companyInfo = null; // 当前财务组织
// 客户
bizPromptBox.setSelector(new GeneralKDPromptSelectorAdaptor(bizPromptBox, new F7CustomerTreeDetailListUI(), ui));
// 供应商
bizPromptBox.setSelector(new GeneralKDPromptSelectorAdaptor(bizPromptBox, new F7SupplierTreeDetailListUI(), ui));
// 物料
bizPromptBox.setSelector(new GeneralKDPromptSelectorAdaptor(bizPromptBox, new F7MaterialTreeListUI(), ui));
// 职员
HashMap map = new HashMap();
map.put(PersonF7UI.ALL_ADMIN, "YES");
bizPromptBox.setSelector(new PersonPromptBox(ui, map));
// 公司
CompanyF7 org = new CompanyF7(ui);
org.setRootUnitID("");
bizPromptBox.setSelector(new CompanyF7(ui));
// 成本中心
bizPromptBox.setSelector(new CostCenterF7(ui));
// 行政组织
bizPromptBox.setSelector(new AdminF7(ui));
// 采购组织
bizPromptBox.setSelector(new PurchaseF7(ui));
// 库存组织
bizPromptBox.setSelector(new StorageF7(ui));
// 销售组织
bizPromptBox.setSelector(new SaleF7(ui));
// 利润中心组织
bizPromptBox.setSelector(new ProfitCenterF7(ui));
// 利润中心组织
bizPromptBox.setSelector(new ProfitCenterF7(ui));
// 科目
bizPromptBox.setSelector(new AccountPromptBox(ui, companyInfo, new FilterInfo()));
}
2.15 获取各模块系统状态信息
public void getSystemStatue() throws EASBizException, BOSException
{
CompanyOrgUnitInfo companyInfo = null; // 当前财务组织
// SystemStatusCtrolUtils 工具类可获取各模块系统状态信息,如当前会计期间,系统是否启用或关闭等信息
SystemStatusCtrolUtils.getCurrentPeriod(null/* 上下文信息,如在客户端使用可为null */, SystemEnum.ACCOUNTSPAYABLE, companyInfo/**/);
}
2.16 获取当前登陆信息
public void getSystemInfo()
{
// SysContext工具类可获取当前登陆用户的信息,可根据需要进行调用。
// 举两例如下:
SysContext.getSysContext().getCurrentUserInfo();// 获取当前登陆用户信息
SysContext.getSysContext().getCurrentFIUnit();// 获取当前财务组织
}
2.17 获取参数平台参数设置的示例代码
public void getParam() throws EASBizException, BOSException
{
CompanyOrgUnitInfo companyInfo = null; // 当前财务组织
ObjectUuidPK orgPk = new ObjectUuidPK(companyInfo.getId());
// ParamManager工具类提供了不同的方法获取参数俱,可根据自己的需要进行调用,
// 示例如下:
ParamManager.getParamValue(null/* 上下文信息,客户端调用可以为null */, orgPk, "AR_INIT_CHECK_TYPE");
}
2.18 网络互斥功能示手工控制
public void doMutexService()
{
IMutexServiceControl mutex = MutexServiceControlFactory.getRemoteInstance();
UserInfo user = null; // 请求锁有用户
String billId = null; // 要锁定/解锁的单据Id
// 请求锁定
mutex.requestObjIDForUpdate(billId, user.getString("id"));
// 解除锁
mutex.releaseObjIDForUpdate(billId);
}
Tree:TreeBase(增加parentid级次)
Data:DataBase、BillBase(增加关联关系,对Tree的引用)
2.19 Tree- List实现方法1
protected ITreeBase getTreeInterface() throws Exception
{
return com.kingdee.eas.custom.TreeGroupTestTreeFactory.getRemoteInstance();
}
2.20 Tree-List点击树上结点时形成过滤条件时的字段
如:protected String getQueryFieldName()
{
return "treeid.id";
}
2.21 Tree-树形控件的初始化级次 [optional]
protected int getTreeInitialLevel()
{
return TreeBuilderFactory.DEFAULT_INITIAL_LEVEL;
}
2.22 Tree-树形空间的默认展开级次 [optional]
protected int getTreeExpandLevel()
{
return TreeBuilderFactory.DEFAULT_EXPAND_LEVEL;
}
2.23 Tree-返回树形控件的根名称
protected String getRootName()
{
return "TreeGroupTest";
}
2.24 Tree-数据过滤(重载实现对树的过滤)
getDefaultFilterForTree()方法,是默认的cu过滤条件
2.25 Tree-控件基本使用
2.25.1 初始化树形控件
//treeMain控件名
protected void initTree() throws Exception
{
TreeSelectionListener[] listeners = treeMain.getTreeSelectionListeners();
TreeSelectionListener treeSelectionListener = listeners[0];
treeMain.removeTreeSelectionListener(treeSelectionListener);
ITreeBuilder treeBuilder
= TreeBuilderFactory.createTreeBuilder(getLNTreeNodeCtrl(),getTreeInitialLevel() , getTreeExpandLevel(),getDefaultFilterForTree());
if (getRootName() != null)
{
KDTreeNode rootNode = new KDTreeNode(getRootObject());
( (DefaultTreeModel) treeMain.getModel()).setRoot(rootNode);
}
else
{
( (DefaultTreeModel) treeMain.getModel()).setRoot(null);
}
//将数据填入控件中
treeBuilder.buildTree(treeMain);
//增加选择事件
treeMain.addTreeSelectionListener(treeSelectionListener);
}
2.25.2 返回选中的树结点
public KDTreeNode getSelectedTreeNode()
{
return (KDTreeNode) treeMain.getLastSelectedPathComponent();
}
2.25.3 返回树结点的值
return (TreeBaseInfo) ((KDTreeNode)
treeMain.getLastSelectedPathComponent()).getUserObject();
2.25.4 删除类别时刷新当前结点的父结点,并定位到当前结点的父结点。
KDTreeNode treeNode = (KDTreeNode) treeMain
.getLastSelectedPathComponent();
if (treeNode != null && treeNode.getParent() != null)
{
TreePath parentPath = treeMain.getSelectionPath().getParentPath();
KDTreeNode parentNode = (KDTreeNode) treeNode.getParent();
parentNode.remove(treeNode);
treeMain.updateUI();
treeMain.setSelectionPath(parentPath);
treeBuilder.refreshTreeNode(treeMain , parentNode ,this.getDefaultFilterForTree());
treeMain.expandPath(parentPath);
}
//刷新Query数据
CacheServiceFactory.getInstance().discardQuery(this.mainQueryPK);
2.25.5 设置选中根结点
treeMain.setSelectionRow(0);
2.25.6 类别新增与修改时,刷新当前选中结点
KDTreeNode treeNode = (KDTreeNode) treeMain
.getLastSelectedPathComponent();
if (treeNode != null && treeNode.getParent() == null)
{
TreePath oldPath = treeMain.getSelectionPath();
treeBuilder.refreshTreeNode(treeMain , treeNode,this.getDefaultFilterForTree());
treeMain.setSelectionPath(oldPath);
treeMain.expandPath(oldPath);
}
2.25.7 修改类别时刷新当前结点的父结点,并定位到当前结点
KDTreeNode treeNode = (KDTreeNode) treeMain.getLastSelectedPathComponent();
if (treeNode != null && treeNode.getParent() != null)
{
TreePath oldPath = treeMain.getSelectionPath();
TreePath parentPath = treeMain.getSelectionPath().getParentPath();
KDTreeNode parentNode = (KDTreeNode) treeNode.getParent();
treeBuilder.refreshTreeNode(treeMain , parentNode ,this.getDefaultFilterForTree());
treeMain.setSelectionPath(TreePathUtil.getNewTreePath(treeMain ,
treeMain.getModel() , oldPath));
}