private void addWare(java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addWare // determine which ware should be added and how many pieces of it WareChooserDialog dia = new WareChooserDialog(client, true, client.getDatabaseConnection()); dia.setVisible(true); int chosenWareID = dia.getSelectedWareID(); int pieces = dia.getPieces(); if (chosenWareID < 0 || pieces <= 0) return; try { // Check if ware is already in the list. If so, add the amount to be bought. boolean wareAlreadyInList = false; ResultSet orderPart = stmt.executeQuery( "SELECT pieces FROM orderParts" + " WHERE orderId = " + orderID + " AND wareId = " + chosenWareID); if (orderPart.next()) { pieces += orderPart.getInt("pieces"); wareAlreadyInList = true; } // add visual representation ResultSet ware = stmt.executeQuery("SELECT (name) FROM goods WHERE" + " id = " + chosenWareID); ware.next(); String wareEntry = ""; wareEntry += chosenWareID + " // "; wareEntry += ware.getString("name") + " // "; wareEntry += pieces; if (!wareAlreadyInList) wareListModel.addElement(wareEntry); else { for (int ct = 0; ct < wareListModel.getSize(); ct++) { int wareID = Integer.parseInt(((String) wareListModel.getElementAt(ct)).split(" // ")[0]); if (wareID == chosenWareID) { int index = wareListModel.indexOf(wareListModel.getElementAt(ct)); wareListModel.removeElementAt(index); wareListModel.insertElementAt(wareEntry, index); } } } } catch (SQLException e) { JOptionPane.showMessageDialog( client, "Fehler bei der" + "Kommunikation mit der Datenbank.", "Fehler beim Speichern", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); return; } // save order and update total numbers saveOrder(); updateTotalNumbers(); } // GEN-LAST:event_addWare
private void changeWare(java.awt.event.ActionEvent evt) { // GEN-FIRST:event_changeWare // find ware to be changed int index; try { index = wareList.getSelectedIndex(); } catch (ArrayIndexOutOfBoundsException e) { return; } if (index < 0) return; String wareDescr = (String) wareListModel.get(index); int oldWareID = Integer.parseInt(wareDescr.split("//")[0].trim()); int oldPieces = Integer.parseInt(wareDescr.split("//")[2].trim()); // show WareChooserDialog WareChooserDialog dia = new WareChooserDialog(client, true, client.getDatabaseConnection(), oldWareID, oldPieces); dia.setVisible(true); int newPieces = dia.getPieces(); int newWareID = dia.getSelectedWareID(); if (newWareID < 0 || newPieces < 0) return; try { // delete old ware stmt.executeUpdate( "DELETE FROM orderParts WHERE wareId = " + oldWareID + " AND orderId = " + orderID); wareListModel.remove(index); // add new Ware ResultSet ware = stmt.executeQuery("SELECT (name) FROM goods WHERE" + " id = " + newWareID); ware.next(); String wareEntry = ""; wareEntry += newWareID + " // "; wareEntry += ware.getString("name") + " // "; wareEntry += newPieces; wareListModel.addElement(wareEntry); } catch (SQLException e) { JOptionPane.showMessageDialog( client, "Fehler bei der Kommunikation" + "mit der Datenbank.", "Netzwerkfehler", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); return; } // save order and update total numbers saveOrder(); updateTotalNumbers(); } // GEN-LAST:event_changeWare