├── src
└── main
│ ├── resources
│ ├── img
│ │ └── bck.png
│ └── view
│ │ ├── DashboardForm.fxml
│ │ ├── CustomerForm.fxml
│ │ ├── PlaceOrderForm.fxml
│ │ └── ItemForm.fxml
│ └── java
│ ├── Main.java
│ ├── dto
│ ├── ItemDto.java
│ ├── OrderDetailsDto.java
│ ├── OrderDto.java
│ ├── tm
│ │ ├── OrderTm.java
│ │ ├── ItemTm.java
│ │ └── CustomerTm.java
│ └── CustomerDto.java
│ ├── model
│ ├── OrderDetailsModel.java
│ ├── OrderModel.java
│ ├── ItemModel.java
│ ├── CustomerModel.java
│ └── impl
│ │ ├── OrderDetailsModelImpl.java
│ │ ├── ItemModelImpl.java
│ │ ├── OrderModelImpl.java
│ │ └── CustomerModelImpl.java
│ ├── AppInitializer.java
│ ├── db
│ └── DBConnection.java
│ └── controller
│ ├── DashboardFormController.java
│ ├── CustomerFormController.java
│ ├── ItemFormController.java
│ └── PlaceOrderFormController.java
├── target
├── classes
│ ├── AppInitializer.class
│ ├── controller
│ │ └── DashboardFormController.class
│ └── view
│ │ └── DashboardForm.fxml
└── maven-status
│ └── maven-compiler-plugin
│ └── compile
│ └── default-compile
│ ├── createdFiles.lst
│ └── inputFiles.lst
├── .idea
├── vcs.xml
├── .gitignore
├── dataSources.xml
├── misc.xml
├── compiler.xml
├── jarRepositories.xml
└── uiDesigner.xml
└── pom.xml
/src/main/resources/img/bck.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HasinduEshan/mvc-maven-pos/HEAD/src/main/resources/img/bck.png
--------------------------------------------------------------------------------
/target/classes/AppInitializer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HasinduEshan/mvc-maven-pos/HEAD/target/classes/AppInitializer.class
--------------------------------------------------------------------------------
/src/main/java/Main.java:
--------------------------------------------------------------------------------
1 | public class Main {
2 | public static void main(String[] args) {
3 | AppInitializer.main(args);
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/target/classes/controller/DashboardFormController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HasinduEshan/mvc-maven-pos/HEAD/target/classes/controller/DashboardFormController.class
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/src/main/java/dto/ItemDto.java:
--------------------------------------------------------------------------------
1 | package dto;
2 |
3 | import lombok.*;
4 |
5 | @AllArgsConstructor
6 | @NoArgsConstructor
7 | @ToString
8 | @Getter
9 | @Setter
10 | public class ItemDto {
11 | private String code;
12 | private String desc;
13 | private double unitPrice;
14 | private int qty;
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/model/OrderDetailsModel.java:
--------------------------------------------------------------------------------
1 | package model;
2 |
3 | import dto.OrderDetailsDto;
4 |
5 | import java.sql.SQLException;
6 | import java.util.List;
7 |
8 | public interface OrderDetailsModel {
9 | boolean saveOrderDetails(List list) throws SQLException, ClassNotFoundException;
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/model/OrderModel.java:
--------------------------------------------------------------------------------
1 | package model;
2 |
3 | import dto.OrderDto;
4 |
5 | import java.sql.SQLException;
6 |
7 | public interface OrderModel {
8 | boolean saveOrder(OrderDto dto) throws SQLException, ClassNotFoundException;
9 | OrderDto lastOrder() throws SQLException, ClassNotFoundException;
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/dto/OrderDetailsDto.java:
--------------------------------------------------------------------------------
1 | package dto;
2 |
3 | import lombok.*;
4 |
5 | @AllArgsConstructor
6 | @NoArgsConstructor
7 | @Setter
8 | @Getter
9 | @ToString
10 | public class OrderDetailsDto {
11 | private String orderId;
12 | private String itemCode;
13 | private int qty;
14 | private double unitPrice;
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/dto/OrderDto.java:
--------------------------------------------------------------------------------
1 | package dto;
2 |
3 | import lombok.*;
4 |
5 | import java.util.List;
6 |
7 | @AllArgsConstructor
8 | @NoArgsConstructor
9 | @Setter
10 | @Getter
11 | @ToString
12 | public class OrderDto {
13 | private String orderId;
14 | private String date;
15 | private String custId;
16 | private List list;
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/model/ItemModel.java:
--------------------------------------------------------------------------------
1 | package model;
2 |
3 | import dto.ItemDto;
4 |
5 | import java.sql.SQLException;
6 | import java.util.List;
7 |
8 | public interface ItemModel {
9 | boolean saveItem(ItemDto dto);
10 | boolean updateItem(ItemDto dto);
11 | boolean deleteItem(String code);
12 | ItemDto getItem(String code) throws SQLException, ClassNotFoundException;
13 | List allItems() throws SQLException, ClassNotFoundException;
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/dto/tm/OrderTm.java:
--------------------------------------------------------------------------------
1 | package dto.tm;
2 |
3 | import com.jfoenix.controls.JFXButton;
4 | import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject;
5 | import lombok.*;
6 |
7 |
8 | @AllArgsConstructor
9 | @NoArgsConstructor
10 | @Setter
11 | @Getter
12 | @ToString
13 | public class OrderTm extends RecursiveTreeObject {
14 | private String code;
15 | private String desc;
16 | private int qty;
17 | private double amount;
18 | private JFXButton btn;
19 | }
20 |
--------------------------------------------------------------------------------
/.idea/dataSources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | mysql.8
6 | true
7 | com.mysql.cj.jdbc.Driver
8 | jdbc:mysql://localhost:3306
9 | $ProjectFileDir$
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/java/model/CustomerModel.java:
--------------------------------------------------------------------------------
1 | package model;
2 |
3 | import dto.CustomerDto;
4 |
5 | import java.sql.SQLException;
6 | import java.util.List;
7 |
8 | public interface CustomerModel {
9 | boolean saveCustomer(CustomerDto dto) throws SQLException, ClassNotFoundException;
10 | boolean updateCustomer(CustomerDto dto) throws SQLException, ClassNotFoundException;
11 | boolean deleteCustomer(String id) throws SQLException, ClassNotFoundException;
12 | List allCustomers() throws SQLException, ClassNotFoundException;
13 | CustomerDto searchCustomer(String id);
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/AppInitializer.java:
--------------------------------------------------------------------------------
1 | import javafx.application.Application;
2 | import javafx.fxml.FXMLLoader;
3 | import javafx.scene.Scene;
4 | import javafx.stage.Stage;
5 |
6 | import java.io.IOException;
7 |
8 | public class AppInitializer extends Application {
9 |
10 | public static void main(String[] args) {
11 | launch(args);
12 | }
13 |
14 | @Override
15 | public void start(Stage primaryStage) throws IOException {
16 | primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("view/DashboardForm.fxml"))));
17 | primaryStage.centerOnScreen();
18 | primaryStage.setResizable(false);
19 | primaryStage.show();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/dto/tm/ItemTm.java:
--------------------------------------------------------------------------------
1 | package dto.tm;
2 |
3 | import com.jfoenix.controls.JFXButton;
4 | import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject;
5 | import lombok.*;
6 |
7 | @AllArgsConstructor
8 | @NoArgsConstructor
9 | @ToString
10 | @Getter
11 | @Setter
12 | public class ItemTm extends RecursiveTreeObject {
13 | private String code;
14 | private String desc;
15 | private double unitPrice;
16 | private int qty;
17 | private JFXButton btn;
18 |
19 | public ItemTm(String code, String desc, double unitPrice, int qty) {
20 | this.code = code;
21 | this.desc = desc;
22 | this.unitPrice = unitPrice;
23 | this.qty = qty;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/db/DBConnection.java:
--------------------------------------------------------------------------------
1 | package db;
2 |
3 | import java.sql.Connection;
4 | import java.sql.DriverManager;
5 | import java.sql.SQLException;
6 |
7 | public class DBConnection {
8 | private static DBConnection dbConnection;
9 | private Connection connection;
10 | private DBConnection() throws ClassNotFoundException, SQLException {
11 | Class.forName("com.mysql.cj.jdbc.Driver");
12 | connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/thogakade","root","1234");
13 | }
14 |
15 | public static DBConnection getInstance() throws ClassNotFoundException, SQLException {
16 | return dbConnection!=null ? dbConnection : (dbConnection=new DBConnection());
17 | }
18 |
19 | public Connection getConnection(){
20 | return connection;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst:
--------------------------------------------------------------------------------
1 | dto\tm\CustomerTm.class
2 | controller\PlaceOrderFormController.class
3 | model\ItemModel.class
4 | Main.class
5 | controller\ItemFormController$1.class
6 | model\OrderModel.class
7 | controller\ItemFormController.class
8 | model\impl\CustomerModelImpl.class
9 | controller\DashboardFormController.class
10 | db\DBConnection.class
11 | dto\tm\OrderTm.class
12 | dto\OrderDto.class
13 | controller\ItemFormController$1$1.class
14 | dto\CustomerDto.class
15 | dto\ItemDto.class
16 | controller\CustomerFormController.class
17 | model\impl\OrderDetailsModelImpl.class
18 | model\OrderDetailsModel.class
19 | model\impl\ItemModelImpl.class
20 | model\CustomerModel.class
21 | dto\OrderDetailsDto.class
22 | AppInitializer.class
23 | model\impl\OrderModelImpl.class
24 | dto\tm\ItemTm.class
25 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/java/model/impl/OrderDetailsModelImpl.java:
--------------------------------------------------------------------------------
1 | package model.impl;
2 |
3 | import db.DBConnection;
4 | import dto.OrderDetailsDto;
5 | import model.OrderDetailsModel;
6 |
7 | import java.sql.PreparedStatement;
8 | import java.sql.SQLException;
9 | import java.util.List;
10 |
11 | public class OrderDetailsModelImpl implements OrderDetailsModel {
12 | @Override
13 | public boolean saveOrderDetails(List list) throws SQLException, ClassNotFoundException {
14 | boolean isDetailsSaved = true;
15 | for (OrderDetailsDto dto:list) {
16 | String sql = "INSERT INTO orderdetail VALUES(?,?,?,?)";
17 | PreparedStatement pstm = DBConnection.getInstance().getConnection().prepareStatement(sql);
18 | pstm.setString(1,dto.getOrderId());
19 | pstm.setString(2,dto.getItemCode());
20 | pstm.setInt(3,dto.getQty());
21 | pstm.setDouble(4,dto.getUnitPrice());
22 |
23 | if(!(pstm.executeUpdate()>0)){
24 | isDetailsSaved = false;
25 | }
26 | }
27 | return isDetailsSaved;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/dto/CustomerDto.java:
--------------------------------------------------------------------------------
1 | package dto;
2 |
3 | public class CustomerDto {
4 | private String id;
5 | private String name;
6 | private String address;
7 | private double salary;
8 |
9 | public CustomerDto(String id, String name, String address, double salary) {
10 | this.id = id;
11 | this.name = name;
12 | this.address = address;
13 | this.salary = salary;
14 | }
15 |
16 | public CustomerDto() {
17 | }
18 |
19 | @Override
20 | public String toString() {
21 | return "Customer{" +
22 | "id='" + id + '\'' +
23 | ", name='" + name + '\'' +
24 | ", address='" + address + '\'' +
25 | ", salary=" + salary +
26 | '}';
27 | }
28 |
29 | public String getId() {
30 | return id;
31 | }
32 |
33 | public void setId(String id) {
34 | this.id = id;
35 | }
36 |
37 | public String getName() {
38 | return name;
39 | }
40 |
41 | public void setName(String name) {
42 | this.name = name;
43 | }
44 |
45 | public String getAddress() {
46 | return address;
47 | }
48 |
49 | public void setAddress(String address) {
50 | this.address = address;
51 | }
52 |
53 | public double getSalary() {
54 | return salary;
55 | }
56 |
57 | public void setSalary(double salary) {
58 | this.salary = salary;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/target/classes/view/DashboardForm.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/main/java/dto/tm/CustomerTm.java:
--------------------------------------------------------------------------------
1 | package dto.tm;
2 |
3 | import javafx.scene.control.Button;
4 |
5 | public class CustomerTm {
6 | private String id;
7 | private String name;
8 | private String address;
9 | private double salary;
10 | private Button btn;
11 |
12 | public CustomerTm() {
13 | }
14 |
15 | public CustomerTm(String id, String name, String address, double salary, Button btn) {
16 | this.id = id;
17 | this.name = name;
18 | this.address = address;
19 | this.salary = salary;
20 | this.btn = btn;
21 | }
22 |
23 | public String getId() {
24 | return id;
25 | }
26 |
27 | public void setId(String id) {
28 | this.id = id;
29 | }
30 |
31 | public String getName() {
32 | return name;
33 | }
34 |
35 | public void setName(String name) {
36 | this.name = name;
37 | }
38 |
39 | public String getAddress() {
40 | return address;
41 | }
42 |
43 | public void setAddress(String address) {
44 | this.address = address;
45 | }
46 |
47 | public double getSalary() {
48 | return salary;
49 | }
50 |
51 | public void setSalary(double salary) {
52 | this.salary = salary;
53 | }
54 |
55 | public Button getBtn() {
56 | return btn;
57 | }
58 |
59 | public void setBtn(Button btn) {
60 | this.btn = btn;
61 | }
62 |
63 | @Override
64 | public String toString() {
65 | return "CustomerTm{" +
66 | "id='" + id + '\'' +
67 | ", name='" + name + '\'' +
68 | ", address='" + address + '\'' +
69 | ", salary=" + salary +
70 | ", btn=" + btn +
71 | '}';
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/resources/view/DashboardForm.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst:
--------------------------------------------------------------------------------
1 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\model\CustomerModel.java
2 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\dto\tm\ItemTm.java
3 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\dto\ItemDto.java
4 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\model\OrderDetailsModel.java
5 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\controller\PlaceOrderFormController.java
6 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\dto\tm\CustomerTm.java
7 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\model\impl\OrderDetailsModelImpl.java
8 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\AppInitializer.java
9 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\db\DBConnection.java
10 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\controller\CustomerFormController.java
11 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\controller\ItemFormController.java
12 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\model\impl\OrderModelImpl.java
13 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\dto\OrderDetailsDto.java
14 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\model\OrderModel.java
15 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\dto\CustomerDto.java
16 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\model\impl\CustomerModelImpl.java
17 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\model\ItemModel.java
18 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\Main.java
19 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\dto\tm\OrderTm.java
20 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\controller\DashboardFormController.java
21 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\dto\OrderDto.java
22 | E:\iCET\Teach\ICM105\JavaFx\maven-pos\src\main\java\model\impl\ItemModelImpl.java
23 |
--------------------------------------------------------------------------------
/src/main/java/model/impl/ItemModelImpl.java:
--------------------------------------------------------------------------------
1 | package model.impl;
2 |
3 | import db.DBConnection;
4 | import dto.ItemDto;
5 | import model.ItemModel;
6 |
7 | import java.sql.PreparedStatement;
8 | import java.sql.ResultSet;
9 | import java.sql.SQLException;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class ItemModelImpl implements ItemModel {
14 | @Override
15 | public boolean saveItem(ItemDto dto) {
16 | return false;
17 | }
18 |
19 | @Override
20 | public boolean updateItem(ItemDto dto) {
21 | return false;
22 | }
23 |
24 | @Override
25 | public boolean deleteItem(String code) {
26 | return false;
27 | }
28 |
29 | @Override
30 | public ItemDto getItem(String code) throws SQLException, ClassNotFoundException {
31 | String sql = "SELECT * FROM item WHERE code=?";
32 | PreparedStatement pstm = DBConnection.getInstance().getConnection().prepareStatement(sql);
33 | pstm.setString(1,code);
34 | ResultSet resultSet = pstm.executeQuery();
35 | if (resultSet.next()){
36 | return new ItemDto(
37 | resultSet.getString(1),
38 | resultSet.getString(2),
39 | resultSet.getDouble(3),
40 | resultSet.getInt(4)
41 | );
42 | }
43 | return null;
44 | }
45 |
46 | @Override
47 | public List allItems() throws SQLException, ClassNotFoundException {
48 | List list = new ArrayList<>();
49 | String sql = "SELECT * FROM item";
50 | PreparedStatement pstm = DBConnection.getInstance().getConnection().prepareStatement(sql);
51 | ResultSet resultSet = pstm.executeQuery();
52 | while (resultSet.next()){
53 | list.add(new ItemDto(
54 | resultSet.getString(1),
55 | resultSet.getString(2),
56 | resultSet.getDouble(3),
57 | resultSet.getInt(4)
58 | ));
59 | }
60 | return list;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/model/impl/OrderModelImpl.java:
--------------------------------------------------------------------------------
1 | package model.impl;
2 |
3 | import db.DBConnection;
4 | import dto.OrderDto;
5 | import model.OrderDetailsModel;
6 | import model.OrderModel;
7 |
8 | import java.sql.Connection;
9 | import java.sql.PreparedStatement;
10 | import java.sql.ResultSet;
11 | import java.sql.SQLException;
12 |
13 | public class OrderModelImpl implements OrderModel {
14 |
15 | OrderDetailsModel orderDetailsModel = new OrderDetailsModelImpl();
16 |
17 | @Override
18 | public boolean saveOrder(OrderDto dto) throws SQLException {
19 | Connection connection=null;
20 | try {
21 | connection = DBConnection.getInstance().getConnection();
22 | connection.setAutoCommit(false);
23 |
24 | String sql = "INSERT INTO orders VALUES(?,?,?)";
25 | PreparedStatement pstm = connection.prepareStatement(sql);
26 | pstm.setString(1, dto.getOrderId());
27 | pstm.setString(2, dto.getDate());
28 | pstm.setString(3, dto.getCustId());
29 | if (pstm.executeUpdate() > 0) {
30 | boolean isDetailSaved = orderDetailsModel.saveOrderDetails(dto.getList());
31 | if (isDetailSaved) {
32 | connection.commit();
33 | return true;
34 | }
35 | }
36 | }catch (SQLException | ClassNotFoundException ex){
37 | connection.rollback();
38 | ex.printStackTrace();
39 | }finally {
40 | connection.setAutoCommit(true);
41 | }
42 | return false;
43 | }
44 |
45 | @Override
46 | public OrderDto lastOrder() throws SQLException, ClassNotFoundException {
47 | String sql = "SELECT * FROM orders ORDER BY id DESC LIMIT 1";
48 | PreparedStatement pstm = DBConnection.getInstance().getConnection().prepareStatement(sql);
49 | ResultSet resultSet = pstm.executeQuery();
50 |
51 | if (resultSet.next()){
52 | return new OrderDto(
53 | resultSet.getString(1),
54 | resultSet.getString(2),
55 | resultSet.getString(3),
56 | null
57 | );
58 | }
59 |
60 | return null;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/model/impl/CustomerModelImpl.java:
--------------------------------------------------------------------------------
1 | package model.impl;
2 |
3 | import db.DBConnection;
4 | import dto.CustomerDto;
5 | import model.CustomerModel;
6 |
7 | import java.sql.PreparedStatement;
8 | import java.sql.ResultSet;
9 | import java.sql.SQLException;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class CustomerModelImpl implements CustomerModel {
14 | @Override
15 | public boolean saveCustomer(CustomerDto dto) throws SQLException, ClassNotFoundException {
16 | String sql = "INSERT INTO customer VALUES(?,?,?,?)";
17 | PreparedStatement pstm = DBConnection.getInstance().getConnection().prepareStatement(sql);
18 |
19 | return pstm.executeUpdate()>0;
20 | }
21 |
22 | @Override
23 | public boolean updateCustomer(CustomerDto dto) throws SQLException, ClassNotFoundException {
24 | String sql = "UPDATE customer SET name=?, address=?, salary=? WHERE id=?";
25 | PreparedStatement pstm = DBConnection.getInstance().getConnection().prepareStatement(sql);
26 | pstm.setString(1,dto.getName());
27 | pstm.setString(2,dto.getAddress());
28 | pstm.setDouble(3,dto.getSalary());
29 | pstm.setString(4,dto.getId());
30 |
31 | return pstm.executeUpdate()>0;
32 | }
33 |
34 | @Override
35 | public boolean deleteCustomer(String id) throws SQLException, ClassNotFoundException {
36 | String sql = "DELETE from customer WHERE id=?";
37 | PreparedStatement pstm = DBConnection.getInstance().getConnection().prepareStatement(sql);
38 | pstm.setString(1,id);
39 | return pstm.executeUpdate()>0;
40 | }
41 |
42 | @Override
43 | public List allCustomers() throws SQLException, ClassNotFoundException {
44 | List list = new ArrayList<>();
45 |
46 | String sql = "SELECT * FROM customer";
47 | PreparedStatement pstm = DBConnection.getInstance().getConnection().prepareStatement(sql);
48 | ResultSet resultSet = pstm.executeQuery();
49 | while (resultSet.next()){
50 | list.add(new CustomerDto(
51 | resultSet.getString(1),
52 | resultSet.getString(2),
53 | resultSet.getString(3),
54 | resultSet.getDouble(4)
55 | ));
56 | }
57 | return list;
58 | }
59 |
60 | @Override
61 | public CustomerDto searchCustomer(String id) {
62 | return null;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/controller/DashboardFormController.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | import javafx.animation.Animation;
4 | import javafx.animation.KeyFrame;
5 | import javafx.animation.Timeline;
6 | import javafx.event.ActionEvent;
7 | import javafx.fxml.FXMLLoader;
8 | import javafx.scene.Scene;
9 | import javafx.scene.control.Label;
10 | import javafx.scene.layout.AnchorPane;
11 | import javafx.stage.Stage;
12 | import javafx.util.Duration;
13 |
14 | import java.io.IOException;
15 | import java.time.LocalDateTime;
16 | import java.time.format.DateTimeFormatter;
17 |
18 | public class DashboardFormController {
19 | public AnchorPane pane;
20 | public Label lblTime;
21 |
22 | public void initialize(){
23 | calculateTime();
24 | }
25 |
26 | private void calculateTime() {
27 | Timeline timeline = new Timeline(new KeyFrame(
28 | Duration.ZERO,
29 | actionEvent -> lblTime.setText(LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")))
30 | ), new KeyFrame(Duration.seconds(1)));
31 |
32 | timeline.setCycleCount(Animation.INDEFINITE);
33 | timeline.play();
34 | }
35 |
36 | public void customerButtonOnAction(ActionEvent actionEvent) {
37 | Stage stage = (Stage) pane.getScene().getWindow();
38 | try {
39 | stage.setScene(new Scene(FXMLLoader.load(getClass().getResource("/view/CustomerForm.fxml"))));
40 | stage.setTitle("Customer Form");
41 | stage.show();
42 | } catch (IOException e) {
43 | e.printStackTrace();
44 | }
45 | }
46 |
47 | public void itemsButtonOnAction(ActionEvent actionEvent) {
48 | Stage stage = (Stage) pane.getScene().getWindow();
49 | try {
50 | stage.setScene(new Scene(FXMLLoader.load(getClass().getResource("/view/ItemForm.fxml"))));
51 | stage.setResizable(true);
52 | stage.setTitle("Item Form");
53 | stage.show();
54 | } catch (IOException e) {
55 | e.printStackTrace();
56 | }
57 | }
58 |
59 | public void placeOrderButtonOnAction(ActionEvent actionEvent) {
60 | Stage stage = (Stage) pane.getScene().getWindow();
61 | try {
62 | stage.setScene(new Scene(FXMLLoader.load(getClass().getResource("/view/PlaceOrderForm.fxml"))));
63 | stage.setResizable(true);
64 | stage.setTitle("Place Order Form");
65 | stage.show();
66 | } catch (IOException e) {
67 | e.printStackTrace();
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/resources/view/CustomerForm.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | maven-pos
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 11
13 | 11
14 |
15 |
16 |
17 |
18 |
19 | org.openjfx
20 | javafx-fxml
21 | 19.0.2.1
22 |
23 |
24 | org.openjfx
25 | javafx-controls
26 | 19.0.2.1
27 |
28 |
29 | com.jfoenix
30 | jfoenix
31 | 9.0.1
32 |
33 |
34 | mysql
35 | mysql-connector-java
36 | 8.0.32
37 |
38 |
39 | org.projectlombok
40 | lombok
41 | 1.18.28
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.openjfx
50 | javafx-maven-plugin
51 | 0.0.8
52 |
53 | AppInitializer
54 |
55 |
56 |
57 | org.apache.maven.plugins
58 | maven-shade-plugin
59 | 3.2.4
60 |
61 |
62 | package
63 |
64 | shade
65 |
66 |
67 | true
68 | project-classifier
69 | shade\${project.artifactId}.jar
70 |
71 |
72 | Main
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/src/main/resources/view/PlaceOrderForm.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
52 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/src/main/java/controller/CustomerFormController.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | import db.DBConnection;
4 | import javafx.collections.FXCollections;
5 | import javafx.collections.ObservableList;
6 | import javafx.event.ActionEvent;
7 | import javafx.fxml.FXML;
8 | import javafx.fxml.FXMLLoader;
9 | import javafx.scene.Scene;
10 | import javafx.scene.control.*;
11 | import javafx.scene.control.cell.PropertyValueFactory;
12 | import javafx.stage.Stage;
13 | import dto.CustomerDto;
14 | import dto.tm.CustomerTm;
15 | import model.CustomerModel;
16 | import model.impl.CustomerModelImpl;
17 |
18 | import java.io.IOException;
19 | import java.sql.*;
20 | import java.util.List;
21 |
22 |
23 | public class CustomerFormController {
24 |
25 | @FXML
26 | private TableColumn colAddress;
27 |
28 | @FXML
29 | private TableColumn colId;
30 |
31 | @FXML
32 | private TableColumn colName;
33 |
34 | @FXML
35 | private TableColumn colOption;
36 |
37 | @FXML
38 | private TableColumn colSalary;
39 |
40 | @FXML
41 | private TableView tblCustomer;
42 |
43 | @FXML
44 | private TextField txtAddress;
45 |
46 | @FXML
47 | private TextField txtId;
48 |
49 | @FXML
50 | private TextField txtName;
51 |
52 | @FXML
53 | private TextField txtSalary;
54 |
55 | private CustomerModel customerModel = new CustomerModelImpl();
56 |
57 | public void initialize(){
58 | colId.setCellValueFactory(new PropertyValueFactory<>("id"));
59 | colName.setCellValueFactory(new PropertyValueFactory<>("name"));
60 | colAddress.setCellValueFactory(new PropertyValueFactory<>("address"));
61 | colSalary.setCellValueFactory(new PropertyValueFactory<>("salary"));
62 | colOption.setCellValueFactory(new PropertyValueFactory<>("btn"));
63 | loadCustomerTable();
64 |
65 | tblCustomer.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
66 | setData(newValue);
67 | });
68 | }
69 |
70 | private void setData(CustomerTm newValue) {
71 | if (newValue != null) {
72 | txtId.setEditable(false);
73 | txtId.setText(newValue.getId());
74 | txtName.setText(newValue.getName());
75 | txtAddress.setText(newValue.getAddress());
76 | txtSalary.setText(String.valueOf(newValue.getSalary()));
77 | }
78 | }
79 |
80 | private void loadCustomerTable() {
81 | ObservableList tmList = FXCollections.observableArrayList();
82 |
83 | try {
84 | List dtoList = customerModel.allCustomers();
85 |
86 | for (CustomerDto dto:dtoList) {
87 | Button btn = new Button("Delete");
88 |
89 | CustomerTm c = new CustomerTm(
90 | dto.getId(),
91 | dto.getName(),
92 | dto.getAddress(),
93 | dto.getSalary(),
94 | btn
95 | );
96 |
97 | btn.setOnAction(actionEvent -> {
98 | deleteCustomer(c.getId());
99 | });
100 |
101 | tmList.add(c);
102 | }
103 |
104 | tblCustomer.setItems(tmList);
105 | } catch (SQLException e) {
106 | e.printStackTrace();
107 | } catch (ClassNotFoundException e) {
108 | e.printStackTrace();
109 | }
110 | }
111 |
112 | private void deleteCustomer(String id) {
113 | try {
114 | boolean isDeleted = customerModel.deleteCustomer(id);
115 | if (isDeleted){
116 | new Alert(Alert.AlertType.INFORMATION,"Customer Deleted!").show();
117 | loadCustomerTable();
118 | }else{
119 | new Alert(Alert.AlertType.ERROR,"Something went wrong!").show();
120 | }
121 |
122 | } catch (ClassNotFoundException | SQLException e) {
123 | e.printStackTrace();
124 | }
125 | }
126 |
127 | @FXML
128 | void reloadButtonOnAction(ActionEvent event) {
129 | loadCustomerTable();
130 | tblCustomer.refresh();
131 | clearFields();
132 | }
133 |
134 | private void clearFields() {
135 | tblCustomer.refresh();
136 | txtSalary.clear();
137 | txtAddress.clear();
138 | txtName.clear();
139 | txtId.clear();
140 | txtId.setEditable(true);
141 | }
142 |
143 | @FXML
144 | void saveButtonOnAction(ActionEvent event) {
145 | try {
146 | boolean isSaved = customerModel.saveCustomer(new CustomerDto(txtId.getText(),
147 | txtName.getText(),
148 | txtAddress.getText(),
149 | Double.parseDouble(txtSalary.getText())
150 | ));
151 | if (isSaved){
152 | new Alert(Alert.AlertType.INFORMATION,"Customer Saved!").show();
153 | loadCustomerTable();
154 | clearFields();
155 | }
156 |
157 | } catch (SQLIntegrityConstraintViolationException ex){
158 | new Alert(Alert.AlertType.ERROR,"Duplicate Entry").show();
159 | } catch (ClassNotFoundException | SQLException e) {
160 | e.printStackTrace();
161 | }
162 | }
163 |
164 | @FXML
165 | void updateButtonOnAction(ActionEvent event) {
166 | try {
167 | boolean isUpdated = customerModel.updateCustomer(new CustomerDto(txtId.getText(),
168 | txtName.getText(),
169 | txtAddress.getText(),
170 | Double.parseDouble(txtSalary.getText())
171 | ));
172 | if (isUpdated){
173 | new Alert(Alert.AlertType.INFORMATION,"Customer Updated!").show();
174 | loadCustomerTable();
175 | clearFields();
176 | }
177 | } catch (ClassNotFoundException | SQLException e) {
178 | e.printStackTrace();
179 | }
180 | }
181 |
182 | public void backButtonOnAction(ActionEvent actionEvent) {
183 | Stage stage = (Stage) tblCustomer.getScene().getWindow();
184 | try {
185 | stage.setScene(new Scene(FXMLLoader.load(getClass().getResource("/view/DashboardForm.fxml"))));
186 | stage.show();
187 | } catch (IOException e) {
188 | e.printStackTrace();
189 | }
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/src/main/java/controller/ItemFormController.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | import com.jfoenix.controls.JFXButton;
4 | import com.jfoenix.controls.JFXTextField;
5 | import com.jfoenix.controls.JFXTreeTableView;
6 | import com.jfoenix.controls.RecursiveTreeItem;
7 | import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject;
8 | import db.DBConnection;
9 | import dto.CustomerDto;
10 | import dto.ItemDto;
11 | import dto.tm.CustomerTm;
12 | import javafx.beans.value.ChangeListener;
13 | import javafx.beans.value.ObservableValue;
14 | import javafx.collections.FXCollections;
15 | import javafx.collections.ObservableList;
16 | import javafx.event.ActionEvent;
17 | import javafx.fxml.FXML;
18 | import javafx.fxml.FXMLLoader;
19 | import javafx.scene.Scene;
20 | import javafx.scene.control.Alert;
21 | import javafx.scene.control.Button;
22 | import javafx.scene.control.TreeItem;
23 | import javafx.scene.control.TreeTableColumn;
24 | import javafx.scene.control.cell.PropertyValueFactory;
25 | import javafx.scene.control.cell.TreeItemPropertyValueFactory;
26 | import javafx.scene.layout.BorderPane;
27 | import javafx.scene.text.Font;
28 | import javafx.stage.Stage;
29 | import dto.tm.ItemTm;
30 |
31 | import java.io.IOException;
32 | import java.sql.*;
33 | import java.util.function.Predicate;
34 |
35 | public class ItemFormController {
36 |
37 | @FXML
38 | private TreeTableColumn colCode;
39 |
40 | @FXML
41 | private TreeTableColumn colDesc;
42 |
43 | @FXML
44 | private TreeTableColumn colOption;
45 |
46 | @FXML
47 | private TreeTableColumn colQty;
48 |
49 | @FXML
50 | private TreeTableColumn colUnitPrice;
51 |
52 | @FXML
53 | private BorderPane pane;
54 |
55 | @FXML
56 | private JFXTreeTableView tblItem;
57 |
58 | @FXML
59 | private JFXTextField txtCode;
60 |
61 | @FXML
62 | private JFXTextField txtDesc;
63 |
64 | @FXML
65 | private JFXTextField txtQty;
66 |
67 | @FXML
68 | private JFXTextField txtSearch;
69 |
70 | @FXML
71 | private JFXTextField txtUnitPrice;
72 |
73 | public void initialize(){
74 | colCode.setCellValueFactory(new TreeItemPropertyValueFactory<>("code"));
75 | colDesc.setCellValueFactory(new TreeItemPropertyValueFactory<>("desc"));
76 | colUnitPrice.setCellValueFactory(new TreeItemPropertyValueFactory<>("unitPrice"));
77 | colQty.setCellValueFactory(new TreeItemPropertyValueFactory<>("qty"));
78 | colOption.setCellValueFactory(new TreeItemPropertyValueFactory<>("btn"));
79 | loadItemTable();
80 |
81 | txtSearch.textProperty().addListener(new ChangeListener() {
82 | @Override
83 | public void changed(ObservableValue extends String> observableValue, String s, String newValue) {
84 | tblItem.setPredicate(new Predicate>() {
85 | @Override
86 | public boolean test(TreeItem treeItem) {
87 | return treeItem.getValue().getCode().contains(newValue) ||
88 | treeItem.getValue().getDesc().contains(newValue);
89 | }
90 | });
91 | }
92 | });
93 | }
94 |
95 | private void loadItemTable() {
96 | ObservableList tmList = FXCollections.observableArrayList();
97 | String sql = "SELECT * FROM item";
98 |
99 | try {
100 | Statement stm = DBConnection.getInstance().getConnection().createStatement();
101 | ResultSet result = stm.executeQuery(sql);
102 |
103 | while (result.next()){
104 | JFXButton btn = new JFXButton("Delete");
105 |
106 | ItemTm tm = new ItemTm(
107 | result.getString(1),
108 | result.getString(2),
109 | result.getDouble(3),
110 | result.getInt(4),
111 | btn
112 | );
113 |
114 | btn.setOnAction(actionEvent -> {
115 | deleteItem(tm.getCode());
116 | });
117 |
118 | tmList.add(tm);
119 | }
120 |
121 | TreeItem treeItem = new RecursiveTreeItem<>(tmList, RecursiveTreeObject::getChildren);
122 | tblItem.setRoot(treeItem);
123 | tblItem.setShowRoot(false);
124 |
125 | } catch (ClassNotFoundException | SQLException e) {
126 | e.printStackTrace();
127 | }
128 | }
129 |
130 | private void deleteItem(String code) {
131 | String sql = "DELETE from item WHERE code=?";
132 |
133 | try {
134 | PreparedStatement pstm = DBConnection.getInstance().getConnection().prepareStatement(sql);
135 | pstm.setString(1,code);
136 | int result = pstm.executeUpdate(sql);
137 | if (result>0){
138 | new Alert(Alert.AlertType.INFORMATION,"Item Deleted!").show();
139 | loadItemTable();
140 | }else{
141 | new Alert(Alert.AlertType.ERROR,"Something went wrong!").show();
142 | }
143 |
144 | } catch (ClassNotFoundException | SQLException e) {
145 | e.printStackTrace();
146 | }
147 | }
148 |
149 | @FXML
150 | void backButtonOnAction(ActionEvent event) {
151 | Stage stage = (Stage) pane.getScene().getWindow();
152 | try {
153 | stage.setScene(new Scene(FXMLLoader.load(getClass().getResource("/view/DashboardForm.fxml"))));
154 | stage.show();
155 | } catch (IOException e) {
156 | e.printStackTrace();
157 | }
158 | }
159 |
160 | @FXML
161 | void saveButtonOnAction(ActionEvent event) {
162 | ItemDto dto = new ItemDto(txtCode.getText(),
163 | txtDesc.getText(),
164 | Double.parseDouble(txtUnitPrice.getText()),
165 | Integer.parseInt(txtQty.getText())
166 | );
167 | String sql = "INSERT INTO item VALUES(?,?,?,?)";
168 |
169 | try {
170 | PreparedStatement pstm = DBConnection.getInstance().getConnection().prepareStatement(sql);
171 | pstm.setString(1,dto.getCode());
172 | pstm.setString(2,dto.getDesc());
173 | pstm.setDouble(3,dto.getUnitPrice());
174 | pstm.setInt(4,dto.getQty());
175 | int result = pstm.executeUpdate();
176 | if (result>0){
177 | new Alert(Alert.AlertType.INFORMATION,"Item Saved!").show();
178 | loadItemTable();
179 | // clearFields();
180 | }
181 |
182 | } catch (SQLIntegrityConstraintViolationException ex){
183 | new Alert(Alert.AlertType.ERROR,"Duplicate Entry").show();
184 | } catch (ClassNotFoundException | SQLException e) {
185 | e.printStackTrace();
186 | }
187 | }
188 |
189 | @FXML
190 | void updateButtonOnAction(ActionEvent event) {
191 |
192 | }
193 |
194 | }
195 |
--------------------------------------------------------------------------------
/src/main/resources/view/ItemForm.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/src/main/java/controller/PlaceOrderFormController.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | import com.jfoenix.controls.*;
4 | import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject;
5 | import dto.CustomerDto;
6 | import dto.ItemDto;
7 | import dto.OrderDetailsDto;
8 | import dto.OrderDto;
9 | import dto.tm.OrderTm;
10 | import javafx.collections.FXCollections;
11 | import javafx.collections.ObservableList;
12 | import javafx.event.ActionEvent;
13 | import javafx.scene.control.Alert;
14 | import javafx.scene.control.Label;
15 | import javafx.scene.control.TreeItem;
16 | import javafx.scene.control.TreeTableColumn;
17 | import javafx.scene.control.cell.TreeItemPropertyValueFactory;
18 | import model.CustomerModel;
19 | import model.ItemModel;
20 | import model.OrderModel;
21 | import model.impl.CustomerModelImpl;
22 | import model.impl.ItemModelImpl;
23 | import model.impl.OrderModelImpl;
24 |
25 | import java.sql.SQLException;
26 | import java.time.LocalDateTime;
27 | import java.time.format.DateTimeFormatter;
28 | import java.util.ArrayList;
29 | import java.util.List;
30 |
31 | public class PlaceOrderFormController {
32 | public JFXComboBox cmbCustId;
33 | public JFXComboBox cmbItemCode;
34 | public JFXTextField txtCustName;
35 | public JFXTextField txtDesc;
36 | public JFXTextField txtUnitPrice;
37 | public JFXTextField txtQty;
38 | public JFXTreeTableView tblOrder;
39 | public TreeTableColumn colCode;
40 | public TreeTableColumn colDesc;
41 | public TreeTableColumn colQty;
42 | public TreeTableColumn colAmount;
43 | public TreeTableColumn colOption;
44 | public Label lblTotal;
45 | public Label lblOrderId;
46 |
47 | private List customers;
48 | private List items;
49 | private double tot = 0;
50 |
51 | private CustomerModel customerModel = new CustomerModelImpl();
52 | private ItemModel itemModel = new ItemModelImpl();
53 | private OrderModel orderModel = new OrderModelImpl();
54 |
55 | private ObservableList tmList = FXCollections.observableArrayList();
56 |
57 | public void initialize(){
58 | colCode.setCellValueFactory(new TreeItemPropertyValueFactory<>("code"));
59 | colDesc.setCellValueFactory(new TreeItemPropertyValueFactory<>("desc"));
60 | colQty.setCellValueFactory(new TreeItemPropertyValueFactory<>("qty"));
61 | colAmount.setCellValueFactory(new TreeItemPropertyValueFactory<>("amount"));
62 | colOption.setCellValueFactory(new TreeItemPropertyValueFactory<>("btn"));
63 |
64 | generateId();
65 |
66 | loadCustomerIds();
67 | loadItemCodes();
68 |
69 | cmbCustId.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, id) -> {
70 | for (CustomerDto dto:customers) {
71 | if (dto.getId().equals(id)){
72 | txtCustName.setText(dto.getName());
73 | }
74 | }
75 | });
76 |
77 | cmbItemCode.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, code) -> {
78 | for (ItemDto dto:items) {
79 | if (dto.getCode().equals(code)){
80 | txtDesc.setText(dto.getDesc());
81 | txtUnitPrice.setText(String.format("%.2f",dto.getUnitPrice()));
82 | }
83 | }
84 | });
85 | }
86 |
87 | private void loadItemCodes() {
88 | try {
89 | items = itemModel.allItems();
90 | ObservableList list = FXCollections.observableArrayList();
91 | for (ItemDto dto:items) {
92 | list.add(dto.getCode());
93 | }
94 | cmbItemCode.setItems(list);
95 | } catch (SQLException e) {
96 | e.printStackTrace();
97 | } catch (ClassNotFoundException e) {
98 | e.printStackTrace();
99 | }
100 | }
101 |
102 | private void loadCustomerIds() {
103 | try {
104 | customers = customerModel.allCustomers();
105 | ObservableList list = FXCollections.observableArrayList();
106 | for (CustomerDto dto:customers) {
107 | list.add(dto.getId());
108 | }
109 | cmbCustId.setItems(list);
110 | } catch (SQLException e) {
111 | e.printStackTrace();
112 | } catch (ClassNotFoundException e) {
113 | e.printStackTrace();
114 | }
115 | }
116 |
117 | public void backButtonOnAction(ActionEvent actionEvent) {
118 |
119 | }
120 |
121 | public void addToCartButtonOnAction(ActionEvent actionEvent) {
122 | try {
123 | double amount = itemModel.getItem(cmbItemCode.getValue().toString()).getUnitPrice() * Integer.parseInt(txtQty.getText());
124 | JFXButton btn = new JFXButton("Delete");
125 |
126 | OrderTm tm = new OrderTm(
127 | cmbItemCode.getValue().toString(),
128 | txtDesc.getText(),
129 | Integer.parseInt(txtQty.getText()),
130 | amount,
131 | btn
132 | );
133 |
134 | btn.setOnAction(actionEvent1 -> {
135 | tmList.remove(tm);
136 | tot -= tm.getAmount();
137 | tblOrder.refresh();
138 | lblTotal.setText(String.format("%.2f",tot));
139 | });
140 |
141 | boolean isExist = false;
142 |
143 | for (OrderTm order:tmList) {
144 | if (order.getCode().equals(tm.getCode())){
145 | order.setQty(order.getQty()+tm.getQty());
146 | order.setAmount(order.getAmount()+tm.getAmount());
147 | isExist = true;
148 | tot+=tm.getAmount();
149 | }
150 | }
151 |
152 | if (!isExist){
153 | tmList.add(tm);
154 | tot+= tm.getAmount();
155 | }
156 |
157 | TreeItem treeObject = new RecursiveTreeItem(tmList, RecursiveTreeObject::getChildren);
158 | tblOrder.setRoot(treeObject);
159 | tblOrder.setShowRoot(false);
160 |
161 | lblTotal.setText(String.format("%.2f",tot));
162 | } catch (SQLException e) {
163 | e.printStackTrace();
164 | } catch (ClassNotFoundException e) {
165 | e.printStackTrace();
166 | }
167 |
168 | }
169 |
170 | public void generateId(){
171 | try {
172 | OrderDto dto = orderModel.lastOrder();
173 | if (dto!=null){
174 | String id = dto.getOrderId();
175 | int num = Integer.parseInt(id.split("[D]")[1]);
176 | num++;
177 | lblOrderId.setText(String.format("D%03d",num));
178 | }else{
179 | lblOrderId.setText("D001");
180 | }
181 | } catch (SQLException e) {
182 | e.printStackTrace();
183 | } catch (ClassNotFoundException e) {
184 | e.printStackTrace();
185 | }
186 | }
187 |
188 | public void placeOrderButtonOnAction(ActionEvent actionEvent) {
189 | List list = new ArrayList<>();
190 | for (OrderTm tm:tmList) {
191 | list.add(new OrderDetailsDto(
192 | lblOrderId.getText(),
193 | tm.getCode(),
194 | tm.getQty(),
195 | tm.getAmount()/tm.getQty()
196 | ));
197 | }
198 | // if (!tmList.isEmpty()){
199 | boolean isSaved = false;
200 | try {
201 | isSaved = orderModel.saveOrder(new OrderDto(
202 | lblOrderId.getText(),
203 | LocalDateTime.now().format(DateTimeFormatter.ofPattern("YYYY-MM-dd")),
204 | cmbCustId.getValue().toString(),
205 | list
206 | ));
207 | if (isSaved){
208 | new Alert(Alert.AlertType.INFORMATION,"Order Saved!").show();
209 | }else{
210 | new Alert(Alert.AlertType.ERROR,"Something went wrong!").show();
211 | }
212 | } catch (SQLException e) {
213 | e.printStackTrace();
214 | } catch (ClassNotFoundException e) {
215 | e.printStackTrace();
216 | }
217 |
218 |
219 | // }
220 | }
221 | }
222 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------