Skip to content

Commit

Permalink
acc: fixed all CRUD views; console debug extended
Browse files Browse the repository at this point in the history
  • Loading branch information
OPersian committed Jan 11, 2016
1 parent f24ce13 commit 9590c4b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
2 changes: 1 addition & 1 deletion AppStockAccounting/Entity/Commodity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
22 changes: 20 additions & 2 deletions AppStockAccounting/Model/CommodityDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
Expand All @@ -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
Expand All @@ -139,7 +154,9 @@ public void updateCommodity(Commodity c) {
public List<Commodity> getAllCommodities() {
List<Commodity> commoditiestList = new ArrayList<Commodity>();
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
Expand Down Expand Up @@ -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"));
Expand Down
13 changes: 1 addition & 12 deletions AppStockAccounting/Views/EditViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +17,7 @@
*
* @author Olena
*/
public class EditViewController implements Initializable {
public class EditViewController {

@FXML private TextField commodityNameField;
@FXML private TextField commodityDescriptionField;
Expand All @@ -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.
Expand Down
42 changes: 35 additions & 7 deletions AppStockAccounting/Views/MainViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import persaccounting.Auxiliaries.AlertManagement;
import persaccounting.Configs;
import persaccounting.Main;
import persaccounting.ViewNavigation;

/**
* FXML Controller class
Expand Down Expand Up @@ -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())));
Expand All @@ -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();
}

/**
Expand All @@ -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));
Expand All @@ -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();

Expand All @@ -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
}
}

Expand All @@ -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(
Expand All @@ -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 {
Expand Down

0 comments on commit 9590c4b

Please sign in to comment.