Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sahm124 authored Jun 26, 2020
1 parent df755bf commit 4b68baf
Show file tree
Hide file tree
Showing 48 changed files with 608 additions and 470 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.io.IOException;

public abstract class AccountPageController {
protected Shop shop = Shop.getInstance();
//protected Shop Shop.getInstance() = Shop.getInstance();
protected static Account user;

public static Account getUser() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import Model.Category;
import Model.Product;
import Model.Requests.Request;
import Model.Shop;

import java.util.ArrayList;
import java.util.GregorianCalendar;
Expand Down Expand Up @@ -46,23 +47,24 @@ public StringBuilder getAllPhoneNumbersController(String userName){

public void deleteUserController(String userName){ user.deleteUserMoudel(userName); }

public void deleteDiscountController(String code){ shop.deleteDiscountMoudel(code); }
public void deleteDiscountController(String code){
Shop.getInstance().deleteDiscountMoudel(code); }

public StringBuilder showAllDiscountsController() throws Exception { return shop.showAllDiscountsMoudel(); }
public StringBuilder showAllDiscountsController() throws Exception { return Shop.getInstance().showAllDiscountsMoudel(); }

public String showAllRequestsController(){ return Request.showAllRequestsMoudel().toString(); }

public void deleteProductController(long id) throws Exceptions.NoProductByThisIdException { shop.deleteProductMoudel(id);}
public void deleteProductController(long id) throws Exceptions.NoProductByThisIdException { Shop.getInstance().deleteProductMoudel(id);}

public void editDiscountController(String code, GregorianCalendar begin, GregorianCalendar end, double discountPercent,int discountAmountLimit, int repeatCountForEachCustomer , HashMap<CustomerAccount, Integer> effectingCustomersAndUsageCount){ shop.editDiscountMoudel(code,begin,end,discountPercent,discountAmountLimit,repeatCountForEachCustomer ,effectingCustomersAndUsageCount);}
public void editDiscountController(String code, GregorianCalendar begin, GregorianCalendar end, double discountPercent,int discountAmountLimit, int repeatCountForEachCustomer , HashMap<CustomerAccount, Integer> effectingCustomersAndUsageCount){ Shop.getInstance().editDiscountMoudel(code,begin,end,discountPercent,discountAmountLimit,repeatCountForEachCustomer ,effectingCustomersAndUsageCount);}

public void deleteCategoryController(String name){ shop.deleteCategoryMoudel(name); }
public void deleteCategoryController(String name){ Shop.getInstance().deleteCategoryMoudel(name); }

public void addCategoryController(String name, String attribute, Category parentCategory, ArrayList<Category> subCategories, HashMap<Product, Integer> productsAndCount){shop.addCategoryMoudel(name,attribute,parentCategory, subCategories,productsAndCount);}
public void addCategoryController(String name, String attribute, String parentCategory, ArrayList<Category> subCategories, HashMap<Product, Integer> productsAndCount){Shop.getInstance().addCategoryMoudel(name,attribute,parentCategory, subCategories,productsAndCount);}

public void createManagerAccountController(String userName, String firstName, String lastName, String email, String phoneNumber, String password, String accountType, boolean isMain){user.createManagerAccountMouddel(userName,firstName,lastName,email,phoneNumber,password,accountType,isMain);}

public StringBuilder showAllProductsController() throws Exception {return shop.showAllProductsMoudel();}
public StringBuilder showAllProductsController() throws Exception {return Shop.getInstance().showAllProductsMoudel();}

public void checkUsernameIsUsedController(String username) throws Exception {user.checkUsernameIsUsedMoudel(username);}

Expand All @@ -73,7 +75,7 @@ public void createDiscountCodeController(String discountCode, GregorianCalendar

public void checkValidationDiscountCodeController(String code) throws Exception {user.checkValidationOfDiscountCodeMoudel(code);}

public String viewDiscount(String discountCode){ return shop.discountView(discountCode);}
public String viewDiscount(String discountCode){ return Shop.getInstance().discountView(discountCode);}

public CustomerAccount getCustomerAccountAccountTypeByUsernameController(String username) throws Exception {return user.getCustomerAccountAccountTypeByUserNameMoudel(username);}

Expand All @@ -83,13 +85,19 @@ public void createDiscountCodeController(String discountCode, GregorianCalendar

public void declineRequest(int id) throws Exception {user.answerRequest(id,"decline");}

public Category getCategoryBynameCategoryTypeMoudel(String name) throws Exception {return shop.getCategoryBynameCategoryTypeMoudel(name);}
public Category getCategoryBynameCategoryTypeMoudel(String name) throws Exception {return Shop.getInstance().getCategoryBynameCategoryTypeMoudel(name);}

public void editCategory(Category category,String newName ,String attribute,Category parentCategory){category.editCategory(newName, attribute, parentCategory);}

public Product productByName(int id) throws Exception {return shop.getProductByIdd(id);}
public Product productByName(int id) throws Exception {return Shop.getInstance().getProductByIdd(id);}

public Integer productCount(Product product){ return shop.countOfProduct(product);}
public Integer productCount(Product product){ return Shop.getInstance().countOfProduct(product);}

public String getAllCategories() throws Exception {return String.valueOf(shop.getAllCategories());}
public String getAllCategories() throws Exception {
StringBuilder stringBuilder = new StringBuilder();
for (Category category : Shop.getInstance().getAllCategories()) {
stringBuilder.append(String.valueOf(category)+"\n");
}
return String.valueOf(stringBuilder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import Model.Off;
import Model.Product;
import Model.Requests.AddProductRequest;
import Model.Requests.CreateOffRequest;
import Model.Requests.Request;
import Model.Shop;

import java.io.IOException;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashMap;

public class SellerPageController extends AccountPageController {
Expand Down Expand Up @@ -42,17 +45,21 @@ public String showBalance(){
return user.getBalance();
}

public void showSaleHistory(){
public String showSaleHistory(){
StringBuilder stringBuilder = new StringBuilder();
for (SellLog thisSellerAllSellLog : user.getThisSellerAllSellLogs()) {
System.out.println(thisSellerAllSellLog);
stringBuilder.append(thisSellerAllSellLog + "\n");
}
return String.valueOf(stringBuilder);
}

public void showSellerProduct(){
public String showSellerProduct(){
StringBuilder stringBuilder = new StringBuilder();
HashMap<Product, Integer> sellableProductAndCounts = user.getSellableProductAndCounts();
for (Product product : sellableProductAndCounts.keySet()) {
System.out.println("" + product.getProductId() + " " + product.getName());
stringBuilder.append("" + product.getProductId() + " " + product.getName()+"\n");
}
return String.valueOf(stringBuilder);
}

public void viewBuyers(int productId) throws Exceptions.NoProductByThisIdException {
Expand All @@ -77,12 +84,14 @@ public void showCategories() throws Exception {
}
}

public void showOff(){
public String showOff(){
StringBuilder stringBuilder = new StringBuilder();
for (Integer offId : user.getOffs()) {
try {
System.out.println(shop.getOffById(offId));
stringBuilder.append(shop.getOffById(offId)+ "\n");
} catch (Exceptions.NoOffByThisId noOffByThisId) {}
}
return String.valueOf(stringBuilder);
}

public void addProduct(boolean isNew ,SellerAccount sellerAccount,String name,int id,int count ,String brand,double price,Category category,String descrption,String arrtibute)throws Exceptions.NoCategoryException{
Expand Down Expand Up @@ -113,8 +122,15 @@ public void editProduct(SellerAccount sellerAccount,String name,int id,int count

public void removeProduct(int id) throws Exceptions.NoProductByThisIdException {
user.removeProduct(shop.getProductById(id));
shop.removeProduct(shop.getProductById(id),user.getCountOfProduct(shop.getProductById(id)));
}

public void createOffRequest(ArrayList<Product> listOfProduct, GregorianCalendar start,GregorianCalendar end, double persentage){
CreateOffRequest request = new CreateOffRequest(this.user.getUserName(),false, null, listOfProduct, start, end, persentage);

}
public void editOffRequest(int id,ArrayList<Product> listofProduct,GregorianCalendar start, GregorianCalendar end, double persentage) throws Exceptions.NoOffByThisId {
new CreateOffRequest(this.user.getUserName(),true, shop.getOffById(id), listofProduct, start, end, persentage);

}
}

70 changes: 59 additions & 11 deletions AP Project/src/main/java/Controller/AllProductsPageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ public class AllProductsPageController {

private AllProductsPageController() {
allFilteredProduct = new ArrayList<>();
allFilteredProduct.addAll(shop.getAllProductAndCount().keySet());
allFilteredProduct.addAll(Shop.getInstance().getAllProducts());
allProducts = new ArrayList<>();
allProducts.addAll(shop.getAllProductAndCount().keySet());
allProducts.addAll(Shop.getInstance().getAllProducts());
allFilteredProductOnOff = new ArrayList<>();
allFilteredProductOnOff.addAll(shop.getAllProductOnOffsAndCount().keySet());
allFilteredProductOnOff.addAll(Shop.getInstance().getAllProductOnOffsAndCount().keySet());
allProductsOnOff = new ArrayList<>();
allProductsOnOff.addAll(shop.getAllProductOnOffsAndCount().keySet());
allProductsOnOff.addAll(Shop.getInstance().getAllProductOnOffsAndCount().keySet());
}

public static AllProductsPageController getInstance() {
return allProductsPageController;
}

private Shop shop = Shop.getInstance();
private ArrayList<Product> allFilteredProduct;
private ArrayList<Product> allProducts;
private ArrayList<Product> allFilteredProductOnOff;
Expand Down Expand Up @@ -146,16 +145,18 @@ public void setCategoryZiroForOff() {
this.categoryForFilterOnOff = null;
}

public void showOFFProducts() {
for (Product product : shop.getAllProductOnOffsAndCount().keySet()) {
System.out.println(product);
public String showOFFProducts() {
StringBuilder stringBuilder= new StringBuilder();
for (Product product : Shop.getInstance().getAllProductOnOffsAndCount().keySet()) {
stringBuilder.append(product+"\n");
}
return String.valueOf(stringBuilder);
}

public String showCategories() throws Exception {
StringBuilder stringBuilder = new StringBuilder();
if (!shop.getAllCategories().isEmpty()) {
for (Category category : shop.getAllCategories()) {
if (!Shop.getInstance().getAllCategories().isEmpty()) {
for (Category category : Shop.getInstance().getAllCategories()) {
stringBuilder.append(category.toString() + "\n");
}
}
Expand Down Expand Up @@ -267,6 +268,14 @@ public void showAvailableFilters() {
"rate minrate ");
}

public void showAvailableSort(){
System.out.println("visit " +
"max price " +
"min price " +
"time " +
"rate" );
}

public ArrayList<Product> getAllFilteredProduct() {
return allFilteredProduct;
}
Expand Down Expand Up @@ -331,7 +340,46 @@ public int compare(Product a, Product b) {
}

public Product getProductById (int id) throws Exceptions.NoProductByThisIdException {
return shop.getProductById(id);
return Shop.getInstance().getProductById(id);
}

public void sorting(String type){
switch (type){
case "vist":
allFilteredProduct = sortByVisit(allFilteredProduct);
break;
case "time":
allFilteredProduct = sortByTime(allFilteredProduct);
break; case
"min":
allFilteredProduct = sortByMinPrice(allFilteredProduct);
break; case
"max":
allFilteredProduct = sortByMaxPrice(allFilteredProduct);
break;
case "rate":
allFilteredProductOnOff = sortByRate(allFilteredProductOnOff);
break;
}
}
public void sortingForOff(String type){
switch (type){
case "vist":
allFilteredProductOnOff = sortByVisit(allFilteredProductOnOff);
break;
case "time":
allFilteredProductOnOff = sortByTime(allFilteredProductOnOff);
break; case
"min":
allFilteredProductOnOff = sortByMinPrice(allFilteredProductOnOff);
break;
case "max":
allFilteredProductOnOff = sortByMaxPrice(allFilteredProductOnOff);
break;
case "rate":
allFilteredProductOnOff = sortByRate(allFilteredProductOnOff);
break;
}
}
}

Loading

0 comments on commit 4b68baf

Please sign in to comment.