Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/workspace.xml
#	Data/Accounts/Buyers.json
#	src/main/java/Controller/ClientThread.java
#	src/main/java/Model/Account/BuyerAccount.java
  • Loading branch information
parhampch committed Jul 24, 2020
2 parents b01e39c + 8eabae1 commit a2b886c
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 8 deletions.
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
`
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/Controller/BuyerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/Controller/ClientThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ else if (input.startsWith("SetMostPriceOfAuction"))
details = input.split(" ");
output = buyerManager.setPriceForAuction(Integer.parseInt(details[1]), Integer.parseInt(details[2]), account);
}
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();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/Controller/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public static ArrayList<Auction> getAllAuction() {
return allAuction;
}

public static ArrayList<Chat> getAllChats() {
return allChats;
}

public static Account getAccountByUsername(String username) {
for (Account account : allAccounts) {
if (account.getUsername().equals(username))
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/Model/Account/BuyerAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class BuyerAccount extends Account {
private ArrayList<Integer> discountIds = new ArrayList<>();
private HashMap<Integer, Integer> numberOfUse = new HashMap<>();
private Cart cart;
//private ArrayList<Chat> chats = new ArrayList<>();
private ArrayList<Chat> chats = new ArrayList<>();


/*public void addChat(Chat chat) {
Expand All @@ -30,8 +30,7 @@ public BuyerAccount(String username, String firstName, String lastName, String p

public Chat hasChatWith(Account account) {
ArrayList<Account> arrayList;
ArrayList<Chat> allChats = Database.getAllChats();
for (Chat chat : allChats) {
for (Chat chat : chats) {
arrayList = chat.getMembers();
if (arrayList.size() == 2 && arrayList.contains(account))
return chat;
Expand Down
98 changes: 96 additions & 2 deletions src/main/java/View/Menu/BuyerMenus/ViewCartMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);

Expand All @@ -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<Product> allProducts = null;
try {
dataOutputStream.writeUTF("PrOfCart");
dataOutputStream.flush();
allProducts = new Gson().fromJson(dataInputStream.readUTF(), new TypeToken<ArrayList<Product>>(){}.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);
Expand Down

0 comments on commit a2b886c

Please sign in to comment.