diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index b1db480..dd8996d 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -10,6 +10,7 @@
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 7417b01..d528a03 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,7 +12,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7814d5c..423f2fa 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,8 +2,16 @@
+
+
-
+
+
+
+
+
+
+
@@ -68,7 +76,7 @@
-
+
@@ -77,20 +85,20 @@
+
+
+
+
-
-
-
-
-
+
-
+
@@ -104,7 +112,7 @@
-
+
@@ -365,6 +373,10 @@
+
+
+
+
1591744467884
@@ -720,7 +732,9 @@
@@ -801,6 +815,10 @@
+
+
+
+
@@ -810,11 +828,11 @@
-
+
-
+
@@ -824,6 +842,10 @@
+
+
+
+
@@ -842,11 +864,11 @@
-
-
+
+
-
+
@@ -869,11 +891,11 @@
-
+
-
+
@@ -896,30 +918,30 @@
-
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
@@ -957,11 +979,11 @@
-
-
+
+
-
+
@@ -1006,48 +1028,48 @@
-
- ControllerTest.*
-
-
+
ControllerTest.*
ControllerTest.*
+
+ ModelTest.*
+
+
ControllerTest.*
*
+
ControllerTest.*
-
+
ControllerTest.*
-
*
-
+
ControllerTest.*
-
+
+
ControllerTest.*
-
+
ControllerTest.*
-
-
+
ControllerTest.*
-
- ModelTest.*
+
+ ControllerTest.*
-
-
+
ControllerTest.*
diff --git a/Data/Accounts/Buyers.json b/Data/Accounts/Buyers.json
index 326f25e..3cb94fb 100644
--- a/Data/Accounts/Buyers.json
+++ b/Data/Accounts/Buyers.json
@@ -1 +1 @@
-[{"buyLogs":[{"discountValue":0,"sellerUsername":"Seller","addressOfBuyer":"home","wasProductHasFile":false,"date":"2020/07/24 01:00:20","price":10,"deliveryStatus":"Received","logId":26,"productId":10},{"discountValue":0,"sellerUsername":"Seller","addressOfBuyer":"my","wasProductHasFile":false,"date":"2020/07/24 01:04:44","price":10,"deliveryStatus":"Received","logId":27,"productId":10}],"discountIds":[1,2,3,4],"numberOfUse":{"1":0,"2":2,"3":2,"4":2},"cart":{"productsID":[],"muchOfProductID":{}},"username":"Buyer","firstName":"Buyer","lastName":"Buyer","password":"Buyer","email":"Buye@gmail.com","phoneNumber":"021","credit":8731},{"buyLogs":[],"discountIds":[1,2,4],"numberOfUse":{"1":0,"2":0,"4":0},"cart":{"productsID":[],"muchOfProductID":{}},"username":"parham","firstName":"parham","lastName":"chavoshian","password":"parham","email":"parham@gmail.com","phoneNumber":"021","credit":99970},{"buyLogs":[],"discountIds":[],"numberOfUse":{},"cart":{"productsID":[],"muchOfProductID":{}},"username":"milad","firstName":"milad","lastName":"saadat","password":"salam","email":"m@gmail.com","phoneNumber":"1231","credit":12312}]
+[{"buyLogs":[{"discountValue":0,"sellerUsername":"Seller","addressOfBuyer":"home","wasProductHasFile":false,"date":"2020/07/24 01:00:20","price":10,"deliveryStatus":"Received","logId":26,"productId":10},{"discountValue":0,"sellerUsername":"Seller","addressOfBuyer":"my","wasProductHasFile":false,"date":"2020/07/24 01:04:44","price":10,"deliveryStatus":"Received","logId":27,"productId":10}],"discountIds":[1,2,3,4],"numberOfUse":{"1":0,"2":2,"3":2,"4":2},"cart":{"productsID":[],"muchOfProductID":{}},"username":"Buyer","firstName":"Buyer","lastName":"Buyer","password":"Buyer","email":"Buye@gmail.com","phoneNumber":"021","credit":8731},{"buyLogs":[],"discountIds":[1,2,4],"numberOfUse":{"1":0,"2":0,"4":0},"cart":{"productsID":[],"muchOfProductID":{}},"username":"parham","firstName":"parham","lastName":"chavoshian","password":"parham","email":"parham@gmail.com","phoneNumber":"021","credit":99970},{"buyLogs":[],"discountIds":[],"numberOfUse":{},"cart":{"productsID":[],"muchOfProductID":{}},"username":"milad","firstName":"milad","lastName":"saadat","password":"salam","email":"m@gmail.com","phoneNumber":"1231","credit":12312}]
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index b3af01a..56287ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,4 @@
- `
-
+
diff --git a/src/main/java/Controller/BuyerManager.java b/src/main/java/Controller/BuyerManager.java
index a0eed06..fb531dd 100644
--- a/src/main/java/Controller/BuyerManager.java
+++ b/src/main/java/Controller/BuyerManager.java
@@ -119,6 +119,23 @@ public void payToSeller(int discountId, Account account, String addressOfBuyer)
}
}
+ public String bankPay(Account account , int discountId , String address , String bankUsername , String bankPassword , String bankID){
+ if (Database.getDiscountById(discountId) == null && discountId != -1)
+ return " your discount is not valid";
+ if (discountId!=-1 && !((BuyerAccount) account).canUseDiscount(discountId))
+ return "You can't use this discount";
+ else {
+ String res = bankBuy(discountId,account, address);
+ if (res.equals("done successfully"))
+ return "product bought successfully";
+ return res;
+ }
+ }
+
+ private String bankBuy(int discountId, Account account, String address) {
+ return "";
+ }
+
public void joinAuction(Auction auction, Account account){
auction.joinAuction((BuyerAccount) account);
}
diff --git a/src/main/java/Controller/ClientThread.java b/src/main/java/Controller/ClientThread.java
index ae27930..a26704b 100644
--- a/src/main/java/Controller/ClientThread.java
+++ b/src/main/java/Controller/ClientThread.java
@@ -443,10 +443,14 @@ else if (input.startsWith("addMessage")) {
arrayList.add(account);
arrayList.add((Database.getAccountByUsername(split[1])));
Chat chat = new Chat(arrayList);
- buyerAccount.addChat(chat);
+ //buyerAccount.addChat(chat);
output = String.valueOf(chat.getId());
}
}
+ else if (input.startsWith("BankPay ")){
+ details = input.split(" ");
+ buyerManager.bankPay(account , Integer.parseInt(details[1]), details[2] , details[3], details[4] ,details[5]);
+ }
else if (input.startsWith("Exit"))
{
clientSocket.close();
diff --git a/src/main/java/Controller/Database.java b/src/main/java/Controller/Database.java
index cdf5f56..bf7c54c 100644
--- a/src/main/java/Controller/Database.java
+++ b/src/main/java/Controller/Database.java
@@ -68,6 +68,10 @@ public static ArrayList getAllAuction() {
return allAuction;
}
+ public static ArrayList getAllChats() {
+ return allChats;
+ }
+
public static Account getAccountByUsername(String username) {
for (Account account : allAccounts) {
if (account.getUsername().equals(username))
diff --git a/src/main/java/Model/Account/BuyerAccount.java b/src/main/java/Model/Account/BuyerAccount.java
index 8e5995b..011796a 100644
--- a/src/main/java/Model/Account/BuyerAccount.java
+++ b/src/main/java/Model/Account/BuyerAccount.java
@@ -15,12 +15,12 @@ public class BuyerAccount extends Account {
private ArrayList discountIds = new ArrayList<>();
private HashMap numberOfUse = new HashMap<>();
private Cart cart;
- private ArrayList chats = new ArrayList<>();
+ //private ArrayList chats = new ArrayList<>();
- public void addChat(Chat chat) {
- chats.add(chat);
- }
+// public void addChat(Chat chat) {
+// chats.add(chat);
+// }
public BuyerAccount(String username, String firstName, String lastName, String password, String email, String phoneNumber, int credit) throws Exception {
super(username, firstName, lastName, password, email, phoneNumber, credit);
@@ -30,9 +30,9 @@ public BuyerAccount(String username, String firstName, String lastName, String p
public Chat hasChatWith(Account account) {
ArrayList arrayList;
- for (Chat chat : chats) {
+ for (Chat chat : Database.getAllChats()) {
arrayList = chat.getMembers();
- if (arrayList.size() == 2 && arrayList.contains(account))
+ if (arrayList.size() == 2 && arrayList.contains(account) && arrayList.contains(this))
return chat;
}
return null;
diff --git a/src/main/java/View/Menu/BuyerMenus/ViewCartMenu.java b/src/main/java/View/Menu/BuyerMenus/ViewCartMenu.java
index 03ed9fa..ed43460 100644
--- a/src/main/java/View/Menu/BuyerMenus/ViewCartMenu.java
+++ b/src/main/java/View/Menu/BuyerMenus/ViewCartMenu.java
@@ -173,6 +173,20 @@ public void show() {
newWindow.showAndWait();
});
+
+ Button bankPayButton = new Button("Pay with bank");
+ bankPayButton.setAlignment(Pos.CENTER);
+ bankPayButton.setMaxWidth(Double.MAX_VALUE);
+ bankPayButton.getStyleClass().add("dark-blue");
+ bankPayButton.setOnAction(e ->{
+ Stage newWindow = new Stage();
+ newWindow.initModality(Modality.APPLICATION_MODAL);
+
+ handleBankPay(newWindow);
+
+ newWindow.showAndWait();
+ });
+
long totalCost = 0;
try {
dataOutputStream.writeUTF("GetCostOfAccountCart");
@@ -191,8 +205,8 @@ public void show() {
message.setFont(Font.font(15));
GridPane.setHalignment(message, HPos.CENTER);
GridPane.setConstraints(payButton, 6 , i+1);
-
- gridPane.getChildren().addAll(back, costOfAll, payButton, message);
+ GridPane.setConstraints(bankPayButton ,5 , i+1);
+ gridPane.getChildren().addAll(back, costOfAll, payButton, message, bankPayButton);
super.mainPane.setCenter(gridPane);
@@ -204,6 +218,86 @@ public void show() {
}
}
+ private void handleBankPay(Stage newWindow) {
+ GridPane gridPane = new GridPane();
+ Scene scene = new Scene(gridPane, 600,400);
+ scene.getStylesheets().add(new File("Data/Styles/Buttons.css").toURI().toString());
+ scene.getStylesheets().add(new File("Data/Styles/textfield.css").toURI().toString());
+ scene.getStylesheets().add(new File("Data/Styles/backgrounds.css").toURI().toString());
+ gridPane.getStyleClass().add("cart");
+
+ TextField discountId = new TextField();
+ discountId.setPromptText("DiscountID");
+ discountId.getStyleClass().add("text-field");
+ TextField address = new TextField();
+ address.setPromptText("Address");
+ address.getStyleClass().add("text-field");
+
+ TextField bankUsername = new TextField();
+ bankUsername.setPromptText("Bank Username");
+ bankUsername.getStyleClass().add("text-field");
+
+ TextField bankPassword = new TextField();
+ bankPassword.setPromptText("Bank Password");
+ bankPassword.getStyleClass().add("text-field");
+
+ TextField bankId = new TextField();
+ bankId.setPromptText("Bank Id");
+ bankId.getStyleClass().add("text-field");
+
+ Button submit = new Button("Pay");
+ submit.getStyleClass().add("dark-blue");
+ submit.setAlignment(Pos.CENTER);
+ submit.setOnAction(e->{
+ int id = -1;
+ if (discountId.getText() != null && discountId.getText().matches("[0-9]+"))
+ id = Integer.parseInt(discountId.getText());
+ String res = "";
+ ArrayList allProducts = null;
+ try {
+ dataOutputStream.writeUTF("PrOfCart");
+ dataOutputStream.flush();
+ allProducts = new Gson().fromJson(dataInputStream.readUTF(), new TypeToken>(){}.getType());
+ dataOutputStream.writeUTF("BankPay " + id + " " + address.getText() + " " + bankUsername.getText() + " " + bankPassword.getText() + " " + bankId.getText());
+ dataOutputStream.flush();
+ res = dataInputStream.readUTF();
+ } catch (IOException ex) {
+ System.out.println(ex.getMessage());;
+ }
+ Alert alert = new Alert(Alert.AlertType.INFORMATION);
+ alert.setTitle("Result");
+ alert.setHeaderText("Process Result");
+ alert.setContentText(res);
+ alert.showAndWait();
+ if (res.equalsIgnoreCase("product bought successfully"))
+ {
+ for (Product product : allProducts) {
+ if (product.doesHasFile())
+ {
+ getFileOfProduct(product);
+ }
+ }
+ }
+ show();
+ newWindow.close();
+ });
+
+ GridPane.setConstraints(discountId, 0, 0);
+ GridPane.setConstraints(address, 0, 1);
+ GridPane.setConstraints(bankUsername, 0, 2);
+ GridPane.setConstraints(bankPassword, 0, 3);
+ GridPane.setConstraints(bankId, 0, 4);
+
+ GridPane.setConstraints(submit, 0, 5);
+ GridPane.setHalignment(submit, HPos.CENTER);
+ gridPane.setAlignment(Pos.CENTER);
+ gridPane.setVgap(10);
+ gridPane.getChildren().addAll(discountId, address, bankUsername , bankPassword , bankId, submit);
+
+ newWindow.setScene(scene);
+
+ }
+
private void handlePay(Stage newWindow) {
GridPane gridPane = new GridPane();
Scene scene = new Scene(gridPane, 600,400);