Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private final Action addService = new AbstractAction() {
- @Override
- public void actionPerformed(ActionEvent e) {
- var id = (int) table.getModel().getValueAt(table.getSelectedRow(), 0);
- var record = handler.getRecord(id);
- var services = handler.getServicesList();
- Object[] servicesString = new Object[services.size()];
- for (var i = 0; i < services.size(); i++) {
- var service = services.get(i);
- servicesString[i] = String.format("%s. %s - %s руб./сутки",
- service.getId(), service.getName(), service.getPrice()
- );
- }
- if (services.size() == 0) {
- JOptionPane.showMessageDialog(
- null,
- "Список услуг пуст",
- "Ошибка",
- JOptionPane.ERROR_MESSAGE
- );
- return;
- }
- var service = (String) JOptionPane.showInputDialog(
- null,
- "Услуга:",
- "Услуга",
- JOptionPane.QUESTION_MESSAGE,
- null,
- servicesString,
- servicesString[0]
- );
- if (service == null) {
- return;
- }
- var date = "";
- while (Objects.equals(date, "")) {
- date = JOptionPane.showInputDialog(
- null,
- "Дата оказания услуги (пример 2022-01-31):",
- "Услуга",
- JOptionPane.QUESTION_MESSAGE
- );
- if (date == null) {
- return;
- }
- if (!DATE_PATTERN.matcher(date).matches() || !checkIfDateInBookPeriod(id, date)) {
- date = "";
- }
- }
- var serviceObject = handler.getServiceById(Integer.parseInt(service.split(" ")[0].replaceAll("\\.", "")));
- var servicesOrders = handler.getServiceOrdersList();
- var servicesOrder = new ServiceOrder(
- servicesOrders.size() != 0 ? servicesOrders.get(servicesOrders.size() - 1).getId() + 1 : 0,
- serviceObject,
- record,
- date
- );
- handler.addServiceOrder(servicesOrder);
- showRecordsList();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement