代码如下,代码里直接设置为核准状态,查看数据库中的数据,比较手动新增的数据,没有差别,已维护财务资料,库存资料,并核准,但是在采购入库单新增时,选择不到该物料,求指教。
public void updateMaterial(Connection cn, PreparedStatement ps) throws SQLException, EASBizException, BOSException, UuidException {
// TODO Auto-generated method stub
StringBuffer sql1 = new StringBuffer();//sql1=物料
sql1.append("select sid, p_sid,ContractID,matGroupNumber,matgroupName" +
",matName,matMeasure,matPrice,matQuantity,matSpec,matMat from HH_Contract_Detail where matgroupName <> ''");
StringBuffer sql2 = new StringBuffer();//sql2=物料
sql2.append("update STK_MI_DETAIL set istransfer=1 where code in ( ");
i = 0;//计数器,统计同步物料个数
if(cn != null){
ps = cn.prepareStatement(sql1.toString());
ResultSet rs = ps.executeQuery();
while(rs.next()){
String code = rs.getString("matgroupName");
String name = rs.getString("matName");
String unit = rs.getString("matMeasure");
String type = rs.getString("matSpec");
MaterialInfo material = new MaterialInfo();
EntityViewInfo viewinfo = new EntityViewInfo();
FilterInfo filterinfo = new FilterInfo();
filterinfo.getFilterItems().add(new FilterItemInfo("number", code,CompareType.EQUALS));
viewinfo.setFilter(filterinfo);
MaterialCollection matColl = MaterialFactory.getRemoteInstance().getMaterialCollection(viewinfo);
if(matColl != null && matColl.size()>0){
material = matColl.get(0);
}
MeasureUnitCollection unitColl = MeasureUnitFactory.getRemoteInstance().getMeasureUnitCollection("select * where name ='"+unit+"'");//默认单位 台
if(unitColl !=null && unitColl.size()>0){
material.setBaseUnit(unitColl.get(0));
}else{
// MeasureUnitInfo unitinfo = MeasureUnitFactory.getRemoteInstance().getMeasureUnitInfo(new ObjectUuidPK(BOSUuid
// .read("NuyMUAEWEADgAEmVCgAAAluCXFc=")));//默认单位 台
MeasureUnitCollection unitcoll = MeasureUnitFactory.getRemoteInstance().getMeasureUnitCollection("select * where name='个'");//默认单位 个
material.setBaseUnit(unitcoll.get(0));
}
// MaterialGroupInfo groupinfo = MaterialGroupFactory.getRemoteInstance().getMaterialGroupInfo(new ObjectUuidPK(BOSUuid
// .read("bDfvFJ2KSEKV9cFuRDr4gMefwEI=")));//默认CBS基本分类
EntityViewInfo matGroupviewinfo = new EntityViewInfo();
FilterInfo filter = new FilterInfo();
filter.getFilterItems().add(new FilterItemInfo("number","CBS",CompareType.EQUALS));
matGroupviewinfo.setFilter(filter);
MaterialGroupCollection groupcoll = MaterialGroupFactory.getRemoteInstance().getMaterialGroupCollection(matGroupviewinfo);//默认CBS基本分类
MaterialGroupInfo groupinfo = null;
if(groupcoll!=null && groupcoll.size()>0){
groupinfo = groupcoll.get(0);
}else{
MsgBox.showError("缺少物料分组CBS,请增加物料分组,编码为CBS");
abort();
}
material.setNumber(code);
material.setName(name);
material.setModel(type);
material.setAdminCU(SysContext.getSysContext().getCurrentCtrlUnit());//默认当前登陆组织
material.setCU(SysContext.getSysContext().getCurrentCtrlUnit());//控制单元,默认当前登陆组织
// material.setCreator((com.kingdee.eas.base.permission.UserInfo)(com.kingdee.eas.common.client.SysContext.getSysContext().getCurrentUser()));
// material.setCreateTime(new Timestamp(new Date().getTime()));
material.setEquipProperty(EquipmentPropertyEnum.EQUIPMENT);
material.setMaterialGroup(groupinfo);
material.setEffectedStatus(2);//1=暂存,2=保存
material.setStatus(UsedStatusEnum.UNAPPROVE);//核准
material.setVersion(1);//版本号
material.setPricePrecision(6);
if(matColl != null && matColl.size()>0){
IObjectPK id = MaterialFactory.getRemoteInstance().submit(material);
MaterialFactory.getRemoteInstance().approve(id);
}else{
IObjectPK id = MaterialFactory.getRemoteInstance().submit(material);
MaterialFactory.getRemoteInstance().approve(id);
}
// material.setMaterialGroup(item);
// MsgBox.showInfo(code);
/*
* 删除保存成功的物料
*/
sql2.append("'").append(code).append("',");
i=i+1;//计数器+1
}
ps.close();
//根据计数器判断是否进行删除
if(i>1){//
sql2.deleteCharAt(sql2.length()-1);//删除最后一个字符 “,”
sql2.append(")");
// ps = cn.prepareStatement(sql2.toString());
// ps.executeUpdate();
// ps.close();
}
}
}
推荐阅读