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
  • Loading branch information
milad-saadat committed Jul 24, 2020
2 parents a391e4b + 739a0ca commit 3f8a382
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 87 deletions.
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.

140 changes: 68 additions & 72 deletions .idea/workspace.xml

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions src/main/java/Controller/AdminManager.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package Controller;

import Model.Account.Account;
import Model.Account.AdminAccount;
import Model.Account.BuyerAccount;
import Model.Account.SellerAccount;
import Model.Account.*;
import Model.Product.Category;
import Model.Product.DiscountAndOff.Discount;
import Model.Product.DiscountAndOff.Off;
Expand Down Expand Up @@ -67,6 +64,17 @@ public String addNewAdminAccount(String username, String firstName, String lastN
return "New admin account registered.";
}

public String addNewSupporterAccount(String username, String firstName, String lastName, String email, String phoneNumber, String password, int credit) {
if (Database.getAccountByUsername(username) != null)
return "Exist account with this username.";
try {
Database.addAllAccounts(new SupporterAccount(username, firstName, lastName, password, email, phoneNumber, credit));
} catch (Exception e) {
e.printStackTrace();
}
return "New Supporter account registered.";
}

public String showRequestByiId(int id){
Request request = Database.getRequestById(id);
if (request == null)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/Controller/ClientThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ else if (input.startsWith("AddAdmin"))
details = input.split(" ");
output = adminManager.addNewAdminAccount(details[1], details[2], details[3], details[4], details[5], details[6], Integer.parseInt(details[7]));
}
else if (input.startsWith("AddSupporter")) {
output = adminManager.addNewSupporterAccount(split[1], split[2], split[3], split[4], split[5], split[6], Integer.parseInt(split[7]));
}
else if (input.startsWith("ViewUsername"))
{
Account temp = Database.getAccountByUsername(input.split(" ")[1]);
Expand Down Expand Up @@ -430,6 +433,9 @@ else if (input.startsWith("ReceivedBuyLog"))
{
Objects.requireNonNull(Database.getBuyLogByID(Integer.parseInt(input.split(" ")[1]))).setDeliveryStatus("Received");
}
else if (input.startsWith("getAllSupporters")){
output = Database.getUsers();
}
else if (input.startsWith("addMessage")) {
chatManager.addMessage(Integer.parseInt(split[1]), split[2], account);
} else if (input.startsWith("getChatById")) {
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/Controller/Database.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package Controller;

import Model.Account.Account;
import Model.Account.AdminAccount;
import Model.Account.BuyerAccount;
import Model.Account.SellerAccount;
import Model.Account.*;
import Model.Log.BuyLog;
import Model.Messaging.Chat;
import Model.Product.Auction;
Expand Down Expand Up @@ -97,6 +94,15 @@ public static Auction getAuctionByID(int auctionId){
}


public static String getUsers() {
String res = "";
for (Account account : allAccounts) {
if (account instanceof BuyerAccount || account instanceof SupporterAccount)
res += account.getUsername() + "\\n";
}
return res;
}

public static Request getRequestById(int id) {
for (Request request : allRequest) {
if (request.getId() == id)
Expand Down
87 changes: 86 additions & 1 deletion src/main/java/View/Menu/AdminMenus/AdminMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public void show() {
manageAddAdmin.getStyleClass().add("dark-blue");
manageAddAdmin.setMaxWidth(Double.MAX_VALUE);

Button manageAddSupporter = new Button("Add Supporter");
manageAddSupporter.setOnAction(e -> handleAddSupporter());
manageAddSupporter.getStyleClass().add("dark-blue");
manageAddSupporter.setMaxWidth(Double.MAX_VALUE);


GridPane.setConstraints(editInfoButton, 0, 0);
GridPane.setConstraints(manageUser, 0, 1);
Expand All @@ -116,6 +121,7 @@ public void show() {
GridPane.setConstraints(manageAddAdmin, 0, 7);
GridPane.setConstraints(manageLogs, 0, 8);
GridPane.setConstraints(logout, 0, 9);
GridPane.setConstraints(manageAddSupporter,0,10);
GridPane.setHalignment(manageLogs, HPos.CENTER);
GridPane.setHalignment(editInfoButton, HPos.CENTER);
GridPane.setHalignment(manageUser, HPos.CENTER);
Expand All @@ -126,7 +132,7 @@ public void show() {
GridPane.setHalignment(manageDiscounts, HPos.CENTER);
GridPane.setHalignment(manageAddAdmin, HPos.CENTER);
GridPane.setHalignment(logout, HPos.CENTER);

GridPane.setHalignment(manageAddSupporter, HPos.CENTER);
allButtons.getChildren().addAll(editInfoButton, manageUser, manageRequest, manageProduct, manageCategories, manageDiscounts, manageAddAdmin, logout, onlineUser, manageLogs);

try {
Expand Down Expand Up @@ -1434,4 +1440,83 @@ public void handleAddAdmin()

Menu.window.setScene(scene);
}

public void handleAddSupporter()
{
super.setPane();
Scene scene = new Scene(super.mainPane, 1000, 600);
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());
scene.getStylesheets().add(new File("Data/Styles/choicebox.css").toURI().toString());
super.mainPane.getStyleClass().add("admin-page");

GridPane gridPane = new GridPane();
gridPane.setHgap(20);
gridPane.setVgap(10);
gridPane.setAlignment(Pos.CENTER);
Label status = new Label();
TextField userName = new TextField();
userName.getStyleClass().add("text-field");
userName.setPromptText("username");
TextField firstName = new TextField();
firstName.setPromptText("first name");
TextField lastName = new TextField();
lastName.setPromptText("last name");
TextField email = new TextField();
email.setPromptText("email");
TextField phoneNumber = new TextField();
phoneNumber.setPromptText("phone number");
TextField password = new TextField();
password.setPromptText("password");
TextField credit = new TextField();
credit.setPromptText("credit");

Button register = new Button("Register");
register.getStyleClass().add("dark-blue");
register.setMaxWidth(Double.MAX_VALUE);
register.setOnAction(e -> {
try
{
dataOutputStream.writeUTF("AddSupporter " + userName.getText() + " " + firstName.getText() + " " + lastName.getText() + " " + email.getText() + " "
+ phoneNumber.getText() + " " + password.getText() + " " + credit.getText());
dataOutputStream.flush();
status.setText(dataInputStream.readUTF());
}
catch (Exception ex)
{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Register Fail");
alert.setContentText(ex.getMessage());

alert.showAndWait();
}
});

Button back = new Button("Back");
back.getStyleClass().add("dark-blue");
back.setMaxWidth(Double.MAX_VALUE);
back.setOnAction(e -> show());

GridPane.setConstraints(userName, 0, 0);
GridPane.setConstraints(firstName, 0, 1);
GridPane.setConstraints(lastName, 0, 2);
GridPane.setConstraints(email, 0, 3);
GridPane.setConstraints(phoneNumber, 0, 4);
GridPane.setConstraints(password, 0, 5);
GridPane.setConstraints(credit, 0, 6);
GridPane.setConstraints(register, 0, 7);
GridPane.setConstraints(back, 0, 8);
GridPane.setConstraints(status, 0, 9);
GridPane.setHalignment(register, HPos.CENTER);
GridPane.setHalignment(back, HPos.CENTER);
GridPane.setHalignment(status, HPos.CENTER);

gridPane.getChildren().addAll(userName, firstName, lastName, email, phoneNumber, password, credit, register, back, status);

super.mainPane.setCenter(gridPane);

Menu.window.setScene(scene);
}
}
2 changes: 1 addition & 1 deletion src/main/java/View/Menu/ChatRoomMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private VBox getSupporters() {
String input = dataInputStream.readUTF();
String[] splitInput = input.split("\\n");
for (String s : splitInput) {
Button button = new Button( "SupporterName: " + s);
Button button = new Button( "User: " + s);
vBox.getChildren().add(button);
button.setOnAction(e -> {
String[] split = button.getText().split(" ");
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/View/Menu/LoginMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Model.Account.AdminAccount;
import Model.Account.BuyerAccount;
import Model.Account.SellerAccount;
import Model.Account.SupporterAccount;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import javafx.geometry.HPos;
Expand Down Expand Up @@ -111,6 +112,10 @@ else if (role.equalsIgnoreCase("Buyer"))
type = new TypeToken<BuyerAccount>(){}.getType();
Menu.account = new Gson().fromJson(accountInJson, type);
}
else if (role.equalsIgnoreCase("Supporter")) {
type = new TypeToken<SupporterAccount>() {}.getType();
Menu.account = new Gson().fromJson(accountInJson, type);
}
else {
Menu.account = null;
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/View/Menu/SupporterMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package View.Menu;


import javafx.scene.Scene;
import javafx.scene.control.Button;

public class SupporterMenu extends Menu {

public SupporterMenu(Menu parentMenu) {
super("Supporter Menu", parentMenu);
}

@Override
public void show () {
super.setPane();
Button button = new Button("chat With Buyers");
button.setOnAction( e -> {
new ChatRoomMenu(this).show();
});
Button backButton = new Button("Back");
backButton.setOnAction(e -> parentMenu.show());
Scene scene = new Scene(mainPane, 1000, 600);
window.setScene(scene);
window.show();
}
}
10 changes: 6 additions & 4 deletions src/main/java/View/Menu/UserMenu.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package View.Menu;

import Model.Account.Account;
import Model.Account.AdminAccount;
import Model.Account.BuyerAccount;
import Model.Account.SellerAccount;
import Model.Account.*;
import View.Menu.AdminMenus.AdminMenu;
import View.Menu.BuyerMenus.BuyerMenu;
import View.Menu.SellerMenus.SellerMenu;
Expand All @@ -13,6 +10,7 @@ public class UserMenu extends Menu {
SellerMenu sellerMenu = new SellerMenu(this.parentMenu);
AdminMenu adminMenu = new AdminMenu(this.parentMenu);
LoginMenu loginMenu = new LoginMenu(this.parentMenu);
ChatRoomMenu chatRoomMenu = new ChatRoomMenu(this.parentMenu);
Account account;
public UserMenu(Menu parentMenu) {
super("User Menu", parentMenu);
Expand All @@ -37,5 +35,9 @@ else if(Menu.account == null)
{
loginMenu.show();
}
else if(Menu.account instanceof SupporterAccount)
{
chatRoomMenu.show();
}
}
}

0 comments on commit 3f8a382

Please sign in to comment.