package com.langtech.plm.project; import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import com.teamcenter.rac.aif.AbstractAIFApplication; import com.teamcenter.rac.aif.kernel.AIFComponentContext; import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; 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.TCComponentDataset; import com.teamcenter.rac.kernel.TCComponentItem; import com.teamcenter.rac.kernel.TCComponentItemRevision; import com.teamcenter.rac.kernel.TCComponentMEOP; import com.teamcenter.rac.kernel.TCComponentMEOPRevision; import com.teamcenter.rac.kernel.TCComponentTcFile; import com.teamcenter.rac.kernel.TCException; import com.teamcenter.rac.kernel.TCPreferenceService; import com.teamcenter.rac.kernel.TCSession; import com.teamcenter.rac.util.MessageBox; import com.teamcenter.rac.util.PropertyLayout; import com.teamcenter.rac.util.UIUtilities; public class CalculateDialog extends JFrame implements ActionListener { /** * */ private static final long serialVersionUID = 1L; private AbstractAIFApplication application; private TCComponentMEOPRevision meop; private TCSession session; TCComponentItemRevision rawMaterialRevision; //打印界面控件 //图纸零件轮廓直径D private JLabel zjdLabel; private JTextField zjdTextField; //图纸零件轮廓长 private JLabel lkcLabel; private JTextField lkcTextField; //切断用长度 private JLabel qdycdLabel; private JTextField qdycdTextField; //车端面用长度 private JLabel cdmycdLabel; private JTextField cdmycdTextField; //夹头用长度 private JLabel jtycdLabel; private JTextField jtycdTextField; //可制零件数 private JLabel kzljsLabel; private JTextField kzljsTextField; //规格 private JLabel ggLabel; private JTextField ggTextField; //材料牌号 private JLabel clphLabel; private JTextField clphTextField; //计算结果控件 //总长 private JLabel zcLabel; private JTextField zcTextField; //单件长度 private JLabel djcdLabel; private JTextField djcdTextField; //单件重量 private JLabel djzlLabel; private JTextField djzlTextField; //标准工时 private JLabel bzgsLabel; private JTextField bzgsTextField; //辅助工时 private JLabel fzgsLabel; private JTextField fzgsTextField; //计算按钮 private JButton calculateButton; //同步按钮 private JButton syncButton; //取消按钮 private JButton celButton; //密度 private String density; //横截面 private String crossSection; //辅助时间 private String auxiliaryTime; //固定时间 private String fixedTime; //切割时间 private String cuttingTime; public CalculateDialog(AbstractAIFApplication application,TCComponentMEOPRevision meop) throws TCException { this.application = application; this.meop = meop; this.session = (TCSession) application.getSession(); initUI(); getProperties(this.meop); } private JPanel getTopPanel() { JPanel centerPanel = new JPanel(new PropertyLayout()); centerPanel.add("1.1.left.top",this.zjdLabel); centerPanel.add("1.2.left.top",this.zjdTextField); centerPanel.add("2.1.left.top",this.lkcLabel); centerPanel.add("2.2.left.top",this.lkcTextField); centerPanel.add("3.1.left.top",this.qdycdLabel); centerPanel.add("3.2.left.top",this.qdycdTextField); centerPanel.add("4.1.left.top",this.cdmycdLabel); centerPanel.add("4.2.left.top",this.cdmycdTextField); centerPanel.add("5.1.left.top",this.jtycdLabel); centerPanel.add("5.2.left.top",this.jtycdTextField); centerPanel.add("6.1.left.top",this.kzljsLabel); centerPanel.add("6.2.left.top",this.kzljsTextField); centerPanel.add("7.1.left.top",this.ggLabel); centerPanel.add("7.2.left.top",this.ggTextField); centerPanel.add("8.1.left.top",this.clphLabel); centerPanel.add("8.2.left.top",this.clphTextField); centerPanel.add("1.3.left.top",this.zcLabel); centerPanel.add("1.4.left.top",this.zcTextField); centerPanel.add("2.3.left.top",this.djcdLabel); centerPanel.add("2.4.left.top",this.djcdTextField); centerPanel.add("3.3.left.top",this.djzlLabel); centerPanel.add("3.4.left.top",this.djzlTextField); centerPanel.add("4.3.left.top",this.bzgsLabel); centerPanel.add("4.4.left.top",this.bzgsTextField); centerPanel.add("5.3.left.top",this.fzgsLabel); centerPanel.add("5.4.left.top",this.fzgsTextField); centerPanel.add("6.3.left.top",this.calculateButton); return centerPanel; } /** * 设置界面属性条目 */ private void setPanelProperties() { this.zjdLabel = new JLabel("图纸零件轮廓直径D"); this.lkcLabel = new JLabel("图纸零件轮廓长"); this.qdycdLabel = new JLabel("切断用长度"); this.cdmycdLabel = new JLabel("车端面用长度"); this.jtycdLabel = new JLabel("夹头用长度"); this.kzljsLabel = new JLabel("可制零件数"); this.ggLabel = new JLabel("规格"); this.clphLabel = new JLabel("材料牌号"); this.zcLabel = new JLabel("总长"); this.djcdLabel = new JLabel("单件长度"); this.djzlLabel = new JLabel("单件重量"); this.bzgsLabel = new JLabel("标准工时"); this.fzgsLabel = new JLabel("辅助工时"); this.zjdTextField = new JTextField(32); this.lkcTextField = new JTextField(32); this.qdycdTextField = new JTextField(32); this.cdmycdTextField = new JTextField(32); this.jtycdTextField = new JTextField(32); this.kzljsTextField = new JTextField(32); this.ggTextField = new JTextField(32); this.ggTextField.setEditable(false); this.ggTextField.setBackground(new Color(200, 200, 200)); this.clphTextField = new JTextField(32); this.clphTextField.setEditable(false); this.ggTextField.setBackground(new Color(200, 200, 200)); this.zcTextField = new JTextField(32); this.djcdTextField = new JTextField(32); this.djzlTextField = new JTextField(32); this.bzgsTextField = new JTextField(32); this.fzgsTextField = new JTextField(32); this.calculateButton = new JButton("计算"); this.syncButton = new JButton("同步"); this.celButton = new JButton("取消"); } /** * 获取底部按钮 * @return */ private JPanel getButtomPanel() { JPanel bottomPanel = new JPanel(new FlowLayout(1)); // bottomPanel.add(this.calculateButton); bottomPanel.add(this.syncButton); bottomPanel.add(this.celButton); return bottomPanel; } /** * 初始化图形界面 */ private void initUI() { this.setTitle("材料定额及工时计算"); this.setSize(500, 500); this.setLayout(new BorderLayout()); setPanelProperties(); JPanel centerPanel = getTopPanel(); JPanel bottomPanel = getButtomPanel(); this.add(centerPanel,BorderLayout.CENTER); this.add(bottomPanel,BorderLayout.SOUTH); //添加事件 this.calculateButton.addActionListener(this); this.syncButton.addActionListener(this); this.celButton.addActionListener(this); //放到屏幕中央 UIUtilities.centerToScreen(this); this.setVisible(true); } /** * 获取所选MEOP对象的属性,并赋值给输入框 * @param meop * @throws TCException */ private void getProperties(TCComponentMEOPRevision meop) throws TCException { String outlineDiameter = meop.getStringProperty("ly6_outlineDiameter"); String outlineLength = meop.getStringProperty("ly6_outlineLength"); String cuttingLength = meop.getStringProperty("ly6_cuttingLength"); String transverseLength = meop.getStringProperty("ly6_transverseLength"); String colletLength = meop.getStringProperty("ly6_colletLength"); String manufacturingQuantity =meop.getStringProperty("ly6_manufacturableQuantity"); //规格和牌号单独从bomline下的子项中取得: String specifications = null; String brandNum = null; // String specifications = meop.getStringProperty("ly6_specifications"); // String brandNum = meop.getStringProperty("ly6_material"); TCComponentItem item = meop.getItem(); TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); // 创建视图:传入参数-版本规则(精确、具有状态···),不给则获取默认规则 TCComponentBOMWindow view = winType.create(null); // 发送BOM,即:创建BOM。将item对象发送到BOM,即为创建了一个BOM行 args:item对象 版本对象 ... TCComponentBOMLine topBomLine = view.setWindowTopLine(item, meop, null, null); topBomLine.lock(); if (topBomLine.hasChildren()) { System.out.println("dialog当前对象存在bom子行!"); AIFComponentContext[] childrens = topBomLine.getChildren(); int tag = 0; for (AIFComponentContext children : childrens) { TCComponentBOMLine bomLine = (TCComponentBOMLine)children.getComponent(); TCComponentItemRevision itemRevision = bomLine.getItemRevision(); String childType = itemRevision.getType(); System.out.println("当前通过bomline子项获取到子项类型:"+childType); if (childType.equals("LY6_RawMaterial") || childType.equals("LY6_RawMaterialRevision")) { System.out.println("成功获取到当前对象关联的“原材料”对象!"); specifications = itemRevision.getStringProperty("ly6_specifications"); brandNum = itemRevision.getStringProperty("ly6_material"); System.out.println("获取到规格:"+specifications); System.out.println("获取到牌号:"+brandNum); tag ++; break; } } if (tag == 0) {//bomline的子项中没有类型为:LY6_RawMaterialRevision的对象 MessageBox.post("未绑定原材料对象","提示",MessageBox.INFORMATION); //todo burangjisuan topBomLine.unlock(); view.close(); //关闭 this.setVisible(false); //释放 this.dispose(); return; } }else { MessageBox.post("未绑定原材料对象","提示",MessageBox.INFORMATION); //todo burangjisuan topBomLine.unlock(); view.close(); //关闭 this.setVisible(false); //释放 this.dispose(); return; } topBomLine.unlock(); view.close(); this.zjdTextField.setText(outlineDiameter != null ? outlineDiameter : ""); this.lkcTextField.setText(outlineLength != null ? outlineLength : ""); this.qdycdTextField.setText(cuttingLength != null ? cuttingLength : ""); this.cdmycdTextField.setText(transverseLength != null ? transverseLength : ""); this.jtycdTextField.setText(colletLength != null ? colletLength : ""); this.kzljsTextField.setText(manufacturingQuantity != null ? manufacturingQuantity : ""); this.ggTextField.setText(specifications != null ? specifications : ""); this.clphTextField.setText(brandNum != null ? brandNum : ""); } /** * 计算总长 * @return */ private String calculateTotalLength() { // 获取各个 TextField 的内容 String lkcText = this.lkcTextField.getText(); String qdycdText = this.qdycdTextField.getText(); String cdmycdText = this.cdmycdTextField.getText(); String kzljsText = this.kzljsTextField.getText(); String jtycdText = this.jtycdTextField.getText(); // 将字符串转换为数值 double lkcValue = Double.parseDouble(lkcText); double qdycdValue = Double.parseDouble(qdycdText); double cdmycdValue = Double.parseDouble(cdmycdText); double kzljsValue = Double.parseDouble(kzljsText); double jtycdValue = Double.parseDouble(jtycdText); // 计算结果 double result = (lkcValue + qdycdValue + cdmycdValue) * kzljsValue + jtycdValue; System.out.println("图纸轮廓长:"+lkcValue+"切断用长度:"+qdycdValue+"车端面用长度:"+cdmycdValue+"可制零件数:"+kzljsValue+"夹头用长度:"+jtycdValue); // double cm = result / 10.0; String formattedCm = String.format("%.2f", result); return formattedCm; } /** * 计算单件长度 * @return */ private String calculateSingleLength(){ String zcText = this.zcTextField.getText(); String kzljsText = this.kzljsTextField.getText(); double zcValue = Double.parseDouble(zcText); double kzljsValue = Double.parseDouble(kzljsText); if (kzljsValue == 0){ System.out.println("可制零件数 is 0"); } double result = zcValue / kzljsValue; System.out.println("总长:"+zcValue+"可制零件数:"+kzljsValue); // double cm = result / 10.0; String format = String.format("%.2f", result); return format; } private void downLoadFile(File file) throws Exception { FileInputStream inputStream = new FileInputStream(file); // 指定文件保存的本地路径 String localFilePath = "C:\\"+file.getName(); try { // 创建目标路径 Path path = Paths.get(localFilePath); // 将输入流写入到本地文件 Files.copy(inputStream, path); System.out.println("文件已成功保存: "+localFilePath); } catch (Exception e) { e.printStackTrace(); System.out.println("保存文件时发生错误!"); } finally { // 关闭输入流以释放资源 if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } } /** * 根据首选项中的uid获取数据集(EXCEL) * 根据uid获取item对象,获取该对象下的 * 根据“直径”读取EXCEL表中参与计算的必要条目:辅助工时和标准工时 * @throws Exception */ private void getDataset(){ System.out.println("getDataset"); TCPreferenceService preferenceService = session.getPreferenceService(); String itemId = preferenceService.getStringValue("LY6_MEOPTypeTime"); InterfaceAIFComponent[] resultComponents; try { resultComponents = session.search("零组件...", new String[] {"零组件 ID"}, new String[] {itemId}); InterfaceAIFComponent component = resultComponents[0]; if (component instanceof TCComponentItem){ TCComponentItem item = (TCComponentItem) component; //读取item下已发布最新版本规范关系下的MSEXCEL数据集 TCComponentItemRevision[] releasedItemRevisions = item.getReleasedItemRevisions(); int releaseRevNum = releasedItemRevisions.length; if (releaseRevNum == 0) { System.out.println("错误:当前对象下不存在发布版本"); } TCComponentItemRevision tcComponentItemRevision = releasedItemRevisions[releaseRevNum - 1]; //获取当前版本的规范关系下的数据集 TCComponent[] referenceListProperty = tcComponentItemRevision.getReferenceListProperty("IMAN_specification"); if(referenceListProperty.length>0) { System.out.println("规范关系下的数据集数量:"+referenceListProperty.length); //获取第一个数据集下具体的引用文件 TCComponentTcFile[] tcFiles = ((TCComponentDataset)referenceListProperty[0]).getTcFiles(); if (tcFiles.length > 0) { // System.out.println("数据集下引用文件的数量" + tcFiles.length); File file = tcFiles[0].getFmsFile(); // if (file.exists()) { // System.out.println("开始下载!"); // downLoadFile(file); // } System.out.println("获取到数据集文件:"+file.getName()); // 根据横截面积获取数据集-excel表中,对应的条目数据:辅助时间、固定时间、切割时间 FileInputStream fis = new FileInputStream(file); Workbook workbook = new HSSFWorkbook(fis); Sheet sheet = workbook.getSheetAt(0); //从第3条开始逐行数据(前两条是标题和首行栏) for (int i = 2; i < sheet.getPhysicalNumberOfRows(); i++) { Row row = sheet.getRow(i); //获取表中每行的第一个值,即:直径 // double diam = row.getCell(0).getNumericCellValue(); String diam = row.getCell(0).getStringCellValue(); // 根据规格匹配数据集表中的直径 if (diam.equals(this.ggTextField.getText())){ // if (diam == Double.parseDouble(this.ggTextField.getText())){ System.out.println("=========》直径匹配成功!开始获取辅助工时和标准工时"+"=========》当前行号:"+(i+1)+",当前行的直径:"+diam); //获取第11列的值:标准工时 this.bzgsTextField.setText(row.getCell(10).getStringCellValue()); //获取第12列的值:辅助工时 this.fzgsTextField.setText(row.getCell(11).getStringCellValue()); break; } } workbook.close(); }else { System.out.println("获取数据集文件失败!"); } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 计算辅助工时 * @return */ private String calculateAssistTime() { String result = null; double kzljsNum = Double.parseDouble(this.kzljsTextField.getText()); if (kzljsNum > 0){ double auxiliaryTimeNum = Double.parseDouble(this.auxiliaryTime); double fixedTimeNum = Double.parseDouble(this.fixedTime); double resultNum = Math.round((auxiliaryTimeNum + fixedTimeNum) / kzljsNum / 60 * 100.0) / 100.0; System.out.println("辅助时间:"+auxiliaryTimeNum+",固定时间:"+fixedTimeNum+",可制零件数:"+kzljsNum); result = String.valueOf(resultNum); } return result; } /** * 计算标准工时 * @return */ private String calculateStandardTime() { String result = null; double kzljsNum = Double.parseDouble(this.kzljsTextField.getText()); if (kzljsNum > 0){ System.out.println("=========>获取到的切割时间:"+this.cuttingTime); double cuttingTimeNum = Double.parseDouble(this.cuttingTime); double resultNum = Math.round((cuttingTimeNum / kzljsNum / 60) * 100.0) / 100.0; System.out.println("切割时间:"+cuttingTimeNum+",可制零件数:"+kzljsNum); result = String.valueOf(resultNum); } return result; } /** * 获取密度和截面 * @throws TCException */ private void getDensityAndCrossSection() throws TCException { System.out.println("=========>开始获取密度和横截面:getDensityAndCrossSection"); // 1.获取当前选中MEOP对象的BOM行 TCComponentMEOP meopItem = (TCComponentMEOP) meop.getItem(); TCComponentBOMWindowType winType = (TCComponentBOMWindowType) this.session.getTypeComponent("BOMWindow"); TCComponentBOMWindow view = winType.create(null); TCComponentBOMLine bomLine = view.setWindowTopLine(meopItem, meop, null, null); // 2.遍历BOM行,根据“规格”和“材料”检索符合要求的唯一原材料对象 throughBomline(bomLine); view.close(); } /** * 循环遍历当前bomline下关联的子行,获取符合要求的bom对应的原材料对象,并获取对应的密度和横截面属性 * @param topBomLine 当前BOM行 */ private void throughBomline(TCComponentBOMLine topBomLine) throws TCException{ // 3.获取原材料对象的密度和横截面 boolean hasChildren = topBomLine.hasChildren(); if (hasChildren) { AIFComponentContext[] childrens = topBomLine.getChildren(); for (AIFComponentContext children : childrens) { TCComponentBOMLine bomLine = (TCComponentBOMLine) children.getComponent(); //获取当前bom的事例类型,若是投料,则到当前bom对应的是原材料对象 String propertyValue = bomLine.getProperty("bl_occ_type"); if ("投料".equals(propertyValue)) { //通过原材料对象获取密度和横截面 this.rawMaterialRevision = bomLine.getItemRevision(); String densityString = rawMaterialRevision.getProperty("ly6_density"); String crossSectionString = rawMaterialRevision.getProperty("ly6_crossSection"); System.out.println("==========》成功取得当前原材料对象对应的密度:"+densityString+",横截面:"+crossSectionString); this.density = densityString != null ? densityString : ""; this.crossSection = crossSectionString != null ? crossSectionString : ""; System.out.println("000"); break; } throughBomline(bomLine); } } } /** * 计算单件重量 * @return * @throws TCException */ private String calculateWeight(){ System.out.println("calculateWeight"); //通过获取当前选中对象的bom下关联的原材料对象,获取其密度和横截面 try { getDensityAndCrossSection(); } catch (TCException e) { e.printStackTrace(); } //获取横截面和密度、单件长度,计算单件重量 double crossSectionNum = Double.parseDouble(this.crossSection); double densityNum = 0; if (this.density.contentEquals("")) { densityNum = 0; }else { densityNum = Double.parseDouble(this.density); } double siglengthNum = Double.parseDouble(this.djcdTextField.getText()); double result = crossSectionNum * densityNum * siglengthNum; System.out.println("横截面:"+crossSectionNum+",密度:"+densityNum+",单件长度:"+siglengthNum); double kg = result / 10000.0; String formattedKg = String.format("%.2f", kg); return formattedKg; } /** * 反写属性到对应的对象 * @throws TCException */ private void saveProperty() throws TCException { try { meop.setProperty("ly6_specifications", this.ggTextField.getText() == null ? "" : this.ggTextField.getText()); // rawMaterialRevision.setProperty("ly6_specifications", this.ggTextField.getText() == null ? "" : this.ggTextField.getText()); meop.setProperty("ly6_totalLenght", this.zcTextField.getText() == null ? "" : this.zcTextField.getText()); meop.setProperty("ly6_singleLength", this.djcdTextField.getText() == null ? "" : this.djcdTextField.getText()); meop.setProperty("ly6_weight", this.djzlTextField.getText() == null ? "" : this.djzlTextField.getText()); meop.setProperty("ly6_standardTime", this.bzgsTextField.getText() == null ? "" : this.bzgsTextField.getText()); meop.setProperty("ly6_auxiliaryTime", this.fzgsTextField.getText() == null ? "" : this.fzgsTextField.getText()); // rawMaterialRevision.setProperty("ly6_material", this.clphTextField.getText() == null ? "" : this.clphTextField.getText()); meop.setProperty("ly6_brandNum", this.clphTextField.getText() == null ? "" : this.clphTextField.getText()); meop.setProperty("ly6_outlineDiameter", this.zjdTextField.getText() == null ? "" : this.zjdTextField.getText()); meop.setProperty("ly6_outlineLength", this.lkcTextField.getText() == null ? "" : this.lkcTextField.getText()); meop.setProperty("ly6_cuttingLength", this.qdycdTextField.getText() == null ? "" : this.qdycdTextField.getText()); meop.setProperty("ly6_transverseLength", this.cdmycdTextField.getText()== null ? "" : this.cdmycdTextField.getText()); meop.setProperty("ly6_colletLength", this.jtycdTextField.getText() == null ? "" : this.jtycdTextField.getText()); meop.setProperty("ly6_manufacturableQuantity", this.kzljsTextField.getText() == null ? "" : this.kzljsTextField.getText()); }catch (Exception e){ System.out.println(e.getMessage()); e.printStackTrace(); } } /** * 检查M物料下是否已经挂载原材料 * @throws TCException */ private void checkMaterial() throws TCException { try { System.out.println("开始检查M物料下的挂载情况·········"); boolean isGZ=false; TCComponent[] whereUsed = meop.whereUsed((short) 0); for (TCComponent tcComponent : whereUsed) { //获取到当前工序对象的父级对象-tcComponent String mepRevisionType = tcComponent.getStringProperty("object_type"); //获取首选项中的工艺对象类型,进行匹配 TCSession session = (TCSession) this.application.getSession(); TCPreferenceService preferenceService = session.getPreferenceService(); //根据首选项的名称-C8MyPreference,获取首选项值 String value = preferenceService.getStringValue("LY6_MEPType"); String[] strings = value.split(","); for (int i = 0; i < whereUsed.length; i++) { //工艺对象类型匹配,进行:原材料对象比对 if (strings[i].equals(mepRevisionType)) { System.out.println("========>工艺类型匹配成功"); if (tcComponent instanceof TCComponentItemRevision) { System.out.println("====>获取到的工艺对象:"+tcComponent.getObjectString()); TCComponentItemRevision mepRevision = (TCComponentItemRevision) tcComponent; //获取工艺对象下的物料/制造对象:relatedRevision\\relatedItem TCComponent relatedComponent = mepRevision.getRelatedComponent("IMAN_METarget"); TCComponentItemRevision relatedRevision = (TCComponentItemRevision) relatedComponent; TCComponentItem relatedItem = relatedRevision.getItem(); //检查当前物料对象下是否挂在了原材料对象 TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); TCComponentBOMWindow view = winType.create(null); //获取物料对象/制造对象对应的bomline TCComponentBOMLine bomLine = view.setWindowTopLine(relatedItem, relatedRevision, null, null); //遍历该物料制造对象的bomline下是否挂在了原材料对象 if (bomLine.hasChildren()) { AIFComponentContext[] childrens = bomLine.getChildren(); for(AIFComponentContext children:childrens) { TCComponentBOMLine childrenBomLine = (TCComponentBOMLine) children.getComponent(); TCComponentItemRevision itemRevision = childrenBomLine.getItemRevision(); String uidTag = itemRevision.getUid(); String materialRevUid = this.rawMaterialRevision.getUid(); if (uidTag.equals(materialRevUid)) { System.out.println("M物料对象下已经挂载原材料对象············"); //M物料对象下挂载了原材料对象 isGZ = true; break; } } } //M物料对象下没有挂载原材料对象 if (!isGZ) { System.out.println("M物料对象下没有挂载原材料对象,开始挂载······"); view.lock(); TCComponentItem materialItem = this.rawMaterialRevision.getItem(); bomLine.add(materialItem,this.rawMaterialRevision,null,false,""); bomLine.save(); view.unlock(); } // BOMWindow用完后必须关闭! view.close(); }else { System.out.println("非版本对象异常"); } break; } } } }catch (Exception e){ e.printStackTrace(); System.out.println(e.getMessage()); } } /** * 事件处理:监听按钮的点击事件 */ @Override public void actionPerformed(ActionEvent e) { Object sourceObject = e.getSource(); //如果点击“计算”按钮 if(sourceObject.equals(this.calculateButton)) { try { //长度计算 this.zcTextField.setText(calculateTotalLength()); this.djcdTextField.setText(calculateSingleLength()); // 单件重量计算 this.djzlTextField.setText(calculateWeight()); // 工时计算 getDataset(); // this.bzgsTextField.setText(calculateStandardTime()); // this.fzgsTextField.setText(calculateAssistTime()); }catch (Exception e1){ MessageBox.post("计算失败,请检查属性或手动维护", "提示", MessageBox.ERROR); e1.printStackTrace(); } } else if (sourceObject.equals(this.syncButton)) { //如果点击“同步”按钮,属性反写 try { saveProperty(); //检查M物料 checkMaterial(); MessageBox.post("同步成功", "结果", MessageBox.INFORMATION); this.setVisible(false); this.dispose(); } catch (TCException e1) { e1.printStackTrace(); } }else { //如果点击“取消”按钮 //关闭 this.setVisible(false); //释放 this.dispose(); } } }