private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        try {
            /*
             * Validity check
             */
            if (!valid()) {
                return;
            }
            DateFormatter df = new DateFormatter(new SimpleDateFormat("dd/MM/yyyy"));

            newinvoice.setDate(df.valueToString(datepicker.getDate()));
            Contact _client;
            if (clientBox.getSelectedItem() instanceof Contact) {
                _client = (Contact) clientBox.getSelectedItem();
            } else {
                String clientname = (String) clientBox.getSelectedItem();
                _client = Database.driver().getClientsAlphabetically().get(clientname.toLowerCase());
            }
            newinvoice.setClient(_client);

            newinvoice.setNumber(number);
            newinvoice.setPriceCode(pricecode);
            newinvoice.setSave(saving);
            FunctionResult<Invoice> res = newinvoice.update();
            if (res.getCode() == 0) {
                delegate.editInvoice(oldinvoice, newinvoice);
                oldinvoice = newinvoice;
                disposeLater();
            } else {
                // switch case error code
                String msg;
                switch (res.getCode()) {
                    case 1:
                        msg = "Controleer of alle velden uniek zijn. Informatie van de databank:\n" + res.getMessage();
                        break;
                    case 4:
                        msg = res.getMessage();
                        break;
                    default:
                        msg = "Het toevoegen van het basisingrediënt is foutgelopen (code " + res.getCode() + "). Contacteer de ontwikkelaars met deze informatie.";
                }
                JOptionPane.showMessageDialog(null, msg, "Fout!", JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception e) {
            System.err.println("Error: \n" + e.getMessage());
            JOptionPane.showMessageDialog(null, tools.Utilities.incorrectFormMessage, "Fout!", JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_btnSaveActionPerformed