Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add orders history scenes #32

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/asu/librarysystem/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ public static void main(String[] args) {
Library.addBook(book8);
Library.addBook(book9);
Library.addBook(book10);
Customer customer=new Customer("Ibrahem","123","111");
Customer customer=new Customer("Ibrahem1","123","111");
Library.addCustomer(customer);
Borrower borrower = new Borrower("Ibrahem","111","111");
Library.addBorrower(borrower);
Library.logInByUserName("Ibrahem","111");
Library.logInByUserName("Ibrahem1","123");

customer.addOrder(book1.getId(),2);
customer.addOrder(book2.getId(),2);
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/asu/librarysystem/OrderRow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.asu.librarysystem;

public class OrderRow {
private Order order;
private String owner;

public OrderRow(Order order, String owner) {
this.order = order;
this.owner = owner;
}

public String getOwner() {
return owner;
}

public String getBook() {
return order.getBook();
}

public int getQuantity() {
return order.getQuantity();
}

public double getPrice() {
return order.getPrice();
}

public String getDiscountCode() {
return order.getDiscountCode();
}
}
65 changes: 65 additions & 0 deletions src/main/java/com/asu/librarysystem/OrdersForAdminController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.asu.librarysystem;

import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;

public class OrdersForAdminController implements Initializable {

@FXML
private TableView<OrderRow> mainTable;

@FXML
private TableColumn<OrderRow, String> ownerColumn;

@FXML
private TableColumn<OrderRow, String> bookColumn;

@FXML
private TableColumn<OrderRow, String> discountColumn;

@FXML
private TableColumn<OrderRow, Double> priceColumn;

@FXML
private TableColumn<OrderRow, Integer> quantityColumn;

private ObservableList<OrderRow> tableData = FXCollections.observableArrayList();

@FXML
void back(ActionEvent event) {
Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
stage.close();
}

@Override
public void initialize(URL location, ResourceBundle resources) {
ownerColumn.setCellValueFactory(new PropertyValueFactory<OrderRow, String>("owner"));
bookColumn.setCellValueFactory(new PropertyValueFactory<OrderRow, String>("book"));
quantityColumn.setCellValueFactory(new PropertyValueFactory<OrderRow, Integer>("quantity"));
priceColumn.setCellValueFactory(new PropertyValueFactory<OrderRow, Double>("price"));
discountColumn.setCellValueFactory(new PropertyValueFactory<OrderRow, String>("discountCode"));

Customer activeAccount = (Customer)Library.getActiveAccount();

ArrayList<Order> orders = activeAccount.getOrders();

for (var order : orders) {
tableData.add(new OrderRow(order, activeAccount.getUserName()));
}

mainTable.setItems(tableData);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.asu.librarysystem;

import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;

public class OrdersForCustomerController implements Initializable {

@FXML
private TableView<Order> mainTable;

@FXML
private TableColumn<Order, String> bookColumn;

@FXML
private TableColumn<Order, String> discountColumn;

@FXML
private TableColumn<Order, Double> priceColumn;

@FXML
private TableColumn<Order, Integer> quantityColumn;

private ObservableList<Order> tableData = FXCollections.observableArrayList();

@FXML
void back(ActionEvent event) {
Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
stage.close();
}

@Override
public void initialize(URL location, ResourceBundle resources) {
bookColumn.setCellValueFactory(new PropertyValueFactory<Order, String>("book"));
quantityColumn.setCellValueFactory(new PropertyValueFactory<Order, Integer>("quantity"));
priceColumn.setCellValueFactory(new PropertyValueFactory<Order, Double>("price"));
discountColumn.setCellValueFactory(new PropertyValueFactory<Order, String>("discountCode"));

ArrayList<Order> orders = ((Customer)Library.getActiveAccount()).getOrders();

for (var order : orders) {
tableData.add(order);
}

mainTable.setItems(tableData);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>

<GridPane prefHeight="720.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.asu.librarysystem.OrdersForAdminController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1168.800048828125" minWidth="10.0" prefWidth="640.8001098632812" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="762.3998413085938" minWidth="10.0" prefWidth="639.1998901367188" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="135.00000610351563" minHeight="10.0" prefHeight="65.6000015258789" vgrow="SOMETIMES" />
<RowConstraints maxHeight="210.3999801635742" minHeight="10.0" prefHeight="183.1999984741211" vgrow="SOMETIMES" />
<RowConstraints maxHeight="231.1999694824218" minHeight="10.0" prefHeight="176.7999450683593" vgrow="SOMETIMES" />
<RowConstraints maxHeight="150.99997558593753" minHeight="10.0" prefHeight="125.60005493164067" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" onAction="#back" prefHeight="135.0" prefWidth="261.0" text="Back" GridPane.hgrow="ALWAYS">
<font>
<Font name="Monospaced Regular" size="30.0" />
</font>
</Button>
<Label text="Orders History" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER">
<font>
<Font name="Monospaced Regular" size="30.0" />
</font>
</Label>
<TableView fx:id="mainTable" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" GridPane.rowSpan="3" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="ownerColumn" prefWidth="264.80023193359375" text="Owner" />
<TableColumn fx:id="bookColumn" prefWidth="490.39995497465134" text="Book" />
<TableColumn fx:id="quantityColumn" minWidth="0.0" prefWidth="96.79998397827148" text="Quantity" />
<TableColumn fx:id="priceColumn" prefWidth="148.0" text="Price" />
<TableColumn fx:id="discountColumn" prefWidth="140.0" text="Discount" />
</columns>
<GridPane.margin>
<Insets top="30.0" />
</GridPane.margin>
</TableView>
</children>
</GridPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>

<GridPane prefHeight="720.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.asu.librarysystem.OrdersForCustomerController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1168.800048828125" minWidth="10.0" prefWidth="640.8001098632812" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="762.3998413085938" minWidth="10.0" prefWidth="639.1998901367188" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="135.00000610351563" minHeight="10.0" prefHeight="65.6000015258789" vgrow="SOMETIMES" />
<RowConstraints maxHeight="210.3999801635742" minHeight="10.0" prefHeight="183.1999984741211" vgrow="SOMETIMES" />
<RowConstraints maxHeight="231.1999694824218" minHeight="10.0" prefHeight="176.7999450683593" vgrow="SOMETIMES" />
<RowConstraints maxHeight="150.99997558593753" minHeight="10.0" prefHeight="125.60005493164067" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" onAction="#back" prefHeight="135.0" prefWidth="261.0" text="Back" GridPane.hgrow="ALWAYS">
<font>
<Font name="Monospaced Regular" size="30.0" />
</font>
</Button>
<Label text="Orders History" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER">
<font>
<Font name="Monospaced Regular" size="30.0" />
</font>
</Label>
<TableView fx:id="mainTable" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" GridPane.rowSpan="3" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="bookColumn" prefWidth="490.39995497465134" text="Book" />
<TableColumn fx:id="quantityColumn" minWidth="0.0" prefWidth="96.79998397827148" text="Quantity" />
<TableColumn fx:id="priceColumn" prefWidth="148.0" text="Price" />
<TableColumn fx:id="discountColumn" prefWidth="140.0" text="Discount" />
</columns>
<GridPane.margin>
<Insets top="30.0" />
</GridPane.margin>
</TableView>
</children>
</GridPane>