public void save(File f) { Properties save = new Properties(); OutputStream output = null; try { save.setProperty("provider", selectProviderCb.getValue()); save.setProperty("grain", selectGrainCb.getValue()); save.setProperty("weight", weightTf.getText()); save.setProperty("info", infoTa.getText()); for (Entry<String, TextField> entry : propertiesTf.entrySet()) { TextField tf = entry.getValue(); String propertyName = entry.getKey(); save.setProperty(propertyName, tf.getText()); if (tf.isDisable()) { save.setProperty(propertyName + "_ENABLED", "OFF"); } else { save.setProperty(propertyName + "_ENABLED", "ON"); } } output = new FileOutputStream(f); save.store(output, null); mainStage.setTitle(f.getName()); } catch (Exception ex) { infoTa.setText("Не могу сохранить в файл"); } finally { if (output != null) { try { output.close(); } catch (IOException e) { e.printStackTrace(); } } } }
public void HandlerCalcPriceButton(ActionEvent event) { try { grain = getGrain(selectGrainCb.getValue()); System.out.println("> " + grain.getName()); try { grain.setWeight(Double.parseDouble(weightTf.getText())); } catch (NumberFormatException e) { weightTf.requestFocus(); throw new NumberFormatException("Вес партии зерна"); } for (Entry<String, TextField> entry : propertiesTf.entrySet()) { TextField tf = entry.getValue(); String propertyName = entry.getKey(); System.out.println("\t> " + propertyName); if (!tf.isDisable()) { try { grain.getProperty(propertyName).setValue(Double.parseDouble(tf.getText())); } catch (NumberFormatException e) { tf.requestFocus(); throw new NumberFormatException(grain.getProperty(propertyName).getDescription()); } grain.getProperty(propertyName).setEnabled(true); } else { grain.getProperty(propertyName).setEnabled(false); } } System.out.println("> before calculator"); PriceCalculator calculator = new PriceCalculator(grain, dao); calculator.calculatePrice(); infoTa.setText(calculator.toString()); Supply supply = new Supply(); supply.setProvider(selectProviderCb.getValue()); supply.setDate(new Date(Calendar.getInstance().getTimeInMillis())); // supply.setGrain(grain.getName()); supply.setGrain(grain.getDescription()); supply.setWeight(grain.getWeight()); supply.setPrice(calculator.getPrice()); dao.saveSupply(supply); } catch (RestrictiveConditionException e) { Utils.showErrorDialog("Ограшичительные кондиции!", e); infoTa.clear(); } catch (DataBaseException e) { Utils.showErrorDialog("Обшибка базы данных!", e); infoTa.clear(); } catch (NumberFormatException e) { Utils.showErrorDialog("Неверный ввод!", e); infoTa.clear(); } catch (Exception ex) { Utils.showErrorDialog("Ошибка!", ex); infoTa.clear(); } }