Advertisement
ProgNeo

Untitled

Jun 4th, 2022
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. private final Action addService = new AbstractAction() {
  2. @Override
  3. public void actionPerformed(ActionEvent e) {
  4. var id = (int) table.getModel().getValueAt(table.getSelectedRow(), 0);
  5. var record = handler.getRecord(id);
  6.  
  7. var services = handler.getServicesList();
  8. Object[] servicesString = new Object[services.size()];
  9. for (var i = 0; i < services.size(); i++) {
  10. var service = services.get(i);
  11. servicesString[i] = String.format("%s. %s - %s руб./сутки",
  12. service.getId(), service.getName(), service.getPrice()
  13. );
  14. }
  15.  
  16. if (services.size() == 0) {
  17. JOptionPane.showMessageDialog(
  18. null,
  19. "Список услуг пуст",
  20. "Ошибка",
  21. JOptionPane.ERROR_MESSAGE
  22. );
  23. return;
  24. }
  25.  
  26. var service = (String) JOptionPane.showInputDialog(
  27. null,
  28. "Услуга:",
  29. "Услуга",
  30. JOptionPane.QUESTION_MESSAGE,
  31. null,
  32. servicesString,
  33. servicesString[0]
  34. );
  35. if (service == null) {
  36. return;
  37. }
  38.  
  39. var date = "";
  40.  
  41. while (Objects.equals(date, "")) {
  42. date = JOptionPane.showInputDialog(
  43. null,
  44. "Дата оказания услуги (пример 2022-01-31):",
  45. "Услуга",
  46. JOptionPane.QUESTION_MESSAGE
  47. );
  48. if (date == null) {
  49. return;
  50. }
  51. if (!DATE_PATTERN.matcher(date).matches() || !checkIfDateInBookPeriod(id, date)) {
  52. date = "";
  53. }
  54. }
  55.  
  56. var serviceObject = handler.getServiceById(Integer.parseInt(service.split(" ")[0].replaceAll("\\.", "")));
  57.  
  58. var servicesOrders = handler.getServiceOrdersList();
  59. var servicesOrder = new ServiceOrder(
  60. servicesOrders.size() != 0 ? servicesOrders.get(servicesOrders.size() - 1).getId() + 1 : 0,
  61. serviceObject,
  62. record,
  63. date
  64. );
  65.  
  66. handler.addServiceOrder(servicesOrder);
  67. showRecordsList();
  68. }
  69. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement