package com.connor.dfl.plm.dfl041; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import org.jacorb.idl.runtime.int_token; import com.connor.dfl.plm.dfl019.Dfl019Operation; import com.connor.dfl.plm.dfl020.Dfl020Operation; import com.connor.dfl.plm.exportBOM.ChangeDbomUtil; import com.connor.dfl.plm.util.CopyPropsBean; import com.connor.dfl.plm.util.DataBaseControl; import com.itextpdf.text.Jpeg; import com.teamcenter.rac.aif.AbstractAIFApplication; import com.teamcenter.rac.aif.AbstractAIFDialog; import com.teamcenter.rac.aif.kernel.AIFComponentContext; import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; import com.teamcenter.rac.aifrcp.AIFUtility; import com.teamcenter.rac.commands.userpreferences.ProductContextPreferencesPanel; import com.teamcenter.rac.kernel.ListOfValuesInfo; import com.teamcenter.rac.kernel.ServiceData; import com.teamcenter.rac.kernel.SoaUtil; import com.teamcenter.rac.kernel.TCComponent; import com.teamcenter.rac.kernel.TCComponentBOMLine; import com.teamcenter.rac.kernel.TCComponentBOMWindow; import com.teamcenter.rac.kernel.TCComponentBOMWindowType; import com.teamcenter.rac.kernel.TCComponentFolder; import com.teamcenter.rac.kernel.TCComponentForm; import com.teamcenter.rac.kernel.TCComponentGroup; import com.teamcenter.rac.kernel.TCComponentItem; import com.teamcenter.rac.kernel.TCComponentItemRevision; import com.teamcenter.rac.kernel.TCComponentItemType; import com.teamcenter.rac.kernel.TCComponentListOfValues; import com.teamcenter.rac.kernel.TCComponentListOfValuesType; import com.teamcenter.rac.kernel.TCComponentProject; import com.teamcenter.rac.kernel.TCComponentQuery; import com.teamcenter.rac.kernel.TCComponentQueryType; import com.teamcenter.rac.kernel.TCComponentUser; import com.teamcenter.rac.kernel.TCException; import com.teamcenter.rac.kernel.TCPreferenceService; import com.teamcenter.rac.kernel.TCProperty; import com.teamcenter.rac.kernel.TCSession; import com.teamcenter.rac.kernel.TCTypeService; import com.teamcenter.rac.util.ButtonLayout; import com.teamcenter.rac.util.MessageBox; import com.teamcenter.rac.util.PropertyLayout; import com.teamcenter.rac.util.Utilities; import com.teamcenter.soaictstubs.stringSeq_tHolder; public class CreateNoemBOMDialogs extends AbstractAIFDialog { private static final Object TCComponentItemRevision = null; //private AbstractAIFApplication app; AbstractAIFApplication app = AIFUtility.getCurrentApplication(); private InterfaceAIFComponent targetComp; private TCPreferenceService service; private TCComponent comp; private TCComponent comp1; private TCComponent[] comp2; private TCComponentFolder folder; TCSession session = (TCSession) app.getSession(); private JPanel panel1; private JPanel buttonPanel; private JLabel bomCode_lable; private JComboBox bomCode_combobox; private JLabel BI_lABLE2; private JTextField id_field; private JButton certain_btn; private JButton cancel_btn; private Map groupMap=new HashMap(); private Map sourceMap=new HashMap(); private String[] alls; private String[] eqgroup; private String[] boms; private String[] newArr; private String bomCode; private String xunigroup; private List xunirevlist = new ArrayList();; public CreateNoemBOMDialogs(AbstractAIFApplication app,InterfaceAIFComponent targetComp) { super(); this.app = app; this.session = session; this.service = session.getPreferenceService(); this.targetComp = targetComp; } @Override public void run() { // TODO Auto-generated method stub try { alls = service.getStringValues("dfl_standard_bom"); if(alls == null || alls.length <= 0) { MessageBox.post("首选项dfl_standard_bom未配置,请联系管理员!!", "错误", MessageBox.ERROR); return; } init(); } catch (TCException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 模糊查询 字符串数组 并返回 含有 str 的 字符串数组 * @param arr * @param str * @return */ public String[] filter(String[] strsz, String str){ ArrayList list = new ArrayList<>(); for (String s : strsz) { if (s.contains(str)){ list.add(s); } } System.out.println("模糊查询8.25======="+list); newArr= new String[list.size()]; newArr=list.toArray(newArr); return newArr; } private void init() throws TCException { //标题 this.setTitle("创建标准Bom"); //大小 this.setPreferredSize(new Dimension(450, 450)); //this.setAlwaysOnTop(true); this.setLayout(null); TCComponentItem item = null; //new标签对象 bomCode_lable = new JLabel(" 设备型号 :"); //new下拉框对象 bomCode_combobox = new JComboBox(); bomCode_combobox.addItem(" "); //输出测试,获取首选值 for(int i =0 ;i queryObject(String queryName, String[] keys, String[] values) { TCComponent[] components = null; try { TCComponentQueryType queryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); TCComponentQuery query = (TCComponentQuery) queryType.find(queryName); if (query == null) { MessageBox.post("没有找到查询:" + queryName, "错误", MessageBox.ERROR); return null; } components = query.execute(keys, values); } catch (TCException e) { e.printStackTrace(); } if (components != null && components.length > 0) { List compList = Arrays.asList(components); return compList; } else { return null; } } protected void createItem() { // TODO Auto-generated method stub try { InterfaceAIFComponent comp = app.getTargetComponent(); comp = (TCComponent) targetComp; //设置顶层对象 TCComponentItem item = null; item = (TCComponentItem) comp; TCProperty item_type = item.getTCProperty("object_type"); String equipmenttype = item_type.getStringValue(); //获得对象关系,遍历关系中的文件夹 AIFComponentContext[] refs = item.whereReferenced(); //List list = new ArrayList(); for (int i = 0 ; i<=refs.length-1;i++) { AIFComponentContext parent= refs[i]; comp1 = (TCComponent) parent.getComponent(); String folder_type = comp1.getProperty("object_type"); System.out.println("关系对象类型"+folder_type); //判断关系的对象的类型 if ("文件夹".equals(folder_type) || "Home 文件夹".equals(folder_type)) { folder = (TCComponentFolder) comp1; if("文件夹".equals(folder_type)) { folder = (TCComponentFolder) comp1; } //list.add(folder_type); } } System.out.println("选中的对象类型"+equipmenttype); //设置顶层最新版本版本 TCComponentItemRevision rev =item.getLatestItemRevision(); //item.whereReferenced(); //获取设备版本的分群码和id TCProperty pro2 = rev.getTCProperty("item_id"); TCProperty pro3 = rev.getTCProperty("t2_groupCode"); String equipmentname = pro2.getStringValue(); String equipmentgroup = pro3.getStringValue(); System.out.println("设备分群码"+equipmentgroup); this.setVisible(false); //判断是否为东富龙设备 if("T2_Equipment".equals(equipmenttype)) { boolean flag = true; String[] vals = null; for (int i = 0; i < newArr.length; i++) { String bom = newArr[i]; vals = bom.split("!"); String valss = vals[0]; System.out.println("8.25valss=============="+valss); String[] agree = valss.split("="); String agreement = agree[1]; System.out.println("8.25agreement==========="+agreement); System.out.println("8.25bomCode_combobox============"+bomCode); //判断选中的是否和首选项中的一致,是就跳出循环,不再赋值 if(bomCode.equals(agreement)) { flag = false; break; } } if(vals != null) { TCTypeService service = session.getTypeService(); //获取BOMWindowType TCComponentBOMWindowType winType = (TCComponentBOMWindowType) service .getTypeComponent("BOMWindow"); //创建一个新的window TCComponentBOMWindow view = winType.create(null); view.lock(); //设置顶层的bomline TCComponentBOMLine line = view.setWindowTopLine(item,rev, null, null); TCComponentItemType type = (TCComponentItemType) session.getTypeComponent("T2_Virtual"); String[] values = vals[1].split(";"); //设置虚拟件版本的分群码 String itemrevbomgroup = vals[0];//字符串 设备分群码=虚拟件分群码#bom型号 System.out.println("8.25分群码字段"+itemrevbomgroup); String[] itemrevgroup = itemrevbomgroup.split("#");//数组设备分群码=虚拟件分群码 - bom型号 String itemrevString = itemrevgroup[0];//字符串设备分群=虚拟件分群码 String[] revgruop = itemrevString.split("=");//数组设备分群码 = 虚拟件分群码 String revgropuString = revgruop[1];//字符串 虚拟件分群码 //设置虚拟件版本的来源码 String sourcecode = "X"; TCComponentItem newItem =null; TCComponentItemRevision xunirev = null; for (int j = 0; j < values.length; j++) { String[] nameID = values[j].split("\\|"); String item_id = equipmentname + "" + nameID[0]; String sysandjob =nameID[1];//系统名称$作业编号 String job_num = null; System.out.println("系统名称$作业编号8.23=="+sysandjob); String[] sysandjobsz = sysandjob.split("\\$");//按照$来分开 String object_name =sysandjobsz[0];//系统名称 System.out.println("object_name8.23=="+object_name); System.out.println(item_id); newItem =new TCComponentItem(); //创建新的虚拟件对象 newItem = type.create(item_id, "01", "T2_Virtual", object_name, "", null); //设置对象的位置 folder.add("contents", newItem); //设置虚拟件版本的分群码 xunirev = new TCComponentItemRevision(); xunirev = newItem.getLatestItemRevision(); if (revgropuString != null && revgropuString != "") { xunirev.setStringProperty("t2_groupCode", revgropuString); } //设置虚拟件对象版本的描述 if (object_name != null && object_name != "") { newItem.setStringProperty("object_desc", object_name); xunirev.setStringProperty("object_desc", object_name); } //设置虚拟件版本的来源码 if (sourcecode != null && sourcecode != "") { xunirev.setStringProperty("t2_sourceCode", sourcecode); } //将虚拟件版本添加到集合中 xunirevlist.add(xunirev); //添加子bomline TCComponentBOMLine childBomline = line.add(newItem, newItem.getLatestItemRevision(), null, false, ""); childBomline.setStringProperty("bl_quantity", "1");//设置bomline属性数量为1 //添加作业编号 if (sysandjob.contains("$")) { job_num = sysandjobsz[1];//作业编号 childBomline.setStringProperty("T2_JobNumber", job_num);//设置bomline属性作业编号 } } //传递虚拟件物料到erp //测试物料信息 if (xunirevlist.size()>0) { System.out.println("xunirevlist有值"); for(int i = 0; i < xunirevlist.size(); i++){ TCComponentItemRevision test =new TCComponentItemRevision(); test=(TCComponentItemRevision)xunirevlist.get(i); TCProperty revsid = test.getTCProperty("item_id"); String revsString = revsid.getStringValue(); System.out.println("创建标准bom方法内虚拟件版本id"+revsString); } }else { System.out.println("xunirevlist无值"); } //物料传递erp wuliaotoerp wuliaotoerp = new wuliaotoerp(app, session); wuliaotoerp.Wuliaotoerp(xunirevlist); view.save(); view.unlock(); view.close(); }else { MessageBox.post("没有配置对应的标准BOM结构,需手动创建虚拟系统层级!!!", "提示", MessageBox.INFORMATION); } }else { MessageBox.post("您选中的不是东富龙设备对象","提示",MessageBox.INFORMATION); return; } MessageBox.post("标准bom创建成功","提示",MessageBox.INFORMATION); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); MessageBox.post("错误:" + e.getMessage(), "错误", MessageBox.INFORMATION); } } private TCComponentItem TCComponentItem(TCComponent comp) { // TODO Auto-generated method stub return null; } }