Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
MJavadHzr committed Jul 24, 2020
2 parents 57fc19d + c72f983 commit 4ce7165
Show file tree
Hide file tree
Showing 16 changed files with 461 additions and 108 deletions.
2 changes: 2 additions & 0 deletions AP.iml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.13" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter:5.7.0-M1" level="project" />
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/Controller/ProductManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Controller.SortFactorEnum.ViewBuyersOfProductSortFactor;
import Controller.SortFactorEnum.ProductSortFactor;
import Model.Account.Account;
import Model.Account.Boss;
import Model.Account.Role;
import Model.Log.Log;
import Model.Product.Comment;
Expand Down Expand Up @@ -66,6 +67,7 @@ private boolean checkRemainderFilter(Product product, String s) {


private boolean isProductInFilter(Product product, ArrayList<Object> filters) {
System.out.println(filters);
System.out.println(filters);
for (int i = 0; i < filters.size(); i += 2) {
if (((String) filters.get(i)).equalsIgnoreCase("salesmanIDs")) {
Expand All @@ -88,10 +90,20 @@ private boolean isProductInFilter(Product product, ArrayList<Object> filters) {
return false;
}
}
if (((String) filters.get(i)).equalsIgnoreCase("isOnSale")) {
if (!checkOnSale(product, (String) filters.get(i + 1))) {
return false;
}
}
}
return true;
}

private boolean checkOnSale(Product product, String s) {
if (product.is_on_sale()) return true;
return false;
}

//type = 0--> return all Products, type = 1--> return [username] products
public void showProducts(String username, ArrayList<Object> filters, String sortFactor, String sortType, int type) {
int count = 0;
Expand Down Expand Up @@ -152,6 +164,11 @@ public void searchProduct(String salesmanUser, String productID) {
}

public void deleteProduct(String salesmanUser, String productID) {
Account account = Storage.getAccountWithUsername(salesmanUser);
if (account instanceof Boss) {
Storage.getAllProducts().remove(Storage.getProductById(productID));
return;
}
Product product = Storage.getProductById(productID);
assert product != null;
new Request(salesmanUser, product, "DELETE_PRODUCT");
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/Controller/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,24 @@ else if (command.startsWith("show balance")) {
this.deleteSupporter(command);
} else if (command.startsWith("get online users+")) {
getOnlineUsers();
} else if (command.startsWith("getting all products")) {
this.getAllProducts(command);
}

}

private void getAllProducts(String command) {
String answer = "";
for (Product product : Storage.getAllProducts()) {
if (product.getSalesmanIDs().contains(command.split("\\+")[1])) {
if (product.getRemainderForSalesman(command.split("\\+")[1]) > 0) {
answer += product.getProductID() + "\n";
}
}
}
setAnswer(answer);
}

public void takeActionNotSecure(String command) throws ParseException {
Matcher matcher;
if ((matcher = getMatcher("login\\+(\\w+)\\+(\\w+)", command)).find()) {
Expand Down Expand Up @@ -449,7 +463,7 @@ public void takeActionNotSecure(String command) throws ParseException {
this.addProductPicturePath(command);
} else if (command.startsWith("get product picture path+")) {
this.getProfilePicturePath(command);
}else if (command.startsWith("show products+")) {
} else if (command.startsWith("show products+")) {
this.showProducts(command);
} else if (command.startsWith("show my products+")) {
this.showMyProducts(command);
Expand Down Expand Up @@ -497,7 +511,7 @@ public void takeActionNotSecure(String command) throws ParseException {
this.viewSale(command);
} else if (command.startsWith("show sales")) {
this.showSales(command);
} else if (command.startsWith("what is comment product ID+")) {
} else if (command.startsWith("what is comment product ID+")) {
this.getCommentProductID(command);
} else if (command.startsWith("comment product+")) {
this.commentProduct(command);
Expand Down Expand Up @@ -1286,6 +1300,7 @@ private void showMyProducts(String command) {
}

private void showProducts(String command) {
System.out.println(command);
ArrayList<Object> filters;
filters = getFilters(command);
String[] input = command.split("\\+");
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/GUI/Auction/AllAuctions.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="GUI.Auction.AllAuctions"
prefHeight="400.0" prefWidth="600.0">

</AnchorPane>
4 changes: 4 additions & 0 deletions src/main/java/GUI/Auction/AllAuctionsController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package GUI.Auction;

public class AllAuctionsController {
}
108 changes: 108 additions & 0 deletions src/main/java/GUI/Auction/AuctionBet.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<AnchorPane prefHeight="566.0" prefWidth="869.0" xmlns="http://javafx.com/javafx/10.0.2-internal"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="GUI.Auction.AuctionBetController">
<children>
<ScrollPane layoutX="14.0" layoutY="12.0">
<content>
<VBox fx:id="vBox" prefHeight="542.0" prefWidth="422.0"/>
</content>
</ScrollPane>
<TextField fx:id="maxBet" editable="false" layoutX="638.0" layoutY="81.0"/>
<Label layoutX="502.0" layoutY="85.0" text="Maximum Wage:"/>
<Label layoutX="502.0" layoutY="182.0" text="Enter Your Bet: "/>
<TextField fx:id="myBet" layoutX="638.0" layoutY="178.0"/>
<Button layoutX="547.0" layoutY="246.0" mnemonicParsing="false" onAction="#apply" text="Apply"/>
<Button layoutX="616.0" layoutY="246.0" mnemonicParsing="false" onAction="#back" text="Back"/>
<AnchorPane layoutX="451.0" layoutY="296.0" prefHeight="163.0" prefWidth="412.0">
<children>
<GridPane layoutX="39.0" layoutY="55.0" prefHeight="163.2" prefWidth="412.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="201.0" minWidth="10.0" prefWidth="144.0"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="330.0" minWidth="10.0" prefWidth="268.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<AnchorPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #244949;">
<children>
<ImageView fitHeight="125.0" fitWidth="144.0" layoutX="17.0" layoutY="19.0"
pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@resources/Timer.jpg"/>
</image>
</ImageView>
</children>
</AnchorPane>
<StackPane prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: #9AABAB;"
GridPane.columnIndex="1">
<children>
<GridPane prefHeight="146.0" prefWidth="268.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="128.4" minHeight="10.0" prefHeight="121.4"
vgrow="SOMETIMES"/>
<RowConstraints maxHeight="76.4" minHeight="10.0"
prefHeight="41.400000000000006" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<GridPane prefHeight="165.0" prefWidth="268.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="129.0" minWidth="10.0"
prefWidth="111.0"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="157.0" minWidth="10.0"
prefWidth="157.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<Label text="Hours" textFill="#244949" GridPane.halignment="CENTER">
<font>
<Font name="System Bold" size="12.0"/>
</font>
</Label>
<Label layoutX="51.0" layoutY="21.0" text="Minutes" textFill="#244949"
GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font name="System Bold" size="12.0"/>
</font>
</Label>
<Label layoutX="51.0" layoutY="62.0" text="Seconds" textFill="#244949"
GridPane.halignment="CENTER" GridPane.rowIndex="2">
<font>
<Font name="System Bold" size="12.0"/>
</font>
</Label>
<Label fx:id="hour" prefWidth="28.0" text="Label"
GridPane.columnIndex="1" GridPane.halignment="CENTER"/>
<Label fx:id="minute" layoutX="186.0" layoutY="21.0" text="Label"
GridPane.columnIndex="1" GridPane.halignment="CENTER"
GridPane.rowIndex="1"/>
<Label fx:id="second" layoutX="186.0" layoutY="21.0" text="Label"
GridPane.columnIndex="1" GridPane.halignment="CENTER"
GridPane.rowIndex="2"/>
</children>
</GridPane>
</children>
</GridPane>
</children>
</StackPane>
</children>
</GridPane>
</children>
</AnchorPane>
</children>
</AnchorPane>
66 changes: 66 additions & 0 deletions src/main/java/GUI/Auction/AuctionBetController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package GUI.Auction;

import GUI.MenuHandler;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import java.io.IOException;

public class AuctionBetController {
public TextField maxBet;
public TextField myBet;
public Label hour;
public Label minute;
public Label second;
public VBox vBox;

public void apply(ActionEvent actionEvent) {
}

public void back(ActionEvent actionEvent) throws IOException {
MenuHandler.getStage().setScene(new Scene(FXMLLoader.load(getClass().getResource("/GUI/ProductScene/ProductScene.fxml"))));
}

private void load() throws IOException {
MenuHandler.getConnector().clientToServer("get certain auction+" + MenuHandler.getCurrentAuction() + "+" + MenuHandler.getUsername());
String serverAnswer = MenuHandler.getConnector().serverToClient();
for (String s : serverAnswer.split("\n")) {
String username = s.split("\\+")[0];
String money = s.split("\\+")[1];
HBox hBox = new HBox();
Label userLabel = new Label(username);
Label moneyLabel = new Label(money);
hBox.getChildren().add(userLabel);
hBox.getChildren().add(moneyLabel);
vBox.getChildren().add(hBox);
}
MenuHandler.getConnector().clientToServer("get auction time+" + MenuHandler.getCurrentAuction());
String time = MenuHandler.getConnector().serverToClient();
//Date date = System.currentTimeMillis();
//running here
}

public void initialize() {
Thread thread;
thread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
load();
wait(900);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
});
thread.run();
}
}
Loading

0 comments on commit 4ce7165

Please sign in to comment.