Esempio n. 1
0
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnSave) {
      if (tfFirstName.getText().isEmpty()) {
        JOptionPane.showMessageDialog(null, "Enter first name!");
        return;
      } else if (tfLastName.getText().isEmpty()) {
        JOptionPane.showMessageDialog(null, "Enter last name!");
        return;
      } else if (tfAddress.getText().isEmpty()) {
        JOptionPane.showMessageDialog(null, "Enter Address!");
        return;
      } else if (tfPhoneNumber.getText().isEmpty()) {
        JOptionPane.showMessageDialog(null, "Enter phone number!");
        return;
      } else if (dateModel.getValue().toString().isEmpty()) {
        JOptionPane.showMessageDialog(null, "Enter date of birth!");
        return;
      }
      DBConnection dbconnection = new DBConnection();

      if (person == null) {
        person = new Person();
      }

      person.setFirstName(tfFirstName.getText());
      person.setLastName(tfLastName.getText());
      person.setAddress(tfAddress.getText());
      person.setPhoneNumber(tfPhoneNumber.getText());
      person.setDOB(dateModel.getYear() + "-" + dateModel.getMonth() + "-" + dateModel.getDay());
      int result = -1;
      if (person.getId() == 0) {
        result = dbconnection.savePerson(person);
      } else {
        result = dbconnection.updatePerson(person);
      }

      if (result != -1) {
        JOptionPane.showMessageDialog(null, "Saved Successfully!");
      } else {
        JOptionPane.showMessageDialog(null, "Save Unsuccessful!");
      }
    } else if (e.getSource() == btnReset) {
      tfFirstName.setText("");
      tfLastName.setText("");
      tfAddress.setText("");
      tfPhoneNumber.setText("");
      tfDOB.setText("");
      dateModel.setValue(new Date());
    } else if (e.getSource() == btnDelete) {
      DBConnection dBConnection = new DBConnection();
      int result = dBConnection.deletePerson(person.getId());
      if (result != -1) {
        JOptionPane.showMessageDialog(null, "Deleted Successfully!");
      } else {
        JOptionPane.showMessageDialog(null, "Deletion Unsuccessful!");
      }
    }
  }
Esempio n. 2
0
  private void updateFields(Person person) {
    this.person = person;
    tfFirstName.setText(person.getFirstName());
    tfLastName.setText(person.getLastName());
    tfAddress.setText(person.getAddress());
    tfPhoneNumber.setText(person.getPhoneNumber());

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
    try {
      Date result = df.parse(person.getDOB());
      dateModel.setValue(result);
      dateModel.setSelected(true);
    } catch (ParseException ex) {
      Logger.getLogger(PersonForm.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Esempio n. 3
0
 @Override
 public Date getValue() {
   return dateModel == null ? null : dateModel.getValue();
 }
Esempio n. 4
0
 @Override
 public void doRefresh() {
   final Date date = (Date) get().getValue();
   dateModel.setValue(date);
 }