Skip to content

Commit

Permalink
some debug
Browse files Browse the repository at this point in the history
  • Loading branch information
almaho committed Jun 26, 2020
1 parent 6aa38b1 commit b6d7b0f
Show file tree
Hide file tree
Showing 53 changed files with 98 additions and 80 deletions.
1 change: 1 addition & 0 deletions src/main/java/controller/BuyLogPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void handle(MouseEvent e) {
}

public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/controller/BuyerControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import models.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;

public class BuyerControl {
public static boolean checkDiscount(Account account, Discount discount) {
Buyer buyer = (Buyer) account;
if (discount.getStartDate().isBefore(LocalDateTime.now()) && discount.getFinishDate().isAfter(LocalDateTime.now())) {
if (discount.getStartDate().isBefore(LocalDate.now()) && discount.getFinishDate().isAfter(LocalDate.now())) {
if (discount.getAllDiscountedUsers().contains(account)) {
return true;
}
Expand All @@ -22,7 +23,7 @@ public static boolean purchase(Account account, Discount discount) {
Buyer buyer = (Buyer) account;
int price = buyer.getCart().getTotalPrice();
if (discount != null) {
if (discount.getStartDate().isBefore(LocalDateTime.now()) && discount.getFinishDate().isAfter(LocalDateTime.now())) {
if (discount.getStartDate().isBefore(LocalDate.now()) && discount.getFinishDate().isAfter(LocalDate.now())) {
for (Account user : discount.getAllDiscountedUsers()) {
if (account == user) {
if (discount.getMax() > price * discount.getDiscountPercent() / 100) {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/controller/BuyerLogPage.java

This file was deleted.

1 change: 1 addition & 0 deletions src/main/java/controller/CartPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void handle(MouseEvent e) {
}

public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand Down
25 changes: 13 additions & 12 deletions src/main/java/controller/EditPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,31 @@ public class EditPage {
public Label warning;

public void edit(MouseEvent mouseEvent) throws IOException {
String password = passwordText.toString();
String name = nameText.toString();
String familyName = familyNameText.toString();
String phoneNumber = phoneNumberText.toString();
String email = emailText.toString();
String password = passwordText.getText();
String name = nameText.getText();
String familyName = familyNameText.getText();
String phoneNumber = phoneNumberText.getText();
String email = emailText.getText();
String creditt = creditText.getText();
Account account = Main.getAccount();
Integer credit = null;
try {
credit = Integer.parseInt(creditText.toString());
credit = Integer.parseInt(creditText.getText());
} catch (NumberFormatException e) {
warning.setText("invalid credit");
return;
}
if (password != null) account.setPassword(password);
if (!password.equals("")) account.setPassword(password);

if (name != null) account.setFirstName(name);
if (!name.equals("")) account.setFirstName(name);

if (familyName != null)account.setLastName(familyName);
if (!familyName.equals("")) account.setLastName(familyName);

if (phoneNumber != null)account.setPhoneNumber(phoneNumber);
if (!account.equals("")) account.setPhoneNumber(phoneNumber);

if (email != null)account.setEmail(email);
if (!email.equals("")) account.setEmail(email);

if (creditText != null)account.setCredit(credit);
if (!creditt.equals("")) account.setCredit(credit);


}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/controller/LoginRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static Account createAccount(String type, String username) throws Excepti
return new Manager(username);
} else if (type.equals("seller")) {
Seller seller = new Seller(username);
new Request(seller).addSeller(seller);
new Request(seller,null,null).addSeller(seller);
return seller;
} else {
return new Buyer(username);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/controller/ManageCategoryPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ManageCategoryPage implements Initializable {


public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/controller/ManageDiscountPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void handle(MouseEvent e) {
}

public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/controller/ManageProductPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void handle(MouseEvent e) {
}
String id = name.substring(10, i);
for (Product product: Product.getAllProduct()) {
if (product.equals(id)){
if (product.getName().equals(id)){
chosenProduct = product;
Label info = new Label();
info.setText(product.toString());
Expand All @@ -56,6 +56,7 @@ public void handle(MouseEvent e) {
}

public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/controller/ManageRequestPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void handle(MouseEvent e) {
}
String id = name.substring(10, i);
for (Request request : Request.getRequests()) {
if (request.equals(id)) {
if (request.getRequestId() == Integer.parseInt(id)) {
chosenRequest = request;
Label info = new Label();
info.setText(request.toString());
Expand All @@ -56,6 +56,7 @@ public void handle(MouseEvent e) {
}

public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/controller/ManageUserPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void handle(MouseEvent e) {
}

public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/controller/ManagerPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void edit(MouseEvent mouseEvent) throws IOException {
}

public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/controller/RegisterPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javafx.scene.input.MouseEvent;
import main.Main;
import models.Buyer;
import models.Request;
import models.Seller;


Expand Down Expand Up @@ -48,6 +49,7 @@ public void register(MouseEvent mouseEvent) throws IOException {
seller.setEmail(email);
seller.setPhoneNumber(phoneNumber);
seller.setOrganization(company);
new Request(seller,null,null);
}else{
warning.setText("invalid account type");
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/controller/SellerControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
public class SellerControl {

public static void requestEditPrice(int price, Product product) {
new Request(Page.getAccount()).addProductEditRequest(Page.getAccount(), product, price, null);
new Request(Page.getAccount(),product,null).addProductEditRequest(Page.getAccount(), product, price, null);
}

public static void requestEditExisting(int existing, Product product) {
new Request(Page.getAccount()).addProductEditRequest(Page.getAccount(), product, null, existing);
new Request(Page.getAccount(),product,null).addProductEditRequest(Page.getAccount(), product, null, existing);
}

public static void requestAddOff(ArrayList<Product> product, Off off) {
new Request(Page.getAccount()).addOffRequest(Page.getAccount(), product, off);
new Request(Page.getAccount(),null, off).addOffRequest(Page.getAccount(), product, off);
}

public static void requestAddProduct(Product product) {
new Request(Page.getAccount()).addProductRequest(Page.getAccount(), product);
new Request(Page.getAccount(),product,null).addProductRequest(Page.getAccount(), product);
}

public static void remove(int id) {
Expand All @@ -31,6 +31,6 @@ public static void remove(int id) {
}

public static void requestEditOff(Off off, ArrayList<Product> products, String start, String end, int amount) {
new Request(Page.getAccount()).addOffEditRequest(Page.getAccount(), products, off, start, end, amount);
new Request(Page.getAccount(), null, off).addOffEditRequest(Page.getAccount(), products, off, start, end, amount);
}
}
17 changes: 11 additions & 6 deletions src/main/java/controller/SellerLogPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,22 @@ public void handle(MouseEvent e) {
}
}
};
for (SellLog sellLog: Main.getAccount().getSellLogsList()) {
Button button = new Button();
button.setId(Integer.toString(sellLog.getLogId()));
button.setText(Integer.toString(sellLog.getLogId()));
button.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
vBox.getChildren().add(button);
try {
for (SellLog sellLog : Main.getAccount().getSellLogsList()) {
Button button = new Button();
button.setId(Integer.toString(sellLog.getLogId()));
button.setText(Integer.toString(sellLog.getLogId()));
button.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
vBox.getChildren().add(button);
}
}catch (Exception a){

}
scrollPane.setContent(vBox);
}

public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/controller/SellerOffPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void handle(MouseEvent e) {
}

public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand All @@ -87,7 +88,7 @@ public void create(MouseEvent mouseEvent) {
product.add( Product.getProductById(Integer.parseInt(s)));
}
Seller seller = (Seller) Main.getAccount();
seller.addOff(new Off(startDate, finishDate,Integer.parseInt( amount),product, Integer.parseInt(percent)));
seller.addOff(new Off(startDate, finishDate,Integer.parseInt( amount),product, Integer.parseInt(percent),seller));
}

}
Expand Down
20 changes: 4 additions & 16 deletions src/main/java/controller/SellerPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ public class SellerPage implements Initializable {
public Label discountLabel;
public Label companyText;

public void showCartPage(MouseEvent mouseEvent) throws IOException {
Main.setScene("CartPage");
}

public void showDiscount(MouseEvent mouseEvent) {
Account account = Main.getAccount();
StringBuilder discounts = new StringBuilder();
for (Discount discount : account.getAllDiscounts()) {
discounts.append(discount.getDiscountCode());
}
discountLabel.setText(discounts.toString());
}

public void showLogPage(MouseEvent mouseEvent) throws IOException {
Main.setScene("BuyLogPage");
}

@Override
public void initialize(URL location, ResourceBundle resources) {
Expand Down Expand Up @@ -75,4 +59,8 @@ public void sellerProduct(MouseEvent mouseEvent) throws IOException {
public void showOffPage(MouseEvent mouseEvent) throws IOException {
Main.setScene("SellerOffPage");
}

public void showCategory(MouseEvent mouseEvent) {

}
}
1 change: 1 addition & 0 deletions src/main/java/controller/SellerProduct.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void handle(MouseEvent e) {
}

public void logout(MouseEvent mouseEvent) throws IOException {
Main.setAccount(null);
Main.setScene("MainPage");
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/models/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,12 @@ public void setAccountType(AccountType accountType) {

public String getAccountPage() {
switch (accountType) {
case SELLER:
return "SellerPage";
case BUYER:
return "BuyerPage";
case MANAGER:
return "ManagerPage";
default:
return "";
return "SellerPage";
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/main/java/models/Discount.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package models;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;

public class Discount {
private int discountCode;
private LocalDateTime startDate;
private LocalDateTime finishDate;
private LocalDate startDate;
private LocalDate finishDate;
private int max;
private int discountPercent;
private HashMap<Account, Integer> repeat = new HashMap<>();
private ArrayList<Account> allDiscountedUsers = new ArrayList<>();
private static ArrayList<Discount> allDiscounts = new ArrayList<>();

public Discount(int discountCode, String startDate, String finishDate, int discountPercent, int repeat, ArrayList<Account> allDiscountedUsers, int max) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm");
this.discountCode = discountCode;
this.startDate = LocalDateTime.parse(startDate, formatter);
this.finishDate = LocalDateTime.parse(finishDate, formatter);
this.startDate = LocalDate.parse(startDate, formatter);
this.finishDate = LocalDate.parse(finishDate, formatter);
this.discountPercent = discountPercent;
this.allDiscountedUsers = allDiscountedUsers;
for (Account user : allDiscountedUsers) {
Expand Down Expand Up @@ -92,11 +93,11 @@ public void remove() {
}
}

public LocalDateTime getStartDate() {
public LocalDate getStartDate() {
return startDate;
}

public LocalDateTime getFinishDate() {
public LocalDate getFinishDate() {
return finishDate;
}

Expand All @@ -111,12 +112,12 @@ public void decreaseRepeat(Account account) {

public void setStartDate(String startDate) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm a");
this.startDate = LocalDateTime.parse(startDate, formatter);
this.startDate = LocalDate.parse(startDate, formatter);
}

public void setFinishDate(String finishDate) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm a");
this.finishDate = LocalDateTime.parse(finishDate, formatter);
this.finishDate = LocalDate.parse(finishDate, formatter);
}

public void setMax(int max) {
Expand Down
Loading

0 comments on commit b6d7b0f

Please sign in to comment.