protected LumberLog fromResultSet(ResultSet rs) throws SQLException { LumberLog lumberLog = new LumberLog(); lumberLog.setId(rs.getLong("id")); lumberLog.setLength(rs.getDouble("length")); lumberLog.setRealLength(rs.getLong("reallength")); lumberLog.setVolume(rs.getDouble("volume")); lumberLog.setRealVolume(rs.getDouble("realvolume")); lumberLog.setSmallRadius(rs.getDouble("small_diameter")); lumberLog.setBigRadius(rs.getDouble("big_diameter")); lumberLog.setLumberType(rs.getLong("lumbertype")); lumberLog.setLumberClass(rs.getLong("lumberclass")); lumberLog.setCutPlanId(rs.getLong("planId")); LumberStack stack = new LumberStack(); stack.setName(rs.getString("stackName")); stack.setId(rs.getLong("stack")); lumberLog.setStack(stack); IDPlate plate = new IDPlate(); plate.setId(rs.getLong("idplate")); plate.setLabel(rs.getString("plateName")); lumberLog.setPlate(plate); lumberLog.setSupplierId(rs.getLong("SupplierId")); lumberLog.setTransportCertifiateId(rs.getLong("TransportCertificateId")); if (rs.wasNull()) { lumberLog.setTransportCertifiateId(null); } lumberLog.setMarginPercent(rs.getInt("Margin")); lumberLog.setMarginVolume(rs.getDouble("MarginVolume")); lumberLog.setMarginRealVolume(rs.getDouble("RealMarginVolume")); return lumberLog; }
public static boolean saveLumberLog( LumberLog lumberLog, LumberStack stack, LumberLogEntry stockEntry) { Logger logger = Logger.getLogger("dao"); boolean status = false; boolean saveNewEntry = false; StringBuilder insertStockEntry = null; if (stockEntry.getId() == null) { saveNewEntry = true; insertStockEntry = new StringBuilder("insert into lumberentry(user) values("); insertStockEntry.append(stockEntry.getUser().getID()).append(")"); } StringBuilder insertLumberLog = new StringBuilder( "insert into lumberlog( " + "small_diameter, medium_diameter, big_diameter, length, reallength, volume, realvolume, lumbertype, lumberclass," + " idplate, stack, Status, SupplierId, TransportCertificateId, Margin, MarginVolume, RealMarginVolume, TransportEntryId) values ("); insertLumberLog.append(lumberLog.getSmallRadius()).append(","); insertLumberLog.append("0").append(","); insertLumberLog.append(lumberLog.getBigRadius()).append(","); insertLumberLog.append(lumberLog.getLength()).append(","); insertLumberLog.append(lumberLog.getRealLength()).append(","); insertLumberLog.append(lumberLog.getVolume()).append(","); insertLumberLog.append(lumberLog.getRealVolume()).append(","); insertLumberLog.append(lumberLog.getLumberType()).append(","); insertLumberLog.append(lumberLog.getLumberClass()).append(","); insertLumberLog.append(lumberLog.getPlate().getId()).append(","); insertLumberLog.append(stack.getId()).append(",").append(lumberLog.getStatus()).append(","); insertLumberLog.append(lumberLog.getSupplierId()).append(","); insertLumberLog .append( lumberLog.getTransportCertifiateId() != null ? lumberLog.getTransportCertifiateId() : "NULL") .append(","); insertLumberLog.append(lumberLog.getMarginPercent()).append(","); insertLumberLog.append(lumberLog.getMarginVolume()).append(","); insertLumberLog.append(lumberLog.getMarginRealVolume()).append(","); insertLumberLog.append(lumberLog.getTransportEntryId()).append(")"); StringBuilder insertMapEntrySql = new StringBuilder("insert into lumberentry_to_lumberlog(entryid, lumberlogid) values ("); StringBuilder insertLumberLogDiameter = new StringBuilder( "insert into lumberlog_diameter(lumberlog_id, diameter, metric) values(?, ?, 1)"); Connection con = null; Statement stm = null; PreparedStatement pstm = null; ResultSet rs = null; try { con = DataAccess.getInstance().getDatabaseConnection(); con.setAutoCommit(false); stm = con.createStatement(); logger.info(insertLumberLog.toString()); int rez = stm.executeUpdate(insertLumberLog.toString(), Statement.RETURN_GENERATED_KEYS); if (rez > 0) { rs = stm.getGeneratedKeys(); if (rs.next()) { lumberLog.setId(rs.getLong(1)); } } if (rs != null) { rs.close(); } if (saveNewEntry) { logger.info(insertStockEntry.toString()); rez = stm.executeUpdate(insertStockEntry.toString(), Statement.RETURN_GENERATED_KEYS); if (rez > 0) { rs = stm.getGeneratedKeys(); if (rs.next()) { stockEntry.setId(rs.getLong(1)); } } } if (lumberLog.getMediumRadius() != null && !lumberLog.getMediumRadius().isEmpty()) { pstm = con.prepareStatement(insertLumberLogDiameter.toString()); for (Double radius : lumberLog.getMediumRadius()) { pstm.setLong(1, lumberLog.getId()); pstm.setDouble(2, radius); pstm.executeUpdate(); } } if (lumberLog.getId() != null && stockEntry.getId() != null) { insertMapEntrySql .append(stockEntry.getId()) .append(",") .append(lumberLog.getId()) .append(")"); logger.info(insertMapEntrySql.toString()); rez = stm.executeUpdate(insertMapEntrySql.toString()); if (rez > 0) { status = true; IDPlateManager.removeAvailablePlate(lumberLog.getPlate()); } } } catch (Exception e) { try { con.rollback(); } catch (Exception ex) { } logger.warning(e.getMessage()); logger.log(Level.INFO, "Error", e); status = false; } finally { if (con != null) { try { con.setAutoCommit(true); } catch (Exception ex) { } } if (rs != null) try { rs.close(); } catch (Exception e) { } if (stm != null) try { stm.close(); } catch (Exception e) { } } return status; }
@Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().startsWith("FILTRU")) { int length = Integer.parseInt(e.getActionCommand().substring(6)); for (int index = 0; index < selection.size(); index++) { JCheckBox chk1 = (JCheckBox) selection.get(index); int productLength = Integer.parseInt(chk1.getName().substring(6)); if (!filtru2m.isSelected() && !filtru3m.isSelected() && !filtru4m.isSelected()) { chk1.getParent().setVisible(true); continue; } if (productLength < 3000 && productLength >= 2000 && filtru2m.isSelected()) { chk1.getParent().setVisible(true); } else if (productLength < 4000 && productLength >= 3000 && filtru3m.isSelected()) { chk1.getParent().setVisible(true); } else if (productLength < 5000 && productLength >= 4000 && filtru4m.isSelected()) { chk1.getParent().setVisible(true); } else { chk1.getParent().setVisible(false); } } this.revalidate(); return; } boolean valid = true; JLabel lenLabel = (JLabel) ((JPanel) getComponent(0)).getComponent(0); JFormattedTextField lenRadius = (JFormattedTextField) ((JPanel) getComponent(0)).getComponent(1); JComboBox<String> lenRadiusMetric = (JComboBox<String>) ((JPanel) getComponent(0)).getComponent(2); lenLabel.setForeground(Color.black); if (lenRadius.getValue() == null) { valid = false; lenLabel.setForeground(Color.red); } JLabel smallLabel = (JLabel) ((JPanel) getComponent(1)).getComponent(0); JFormattedTextField smallRadius = (JFormattedTextField) ((JPanel) getComponent(1)).getComponent(1); JComboBox<String> smallRadiusMetric = (JComboBox<String>) ((JPanel) getComponent(1)).getComponent(2); smallLabel.setForeground(Color.black); if (smallRadius.getValue() == null) { valid = false; smallLabel.setForeground(Color.red); } JLabel bigLabel = (JLabel) ((JPanel) getComponent(2)).getComponent(0); JFormattedTextField bigRadius = (JFormattedTextField) ((JPanel) getComponent(2)).getComponent(1); JComboBox<String> bigRadiusMetric = (JComboBox<String>) ((JPanel) getComponent(2)).getComponent(2); bigLabel.setForeground(Color.black); if (bigRadius.getValue() == null) { valid = false; bigLabel.setForeground(Color.red); } double minimumValue = METRIC.toMilimeter((Long) smallRadius.getValue(), smallRadiusMetric.getSelectedIndex()); double maxmimumValue = METRIC.toMilimeter((Long) bigRadius.getValue(), bigRadiusMetric.getSelectedIndex()); if (minimumValue > maxmimumValue) { smallLabel.setForeground(Color.red); bigLabel.setForeground(Color.red); valid = false; } boolean one = false; for (JCheckBox chk : selection) { if (chk.isSelected()) { one = true; break; } } if (!one) { label2.setForeground(Color.red); valid = false; } else { label2.setForeground(Color.black); } if (!valid) { return; } List<Product> selectedProducts = new ArrayList<Product>(); for (int index = 0; index < selection.size(); index++) { if (selection.get(index).isSelected()) { selectedProducts.add(products.get(index)); } } Map<String, Object> targetData = new HashMap<String, Object>(); targetData.put("IDPLATE_LABEL", "Test"); targetData.put("SELECTED_PRODUCTS", selectedProducts); DefaultCutOptionsCalculatorData data = new DefaultCutOptionsCalculatorData(); data.setSelectedProducts(selectedProducts); List<LumberStack> stacks = LumberStackDAO.getAllstack(); List<LumberLog> lumberLogs = new ArrayList<>(); for (long start = (Long) smallRadius.getValue(); start < (Long) bigRadius.getValue(); start++) { LumberLog lumberLog = new LumberLog(); lumberLog.setSmallRadius((double) start); List<Double> middleRadius = new ArrayList<>(); middleRadius.add((double) start); lumberLog.setMediumRadius(middleRadius); lumberLog.setBigRadius((double) start); double lengthValue = METRIC.toMilimeter((Long) lenRadius.getValue(), lenRadiusMetric.getSelectedIndex()); lumberLog.setLength(lengthValue); lumberLog.setRealLength((long) lengthValue); IDPlate plate = new IDPlate(); plate.setId(-1L); LumberStack stack = LumberLogUtil.findLumberStack(lumberLog, stacks); String label = "Diametru " + start; if (stack != null) { label += " " + stack.getName(); } plate.setLabel(label); lumberLog.setPlate(plate); LumberLogUtil.calculateVolume(lumberLog); lumberLogs.add(lumberLog); } data.setLumberLogs(lumberLogs); new CutOptionsTargetFrame(targetData, data); GUITools.closeParentDialog(this); }