diff --git a/AppStockAccounting/Entity/Commodity.java b/AppStockAccounting/Entity/Commodity.java index 373e7e1..7937974 100644 --- a/AppStockAccounting/Entity/Commodity.java +++ b/AppStockAccounting/Entity/Commodity.java @@ -36,7 +36,7 @@ public Commodity() { /* --------------------------------- id -------------------------------- */ public int getId() { return id.get(); } public void setId(int id) { this.id.set(id); } - public IntegerProperty idProperty() { return id; } // TODO: add destination + public IntegerProperty idProperty() { return id; } // to populate TableView /* ------------------------------- name -------------------------------- */ public String getCommodityName() { diff --git a/AppStockAccounting/Model/CommodityDAO.java b/AppStockAccounting/Model/CommodityDAO.java index df40df0..f752c83 100644 --- a/AppStockAccounting/Model/CommodityDAO.java +++ b/AppStockAccounting/Model/CommodityDAO.java @@ -98,8 +98,13 @@ public void addCommodity(Commodity c) { preparedStatement.setString(1, c.getCommodityName()); preparedStatement.setString(2, c.getCommodityDescription()); preparedStatement.setDouble(3, c.getCommodityQuantityInStock()); - preparedStatement.setDouble(4, c.getCommodityPriceWithoutTax()); + preparedStatement.setDouble(4, c.getCommodityPriceWithoutTax()); + + System.out.println("-----------------SQL_INSERT-----------------"); // debug + System.out.println("Creating SQL_INSERT java statement..."); // debug preparedStatement.executeUpdate(); + System.out.println("SQL query has been successfully executed."); // debug + ResultSet generatedKeys = preparedStatement.getGeneratedKeys(); if (generatedKeys.next()) { c.setId(generatedKeys.getInt(1)); @@ -114,7 +119,12 @@ public void deleteCommodity(int commoditytId) { try { PreparedStatement preparedStatement = con.prepareStatement(SQL_DELETE); preparedStatement.setInt(1, commoditytId); + + System.out.println("-----------------SQL_DELETE-----------------"); // debug + System.out.println("Creating SQL_DELETE java statement..."); // debug preparedStatement.executeUpdate(); + System.out.println("SQL query has been successfully executed."); // debug + preparedStatement.close(); } catch (Exception e) { // TODO: implement; OPersian's note @@ -129,7 +139,12 @@ public void updateCommodity(Commodity c) { preparedStatement.setDouble(3, c.getCommodityQuantityInStock()); preparedStatement.setDouble(4, c.getCommodityPriceWithoutTax()); preparedStatement.setInt(5, c.getId()); + + System.out.println("-----------------UPDATE-----------------"); // debug + System.out.println("Creating SQL_UPDATE java statement..."); // debug preparedStatement.executeUpdate(); + System.out.println("SQL query has been successfully executed."); // debug + preparedStatement.close(); } catch (Exception e) { // TODO: implement; OPersian's note @@ -139,7 +154,9 @@ public void updateCommodity(Commodity c) { public List getAllCommodities() { List commoditiestList = new ArrayList(); try { - System.out.println("Creating java statement..."); // debug + System.out.println("========================================="); // debug + System.out.println("-----------------GET_ALL-----------------"); // debug + System.out.println("Creating GET_ALL java statement..."); // debug Statement statement = con.createStatement(); System.out.println("Executing the next SQL query: \n" + SQL_SELECT_ALL); // debug @@ -168,6 +185,7 @@ public Commodity getCommodityById(int commodityId) { try { PreparedStatement preparedStatement = con.prepareStatement(SQL_SELECT_BY_ID); preparedStatement.setInt(1, commodityId); + // TODO: prints to debug ResultSet rs = preparedStatement.executeQuery(); if (rs.next()) { c.setId(rs.getInt("id")); diff --git a/AppStockAccounting/Views/EditViewController.java b/AppStockAccounting/Views/EditViewController.java index 3e386c5..9c4c1c6 100644 --- a/AppStockAccounting/Views/EditViewController.java +++ b/AppStockAccounting/Views/EditViewController.java @@ -5,11 +5,8 @@ */ package persaccounting.AppStockAccounting.Views; -import java.net.URL; -import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.Initializable; import javafx.scene.control.TextField; import javafx.stage.Stage; import persaccounting.AppStockAccounting.Entity.Commodity; @@ -20,7 +17,7 @@ * * @author Olena */ -public class EditViewController implements Initializable { +public class EditViewController { @FXML private TextField commodityNameField; @FXML private TextField commodityDescriptionField; @@ -30,14 +27,6 @@ public class EditViewController implements Initializable { private Stage dialogStage; private Commodity commodity; private boolean okClicked = false; - - /** - * Initializes the controller class. - */ - @Override - public void initialize(URL url, ResourceBundle rb) { - // TODO - } /** * Sets the stage of this dialog. diff --git a/AppStockAccounting/Views/MainViewController.java b/AppStockAccounting/Views/MainViewController.java index ca92baf..0548897 100644 --- a/AppStockAccounting/Views/MainViewController.java +++ b/AppStockAccounting/Views/MainViewController.java @@ -26,6 +26,7 @@ import persaccounting.Auxiliaries.AlertManagement; import persaccounting.Configs; import persaccounting.Main; +import persaccounting.ViewNavigation; /** * FXML Controller class @@ -57,13 +58,34 @@ public void initialize(URL location, ResourceBundle resources) { model = DataModel.GetInstance(); System.out.println("The next DataModel obj is found (if any): \n" + model); // debug model.load(); - // Initialize commodities table with four columns. + + // Initialize commodities table of four columns: commodityNameColumn.setCellValueFactory(new PropertyValueFactory<>("commodityName")); commodityDescriptionColumn.setCellValueFactory(new PropertyValueFactory<>("commodityDescription")); commodityQuantityInStockColumn.setCellValueFactory(new PropertyValueFactory<>("commodityQuantityInStock")); - commodityPriceWithoutTaxColumn.setCellValueFactory(new PropertyValueFactory<>("commodityPriceWithoutTax")); - // averageColumn.setCellValueFactory(cellData -> cellData.getValue().calculatePriceAverage().asObject()); - sM = commoditiesTable.getSelectionModel(); + commodityPriceWithoutTaxColumn.setCellValueFactory(new PropertyValueFactory<>("commodityPriceWithoutTax")); + + // Initialize and populate commodities table of four (?) columns: + /* + commodityNameColumn.setCellValueFactory(cellData -> cellData.getValue().commodityNameProperty()); + commodityDescriptionColumn.setCellValueFactory(cellData -> cellData.getValue().commodityNameDescription()); + */ + // commodityQuantityInStockColumn.setCellValueFactory(cellData -> cellData.getValue().commodityQuantityInStockProperty()); + // commodityPriceWithoutTaxColumn.setCellValueFactory(cellData -> cellData.getValue().commodityPriceWithoutTaxProperty()); + + // TODO: implement (not required): + // averageColumn.setCellValueFactory(cellData -> cellData.getValue().calculateTotalValue().asObject()); + + sM = commoditiesTable.getSelectionModel(); // TODO: consider: usage cases + + model.clear(); // TODO: find other decision (SQL query GET_ALL is still duplicated!) + model.load(); + + /* non-recommended approach is below; refer to: + https://docs.oracle.com/javafx/2/api/javafx/scene/control/ListView.html + */ + commoditiesTable.getItems().setAll(model.getCache()); + totalSumWithoutTaxField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_sum_without_tax(model.getCache()))); totalTaxSumField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_tax_sum(model.getCache()))); totalSumTaxInclField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_sum_tax_included(model.getCache()))); @@ -73,6 +95,7 @@ public void initialize(URL location, ResourceBundle resources) { public void setMainApp(Main mainApp) { this.mainApp = mainApp; commoditiesTable.setItems(model.getCache()); + // model.clear(); } /** @@ -86,8 +109,7 @@ public void setMainApp(Main mainApp) { // TODO: refactor with regard to sub-view! OPersian's note; public boolean showCommodityEditDialog(Commodity commodity) { - try { - + try { // Load the fxml file and create a new stage for the popup dialog. FXMLLoader loader = new FXMLLoader(); loader.setLocation(Main.class.getResource(Configs.ACC_EDIT_VIEW)); @@ -105,7 +127,6 @@ public boolean showCommodityEditDialog(Commodity commodity) { controller.setDialogStage(dialogStage); controller.setCommodity(commodity); - // Show the dialog and wait until the user closes it dialogStage.showAndWait(); @@ -130,6 +151,8 @@ private void handleAdd() { totalSumWithoutTaxField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_sum_without_tax(model.getCache()))); totalTaxSumField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_tax_sum(model.getCache()))); totalSumTaxInclField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_sum_tax_included(model.getCache()))); + + ViewNavigation.loadView(Configs.ACC_MAIN); // instant table reload } } @@ -142,6 +165,9 @@ private void handleDelete() { totalSumWithoutTaxField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_sum_without_tax(model.getCache()))); totalTaxSumField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_tax_sum(model.getCache()))); totalSumTaxInclField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_sum_tax_included(model.getCache()))); + + ViewNavigation.loadView(Configs.ACC_MAIN); // instant table reload + } else { // Nothing selected. AlertManagement.displayPreventionAlert( @@ -162,6 +188,8 @@ private void handleEdit() { totalSumWithoutTaxField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_sum_without_tax(model.getCache()))); totalTaxSumField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_tax_sum(model.getCache()))); totalSumTaxInclField.setText(String.format(FORMAT_EL, SummaryCalculations.calculate_total_sum_tax_included(model.getCache()))); + + ViewNavigation.loadView(Configs.ACC_MAIN); // instant table reload } } else {