欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Part/BOM的导出

程序员文章站 2022-07-14 20:05:37
...
private static ReferenceFactory rf=new ReferenceFactory();
private static final boolean serverFlag=RemoteMethodServer.getDefault().ServerFlag;

/**
* @param args
* @throws WTException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
OutputStream os=new FileOutputStream(new File("E:/test.xls"));
bomexport(os,"VR:wt.part.WTPart:311117");
//bomexport(os, "VR:wt.part.WTPart:311189");

}
public static Object getObjectByOid(String oid) throws WTException{

return rf.getReference(oid).getObject();
}

public static void bomexport(OutputStream os,String oid) throws Exception{
RemoteMethodServer methodServer = RemoteMethodServer.getDefault();
methodServer.setUserName("wcadmin");
methodServer.setPassword("wcadmin");
if(oid!=null && oid.length()>0){
ArrayList list=new ArrayList();

WTPart part=(WTPart) getObjectByOid(oid);
list=getBOM(part,list);
createBOMExcel(os, list, part);
}


}
public static ArrayList getBOM(WTPart part,ArrayList list) throws Exception{
System.out.println("whodd");
//if(serverFlag){

if(part==null){
return list;
}
WTPrincipal currentUser=null;
try {
currentUser=SessionHelper.getPrincipal();
SessionHelper.manager.setAdministrator();
if(part.isEndItem()){
addAttrToList(list, part);
}

QueryResult qr=WTPartHelper.service.getUsesWTPartMasters(part);
if(qr.size()!=0){
while(qr.hasMoreElements()){
WTPartUsageLink link=(WTPartUsageLink) qr.nextElement();
if(link!=null){
WTPartMaster partmaster=(WTPartMaster) link.getRoleBObject();
WTPart subpart=getLastPart(partmaster);
if(subpart!=null){
addAttrToList(list, subpart);

}
getBOM(subpart,list);
}

}
}

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
SessionHelper.manager.setPrincipal(currentUser.getName());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}


}

return list;
相关标签: OS Excel J#