Skip to content

Commit

Permalink
ViewAllAccountsPageController
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenovo committed Jul 24, 2020
1 parent ed7984c commit 34f9ef2
Show file tree
Hide file tree
Showing 89 changed files with 1,083 additions and 52 deletions.
1 change: 0 additions & 1 deletion src/main/java/controller/ManagerAccountController.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public static void processEditCategoryEachForAttributes(
}

public static void processAddCategoryEach(String category, String parentCategory, String imageName) throws CategoryNotExistsException {
ValidationController.checkCategoryExistence(category);
ValidationController.checkCategoryExistence(parentCategory);//if parentCategoryNull
((Manager) LoginPageController.loggedInAccount).addCategory(category, Category.getCategoryByName(parentCategory), imageName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/graphicView/productMenu/ProductsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public void processShowProducts() throws FileNotFoundException, FilterNotExistsE
productName.setOnMouseClicked(mouseEvent -> {
try {
ProductsPageController.setSelectedProduct(Product.getProductByName(productName.getText()));
openProductPage(Main.window.getScene(), Product.getProductByName(productName.getText()));
openProductPage(Main.window.getScene(), Product.getProductByName(productName.getText()));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package graphicView.userRegion.userAccount.managerAccount;

import graphicView.userRegion.userAccount.PurchaserAccountPage;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import main.Main;

import java.io.IOException;

public class AddCategoryPage {
static Stage primaryStage;

public static void display() throws IOException {
Main.setMediaPlayer("The Swimmer.mp3");
primaryStage = new Stage();
Parent root = FXMLLoader.load(AddCategoryPage.class.getResource("/graphicView/userRegion/userAccount/managerAccount/AddCategory.fxml"));
primaryStage.setTitle("Hello World");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setMaximized(true);
Main.setAccountRegionStage(primaryStage);
primaryStage.show();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package graphicView.userRegion.userAccount.managerAccount;

import controller.LoginPageController;
import controller.ManagerAccountController;
import exception.CategoryNotExistsException;
import graphicView.mainMenu.MainMenu;
import graphicView.userRegion.loginPanel.LoginPanelController;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.paint.Color;
import main.Main;

import java.io.IOException;

public class AddCategoryPageController {
public TextField categoryName;
public TextField parentName;
public TextField imageName;
public Label alertMessage;

@FXML
public void logout() throws IOException {
AddCategoryPage.primaryStage.close();
LoginPageController.logout();
LoginPanelController.setLoggedInAccount(null);
MainMenu.display(Main.window);
}
@FXML
public void back() throws IOException {
AddCategoryPage.primaryStage.close();
ViewAllCategoriesPage.display();
}
@FXML
public void add(){
String name = categoryName.getText();
String parent = parentName.getText();
String image = imageName.getText();
try {
ManagerAccountController.processAddCategoryEach(name,parent,image);
alertMessage.setTextFill(Color.GREEN);
alertMessage.setText("Add Category successful!");
} catch (CategoryNotExistsException e) {
alertMessage.setTextFill(Color.RED);
alertMessage.setText(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package graphicView.userRegion.userAccount.managerAccount;

import graphicView.userRegion.userAccount.PurchaserAccountPage;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import main.Main;

import java.io.IOException;

public class AddManagerPage {
static Stage primaryStage;

public static void display() throws IOException {
Main.setMediaPlayer("The Swimmer.mp3");
primaryStage = new Stage();
Parent root = FXMLLoader.load(PurchaserAccountPage.class.getResource("/graphicView/userRegion/userAccount/managerAccount/AddManager.fxml"));
primaryStage.setTitle("Hello World");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setMaximized(true);
Main.setAccountRegionStage(primaryStage);
primaryStage.show();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package graphicView.userRegion.userAccount.managerAccount;

import controller.LoginPageController;
import graphicView.mainMenu.MainMenu;
import graphicView.userRegion.loginPanel.LoginPanelController;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import main.Main;
import model.account.Manager;

import java.io.IOException;

import static javafx.scene.paint.Color.GREEN;

public class AddManagerPageController {
public TextField newFirstName;
public TextField newLastName;
public TextField newUserName;
public TextField newPassWord;
public TextField newEmail;
public TextField newPhoneNumber;
public Label alertMessage;

@FXML
public void addManager(){
String firstName = newFirstName.getText();
String lastName = newLastName.getText();
String userName = newUserName.getText();
String passWord = newPassWord.getText();
String email = newEmail.getText();
String phoneNumber = newPhoneNumber.getText();
if(!firstName.matches("[a-zA-Z]+")){
alertMessage.setText("Please enter a valid first name!");
return;
}
if(!lastName.matches("[a-zA-Z]+")){
alertMessage.setText("Please enter a valid last name!");
return;
}
if (!userName.matches("\\w{8,}")) {
alertMessage.setText("Please enter a valid username!");
return;
}
if (!passWord.matches("\\w{8,}")) {
alertMessage.setText("Please enter a valid password!");
return;
}
if (!email.matches("\\w+[@]\\w+[.]\\w+")) {
alertMessage.setText("Please enter a valid email!");
return;
}
if(!phoneNumber.matches("09\\d\\d\\d\\d\\d\\d\\d\\d\\d")){
alertMessage.setText("Please enter a valid tel!");
return;
}
Manager manager = new Manager(userName,firstName,lastName,email,phoneNumber,passWord);
alertMessage.setText("");
alertMessage.setTextFill(GREEN);
alertMessage.setText("create new manager successful");
}
@FXML
public void logout() throws IOException {
AddManagerPage.primaryStage.close();
LoginPageController.logout();
LoginPanelController.setLoggedInAccount(null);
MainMenu.display(Main.window);
}
@FXML
public void back() throws IOException {
AddManagerPage.primaryStage.close();
ManagerAccountPage.display();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package graphicView.userRegion.userAccount.managerAccount;

import graphicView.userRegion.userAccount.PurchaserAccountPage;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import main.Main;

import java.io.IOException;

public class CategoryPage {
static Stage primaryStage;

public static void display() throws IOException {
Main.setMediaPlayer("The Swimmer.mp3");
primaryStage = new Stage();
Parent root = FXMLLoader.load(CategoryPage.class.getResource("/graphicView/userRegion/userAccount/managerAccount/CategoryPage.fxml"));
primaryStage.setTitle("Hello World");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setMaximized(true);
Main.setAccountRegionStage(primaryStage);
primaryStage.show();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package graphicView.userRegion.userAccount.managerAccount;

import controller.LoginPageController;
import graphicView.mainMenu.MainMenu;
import graphicView.userRegion.loginPanel.LoginPanelController;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import main.Main;
import model.Category;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class CategoryPageController implements Initializable {
private static Category currentCategory;
@FXML
public Label categoryName;
@FXML
public TableView<Attribute> attributesTable;
@FXML
public TableColumn<Attribute, StringProperty> attributesColumn;
@FXML
public TableView<Product> subProductsTable;
@FXML
public TableColumn<Product, StringProperty> subProductsColumn;


public static void setCurrentCategory(Category currentCategory) {
CategoryPageController.currentCategory = currentCategory;
}

public static Category getCurrentCategory() {
return currentCategory;
}

ObservableList<Attribute> getAttributes() {
ObservableList<Attribute> allAttributes = FXCollections.observableArrayList();
for (String attribute : CategoryPageController.currentCategory.getAttributes()) {
allAttributes.add(new Attribute(attribute));
}
return allAttributes;
}

ObservableList<Product> getProducts() {
ObservableList<Product> allProducts = FXCollections.observableArrayList();
for (model.product.Product subProduct : CategoryPageController.currentCategory.getAllSubProducts()) {
allProducts.add(new Product(subProduct.getName()));
}
return allProducts;
}

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
categoryName.setText(CategoryPageController.currentCategory.getName());
attributesColumn.setCellValueFactory(new PropertyValueFactory<>("attributes"));
attributesTable.setItems(getAttributes());
subProductsColumn.setCellValueFactory(new PropertyValueFactory<>("subProducts"));
subProductsTable.setItems(getProducts());
}

@FXML
public void logout() throws IOException {
LoginPageController.logout();
LoginPanelController.setLoggedInAccount(null);
CategoryPage.primaryStage.close();
MainMenu.display(Main.window);
}

@FXML
public void back() throws IOException {
CategoryPage.primaryStage.close();
ViewAllCategoriesPage.display();
}

@FXML
public void edit() throws IOException {
CategoryPage.primaryStage.close();
EditCategoryPage.display();
}

public class Attribute {
private final StringProperty attributes;

public Attribute(String attributes) {
this.attributes = new SimpleStringProperty(attributes);
}

public StringProperty attributesProperty() {
return attributes;
}
}

public class Product {
private final StringProperty subProducts;

public Product(String productName) {
this.subProducts = new SimpleStringProperty(productName);
}

public String getSubProducts() {
return subProducts.get();
}

public StringProperty subProductsProperty() {
return subProducts;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package graphicView.userRegion.userAccount.managerAccount;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import main.Main;

import java.io.IOException;

public class EditCategoryPage {
static Stage primaryStage;

public static void display() throws IOException {
Main.setMediaPlayer("The Swimmer.mp3");
primaryStage = new Stage();
Parent root = FXMLLoader.load(EditCategoryPage.class.getResource("/graphicView/userRegion/userAccount/managerAccount/EditCategory.fxml"));
primaryStage.setTitle("Hello World");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setMaximized(true);
Main.setAccountRegionStage(primaryStage);
primaryStage.show();
}
}
Loading

0 comments on commit 34f9ef2

Please sign in to comment.