Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.3 kB
1
Indexable
Never
public void createCustomerRecord(Customer customer){
            if(!customerID.getText().isEmpty() && !name.getText().isEmpty()) {
                customer.setCustomerID(customerID.getText());
                customer.setName(name.getText());

                String dobDateString = dobTextField.getText().trim();
                String dateOfMemString = dateOfMemTextField.getText().trim();
                String dateOfExpString = dateOfExpTextField.getText().trim();

                if (!dobDateString.isEmpty() && !dateOfMemString.isEmpty() && !dateOfExpString.isEmpty()) {
                    try {

                        java.util.Date dob = new SimpleDateFormat("dd/MM/yyyy").parse(dobDateString);
                        java.util.Date dateOfMem = new SimpleDateFormat("dd/MM/yyyy").parse(dateOfMemString);
                        java.util.Date dateOfExp = new SimpleDateFormat("dd/MM/yyyy").parse(dateOfExpString);

                        customer.setDob(dob);
                        customer.setAddress(address.getText());
                        customer.setTelephone(telephone.getText());
                        customer.setEmail(email.getText());
                        customer.setDateOfMembership(dateOfMem);
                        customer.setDateOfMembershipExpiry(dateOfExp);


                        objOs.writeObject("Add Customer");
                        objOs.flush();
                        objOs.writeObject(customer);
                        objOs.flush();
                        Boolean save = (Boolean) objIs.readObject();
                        logger.info("Customer Added");

                    } catch (ParseException | IOException e) {

                        JOptionPane.showMessageDialog(null, "Date format is not valid", "Date Format Error", JOptionPane.ERROR_MESSAGE);
                        logger.error(e.getMessage());
                        e.printStackTrace();
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }

                } else {

                    JOptionPane.showMessageDialog(null, "Date fields cannot be empty", "Date Field Error", JOptionPane.ERROR_MESSAGE);

                }
            }
    }