private void onOK() {
    try {
      if (!updateModel()) return;

      ShiftDAO dao = new ShiftDAO();
      if (shift.getId() == null && dao.exists(shift.getName())) {
        POSMessageDialog.showError(this, com.floreantpos.POSConstants.SHIFT_NAME_ALREADY_EXISTS);
        return;
      }
      dao.saveOrUpdate(shift);

      setCanceled(false);

      dispose();
    } catch (Exception e) {
      POSMessageDialog.showError(this, com.floreantpos.POSConstants.ERROR_SAVING_SHIFT_STATE, e);
    }
  }
Пример #2
0
  public static Shift getCurrentShift() {
    Calendar calendar = Calendar.getInstance();
    Calendar calendar2 = Calendar.getInstance();
    calendar.clear();

    calendar.set(Calendar.HOUR, calendar2.get(Calendar.HOUR));
    calendar.set(Calendar.MINUTE, calendar2.get(Calendar.MINUTE));
    calendar.set(Calendar.AM_PM, calendar2.get(Calendar.AM_PM));

    Date currentTime = calendar.getTime();

    ShiftDAO shiftDAO = new ShiftDAO();
    List<Shift> shifts = shiftDAO.findAll();

    for (Shift shift : shifts) {
      Date startTime = new Date(shift.getStartTime().getTime());
      Date endTime = new Date(shift.getEndTime().getTime());

      if (currentTime.after(startTime) && currentTime.before(endTime)) {
        return shift;
      }
    }

    calendar.add(Calendar.DATE, 1);
    currentTime = calendar.getTime();
    for (Shift shift : shifts) {
      Date startTime = new Date(shift.getStartTime().getTime());
      Date endTime = new Date(shift.getEndTime().getTime());

      if (currentTime.after(startTime) && currentTime.before(endTime)) {
        return shift;
      }
    }

    return null;
  }