// Fix problem, where scanner sends two CR after scan resulting in two scans // one for the original EAN and one with an empty EAN if (ean.length() == 0) { focusEAN(); return; }
while (ean.length() < 13) ean = "0" + ean;
if (ean.length() > 13) { String msg = "Den angivne EAN er ikke gyldig. EAN kan højst være 13 tegn."; JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(this), msg, "Advarsel!", JOptionPane.ERROR_MESSAGE); focusEAN(); return; }
try { Inventory item = Inventory.get(ean);
// Item was not found. Prompt the user to enter information about the item if (item == null) { new NewItemDialog(JOptionPane.getFrameForComponent(this), ean); item = Inventory.get(ean); }
// Now, we have found the item scanned if (item != null) { if (stateReturn == false) { // This is a sales transaction inv.insert(item, 1); item.decrement(); } else { // This is a return transaction inv.insert(item, -1); item.increment(); handleReturn(); } revalidate(); table.setRowSelectionInterval(0, 0); } else { // Item not found getToolkit().beep(); String msg = "Ukendt VMI vare."; JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(this), msg, "Advarsel!", JOptionPane.ERROR_MESSAGE); } } catch (SQLException e) { e.printStackTrace(); }
inEAN.setText(""); focusEAN(); }
private void handleCancel() { int row = table.getSelectedRow(); if (row >= 0) { // Confirm cancel transaction int result = JOptionPane.showOptionDialog(JOptionPane.getFrameForComponent(this), "Ønsker du annullere den valgte ekspedition?", "Annuller ekspedition", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
// Remove transaction if ( result == JOptionPane.YES_OPTION ) { try { String ean = inv.getEAN(row); int qty = inv.getCount(row); if (inv.delete(row)) { Inventory item = Inventory.get(ean); if (qty == 1) item.increment(); else if (qty == -1) item.decrement(); else RemoteLogger.getInstance().logMessage("Unknown quantity from transaction: " + ean + " / " + qty); revalidate(); } } catch (SQLException e) { e.printStackTrace(); } } }
focusEAN(); }
public void focusEAN() {
inEAN.requestFocusInWindow();
}
private void handleReturn() { // Toggle state of the Return button stateReturn ^= true;
btnReturn = new JButton("Retur"); btnReturn.setToolTipText("Marker før returnering af vare"); btnReturn.addActionListener(this); transaction.add(btnReturn);
// Add content to pane add(transactions); add(transaction, BorderLayout.SOUTH);
}
@Override public void actionPerformed(ActionEvent event) { Object source = event.getSource();
if (source == btnAdd) handleAddTransaction(); else if (source == btnReturn) handleReturn(); else if (source == btnCancel) handleCancel(); } }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.